[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef3d-commits] r574 - in trunk: org.eclipse.draw3d/src/java/org/eclipse/draw3d org.eclipse.draw3d/src/java/org/eclipse/draw3d/geometryext org.eclipse.draw3d/src/java/org/eclipse/draw3d/shapes org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies org.eclipse.gef3d/src/java/org/eclipse/gef3d/requests org.eclipse.gef3d/src/java/org/eclipse/gef3d/tools

Author: jvonpilgrim
Date: 2011-04-26 16:28:15 -0400 (Tue, 26 Apr 2011)
New Revision: 574

Modified:
   trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/LightweightSystem3D.java
   trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/RelativeLocator3D.java
   trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/StackLayout3D.java
   trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/geometryext/SynchronizedPosition3DImpl.java
   trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/shapes/PositionableShape.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/FeedbackHelper3D.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/ResizableEditPolicy3D.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XY3DLayoutPolicy.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XYZConstraintLayoutPolicy.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/requests/ChangeBounds3DRequest.java
   trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/tools/DragEditPartsTracker3D.java
Log:
Fixed bug 300321: 3D figures can be arbitrarily moved and rotated in 3D space.

Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/LightweightSystem3D.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/LightweightSystem3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/LightweightSystem3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -11,9 +11,12 @@
 package org.eclipse.draw3d;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.EnumSet;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -88,17 +91,17 @@
 
 		private ParaxialBoundingBox m_paraxialBounds;
 
-		private ISurface m_surface =
-			new VoidSurface(this, LightweightSystem3D.this, 0.1f);
+		private ISurface m_surface = new VoidSurface(this,
+			LightweightSystem3D.this, 0.1f);
 
 		// the position of the root is the universe.. the root is the universe
 		private Position3DImpl universe = new NullPosition3D(this);
 
