Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2014-04-10 13:03:04 +0000
committerVincent Lorenzo2014-04-10 13:06:42 +0000
commit7e5eae5abeebcd18b5a4927656188501ce65b088 (patch)
treeb56d59946e9770a714c03f9ff741b628aae12392 /plugins
parentd7679373146143b9f25629baf7f8e618acab6fee (diff)
downloadorg.eclipse.papyrus-7e5eae5abeebcd18b5a4927656188501ce65b088.tar.gz
org.eclipse.papyrus-7e5eae5abeebcd18b5a4927656188501ce65b088.tar.xz
org.eclipse.papyrus-7e5eae5abeebcd18b5a4927656188501ce65b088.zip
430702: [Diagram] Moving source of a link moves the target too. remove FixEdgeAnchorAfterCreationDeferredCommand and replace it
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java158
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java172
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java67
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java138
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java35
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java29
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultGraphicalNodeEditPolicy.java45
7 files changed, 461 insertions, 183 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java
new file mode 100644
index 00000000000..07fda752b2a
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java
@@ -0,0 +1,158 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.geometry.RectangleUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.geometry.Segment;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+
+
+/**
+ *
+ * This command is used to fix the edge anchor just after the creation of the edge, in order to get anchor on the sides of the source
+ * and target figure and not somewhere inside the figure.
+ *
+ * This fix allows to avoid to get source (or target) location moving instead you are moving the target (or source) anchor
+ *
+ * see bug 430702: [Diagram] Moving source of a link moves the target too.
+ */
+
+public class FixEdgeAnchorAfterCreationCommand extends AbstractTransactionalCommand {
+
+ private static final String RECT_RIGHT_MIDDLE_ANCHOR = "(1.0,0.5)";
+
+ private static final String RECT_BOTTOM_MIDDLE_ANCHOR = "(0.5,1.0)";
+
+ /**
+ * the request used to create connection view
+ */
+ protected CreateConnectionViewRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param request
+ * the creation request
+ * @param containerEP
+ * the diagram edit part
+ */
+ public FixEdgeAnchorAfterCreationCommand(final TransactionalEditingDomain editingDomain, final CreateConnectionViewRequest request) {
+ super(editingDomain, "Fix Edge Anchor after creation", null); //$NON-NLS-1$
+ this.request = request;
+ }
+
+
+ /**
+ * Executes a fix anchor command for the created edge
+ *
+ */
+ protected CommandResult doExecuteWithResult(final IProgressMonitor progressMonitor, final IAdaptable info) throws ExecutionException {
+ final ConnectionViewDescriptor connectionViewDescriptor = this.request.getConnectionViewDescriptor();
+ final Edge createdEdge = (Edge)connectionViewDescriptor.getAdapter(View.class);
+ final IAdaptable adaptable = (CreateElementRequestAdapter)connectionViewDescriptor.getElementAdapter();
+ final CreateRelationshipRequest createRelationShipRequest = (CreateRelationshipRequest)adaptable.getAdapter(CreateRelationshipRequest.class);
+ final Map<?, ?> requestParameters = createRelationShipRequest.getParameters();
+ final IFigure sourceFigure = (IFigure)requestParameters.get(RequestParameterConstants.EDGE_SOURCE_FIGURE);
+ final IFigure targetFigure = (IFigure)requestParameters.get(RequestParameterConstants.EDGE_TARGET_FIGURE);
+ final Point sourcePoint = (Point)requestParameters.get(RequestParameterConstants.EDGE_SOURCE_POINT);
+ final Point targetPoint = (Point)requestParameters.get(RequestParameterConstants.EDGE_TARGET_POINT);
+ if(createdEdge != null && sourceFigure instanceof IAnchorableFigure && targetFigure instanceof IAnchorableFigure) {
+ final String sourceTerminal;
+ final String targetTerminal;
+ if(sourceFigure == targetFigure) {
+ sourceTerminal = RECT_RIGHT_MIDDLE_ANCHOR.toString();
+ targetTerminal = RECT_BOTTOM_MIDDLE_ANCHOR.toString();
+ } else {
+
+ final Rectangle sourceBds = sourceFigure.getBounds().getCopy();
+ final Rectangle targetBds = targetFigure.getBounds().getCopy();
+ sourceFigure.translateToAbsolute(sourceBds);
+ targetFigure.translateToAbsolute(targetBds);
+
+ final Segment segment = new Segment(sourcePoint, targetPoint);
+ final Point realSourcePoint = RectangleUtils.getIntersectionPoint(sourceBds, segment);
+ final Point realTargetPoint = RectangleUtils.getIntersectionPoint(targetBds, segment);
+
+ //get source anchor terminal
+ final BaseSlidableAnchor anchorSource = (BaseSlidableAnchor)((IAnchorableFigure)sourceFigure).getSourceConnectionAnchorAt(realSourcePoint);
+ sourceTerminal = anchorSource.getTerminal();
+
+ //get target anchor terminal
+ final BaseSlidableAnchor anchorTarget = (BaseSlidableAnchor)((IAnchorableFigure)targetFigure).getTargetConnectionAnchorAt(realTargetPoint);
+ targetTerminal = anchorTarget.getTerminal();
+ //create and set the source anchor
+ }
+ //TODO : it is possible that the result will be not correct when the preferred routing for the link is not the oblique router
+ final IdentityAnchor sourceAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ sourceAnchor.setId(sourceTerminal);
+ createdEdge.setSourceAnchor(sourceAnchor);
+
+ //create an set the target anchor
+ final IdentityAnchor targetAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ targetAnchor.setId(targetTerminal);
+ createdEdge.setTargetAnchor(targetAnchor);
+
+ return CommandResult.newOKCommandResult();
+ }
+ return CommandResult.newErrorCommandResult("Some required element can't be found to fix the anchors of the created edge");//$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
+ *
+ */
+ protected void cleanup() {
+ this.request = null;
+ super.cleanup();
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && this.request != null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java
deleted file mode 100755
index 28715f4bfbe..00000000000
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationDeferredCommand.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.io.ObjectInputStream.GetField;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.swt.widgets.Display;
-
-
-/**
- *
- * This command is used to fix the edge anchor just after the creation of the edge, in order to get anchor on the sides of the source
- * and target figure and not somewhere inside the figure.
- *
- * This fix allows to avoid to get source (or target) location moving instead you are moving the target (or source) anchor
- *
- * see bug 430702: [Diagram] Moving source of a link moves the target too.
- */
-public class FixEdgeAnchorAfterCreationDeferredCommand extends AbstractFixEdgeAnchorDeferredCommand {
-
- /**
- * the request used to create connection view
- */
- protected CreateConnectionViewRequest request;
-
- /**
- *
- * Constructor.
- *
- * @param editingDomain
- * the editing domain
- * @param request
- * the creation request
- * @param containerEP
- * the diagram edit part
- */
- public FixEdgeAnchorAfterCreationDeferredCommand(final TransactionalEditingDomain editingDomain, final CreateConnectionViewRequest request, final IGraphicalEditPart containerEP) {
- super(editingDomain, "Fix Edge Anchor after creation", containerEP); //$NON-NLS-1$
- this.request = request;
- }
-
-
- /**
- * Executes a fix anchor command for the created edge
- *
- */
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- //we execute all ui thread allow to fix anchor after a DnD from the ModelExplorer
- // while(Display.getDefault().readAndDispatch()); //commented because it breaks the tests
-
- //we refresh the editparts
- RefreshConnectionElementsRunnable refreshRunnable = new RefreshConnectionElementsRunnable(this.request, getContainerEP());
- EditPartUtil.synchronizeRunnableToMainThread(getContainerEP(), refreshRunnable);
-
- //we do the work
- final AbstractConnectionEditPart connectionEP = refreshRunnable.getResult();
- if(connectionEP != null) {
- final CompoundCommand cc = new CompoundCommand("Fix connections anchors"); //$NON-NLS-1$
- addFixAnchorCommand(connectionEP, cc);
- if(cc.canExecute()) {
- cc.execute();
- } else {
- Activator.log.warn("Command to fix the anchors is null"); //$NON-NLS-1$
- }
- }
- return CommandResult.newOKCommandResult();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
- *
- */
- protected void cleanup() {
- this.request = null;
- super.cleanup();
- }
-
-
- /**
- *
- * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
- *
- * @return
- */
- @Override
- public boolean canExecute() {
- return super.canExecute() && this.request != null;
- }
-
- /**
- *
- * The runnable used to refresh the views
- *
- */
- private static class RefreshConnectionElementsRunnable extends AbstractRefreshConnectionElementsRunnable<AbstractConnectionEditPart> {
-
- /**
- * the connection request
- */
- final CreateConnectionViewRequest request;
-
- /**
- *
- * Constructor.
- *
- * @param request
- * the request used to create the connection view
- * @param containerEP
- * the edit part owning the new connection editpart
- * @param containerFigure
- */
- public RefreshConnectionElementsRunnable(final CreateConnectionViewRequest request, final IGraphicalEditPart containerEP) {
- super(containerEP);
- this.request = request;
- }
-
- /**
- *
- * @see java.lang.Runnable#run()
- *
- */
- public void run() {
- getContainerEditPart().refresh();
- // We update the figure world
- getContainerFigure().invalidate();
- getContainerFigure().validate();
- final View view = (View)this.request.getConnectionViewDescriptor().getAdapter(View.class);
- if(view != null) {
- final Map<?, ?> epRegistry = getContainerEditPart().getRoot().getViewer().getEditPartRegistry();
- Object editPart = epRegistry.get(view);
- if(editPart instanceof AbstractConnectionEditPart) {
- setResult((AbstractConnectionEditPart)editPart);
- refreshConnection(getResult());
- }
- }
- setStatus(Status.OK_STATUS);
- }
- };
-
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java
new file mode 100644
index 00000000000..55614589608
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java
@@ -0,0 +1,67 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
+
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ *
+ * Utils class for drawd2D Rectangle
+ *
+ */
+public class RectangleUtils {
+
+ private RectangleUtils() {
+ //to prevent instantiation
+ }
+
+
+ /**
+ *
+ * @param rect
+ * a rectangle
+ * @param segment
+ * a segment
+ * @return
+ * the intersection point between the segment and the rectangle, if exists
+ */
+ public static final PrecisionPoint getIntersectionPoint(final Rectangle rect, final Segment segment) {
+ PrecisionPoint result = null;
+
+ //top segment
+ final Segment topSegment = new Segment(rect.getTopLeft(), rect.getTopRight());
+ result = segment.getIntersection(topSegment);
+
+ if(result == null) {
+ //right segment
+ final Segment rightSegment = new Segment(rect.getTopRight(), rect.getBottomRight());
+ result = segment.getIntersection(rightSegment);
+ }
+
+ if(result == null) {
+ //bottom segment
+ final Segment bottomSegment = new Segment(rect.getBottomRight(), rect.getBottomLeft());
+ result = segment.getIntersection(bottomSegment);
+ }
+
+ if(result == null) {
+ //left segment
+ final Segment leftSegment = new Segment(rect.getBottomLeft(), rect.getTopLeft());
+ result = segment.getIntersection(leftSegment);
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java
new file mode 100644
index 00000000000..63a38f32370
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+
+/**
+ *
+ * This class is used to manipulate segment
+ */
+public class Segment {
+
+
+ /**
+ * the start point of the segment
+ */
+ private final PrecisionPoint start;
+
+ /**
+ * the end point of the segment
+ */
+ private final PrecisionPoint end;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param start
+ * the start point of the segment
+ * @param end
+ * the end point of the segment
+ */
+ public Segment(final PrecisionPoint start, final PrecisionPoint end) {
+ this.start = start.getPreciseCopy();
+ this.end = end.getPreciseCopy();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param start
+ * the start point of the segment
+ * @param end
+ * the end point of the segment
+ */
+ public Segment(final Point start, final Point end) {
+ this.start = new PrecisionPoint(start);
+ this.end = new PrecisionPoint(end);
+ }
+
+ /**
+ *
+ * @param segment
+ * a segment
+ * @return
+ * <code>true</code> if the segment has a common point with this one
+ */
+ public boolean hasIntersection(final Segment segment) {
+ return getIntersection(segment) != null;
+ }
+
+ /**
+ *
+ * @return
+ * the start point of the segment
+ */
+ public final PrecisionPoint getStartPoint() {
+ return this.start;
+ }
+
+ /**
+ *
+ * @return
+ * the end point of the segment
+ */
+ public final PrecisionPoint getEndPoint() {
+ return this.end;
+ }
+
+ //find line intersection in awt
+ // static Point get_line_intersection(Line2D.Double pLine1, Line2D.Double pLine2) {
+ // Point result = null;
+ //
+ // double s1_x = pLine1.x2 - pLine1.x1;
+ // double s1_y = pLine1.y2 - pLine1.y1;
+ // double s2_x = pLine2.x2 - pLine2.x1;
+ // double s2_y = pLine2.y2 - pLine2.y1;
+ //
+ // double s = (-s1_y * (pLine1.x1 - pLine2.x1) + s1_x * (pLine1.y1 - pLine2.y1)) / (-s2_x * s1_y + s1_x * s2_y);
+ // double t = (s2_x * (pLine1.y1 - pLine2.y1) - s2_y * (pLine1.x1 - pLine2.x1)) / (-s2_x * s1_y + s1_x * s2_y);
+ //
+ // if(s >= 0 && s <= 1 && t >= 0 && t <= 1) {
+ // // Collision detected
+ // result = new Point((int)(pLine1.x1 + (t * s1_x)), (int)(pLine1.y1 + (t * s1_y)));
+ // } // end if
+ //
+ // return result;
+ // }
+
+ /**
+ *
+ * @param segment
+ * a segment
+ * @return
+ * the intersection point if exists or <code>null</code>
+ */
+ public PrecisionPoint getIntersection(final Segment segment) {
+ double s1_x = segment.getEndPoint().preciseX() - segment.getStartPoint().preciseX();
+ double s1_y = segment.getEndPoint().preciseY() - segment.getStartPoint().preciseY();
+ double s2_x = getEndPoint().preciseX() - getStartPoint().preciseX();
+ double s2_y = getEndPoint().preciseY() - getStartPoint().preciseY();
+ double s = (-s1_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX()) + s1_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY())) / (-s2_x * s1_y + s1_x * s2_y);
+ double t = (s2_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY()) - s2_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX())) / (-s2_x * s1_y + s1_x * s2_y);
+
+ PrecisionPoint result = null;
+ if(s >= 0 && s <= 1 && t >= 0 && t <= 1) {
+ // Collision detected
+ result = new PrecisionPoint((int)(segment.getStartPoint().preciseX() + (t * s1_x)), (int)(segment.getStartPoint().preciseY() + (t * s1_y)));
+ } // end if
+
+ return result;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
index 8bb8d38c5f9..6ded5ab1c40 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/DiagramEditPartsUtil.java
@@ -19,7 +19,9 @@ import java.util.HashSet;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.RootEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
@@ -27,6 +29,7 @@ import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper;
import org.eclipse.papyrus.infra.tools.util.EditorHelper;
import org.eclipse.ui.IWorkbenchPart;
@@ -189,4 +192,36 @@ public class DiagramEditPartsUtil {
}
return null;
}
+
+ /**
+ *
+ * @param anEditPart
+ * an edit part
+ * @return
+ * <code>true</code> if snap to grid is activated for the diagram owning the editpart
+ *
+ */
+ public static final boolean isSnapToGridActive(final EditPart anEditPart) {
+ boolean result = false;
+ final IPreferenceStore store = getDiagramWorkspacePreferenceStore(anEditPart);
+ if(store != null) {
+ result = store.getBoolean(PreferencesConstantsHelper.SNAP_TO_GRID_CONSTANT);
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param anEditPart
+ * an edit part
+ * @return
+ * the value of the grid spacing or -1 if not found
+ */
+ public static final double getDiagramGridSpacing(final EditPart anEditPart) {
+ final RootEditPart rootEP = anEditPart.getRoot();
+ if(rootEP instanceof DiagramRootEditPart) {
+ return ((DiagramRootEditPart)rootEP).getGridSpacing();
+ }
+ return -1.0;
+ }
}
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
index f0060b1f620..f591cf4ca83 100644
--- a/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.edit/src/org/eclipse/papyrus/infra/services/edit/utils/RequestParameterConstants.java
@@ -22,6 +22,7 @@ public interface RequestParameterConstants {
/**
* The ID for the additional parameter SOURCE_PARENT possibly required in link creation request
+ *
* @deprecated
*/
@Deprecated
@@ -29,6 +30,7 @@ public interface RequestParameterConstants {
/**
* The ID for the additional parameter TARGET_PARENT possibly required in link creation request
+ *
* @deprecated
*/
@Deprecated
@@ -36,6 +38,7 @@ public interface RequestParameterConstants {
/**
* The ID for the additional parameter RECONNECT_PARENT possibly required in link reconnect request
+ *
* @deprecated
*/
@Deprecated
@@ -55,20 +58,40 @@ public interface RequestParameterConstants {
* The ID for the additional parameter TARGET_GRAPHICAL_VIEW possibly required in link creation request
*/
public static final String EDGE_CREATE_REQUEST_TARGET_VIEW = "TARGET_GRAPHICAL_VIEW"; //$NON-NLS-1$
-
+
/**
* The ID for the additional parameter RECONNECT_END_VIEW possibly required in link reconnect request
*/
public static final String EDGE_REORIENT_REQUEST_END_VIEW = "RECONNECT_END_VIEW"; //$NON-NLS-1$
-
+
/**
* The ID to store the list of element under re-factoring.
*/
public static final String ASSOCIATION_REFACTORED_ELEMENTS = "ASSOCIATION_REFACTORED_ELEMENTS"; //$NON-NLS-1$
-
+
/**
* The ID to store the list of element that should not be destroyed (avoid dependents destroy).
*/
public static final String DEPENDENTS_TO_KEEP = "DEPENDENTS_TO_KEEP"; //$NON-NLS-1$
+ /**
+ * The ID to store the source figure for an edge creation
+ */
+ public static final String EDGE_SOURCE_FIGURE = "EDGE_SOURCE_FIGURE"; //$NON-NLS-1$
+
+ /**
+ * The ID to store the target figure for an edge creation
+ */
+ public static final String EDGE_TARGET_FIGURE = "EDGE_TARGET_FIGURE"; //$NON-NLS-1$
+
+ /**
+ * the ID to store the source point for an edge creation
+ */
+ public static final String EDGE_SOURCE_POINT = "EDGE_SOURCE_POINT"; //$NON-NLS-1$
+
+ /**
+ * the ID to store the target point for an edge creation
+ */
+ public static final String EDGE_TARGET_POINT = "EDGE_TARGET_POINT"; //$NON-NLS-1$
+
}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultGraphicalNodeEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultGraphicalNodeEditPolicy.java
index c720355cfe2..cc8533b56a5 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultGraphicalNodeEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/DefaultGraphicalNodeEditPolicy.java
@@ -14,15 +14,19 @@
package org.eclipse.papyrus.gmf.diagram.common.edit.policy;
import java.util.Collections;
+import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.common.core.util.StringStatics;
import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionAnchorsCommand;
import org.eclipse.gmf.runtime.diagram.core.commands.SetConnectionEndsCommand;
@@ -41,11 +45,12 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.gmf.diagram.common.commands.CreateViewCommand;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.FixEdgeAnchorAfterCreationDeferredCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.FixEdgeAnchorAfterCreationCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.commands.FixEdgeAnchorsDeferredCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
import org.eclipse.papyrus.sysml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
+
/**
* Default graphical node edit policy replacement used to replace {@link CreateCommand} by {@link CreateViewCommand},
@@ -69,13 +74,36 @@ public class DefaultGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
View targetView = (View)request.getTargetEditPart().getModel();
createElementRequest.setParameter(RequestParameterConstants.EDGE_CREATE_REQUEST_TARGET_VIEW, targetView);
+ createElementRequest.setParameter(RequestParameterConstants.EDGE_TARGET_POINT, request.getLocation());
+
+ //see bug 430702: [Diagram] Moving source of a link moves the target too, we need to store in the parameters :
+ //- the source point
+ //- the target point
+ //- the source figure
+ //- the target figure
+ final EditPart sourceEP = request.getSourceEditPart();
+ if(sourceEP instanceof GraphicalEditPart) {
+ createElementRequest.setParameter(RequestParameterConstants.EDGE_SOURCE_FIGURE, ((GraphicalEditPart)sourceEP).getFigure());
+ }
+ final EditPart targetEP = request.getTargetEditPart();
+ if(targetEP instanceof GraphicalEditPart) {
+ createElementRequest.setParameter(RequestParameterConstants.EDGE_TARGET_FIGURE, ((GraphicalEditPart)targetEP).getFigure());
+ }
+
+ final TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
+ final CompoundCommand cc = new CompoundCommand("ConnectionAndRelationshipCompleteCommand");//$NON-NLS-1$
+ final ICommand fixAnchor = new FixEdgeAnchorAfterCreationCommand(editingDomain, request);
+
- return super.getConnectionAndRelationshipCompleteCommand(request);
+ cc.add(super.getConnectionAndRelationshipCompleteCommand(request));
+ cc.add(new ICommandProxy(fixAnchor));
+ return cc;
}
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("restriction")
@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
if(!(request instanceof CreateConnectionViewRequest))
@@ -89,8 +117,12 @@ public class DefaultGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
CreateCommand createCommand = new CreateViewCommand(editingDomain, req.getConnectionViewDescriptor(), diagramView.getDiagram());
//
setViewAdapter((IAdaptable)createCommand.getCommandResult().getReturnValue());
-
-
+
+ //see bug 430702: [Diagram] Moving source of a link moves the target too, we need to store the source point to fix this bug.
+ @SuppressWarnings("unchecked")
+ Map<Object,Object> parameters = req.getExtendedData();
+ parameters.put(RequestParameterConstants.EDGE_SOURCE_POINT, request.getLocation());
+
SetConnectionEndsCommand sceCommand = new SetConnectionEndsCommand(editingDomain, StringStatics.BLANK);
sceCommand.setEdgeAdaptor(getViewAdapter());
sceCommand.setNewSourceAdaptor(new EObjectAdapter(getView()));
@@ -104,9 +136,6 @@ public class DefaultGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
cc.compose(sceCommand);
cc.compose(scaCommand);
cc.compose(sbbCommand);
-
- // see bug 430702: [Diagram] Moving source of a link moves the target too.
- cc.compose(new FixEdgeAnchorAfterCreationDeferredCommand(editingDomain, req, (IGraphicalEditPart)getHost()));
Command c = new ICommandProxy(cc);
request.setStartCommand(c);
return c;

Back to the top