+		
 		/**
 		 * Creates and initializes a 3D new root figure.
 		 */
 		RootFigure3D() {
-
 			helper = new Figure3DHelper(new Figure3DFriend(this) {
 
 				@Override
@@ -240,6 +243,23 @@
 		/**
 		 * {@inheritDoc}
 		 * 
+		 * @see org.eclipse.draw2d.Figure#getChildren()
+		 */
+		@Override
+		public List getChildren() {
+
+			if (isDebug()) {
+				List children = new ArrayList(super.getChildren());
+				children.addAll(m_debugFigures);
+				return children;
+			} else {
+				return super.getChildren();
+			}
+		}
+
+		/**
+		 * {@inheritDoc}
+		 * 
 		 * @see org.eclipse.draw3d.IFigure2DHost3D#getChildren2D()
 		 */
 		public List<IFigure> getChildren2D() {
@@ -253,7 +273,6 @@
 		 * @see org.eclipse.draw3d.IFigure3D#getChildren3D()
 		 */
 		public List<IFigure3D> getChildren3D() {
-
 			return helper.getChildren3D();
 		}
 
@@ -616,8 +635,8 @@
 	 * Logger for this class
 	 */
 	@SuppressWarnings("unused")
-	private static final Logger log =
-		Logger.getLogger(LightweightSystem3D.class.getName());
+	private static final Logger log = Logger
+		.getLogger(LightweightSystem3D.class.getName());
 
 	private ICamera m_camera;
 
@@ -630,6 +649,8 @@
 
 	private boolean m_debug = false;
 
+	private Set<IFigure3D> m_debugFigures = new HashSet<IFigure3D>();
+
 	private boolean m_drawAxes;
 
 	private List<ISceneListener> m_listeners;
@@ -694,7 +715,21 @@
 		RootFigure f = new RootFigure3D();
 		f.addNotify();
 		f.setOpaque(true);
-		f.setLayoutManager(new StackLayout());
+		f.setLayoutManager(new StackLayout() {
+			/**
+			 * @see org.eclipse.draw2d.LayoutManager#layout(IFigure)
+			 */
+			public void layout(IFigure figure) {
+				org.eclipse.draw2d.geometry.Rectangle r = figure.getClientArea();
+				List children = figure.getChildren();
+				IFigure child;
+				for (int i = 0; i < children.size(); i++) {
+					child = (IFigure) children.get(i);
+					if (! m_debugFigures.contains(child))
+						child.setBounds(r);
+				}
+			}
+		});
 		return f;
 	}
 
@@ -980,4 +1015,17 @@
 		getRenderContext().dispose();
 
 	}
+
+	/**
+	 * @param i_fig
+	 */
+	public void addDebugFigure(IFigure3D i_fig) {
+		m_debugFigures.add(i_fig);
+		i_fig.setParent(this.getRootFigure());
+	}
+
+	public void removeDebugFigure(IFigure3D i_fig) {
+		m_debugFigures.remove(i_fig);
+	}
+
 }

Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/RelativeLocator3D.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/RelativeLocator3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/RelativeLocator3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -47,8 +47,8 @@
 	/**
 	 * Logger for this class
 	 */
-	private static final Logger log =
-		Logger.getLogger(RelativeLocator3D.class.getName());
+	private static final Logger log = Logger.getLogger(RelativeLocator3D.class
+		.getName());
 
 	/**
 	 * Contains the relative offset factors.
@@ -177,14 +177,23 @@
 				Vector3f size = Draw3DCache.getVector3f();
 				try {
 					IFigure3D target3D = (IFigure3D) i_target;
+
 					Position3D refPosition = m_helper.getReferencePosition3D();
+					// refPosition is relative to ref's parent
 
+					// calculate location offset to appropriate vertex/edge:
 					Math3D.scale(m_factors, refPosition.getSize3D(), location);
-					Math3D.add(location, refPosition.getLocation3D(), location);
-
+					// slightly correct position with targets half size
+					// we want to locate the center of the target on the
+					// intended vertex/edge:
 					Math3D.scale(1 / 2f, target3D.getPreferredSize3D(), size);
 					Math3D.sub(location, size, location);
 
+					// "move" target to calculated location and
+					// handle rotation
+					Math3D.rotate(refPosition.getRotation3D(), location, location);
+					Math3D.add(location, refPosition.getLocation3D(), location);
+					
 					refPosition.setLocation3D(location);
 					refPosition.setSize3D(target3D.getPreferredSize3D());
 

Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/StackLayout3D.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/StackLayout3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/StackLayout3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -12,6 +12,10 @@
 
 import org.eclipse.draw2d.IFigure;
 import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw3d.geometry.IVector3f;
+import org.eclipse.draw3d.geometry.Math3D;
+import org.eclipse.draw3d.geometry.Position3D;
+import org.eclipse.draw3d.geometry.Position3DUtil;
 import org.eclipse.draw3d.geometry.Vector3f;
 import org.eclipse.draw3d.geometry.Vector3fImpl;
 
@@ -94,6 +98,17 @@
 			if (constraint == null) {
 				if (isChildStacked(f)) {
 					constraint = new Vector3fImpl(m_lastStackLocation);
+
+					// this is only for testing purposes (didn't want
+					// to remove it yet):
+					// Position3D p = ((IFigure3D) f).getPosition3D();
+					// Position3D a = Position3DUtil.createAbsolutePosition();
+					// a.setPosition(p);
+					// a.setLocation3D((IVector3f) constraint);
+					// a.setRotation3D(new Vector3fImpl(0, Math3D.PI / 4f,
+					// Math3D.PI / 4f));
+					// constraint = a;
+
 					setConstraint(f, constraint);
 					m_lastStackLocation.translate(0, 0, m_distance);
 				} else {

Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/geometryext/SynchronizedPosition3DImpl.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/geometryext/SynchronizedPosition3DImpl.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/geometryext/SynchronizedPosition3DImpl.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -103,6 +103,11 @@
 
 		if (delta.x != 0 || delta.y != 0)
 			host.setBounds(newBounds);
+		
+		// This forces the synced bounds update the location vector.
+		// While this has no direct effect here, a client may has cached
+		// the location vector.
+		getLocation3D();
 
 		invalidate();
 
@@ -136,6 +141,11 @@
 		if (delta.x != 0 || delta.y != 0)
 			host.setBounds(newBounds);
 
+		// This forces the synced bounds update the location vector.
+		// While this has no direct effect here, a client may has cached
+		// the size vector.
+		getLocation3D();
+		
 		invalidate();
 
 		firePositionChanged(PositionHint.SIZE, delta);

Modified: trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/shapes/PositionableShape.java
===================================================================
--- trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/shapes/PositionableShape.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.draw3d/src/java/org/eclipse/draw3d/shapes/PositionableShape.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -13,8 +13,11 @@
 import java.util.Map;
 import java.util.logging.Logger;
 
+import org.eclipse.draw3d.Figure3D;
+import org.eclipse.draw3d.IFigure3D;
 import org.eclipse.draw3d.RenderContext;
 import org.eclipse.draw3d.RenderFragment;
+import org.eclipse.draw3d.ShapeFigure3D;
 import org.eclipse.draw3d.geometry.IMatrix4f;
 import org.eclipse.draw3d.geometry.IPosition3D;
 import org.eclipse.draw3d.geometry.IVector3f;
@@ -37,18 +40,30 @@
 public abstract class PositionableShape implements Shape {
 
 	@SuppressWarnings("unused")
-	private static final Logger log =
-		Logger.getLogger(PositionableShape.class.getName());
+	private static final Logger log = Logger.getLogger(PositionableShape.class
+		.getName());
 
+	/**
+	 * Position of the shape, usually a shared instance contained by the
+	 * {@link IFigure3D} (i.e. a {@link ShapeFigure3D}).
+	 */
 	private IPosition3D m_position3D;
 
 	/**
 	 * Creates a new positionable shape with the given position.
+	 * <p>
+	 * The position of the shape may be a shared instance contained in the
+	 * {@link Figure3D}, usually a {@link ShapeFigure3D}. Thus, changing the
+	 * figure's shape also changes the position of the shape without further
+	 * method calls (as they both use the same position instance).
+	 * </p>
 	 * 
-	 * @param i_position3D the position of this shape
+	 * @param i_position3D the position of this shape, must not be null
 	 * @throws NullPointerException if the given position is <code>null</code>
 	 */
 	public PositionableShape(IPosition3D i_position3D) {
+		if (i_position3D == null) // parameter precondition
+			throw new NullPointerException("i_position3D must not be null");
 
 		m_position3D = i_position3D;
 	}
@@ -84,7 +99,8 @@
 		Map<Object, Object> i_context) {
 
 		if (m_position3D == null
-			|| m_position3D.getTransformationMatrix().equals(IMatrix4f.IDENTITY))
+			|| m_position3D.getTransformationMatrix()
+				.equals(IMatrix4f.IDENTITY))
 			return doGetDistance(i_rayOrigin, i_rayDirection, i_context);
 
 		Vector3f newOrigin = Draw3DCache.getVector3f();
@@ -182,7 +198,8 @@
 			Graphics3D g3d = i_renderContext.getGraphics3D();
 			boolean useModelMatrix =
 				m_position3D != null
-					&& !IMatrix4f.IDENTITY.equals(m_position3D.getTransformationMatrix());
+					&& !IMatrix4f.IDENTITY.equals(m_position3D
+						.getTransformationMatrix());
 
 			g3d.glMatrixMode(Graphics3DDraw.GL_MODELVIEW);
 

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/FeedbackHelper3D.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/FeedbackHelper3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/FeedbackHelper3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -33,6 +33,7 @@
 import org.eclipse.draw3d.picking.Picker;
 import org.eclipse.draw3d.util.Draw3DCache;
 import org.eclipse.gef.editpolicies.FeedbackHelper;
+import org.eclipse.gef3d.requests.ChangeBounds3DRequest;
 
 /**
  * FeedbackHelper3D There should really be more documentation here.
@@ -146,13 +147,15 @@
 	 * @param i_feedback the feedback figure
 	 * @param i_surfaceMoveDelta the move delta
 	 * @param i_surfaceSizeDelta the size delta
+	 * @see XYZConstraintLayoutPolicy#getConstraintFor(org.eclipse.gef.requests.ChangeBoundsRequest,
+	 *      org.eclipse.gef.GraphicalEditPart)
 	 */
 	public void updateFeedbackPosition(IFigure3D i_feedback,
 		Point i_surfaceMoveDelta, Dimension i_surfaceSizeDelta) {
 
-		if (log.isLoggable(Level.INFO)) {
-			log.info("move " + i_surfaceMoveDelta); //$NON-NLS-1$
-		}
+		// if (log.isLoggable(Level.INFO)) {
+		//			log.info("move " + i_surfaceMoveDelta); //$NON-NLS-1$
+		// }
 
 		if (i_feedback == null)
 			throw new NullPointerException("i_feedback must not be null");
@@ -166,14 +169,16 @@
 				Figure3DHelper.getAncestor3D(m_helper.getReference())
 					.getSurface();
 
-			Position3D dummy; // = m_helper.getReferencePosition3D();
+			Position3D newPos; // = m_helper.getReferencePosition3D();
 
-			if (surface != initialSurface
-				&& !(m_helper.getReference() instanceof IFigure3D)) {
-				dummy = m_helper.getReferencePosition3D(surface.getHost());
-			} else {
-				dummy = m_helper.getReferencePosition3D();
-			}
+			// TODO use surface or initialSurface to enable or prevent jumping
+			
+			// if (surface != initialSurface
+			// && !(m_helper.getReference() instanceof IFigure3D)) {
+			newPos = m_helper.getReferencePosition3D(surface.getHost());
+			// } else {
+			// dummy = m_helper.getReferencePosition3D();
+			// }
 			// else
 			{
 
@@ -186,82 +191,69 @@
 				// dummy.setPosition(feedbackPosition);
 				//
 				if (i_surfaceMoveDelta != null) {
-					surfaceRelativeLocation.set(dummy.getLocation3D());
+					surfaceRelativeLocation.set(newPos.getLocation3D());
 					surfaceRelativeLocation.translate(i_surfaceMoveDelta.x,
 						i_surfaceMoveDelta.y, 0);
-					dummy.setLocation3D(surfaceRelativeLocation);
+					newPos.setLocation3D(surfaceRelativeLocation);
 				}
 
 				if (i_surfaceSizeDelta != null) {
-					size.set(dummy.getSize3D());
+					size.set(newPos.getSize3D());
 					size.translate(i_surfaceSizeDelta.width,
 						i_surfaceSizeDelta.height, 0);
 
-					dummy.setSize3D(size);
+					newPos.setSize3D(size);
 				}
 
 				// log.info(feedbackPosition.toString());
 			}
 
-			i_feedback.getPosition3D().setPosition(dummy);
+			i_feedback.getPosition3D().setPosition(newPos);
 		} finally {
 			Draw3DCache.returnVector3f(surfaceRelativeLocation, size);
 		}
 	}
 
 	/**
+	 * Update feedback position in case of rotation or 3D move.
+	 * 
 	 * @param i_feedback3d
-	 * @param i_moveDelta3D
+	 * @param i_newPosition in world coordinates
 	 * @param i_sizeDelta3D
 	 * @param i_rotationDelta3D
+	 * @param i_surface the surface to which the depth move delta is relative
+	 * @see ChangeBounds3DRequest#getTransformedPosition(Position3D)
 	 */
 	public void updateFeedbackPosition(IFigure3D i_feedback,
-		IVector3f i_moveDelta3D, IVector3f i_sizeDelta3D,
-		IVector3f i_rotationDelta3D) {
+		IVector3f i_newPosition, IVector3f i_rotationDelta3D) {
 
 		if (log.isLoggable(Level.INFO)) {
-			log.info("Move " + i_moveDelta3D + ", Rot " + i_rotationDelta3D); //$NON-NLS-1$ //$NON-NLS-2$
+			log.info("Move to " + i_newPosition + ", Rot " + i_rotationDelta3D); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 
 		if (i_feedback == null)
 			throw new NullPointerException("i_feedback must not be null");
 
-		Vector3f newLocation = Draw3DCache.getVector3f();
-		Vector3f size = Draw3DCache.getVector3f();
 		try {
 
-			Position3D dummy = i_feedback.getPosition3D();
+			Position3D rotatedNewPosition = i_feedback.getPosition3D();
 
-			if (i_moveDelta3D != null && i_moveDelta3D != IVector3f.NULLVEC3f) {
-				newLocation.set(dummy.getLocation3D());
-				newLocation.translate(i_moveDelta3D.getX(),
-					i_moveDelta3D.getY(), i_moveDelta3D.getZ());
-				dummy.setLocation3D(newLocation);
+			if (i_newPosition != null) { // && i_moveDelta3D !=
+											// IVector3f.NULLVEC3f) {
+				rotatedNewPosition.setLocation3D(i_newPosition);
 			}
 			if (i_rotationDelta3D != null
 				&& i_rotationDelta3D != IVector3f.NULLVEC3f) {
-				Vector3f v3f = new Vector3fImpl(dummy.getRotation3D());
+				Vector3f v3f =
+					new Vector3fImpl(rotatedNewPosition.getRotation3D());
 				Math3D.add(v3f, i_rotationDelta3D, v3f);
-				dummy.setRotation3D(v3f);
+				rotatedNewPosition.setRotation3D(v3f);
 			}
-
-			// if (i_surfaceSizeDelta != null) {
-			// size.set(dummy.getSize3D());
-			// size.translate(i_surfaceSizeDelta.width,
-			// i_surfaceSizeDelta.height, 0);
-			//
-			// dummy.setSize3D(size);
-			// }
-
-			// log.info(feedbackPosition.toString());
-
-			i_feedback.getPosition3D().setPosition(dummy);
+			i_feedback.getPosition3D().setPosition(rotatedNewPosition);
 		} finally {
-			Draw3DCache.returnVector3f(newLocation, size);
 		}
 
 	}
-	
 
 	/**
 	 * Sets the host figure of this feedback helper.
@@ -290,12 +282,12 @@
 	 * Calls {@link #setInitialFeedbackPosition(IFigure3D, ISurface)} with the
 	 * current surface under the mouse cursor (i.e. the picker's current
 	 * surface). As the surface is always updated to the current surface under
-	 * the mouse cursor, the feedback figure automatically "jumps" to
-	 * match the position of the new surface. This is the default mechanism
-	 * for most operations, it can be avoided by calling
-	 * {@link #setInitialFeedbackPosition(IFigure3D, ISurface)} with
-	 * a non-changing surface, e.g., the surface of the figure or the
-	 * start surface. 
+	 * the mouse cursor, the feedback figure automatically "jumps" to match the
+	 * position of the new surface. This is the default mechanism for most
+	 * operations, it can be avoided by calling
+	 * {@link #setInitialFeedbackPosition(IFigure3D, ISurface)} with a
+	 * non-changing surface, e.g., the surface of the figure or the start
+	 * surface.
 	 * 
 	 * @param i_feedback the feedback figure to modify
 	 */
@@ -313,9 +305,9 @@
 	public void setInitialFeedbackPosition(IFigure3D i_feedback,
 		ISurface surface) {
 
-		if (log.isLoggable(Level.INFO)) {
-			log.info("set initial feedback position"); //$NON-NLS-1$
-		}
+		// if (log.isLoggable(Level.INFO)) {
+		//			log.info("set initial feedback position"); //$NON-NLS-1$
+		// }
 
 		ISurface initialSurface =
 			Figure3DHelper.getAncestor3D(m_helper.getReference()).getSurface();

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/ResizableEditPolicy3D.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/ResizableEditPolicy3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/ResizableEditPolicy3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -26,9 +26,12 @@
 import java.util.logging.Logger;
 
 import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw3d.Figure3D;
 import org.eclipse.draw3d.Figure3DHelper;
 import org.eclipse.draw3d.IFigure3D;
 import org.eclipse.draw3d.ISurface;
+import org.eclipse.draw3d.geometry.Math3D;
+import org.eclipse.draw3d.geometry.Vector3f;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.Handle;
@@ -243,21 +246,36 @@
 		else {
 			IFigure3D feedback3D = (IFigure3D) feedback;
 
-			if (request instanceof ChangeBounds3DRequest
-				&& ((ChangeBounds3DRequest) request).getModifier3D() != Modifier3D.NONE) {
+			if (request instanceof ChangeBounds3DRequest) {
 				ChangeBounds3DRequest cbr = (ChangeBounds3DRequest) request;
-				ISurface figureSurface = getFigureSurface();
-				if (figureSurface != null) {
-					getFeedbackHelper().setInitialFeedbackPosition(feedback3D,
-						figureSurface);
-					// cbr.getStartSurface());
+				if (((ChangeBounds3DRequest) request).getModifier3D() != Modifier3D.NONE) {
 
-					getFeedbackHelper().updateFeedbackPosition(feedback3D,
-						cbr.getMoveDepthDelta3D(), cbr.getDepthDelta3D(),
-						cbr.getRotationDelta3D());
-					return;
-				}
+					ISurface figureSurface = getFigureSurface();
+					if (figureSurface != null) {
+						getFeedbackHelper().setInitialFeedbackPosition(
+							feedback3D, figureSurface);
 
+						Vector3f newPos = null;
+						if (cbr.getModifier3D() == Modifier3D.DEPTH
+							&& getHostFigure() instanceof IFigure3D) {
+
+							newPos =
+								cbr.getStartSurface().getWorldLocation(
+									cbr.getMoveDepthDelta3D(), newPos);
+							Math3D.sub(newPos, cbr.getStartSurface().getHost()
+								.getPosition3D().getLocation3D(), newPos);
+							Math3D.add(((Figure3D) getHostFigure())
+								.getPosition3D().getLocation3D(), newPos,
+								newPos);
+
+						}
+
+						getFeedbackHelper().updateFeedbackPosition(feedback3D,
+							newPos, cbr.getRotationDelta3D());
+						return;
+					}
+
+				} 
 			}
 
 			// default and fall back solution: standard 2D mechanism:
@@ -294,7 +312,7 @@
 			ChangeBounds3DRequest req =
 				new ChangeBounds3DRequest(REQ_MOVE_CHILDREN);
 			req.setEditParts(getHost());
-			
+
 			req.set(request3D);
 
 			// from super:

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XY3DLayoutPolicy.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XY3DLayoutPolicy.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XY3DLayoutPolicy.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -12,8 +12,14 @@
 
 import java.util.logging.Logger;
 
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.draw3d.geometry.IBoundingBox;
+import org.eclipse.draw3d.geometry.IVector3f;
+import org.eclipse.draw3d.geometry.Position3D;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.editpolicies.ResizableEditPolicy;
 import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
 
@@ -57,5 +63,32 @@
 
 		return ret;
 	}
+	
+	/**
+	 * {@inheritDoc}
+	 * <p>
+	 * Overridden as the 3D version may not only handle constraints of type
+	 * {@link Rectangle}, but {@link Position3D}, {@link IBoundingBox} and
+	 * {@link IVector3f} as well, and this might cause class cast exceptions in
+	 * the 2D methods.
+	 * </p>
+	 * 
+	 * @param child the child
+	 * @return the current constraint if it is defined and of type
+	 *         {@link Rectangle}, null otherwise.
+	 * @see org.eclipse.gef.editpolicies.XYLayoutEditPolicy#getCurrentConstraintFor(org.eclipse.gef.GraphicalEditPart)
+	 */
+	@Override
+	protected Rectangle getCurrentConstraintFor(GraphicalEditPart child) {
+		IFigure fig = child.getFigure();
+		Object constraint =
+			fig.getParent().getLayoutManager().getConstraint(fig);
+		if (constraint instanceof Rectangle) {
+			return (Rectangle) fig.getParent().getLayoutManager()
+				.getConstraint(fig);
+		}
 
+		return null;
+	}
+
 }

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XYZConstraintLayoutPolicy.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XYZConstraintLayoutPolicy.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/editpolicies/XYZConstraintLayoutPolicy.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -10,8 +10,16 @@
  ******************************************************************************/
 package org.eclipse.gef3d.editpolicies;
 
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.draw3d.IFigure3D;
+import org.eclipse.draw3d.ISurface;
+import org.eclipse.draw3d.LocatorHelper;
+import org.eclipse.draw3d.geometry.IBoundingBox;
+import org.eclipse.draw3d.geometry.IVector3f;
 import org.eclipse.draw3d.geometry.Position3D;
+import org.eclipse.draw3d.geometry.Vector3f;
+import org.eclipse.draw3d.util.Draw3DCache;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.GraphicalEditPart;
 import org.eclipse.gef.commands.Command;
@@ -19,6 +27,7 @@
 import org.eclipse.gef.requests.CreateRequest;
 import org.eclipse.gef3d.commands.UpdateConstraintCommand;
 import org.eclipse.gef3d.requests.ChangeBounds3DRequest;
+import org.eclipse.gef3d.requests.ChangeBounds3DRequest.Modifier3D;
 
 /**
  * Layout policy creating commands for updating constraints of figures,
@@ -64,6 +73,15 @@
 
 	/**
 	 * {@inheritDoc}
+	 * <p>
+	 * Internal note: The algorithm used to calculate new position is quire
+	 * similar to the one used in
+	 * {@link FeedbackHelper3D#updateFeedbackPosition(IFigure3D, IVector3f, IVector3f)}
+	 * . In case of 3D-movement, the conversion is done in
+	 * {@link ChangeBounds3DRequest#getTransformedPosition(Position3D)}, which
+	 * is similar to
+	 * {@link FeedbackHelper3D#updateFeedbackPosition(IFigure3D, org.eclipse.draw2d.geometry.Point, org.eclipse.draw2d.geometry.Dimension)}
+	 * </p>
 	 * 
 	 * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#getConstraintFor(org.eclipse.gef.requests.ChangeBoundsRequest,
 	 *      org.eclipse.gef.GraphicalEditPart)
@@ -76,14 +94,47 @@
 			&& child.getFigure() instanceof IFigure3D) {
 
 			ChangeBounds3DRequest cbr3D = (ChangeBounds3DRequest) request;
-			Position3D childPos =
-				((IFigure3D) child.getFigure()).getPosition3D();
-			Position3D newPos = childPos.getAbsolute(null);
-			cbr3D.getTransformedPosition(newPos);
-			return getConstraintFor(newPos);
-		} else {
-			return super.getConstraintFor(request, child);
+			IFigure3D child3D = (IFigure3D) child.getFigure();
+
+			if (cbr3D.getModifier3D() != Modifier3D.NONE) {
+				Position3D childPos = child3D.getPosition3D();
+				Position3D newPos = childPos.getAbsolute(null);
+				cbr3D.getTransformedPosition(newPos);
+				return getConstraintFor(newPos);
+			} else {
+
+				ISurface surface = cbr3D.getStartSurface();
+				LocatorHelper locator = new LocatorHelper(child3D);
+				Position3D newPos =
+					locator.getReferencePosition3D(surface.getHost());
+				Vector3f surfaceRelativeLocation = Draw3DCache.getVector3f();
+				Vector3f size = Draw3DCache.getVector3f();
+				try {
+					if (request.getMoveDelta() != null) {
+						surfaceRelativeLocation.set(newPos.getLocation3D());
+						surfaceRelativeLocation.translate(
+							request.getMoveDelta().x, request.getMoveDelta().y,
+							0);
+						newPos.setLocation3D(surfaceRelativeLocation);
+					}
+
+					if (request.getSizeDelta() != null) {
+						size.set(newPos.getSize3D());
+						size.translate(request.getSizeDelta().width,
+							request.getSizeDelta().height, 0);
+						newPos.setSize3D(size);
+					}
+					
+				} finally {
+					Draw3DCache.returnVector3f(surfaceRelativeLocation, size);
+				}
+				return getConstraintFor(newPos);
+			}
 		}
+
+		// fall back to 2D:
+		return super.getConstraintFor(request, child);
+
 	}
 
 	/**

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/requests/ChangeBounds3DRequest.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/requests/ChangeBounds3DRequest.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/requests/ChangeBounds3DRequest.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -10,6 +10,10 @@
  ******************************************************************************/
 package org.eclipse.gef3d.requests;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.draw3d.IFigure3D;
 import org.eclipse.draw3d.ISurface;
 import org.eclipse.draw3d.geometry.IVector3f;
 import org.eclipse.draw3d.geometry.Math3D;
@@ -19,6 +23,7 @@
 import org.eclipse.draw3d.util.Draw3DCache;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef3d.editpolicies.FeedbackHelper3D;
 import org.eclipse.gef3d.tools.DragEditPartsTracker3D;
 
 /**
@@ -37,6 +42,11 @@
  * @since Mar 31, 2008
  */
 public class ChangeBounds3DRequest extends ChangeBoundsRequest {
+	/**
+	 * Logger for this class
+	 */
+	// @SuppressWarnings("unused") //$NON-NLS-1$
+	private static final Logger log = Logger.getLogger(ChangeBounds3DRequest.class.getName());
 
 	public static enum Modifier3D {
 		NONE, DEPTH, ROTATION;
@@ -170,6 +180,7 @@
 
 	/**
 	 * @param io_pos
+	 * @see FeedbackHelper3D#updateFeedbackPosition(IFigure3D, IVector3f, IVector3f)
 	 */
 	public void getTransformedPosition(Position3D io_pos) {
 		Vector3f v = Draw3DCache.getVector3f();
@@ -181,7 +192,12 @@
 				io_pos.setRotation3D(v);
 				return;
 			case DEPTH:
-				Math3D.add(io_pos.getLocation3D(), getMoveDepthDelta3D(), v);
+				if (getStartSurface() != null) {
+					getStartSurface()
+						.getWorldLocation(getMoveDepthDelta3D(), v);
+					Math3D.sub(v, getStartSurface().getHost().getPosition3D().getLocation3D(), v);
+				} 
+				Math3D.add(io_pos.getLocation3D(), v, v);
 				io_pos.setLocation3D(v);
 				return;
 			default:
@@ -210,7 +226,7 @@
 	}
 
 	/**
-	 * Sets 2D and 3D values according to given 3D request. 
+	 * Sets 2D and 3D values according to given 3D request.
 	 * 
 	 * @param i_request3d
 	 */
@@ -228,7 +244,7 @@
 		setDepthDelta3D(i_request3d.getDepthDelta3D());
 		setMoveDepthDelta3D(i_request3d.getMoveDepthDelta3D());
 		setModifier3D(i_request3d.getModifier3D());
+		setStartSurface(i_request3d.getStartSurface());
 
-		
 	}
 }

Modified: trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/tools/DragEditPartsTracker3D.java
===================================================================
--- trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/tools/DragEditPartsTracker3D.java	2011-04-24 16:54:38 UTC (rev 573)
+++ trunk/org.eclipse.gef3d/src/java/org/eclipse/gef3d/tools/DragEditPartsTracker3D.java	2011-04-26 20:28:15 UTC (rev 574)
@@ -21,12 +21,14 @@
 import org.eclipse.draw3d.ISurface;
 import org.eclipse.draw3d.MouseEvent3D;
 import org.eclipse.draw3d.PlaneSurface;
-import org.eclipse.draw3d.camera.ICamera;
+import org.eclipse.draw3d.RenderContext;
+import org.eclipse.draw3d.ShapeFigure3D;
 import org.eclipse.draw3d.geometry.IVector3f;
 import org.eclipse.draw3d.geometry.Math3D;
-import org.eclipse.draw3d.geometry.Position3DUtil;
 import org.eclipse.draw3d.geometry.Vector3f;
 import org.eclipse.draw3d.geometry.Vector3fImpl;
+import org.eclipse.draw3d.shapes.CuboidFigureShape;
+import org.eclipse.draw3d.shapes.Shape;
 import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPartViewer;
 import org.eclipse.gef.GraphicalEditPart;
@@ -35,8 +37,11 @@
 import org.eclipse.gef.tools.DragEditPartsTracker;
 import org.eclipse.gef3d.requests.ChangeBounds3DRequest;
 import org.eclipse.gef3d.requests.ChangeBounds3DRequest.Modifier3D;
+import org.eclipse.gef3d.ui.parts.GraphicalViewer3DImpl;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
 
 /**
  * DragEditPartsTracker3D There should really be more documentation here. The
@@ -83,7 +88,6 @@
 			MODIFIER_3DDRAG = SWT.ALT;
 	}
 
-	
 	/**
 	 * The mouse sensitivity used when computing the rotation based on mouse
 	 * movement
@@ -121,10 +125,27 @@
 	protected PlaneSurface depthSurface;
 
 	/**
+	 * Debug figure
+	 */
+	protected ShapeFigure3D debugDepthSurfaceFigure = new ShapeFigure3D() {
+		@Override
+		protected Shape createShape() {
+			return new CuboidFigureShape(this, false);
+		}
+	};
+
+	/**
 	 * @param i_sourceEditPart
 	 */
 	public DragEditPartsTracker3D(EditPart i_sourceEditPart) {
 		super(i_sourceEditPart);
+
+		// configure the debug figure
+		Color c = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
+		debugDepthSurfaceFigure.setForegroundColor(c);
+		c = Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA);
+		debugDepthSurfaceFigure.setBackgroundColor(c);
+		debugDepthSurfaceFigure.setAlpha(0x77);
 	}
 
 	/**
@@ -169,14 +190,44 @@
 			startWorldLocation = currentMouseEvent3D.getWorldLocation();
 			startScreenLocation = currentMouseEvent3D.getScreenLocation();
 
+			
+			
+			
+			
 			Vector3f depthRotation = startSurface.getSurfaceRotation(null);
-			depthRotation.setX((float) (depthRotation.getX()+Math.PI/2));
-			depthRotation.setZ((float) (depthRotation.getZ()+Math.PI/2));
+			
+			Vector3f b = new Vector3fImpl(0,0,-1);
+			IVector3f no = startSurface.getNormal();
+			
+			Math3D.eulerAngles(no, b, depthRotation);
+			depthRotation.setX((float) (depthRotation.getX() - Math.PI / 2f));
+//			depthRotation.setY((float) (depthRotation.getY() + Math.PI / 2f));
+////			depthRotation.setZ((float) (depthRotation.getZ() + Math.PI / 2f));
 
+			if (Math3D.equals(depthRotation, IVector3f.NULLVEC3f, 0.001f)) {
+				depthRotation.setX(Math3D.PI/2f);
+			}
+			
 			depthSurface = new PlaneSurface();
 			depthSurface.getPosition3D().setLocation3D(startWorldLocation);
 			depthSurface.getPosition3D().setRotation3D(depthRotation);
-			
+			depthSurface.getPosition3D().setSize3D(
+				new Vector3fImpl(20, 40, 5));
+
+			if (getCurrentViewer() instanceof GraphicalViewer3DImpl) {
+				GraphicalViewer3DImpl v =
+					(GraphicalViewer3DImpl) getCurrentViewer();
+				if (v.getLightweightSystem3D().isDebug()) {
+					debugDepthSurfaceFigure.getPosition3D().setPosition(
+						depthSurface.getPosition3D());
+					debugDepthSurfaceFigure.setVisible(true);
+
+					v.getLightweightSystem3D().addDebugFigure(
+						debugDepthSurfaceFigure);
+				}
+
+			}
+
 			if (log.isLoggable(Level.INFO)) {
 				log.info("depthSurface=" + depthSurface + ", startSurface=" + startSurface); //$NON-NLS-1$
 			}
@@ -189,9 +240,16 @@
 		}
 		super.setStartLocation(i_p);
 	}
-	
-	
 
+	public void deactivate() {
+		if (getCurrentViewer() instanceof GraphicalViewer3DImpl) {
+			GraphicalViewer3DImpl v =
+				(GraphicalViewer3DImpl) getCurrentViewer();
+			v.getLightweightSystem3D().removeDebugFigure(
+				debugDepthSurfaceFigure);
+		}
+	};
+
 	/**
 	 * {@inheritDoc}
 	 * <p>
@@ -291,7 +349,7 @@
 				// clear 2D deltas
 				cbr.setMoveDelta(NO_DELTA);
 				cbr.setSizeDelta(NO_DELTA_SIZE);
-				
+
 				switch (cbr.getModifier3D()) {
 				case DEPTH:
 					cbr.setMoveDepthDelta3D(computeDepthDelta3D());
@@ -327,23 +385,25 @@
 	 * @return
 	 */
 	protected IVector3f computeDepthDelta3D() {
+		if (log.isLoggable(Level.INFO)) {
+			log.info("compute depth with depthSurface=" + depthSurface); //$NON-NLS-1$
+		}
+
 		Vector3f end =
 			currentMouseEvent3D.computeWorldLocation(
 				currentMouseEvent3D.getScreenLocation(), depthSurface);
-		
+
 		startSurface.getSurfaceLocation3D(end, end);
-		
+
 		if (log.isLoggable(Level.INFO)) {
 			log.info("new depth: " + end.getZ()); //$NON-NLS-1$
 		}
 		// end.setZ(end.getZ()-depthSurface.getPosition3D().getLocation3D().getZ());
 		end.setY(0);
 		end.setX(0);
-		
-		// startSurface.getWorldLocation(end, end);
-		
-		
 
+//		startSurface.getWorldLocation(end, end);
+
 		return end;
 	}