Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Monnier2014-05-16 17:01:16 +0000
committerLaurent Redor2014-08-16 13:35:37 +0000
commita5a939dfbe69c07ac1b2fc5b6bb5422b9b30adbf (patch)
tree3b2c80ee2ab10a7cc7de48cb3d649b0005752526
parent019415b7c29eff5147783a559b6d9a602ecbafed (diff)
downloadorg.eclipse.sirius-a5a939dfbe69c07ac1b2fc5b6bb5422b9b30adbf.tar.gz
org.eclipse.sirius-a5a939dfbe69c07ac1b2fc5b6bb5422b9b30adbf.tar.xz
org.eclipse.sirius-a5a939dfbe69c07ac1b2fc5b6bb5422b9b30adbf.zip
[437095] Update command and feedback on terminal bendpoint move to only
move the last segment Bug: 437095 Change-Id: Ie4443987bd0dbcf39954101534154fd8d38f5a8f Signed-off-by: Laurent Redor <laurent.redor@obeo.fr> Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java52
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionQuery.java57
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/EdgeQuery.java36
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusGraphicalNodeEditPolicy.java91
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/graphical/edit/policies/SiriusConnectionEndPointEditPolicy.java299
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release Notes.html27
-rw-r--r--plugins/org.eclipse.sirius.doc/doc/Release Notes.textile10
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/draw2d/ui/geometry/LineSegQuery.java58
-rw-r--r--plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java12
10 files changed, 512 insertions, 131 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java
index f4b2bf656b..4efe8d315a 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionEditPartQuery.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.business.api.query;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
+import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
import org.eclipse.gmf.runtime.notation.Diagram;
@@ -49,8 +49,8 @@ public class ConnectionEditPartQuery {
*/
public boolean isLayoutComponent() {
boolean isLayoutComponent = false;
- if (isEdgeTreeRoutingStyle(connectionEditPart)) {
- Diagram diagram = getDiagram(connectionEditPart);
+ if (isEdgeWithTreeRoutingStyle()) {
+ Diagram diagram = getDiagram();
if (diagram != null && diagram.getElement() instanceof DSemanticDiagram) {
DSemanticDiagram dSemanticDiagram = (DSemanticDiagram) diagram.getElement();
Layout layout = dSemanticDiagram.getDescription().getLayout();
@@ -60,18 +60,52 @@ public class ConnectionEditPartQuery {
return isLayoutComponent;
}
- private boolean isEdgeTreeRoutingStyle(ConnectionEditPart editPart) {
+ /**
+ * Check if this ConnectionEditPart has a tree routing style.
+ *
+ * @return true if ConnectionEditPart has a tree routing style, false
+ * otherwise.
+ */
+ public boolean isEdgeWithTreeRoutingStyle() {
boolean isEdgeTreeRoutingStyle = false;
- if (editPart.getModel() instanceof Edge) {
- isEdgeTreeRoutingStyle = new EdgeQuery((Edge) editPart.getModel()).isEdgeWithTreeRoutingStyle();
+ if (connectionEditPart.getModel() instanceof Edge) {
+ isEdgeTreeRoutingStyle = new EdgeQuery((Edge) connectionEditPart.getModel()).isEdgeWithTreeRoutingStyle();
}
return isEdgeTreeRoutingStyle;
}
- private Diagram getDiagram(ConnectionEditPart editPart) {
+ /**
+ * Check if this ConnectionEditPart has a rectilinear routing style.
+ *
+ * @return true if ConnectionEditPart has a rectilinear routing style, false
+ * otherwise.
+ */
+ public boolean isEdgeWithRectilinearRoutingStyle() {
+ boolean isEdgeWithRectilinearRoutingStyle = false;
+ if (connectionEditPart.getModel() instanceof Edge) {
+ isEdgeWithRectilinearRoutingStyle = new EdgeQuery((Edge) connectionEditPart.getModel()).isEdgeWithRectilinearRoutingStyle();
+ }
+ return isEdgeWithRectilinearRoutingStyle;
+ }
+
+ /**
+ * Check if this ConnectionEditPart has an oblique routing style.
+ *
+ * @return true if ConnectionEditPart has an oblique routing style, false
+ * otherwise.
+ */
+ public boolean isEdgeWithObliqueRoutingStyle() {
+ boolean isEdgeWithObliqueRoutingStyle = false;
+ if (connectionEditPart.getModel() instanceof Edge) {
+ isEdgeWithObliqueRoutingStyle = new EdgeQuery((Edge) connectionEditPart.getModel()).isEdgeWithObliqueRoutingStyle();
+ }
+ return isEdgeWithObliqueRoutingStyle;
+ }
+
+ private Diagram getDiagram() {
Diagram diagram = null;
- if (editPart.getParent() instanceof DiagramRootEditPart) {
- DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) editPart.getParent();
+ if (connectionEditPart.getParent() instanceof DiagramRootEditPart) {
+ DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) connectionEditPart.getParent();
if (diagramRootEditPart.getChildren().get(0) instanceof DiagramEditPart) {
DiagramEditPart diagramEditPart = (DiagramEditPart) diagramRootEditPart.getChildren().get(0);
if (diagramEditPart.getModel() instanceof Diagram) {
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionQuery.java
index 8dbfdb1f01..354f40ded3 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ConnectionQuery.java
@@ -27,6 +27,7 @@ import org.eclipse.sirius.ext.base.Options;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
+
/**
* A class aggregating all the queries (read-only!) having a {@link Connection}
* as a starting point.
@@ -165,13 +166,8 @@ public class ConnectionQuery {
Object cons = connection.getRoutingConstraint();
if (cons instanceof List) {
- List<Object> constraintsList = (List<Object>) cons;
- if (constraintsList.size() == 4 && Iterators.all(constraintsList.iterator(), Predicates.instanceOf(RelativeBendpoint.class))) {
- List<RelativeBendpoint> result = Lists.newLinkedList();
- for (Object object : constraintsList) {
- result.add((RelativeBendpoint) object);
- }
- return Options.newSome(result);
+ if (((List<?>) cons).size() == 4) {
+ return getRelativeBendpointsConstraint();
}
}
return Options.newNone();
@@ -181,18 +177,35 @@ public class ConnectionQuery {
* Return the constraint of the connection as list of RelativeBendpoint only
* if :
* <UL>
- * <LI>the constraint is a list of relative bendpoints</LI>
+ * <LI>the constraint is a list of absolute bendpoints</LI>
* <LI>this list contains 4 points (corresponding to a branch of a tree).</LI>
* </UL>
*
- * @return an optional list of {@link RelativeBendpoint}
+ * @return an optional list of {@link AbsoluteBendpoint}
*/
public Option<List<AbsoluteBendpoint>> getTreeAbsoluteBendpointsConstraint() {
Object cons = connection.getRoutingConstraint();
if (cons instanceof List) {
- List<Object> constraintsList = (List<Object>) cons;
- if (constraintsList.size() == 4 && Iterators.all(constraintsList.iterator(), Predicates.instanceOf(AbsoluteBendpoint.class))) {
+ if (((List<?>) cons).size() == 4) {
+ return getAbsoluteBendpointsConstraint();
+ }
+ }
+ return Options.newNone();
+ }
+
+ /**
+ * Return the constraint of the connection as list of RelativeBendpoint only
+ * if the constraint is a list of absolute bendpoints.
+ *
+ * @return an optional list of {@link AbsoluteBendpoint}
+ */
+ public Option<List<AbsoluteBendpoint>> getAbsoluteBendpointsConstraint() {
+
+ Object cons = connection.getRoutingConstraint();
+ if (cons instanceof List) {
+ List<?> constraintsList = (List<?>) cons;
+ if (Iterators.all(constraintsList.iterator(), Predicates.instanceOf(AbsoluteBendpoint.class))) {
List<AbsoluteBendpoint> result = Lists.newLinkedList();
for (Object object : constraintsList) {
result.add((AbsoluteBendpoint) object);
@@ -202,4 +215,26 @@ public class ConnectionQuery {
}
return Options.newNone();
}
+
+ /**
+ * Return the constraint of the connection as list of RelativeBendpoint only
+ * if the constraint is a list of relative bendpoints.
+ *
+ * @return an optional list of {@link RelativeBendpoint}
+ */
+ public Option<List<RelativeBendpoint>> getRelativeBendpointsConstraint() {
+
+ Object cons = connection.getRoutingConstraint();
+ if (cons instanceof List) {
+ List<?> constraintsList = (List<?>) cons;
+ if (Iterators.all(constraintsList.iterator(), Predicates.instanceOf(RelativeBendpoint.class))) {
+ List<RelativeBendpoint> result = Lists.newLinkedList();
+ for (Object object : constraintsList) {
+ result.add((RelativeBendpoint) object);
+ }
+ return Options.newSome(result);
+ }
+ }
+ return Options.newNone();
+ }
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/EdgeQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/EdgeQuery.java
index ac62b5d281..2af1bef7c8 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/EdgeQuery.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/EdgeQuery.java
@@ -186,4 +186,40 @@ public class EdgeQuery {
}
return isEdgeTreeRoutingStyle;
}
+
+ /**
+ * Check if the edge has a rectilinear routing style.
+ *
+ * @return true if the edge has a rectilinear routing style.
+ */
+ public boolean isEdgeWithRectilinearRoutingStyle() {
+ boolean isEdgeRectilinearRoutingStyle = false;
+ for (Object style : edge.getStyles()) {
+ if (style instanceof ConnectorStyle) {
+ ConnectorStyle connectorStyle = (ConnectorStyle) style;
+ if (Routing.RECTILINEAR_LITERAL.getLiteral().equals(connectorStyle.getRouting().getLiteral())) {
+ isEdgeRectilinearRoutingStyle = true;
+ }
+ }
+ }
+ return isEdgeRectilinearRoutingStyle;
+ }
+
+ /**
+ * Check if the edge has an oblique routing style.
+ *
+ * @return true if the edge has an oblique routing style.
+ */
+ public boolean isEdgeWithObliqueRoutingStyle() {
+ boolean isEdgeObliqueRoutingStyle = false;
+ for (Object style : edge.getStyles()) {
+ if (style instanceof ConnectorStyle) {
+ ConnectorStyle connectorStyle = (ConnectorStyle) style;
+ if (Routing.MANUAL_LITERAL.getLiteral().equals(connectorStyle.getRouting().getLiteral())) {
+ isEdgeObliqueRoutingStyle = true;
+ }
+ }
+ }
+ return isEdgeObliqueRoutingStyle;
+ }
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusGraphicalNodeEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusGraphicalNodeEditPolicy.java
index fb7807604e..3a5e2704df 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusGraphicalNodeEditPolicy.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusGraphicalNodeEditPolicy.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
@@ -59,7 +60,6 @@ import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor;
-import org.eclipse.gmf.runtime.notation.ConnectorStyle;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.NotationPackage;
@@ -87,6 +87,7 @@ import org.eclipse.sirius.diagram.description.tool.ReconnectionKind;
import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory;
import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactoryProvider;
import org.eclipse.sirius.diagram.tools.internal.command.builders.EdgeCreationCommandBuilder;
+import org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery;
import org.eclipse.sirius.diagram.ui.business.api.view.SiriusLayoutDataManager;
import org.eclipse.sirius.diagram.ui.business.internal.command.SiriusSetConnectionAnchorsCommand;
import org.eclipse.sirius.diagram.ui.business.internal.command.TreeLayoutSetConnectionAnchorsCommand;
@@ -193,8 +194,14 @@ public class SiriusGraphicalNodeEditPolicy extends TreeGraphicalNodeEditPolicy {
} else if (applySpecificTreeLayout(request.getConnectionEditPart())) {
cmd = getReconnectSourceForTreeLayoutCommand(request);
} else {
- cmd = super.getReconnectSourceCommand(request);
+ ConnectionEditPartQuery cepq = new ConnectionEditPartQuery(request.getConnectionEditPart());
+ if (cepq.isEdgeWithObliqueRoutingStyle() || cepq.isEdgeWithRectilinearRoutingStyle()) {
+ cmd = getReconnectSourceOrTargetForObliqueOrRectilinearCommand(request, true);
+ } else {
+ cmd = super.getReconnectSourceCommand(request);
+ }
}
+
}
return cmd;
@@ -263,15 +270,71 @@ public class SiriusGraphicalNodeEditPolicy extends TreeGraphicalNodeEditPolicy {
result.add(getReconnectTargetCommandAfterTool(request));
cmd = result;
}
- } else if (applySpecificTreeLayout(request.getConnectionEditPart())) {
- cmd = getReconnectTargetForTreeLayoutCommand(request);
} else {
- cmd = super.getReconnectTargetCommand(request);
+ ConnectionEditPartQuery cepq = new ConnectionEditPartQuery(request.getConnectionEditPart());
+ if (cepq.isEdgeWithTreeRoutingStyle() && applySpecificTreeLayout(request.getConnectionEditPart())) {
+ cmd = getReconnectTargetForTreeLayoutCommand(request);
+ } else if (cepq.isEdgeWithObliqueRoutingStyle() || cepq.isEdgeWithRectilinearRoutingStyle()) {
+ cmd = getReconnectSourceOrTargetForObliqueOrRectilinearCommand(request, false);
+ } else {
+ cmd = super.getReconnectTargetCommand(request);
+ }
}
}
return cmd;
}
+ private Command getReconnectSourceOrTargetForObliqueOrRectilinearCommand(ReconnectRequest request, boolean source) {
+ INodeEditPart node = getConnectableEditPart();
+ INodeEditPart targetEP = getConnectionCompleteEditPart(request);
+ if (node == null || targetEP == null)
+ return null;
+
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+
+ ConnectionAnchor targetAnchor = getConnectionTargetAnchor(request);
+
+ // Creation of the command that set the connection end points (source
+ // and target)
+ SetConnectionEndsCommand sceCommand = new SetConnectionEndsCommand(editingDomain, StringStatics.BLANK);
+ sceCommand.setEdgeAdaptor(new EObjectAdapter((EObject) request.getConnectionEditPart().getModel()));
+ if (source) {
+ sceCommand.setNewSourceAdaptor(targetEP);
+ } else {
+ sceCommand.setNewTargetAdaptor(targetEP);
+ }
+ // Creation of the command that set the connection anchors (also source
+ // and target)
+ SetConnectionAnchorsCommand scaCommand = new SetConnectionAnchorsCommand(editingDomain, StringStatics.BLANK);
+ scaCommand.setEdgeAdaptor(new EObjectAdapter((EObject) request.getConnectionEditPart().getModel()));
+ if (source) {
+ scaCommand.setNewSourceTerminal(targetEP.mapConnectionAnchorToTerminal(targetAnchor));
+ } else {
+ scaCommand.setNewTargetTerminal(targetEP.mapConnectionAnchorToTerminal(targetAnchor));
+ }
+ // Both command are composed in a composite command
+ CompositeCommand cc = new CompositeCommand(DiagramUIMessages.Commands_SetConnectionEndsCommand_Target);
+ cc.compose(sceCommand);
+ cc.compose(scaCommand);
+ // Set points of Edge as they are graphically
+ Connection connection = (Connection) ((GraphicalEditPart) request.getConnectionEditPart()).getFigure();
+ Point tempSourceRefPoint = connection.getSourceAnchor().getReferencePoint();
+ connection.translateToRelative(tempSourceRefPoint);
+
+ Point tempTargetRefPoint = connection.getTargetAnchor().getReferencePoint();
+ connection.translateToRelative(tempTargetRefPoint);
+
+ PointList connectionPointList = connection.getPoints().getCopy();
+
+ // Set the connection bendpoints with a PointList using a command
+ SetConnectionBendpointsCommand sbbCommand = new SetConnectionBendpointsCommand(editingDomain);
+ sbbCommand.setEdgeAdapter(request.getConnectionEditPart());
+ sbbCommand.setNewPointList(connectionPointList, tempSourceRefPoint, tempTargetRefPoint);
+ cc.compose(sbbCommand);
+
+ return new ICommandProxy(cc);
+ }
+
/**
* Same behavior has super.getReconnectTargetCommand but using a custom
* SetConnectionAnchorsCommand because modification on reconnected edge are
@@ -988,7 +1051,7 @@ public class SiriusGraphicalNodeEditPolicy extends TreeGraphicalNodeEditPolicy {
*/
private boolean applySpecificTreeLayout(ConnectionEditPart connectionEditPart) {
boolean isLayoutComponent = false;
- if (isEdgeTreeRoutingStyle(connectionEditPart) && !isSourceOrTargetIsEdge(connectionEditPart)) {
+ if (!isSourceOrTargetIsEdge(connectionEditPart)) {
Diagram diagram = getDiagram(connectionEditPart);
if (diagram != null && diagram.getElement() instanceof DSemanticDiagram) {
DSemanticDiagram dSemanticDiagram = (DSemanticDiagram) diagram.getElement();
@@ -1012,22 +1075,6 @@ public class SiriusGraphicalNodeEditPolicy extends TreeGraphicalNodeEditPolicy {
return connectionEditPart.getSource() instanceof ConnectionEditPart || connectionEditPart.getTarget() instanceof ConnectionEditPart;
}
- private boolean isEdgeTreeRoutingStyle(ConnectionEditPart connectionEditPart) {
- boolean isEdgeTreeRoutingStyle = false;
- if (connectionEditPart.getModel() instanceof Edge) {
- Edge edge = (Edge) connectionEditPart.getModel();
- if (!edge.getStyles().isEmpty()) {
- if (edge.getStyles().get(0) instanceof ConnectorStyle) {
- ConnectorStyle connectorStyle = (ConnectorStyle) edge.getStyles().get(0);
- if (Routing.TREE_LITERAL.getLiteral().equals(connectorStyle.getRouting().getLiteral())) {
- isEdgeTreeRoutingStyle = true;
- }
- }
- }
- }
- return isEdgeTreeRoutingStyle;
- }
-
private Diagram getDiagram(ConnectionEditPart connectionEditPart) {
Diagram diagram = null;
if (connectionEditPart.getParent() instanceof DiagramRootEditPart) {
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/graphical/edit/policies/SiriusConnectionEndPointEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/graphical/edit/policies/SiriusConnectionEndPointEditPolicy.java
index 5f65bae147..7ebe5676c5 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/graphical/edit/policies/SiriusConnectionEndPointEditPolicy.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/graphical/edit/policies/SiriusConnectionEndPointEditPolicy.java
@@ -14,17 +14,25 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.draw2d.AbsoluteBendpoint;
+import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.ConnectionLocator;
import org.eclipse.draw2d.RelativeBendpoint;
+import org.eclipse.draw2d.XYAnchor;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
import org.eclipse.gef.requests.ReconnectRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+import org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery;
import org.eclipse.sirius.diagram.ui.business.api.query.ConnectionQuery;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramEdgeEditPart;
import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.handles.SiriusConnectionEndPointHandle;
import org.eclipse.sirius.ext.base.Option;
+import org.eclipse.sirius.ext.gmf.runtime.draw2d.ui.geometry.LineSegQuery;
+import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import com.google.common.collect.Lists;
@@ -67,47 +75,26 @@ public class SiriusConnectionEndPointEditPolicy extends ConnectionEndpointEditPo
/**
* {@inheritDoc} <BR>
- * Override this method to fix the points of the edge if it is on orthogonal
- * tree branch. Without this fix, a move of the source or the target has
- * incidence on all the points.
+ * Override this method to fix the points of the edge:
+ * <UL>
+ * <LI>if it is on orthogonal tree branch</LI>
+ * <LI>if connection has oblique or rectilinear router, to move only the
+ * points corresponding to the last segment.</LI>
+ * </UL>
+ * Without this fix, a move of the source or the target has incidence on all
+ * the points.
*
* @see org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy#showConnectionMoveFeedback(org.eclipse.gef.requests.ReconnectRequest)
*/
@Override
protected void showConnectionMoveFeedback(ReconnectRequest request) {
- boolean isOrthogonalTreeBranch = new ConnectionQuery(getConnection()).isOrthogonalTreeBranch(getConnection().getPoints());
ConnectionQuery connectionQuery = new ConnectionQuery(getConnection());
- if (isOrthogonalTreeBranch) {
- if (originalAnchor == null) {
- if (request.isMovingStartAnchor()) {
- originalAnchor = getConnection().getSourceAnchor();
- } else {
- originalAnchor = getConnection().getTargetAnchor();
- }
- originalPoints = Lists.newLinkedList();
- originalConstraint = getConnection().getRoutingConstraint();
- Option<List<RelativeBendpoint>> optionalRelativeBendpointsContraint = connectionQuery.getTreeRelativeBendpointsConstraint();
- if (optionalRelativeBendpointsContraint.some()) {
- for (RelativeBendpoint relativeBendpoint : optionalRelativeBendpointsContraint.get()) {
- originalPoints.add(relativeBendpoint.getLocation());
- }
- } else {
- Option<List<AbsoluteBendpoint>> optionalAsboluteBendpointsContraint = connectionQuery.getTreeAbsoluteBendpointsConstraint();
- if (optionalAsboluteBendpointsContraint.some()) {
- for (AbsoluteBendpoint absoluteBendpoint : optionalAsboluteBendpointsContraint.get()) {
- originalPoints.add(absoluteBendpoint.getLocation().getCopy());
- }
- }
- }
- if (originalPoints.isEmpty()) {
- // The constraint probably contains only 2 points (it's
- // possible just after an edge creation for example). So in
- // this case, we use the points of the edge
- for (int i = 0; i < getConnection().getPoints().size(); i++) {
- originalPoints.add(getConnection().getPoints().getPoint(i).getCopy());
- }
- }
- }
+ ConnectionEditPartQuery cepq = new ConnectionEditPartQuery((ConnectionEditPart) getHost());
+ boolean isOrthogonalTreeBranch = connectionQuery.isOrthogonalTreeBranch(getConnection().getPoints());
+ boolean isEdgeWithObliqueRoutingStyle = cepq.isEdgeWithObliqueRoutingStyle();
+ boolean isEdgeWithRectilinearRoutingStyle = cepq.isEdgeWithRectilinearRoutingStyle();
+ if (isOrthogonalTreeBranch || isEdgeWithObliqueRoutingStyle || isEdgeWithRectilinearRoutingStyle) {
+ preShowConnectionMoveFeedback(request);
} else if (originalAnchor != null) {
// We probably go out of the previous target node so erase the
// previous custom feedback
@@ -115,61 +102,215 @@ public class SiriusConnectionEndPointEditPolicy extends ConnectionEndpointEditPo
}
super.showConnectionMoveFeedback(request);
if (isOrthogonalTreeBranch) {
- // Change the constraints of the connection according to the new
- // anchor
- Option<List<RelativeBendpoint>> optionalRelativeBendpointsContraint = connectionQuery.getTreeRelativeBendpointsConstraint();
- Option<List<AbsoluteBendpoint>> optionalAsboluteBendpointsContraint = connectionQuery.getTreeAbsoluteBendpointsConstraint();
- List<Point> points = Lists.newArrayList();
- for (Point point : originalPoints) {
- points.add(point.getCopy());
- }
- Point newSourceRefPoint = getConnection().getSourceAnchor().getReferencePoint();
- getConnection().translateToRelative(newSourceRefPoint);
- Point newTargetRefPoint = getConnection().getTargetAnchor().getReferencePoint();
- getConnection().translateToRelative(newTargetRefPoint);
+ postShowConnectionMoveFeedbackForOrthogonalTreeBranch(request);
+ } else if (isEdgeWithObliqueRoutingStyle || isEdgeWithRectilinearRoutingStyle) {
+ postShowConnectionMoveFeedbackForObliqueOrRectilinearConnection(request);
+ }
+
+ }
+
+ /**
+ * Store the original anchor (source or target), routing constraint and
+ * points.
+ *
+ * @param request
+ * the reconnect request
+ */
+ private void preShowConnectionMoveFeedback(ReconnectRequest request) {
+ if (originalAnchor == null) {
if (request.isMovingStartAnchor()) {
- // Compute the x delta
- int deltaX = points.get(0).x - newSourceRefPoint.x;
- // The first and the second points must be shift on the x
- // coordinate
- points.get(0).translate(deltaX, 0);
- points.get(1).translate(deltaX, 0);
+ originalAnchor = getConnection().getSourceAnchor();
} else {
- // Compute the x delta
- int deltaX = newTargetRefPoint.x - points.get(3).x;
- // The third and the last points must be shift on the x
- // coordinate
- points.get(2).translate(deltaX, 0);
- points.get(3).translate(deltaX, 0);
+ originalAnchor = getConnection().getTargetAnchor();
}
- if (optionalRelativeBendpointsContraint.some() || optionalAsboluteBendpointsContraint.some()) {
- if (optionalRelativeBendpointsContraint.some()) {
- for (int i = 0; i < points.size(); i++) {
- Dimension s = points.get(i).getDifference(newSourceRefPoint);
- Dimension t = points.get(i).getDifference(newTargetRefPoint);
- optionalRelativeBendpointsContraint.get().get(i).setRelativeDimensions(s, t);
- }
- getConnection().setRoutingConstraint(optionalRelativeBendpointsContraint.get());
- } else {
- for (int i = 0; i < points.size(); i++) {
- optionalAsboluteBendpointsContraint.get().get(i).setLocation(points.get(i));
+ originalPoints = Lists.newLinkedList();
+ originalConstraint = getConnection().getRoutingConstraint();
+ ConnectionQuery connectionQuery = new ConnectionQuery(getConnection());
+ Option<List<RelativeBendpoint>> optionalRelativeBendpointsContraint = connectionQuery.getTreeRelativeBendpointsConstraint();
+ if (optionalRelativeBendpointsContraint.some()) {
+ for (RelativeBendpoint relativeBendpoint : optionalRelativeBendpointsContraint.get()) {
+ originalPoints.add(relativeBendpoint.getLocation());
+ }
+ } else {
+ Option<List<AbsoluteBendpoint>> optionalAsboluteBendpointsContraint = connectionQuery.getTreeAbsoluteBendpointsConstraint();
+ if (optionalAsboluteBendpointsContraint.some()) {
+ for (AbsoluteBendpoint absoluteBendpoint : optionalAsboluteBendpointsContraint.get()) {
+ originalPoints.add(absoluteBendpoint.getLocation().getCopy());
}
- getConnection().setRoutingConstraint(optionalAsboluteBendpointsContraint.get());
}
+ }
+ if (originalPoints.isEmpty()) {
+ // The constraint probably contains only 2 points (it's
+ // possible just after an edge creation for example). So in
+ // this case, we use the points of the edge
+ for (int i = 0; i < getConnection().getPoints().size(); i++) {
+ originalPoints.add(getConnection().getPoints().getPoint(i).getCopy());
+ }
+ }
+ }
+ }
+
+ /**
+ * Change the routing constraint of the Connection according to a change of
+ * the first vertical segment or of the last vertical segment.
+ *
+ * @param request
+ * the reconnect request
+ */
+ private void postShowConnectionMoveFeedbackForOrthogonalTreeBranch(ReconnectRequest request) {
+ // Change the constraints of the connection according to the new anchor
+ // (move the vertical first segment or the vertical last segment).
+ List<Point> points = Lists.newArrayList();
+ for (Point point : originalPoints) {
+ points.add(point.getCopy());
+ }
+ Point newSourceRefPoint = getConnection().getSourceAnchor().getReferencePoint();
+ getConnection().translateToRelative(newSourceRefPoint);
+ Point newTargetRefPoint = getConnection().getTargetAnchor().getReferencePoint();
+ getConnection().translateToRelative(newTargetRefPoint);
+ if (request.isMovingStartAnchor()) {
+ // Compute the x delta
+ int deltaX = points.get(0).x - newSourceRefPoint.x;
+ // The first and the second points must be shift on the x
+ // coordinate
+ points.get(0).translate(deltaX, 0);
+ points.get(1).translate(deltaX, 0);
+ } else {
+ // Compute the x delta
+ int deltaX = newTargetRefPoint.x - points.get(3).x;
+ // The third and the last points must be shift on the x
+ // coordinate
+ points.get(2).translate(deltaX, 0);
+ points.get(3).translate(deltaX, 0);
+ }
+ // Change the routing constraint (bendpoints constraints) of the
+ // Connection according to this new points.
+ changeRoutingConstraint(points, newSourceRefPoint, newTargetRefPoint);
+ }
+
+ /**
+ * Change the routing constraint (bendpoints constraints) of the
+ * {@link Connection} according to this new points.
+ *
+ * @param points
+ * List of points to follow
+ * @param sourceRefPoint
+ * Source reference point
+ * @param targetRefPoint
+ * Target reference point
+ */
+ private void changeRoutingConstraint(List<Point> points, Point sourceRefPoint, Point targetRefPoint) {
+ ConnectionQuery connectionQuery = new ConnectionQuery(getConnection());
+ Option<List<RelativeBendpoint>> optionalRelativeBendpointsContraint = connectionQuery.getTreeRelativeBendpointsConstraint();
+ Option<List<AbsoluteBendpoint>> optionalAsboluteBendpointsContraint = connectionQuery.getTreeAbsoluteBendpointsConstraint();
+ if (optionalRelativeBendpointsContraint.some() || optionalAsboluteBendpointsContraint.some()) {
+ if (optionalRelativeBendpointsContraint.some()) {
+ for (int i = 0; i < points.size(); i++) {
+ Dimension s = points.get(i).getDifference(sourceRefPoint);
+ Dimension t = points.get(i).getDifference(targetRefPoint);
+ optionalRelativeBendpointsContraint.get().get(i).setRelativeDimensions(s, t);
+ }
+ getConnection().setRoutingConstraint(optionalRelativeBendpointsContraint.get());
} else {
- List<RelativeBendpoint> newConstraint = Lists.newLinkedList();
for (int i = 0; i < points.size(); i++) {
- Dimension s = points.get(i).getDifference(newSourceRefPoint);
- Dimension t = points.get(i).getDifference(newTargetRefPoint);
- RelativeBendpoint rb = new RelativeBendpoint(getConnection());
- rb.setRelativeDimensions(s, t);
- rb.setWeight(i / ((float) points.size() - 1));
- newConstraint.add(rb);
+ optionalAsboluteBendpointsContraint.get().get(i).setLocation(points.get(i));
+ }
+ getConnection().setRoutingConstraint(optionalAsboluteBendpointsContraint.get());
+ }
+ } else {
+ List<RelativeBendpoint> newConstraint = Lists.newLinkedList();
+ for (int i = 0; i < points.size(); i++) {
+ Dimension s = points.get(i).getDifference(sourceRefPoint);
+ Dimension t = points.get(i).getDifference(targetRefPoint);
+ RelativeBendpoint rb = new RelativeBendpoint(getConnection());
+ rb.setRelativeDimensions(s, t);
+ rb.setWeight(i / ((float) points.size() - 1));
+ newConstraint.add(rb);
+ }
+ getConnection().setRoutingConstraint(newConstraint);
+ }
+ }
+
+ /**
+ * Change the routing constraint of the Connection according to a change of
+ * the first or of the last segment.
+ *
+ * @param request
+ * the reconnect request
+ */
+ private void postShowConnectionMoveFeedbackForObliqueOrRectilinearConnection(ReconnectRequest request) {
+ // Compute the move delta
+ PrecisionPoint moveDelta;
+ List<Point> points = Lists.newArrayList();
+ for (Point point : originalPoints) {
+ points.add(point.getCopy());
+ }
+ Connection connection = getConnection();
+ ConnectionEditPart connectionEditPart = (ConnectionEditPart) getHost();
+
+ Point newSourceRefPoint = connection.getSourceAnchor().getReferencePoint();
+ connection.translateToRelative(newSourceRefPoint);
+ Point newTargetRefPoint = connection.getTargetAnchor().getReferencePoint();
+ connection.translateToRelative(newTargetRefPoint);
+
+ PrecisionPoint scrollSize = new PrecisionPoint(GraphicalHelper.getScrollSize(connectionEditPart));
+ GraphicalHelper.applyInverseZoomOnPoint(connectionEditPart, scrollSize);
+
+ // If the source or target is disconnected, the anchor is changed from a
+ // SlidableAnchor to a XYAnchor. The location computation is different
+ // and we need to introduce scroll and zoom. Otherwise the dragged
+ // extremity will not be under the mouse.
+ if (!request.isMovingStartAnchor() && !connectionEditPart.getTarget().equals(request.getTarget()) && connection.getTargetAnchor() instanceof XYAnchor) {
+ ((XYAnchor) connection.getTargetAnchor()).setLocation(GraphicalHelper.applyZoomOnPoint(connectionEditPart, newTargetRefPoint.getTranslated(-scrollSize.x, -scrollSize.y)));
+ newTargetRefPoint = connection.getTargetAnchor().getReferencePoint().getCopy();
+ connection.translateToRelative(newTargetRefPoint);
+ } else if (request.isMovingStartAnchor() && !connectionEditPart.getSource().equals(request.getTarget()) && connection.getSourceAnchor() instanceof XYAnchor) {
+ ((XYAnchor) connection.getSourceAnchor()).setLocation(GraphicalHelper.applyZoomOnPoint(connectionEditPart, newSourceRefPoint.getTranslated(-scrollSize.x, -scrollSize.y)));
+ newSourceRefPoint = connection.getSourceAnchor().getReferencePoint().getCopy();
+ connection.translateToRelative(newSourceRefPoint);
+ }
+
+ if (request.isMovingStartAnchor()) {
+ moveDelta = new PrecisionPoint(points.get(0).x - newSourceRefPoint.x, points.get(0).y - newSourceRefPoint.y);
+ } else {
+ moveDelta = new PrecisionPoint(newTargetRefPoint.x - points.get(points.size() - 1).x, newTargetRefPoint.y - points.get(points.size() - 1).y);
+ }
+ // Change the constraints of the connection according to the new anchor
+ // (move the first or the last segment).
+ if (request.isMovingStartAnchor()) {
+ moveDelta.negate();
+ LineSeg firstSegment = new LineSeg(points.get(0), points.get(1));
+ LineSegQuery lineSegQuery = new LineSegQuery(firstSegment);
+ // Change the first point according to the move
+ points.set(0, points.get(0).getTranslated(moveDelta));
+ if (new ConnectionEditPartQuery(connectionEditPart).isEdgeWithRectilinearRoutingStyle()) {
+ // and also change the second point only if the edge has a
+ // rectilinear routing constraint.
+ if (lineSegQuery.isHorizontal()) {
+ points.set(1, points.get(1).getTranslated(0, moveDelta.preciseY()));
+ } else {
+ points.set(1, points.get(1).getTranslated(moveDelta.preciseX(), 0));
+ }
+ }
+ } else {
+ LineSeg lastSegment = new LineSeg(points.get(points.size() - 2), points.get(points.size() - 1));
+ LineSegQuery lineSegQuery = new LineSegQuery(lastSegment);
+ // Change the last point according to the move
+ points.set(points.size() - 1, points.get(points.size() - 1).getTranslated(moveDelta));
+ // and also change the penultimate point only if the edge has a
+ // rectilinear routing constraint.
+ if (new ConnectionEditPartQuery(connectionEditPart).isEdgeWithRectilinearRoutingStyle()) {
+ if (lineSegQuery.isHorizontal()) {
+ points.set(points.size() - 2, points.get(points.size() - 2).getTranslated(0, moveDelta.preciseY()));
+ } else {
+ points.set(points.size() - 2, points.get(points.size() - 2).getTranslated(moveDelta.preciseX(), 0));
}
- getConnection().setRoutingConstraint(newConstraint);
}
}
+ // Change the routing constraint (bendpoints constraints) of the
+ // Connection according to this new points.
+ changeRoutingConstraint(points, newSourceRefPoint, newTargetRefPoint);
}
/**
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
index 7ffa10f630..7314c3cf63 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
+++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.html
@@ -40,7 +40,8 @@
<h2 id="sirius2.0.0">Changes in Sirius 2.0.0 (from Sirius 1.0.0)</h2>
<h3 id="UserVisibleChanges">User-Visible Changes</h3>
<ul>
- <li>It is now possible to select element that intersects the selection rectangle and not that is completely contained by the selection rectangle. This new behavior is enabled when user selects elements from right to left. The normal mode (previous mode) remains when the user selects elements from left to right. </li>
+ <li>It is now possible to select element that intersects the selection rectangle and not that is completely contained by the selection rectangle. This new behavior is enabled when user selects elements from right to left. The normal mode (previous mode) remains when the user selects elements from left to right.</li>
+ <li>The edges appearance is now kept, as much as possible, when one of its extremity is moved. A move of an extremity should move only the closest segment of the edge.</li>
</ul>
<h3 id="APIChanges">API Changes</h3>
<h4 id="Changesinorg.eclipse.sirius">Changes in
@@ -76,6 +77,24 @@
<code>additionalFiguresForConflictDetection</code> has been added to several methods of
<code>org.eclipse.sirius.diagram.ui.tools.api.figure.locator.DBorderItemLocator</code>. This parameter is used in case of simultaneous border nodes moves. This list corresponds to the already known border nodes feedbacks. They are used to detect conflicts with other moved nodes.
</li>
+ <li>
+ <code>org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery</code> now provides two new methods
+ <code>isEdgeWithRectilinearRoutingStyle()</code> and
+ <code>isEdgeWithObliqueRoutingStyle()</code> that respectively checks if an edge has a rectilinear routing style or an oblique routing style.
+ </li>
+ <li>
+ <code>org.eclipse.sirius.diagram.ui.business.api.query.ConnectionQuery</code> now provides two new methods
+ <code>getAbsoluteBendpointsConstraint()</code> and
+ <code>getRelativeBendpointsConstraint()</code> that returns an option of list of
+ <code>Bendpoint</code> of a connection whether they are respectively
+ <code>AbsoluteBendpoint</code> or
+ <code>RelatveBendpoint</code>.
+ </li>
+ <li>
+ <code>org.eclipse.sirius.diagram.ui.business.api.query.EdgeQuery</code> also provides two new methods
+ <code>isEdgeWithRectilinearRoutingStyle()</code> and
+ <code>isEdgeWithObliqueRoutingStyle()</code> that respectively checks if an edge has a rectilinear routing style or an oblique routing style.
+ </li>
</ul>
<h4 id="Changesinorg.eclipse.sirius.ext.gmf.runtime">Changes in
<code>org.eclipse.sirius.ext.gmf.runtime</code>
@@ -87,12 +106,14 @@
<li>
<code>applyZoomOnPoint(IGraphicalEditPart, Point)</code>: Apply the current zoom (of
<code>IGraphicalEditPart</code>'s diagram) on the
- <code>Point</code>.
+ <code>Point</code> and return the
+ <code>Point</code> for convenience.
</li>
<li>
<code>applyInverseZoomOnPoint(IGraphicalEditPart, Point)</code>: Apply the inverse of the current zoom (of
<code>IGraphicalEditPart</code>'s diagram) on the
- <code>Point</code>.
+ <code>Point</code> and return the
+ <code>Point</code> for convenience.
</li>
<li>
<code>appliedZoomOnRelativePoint(IGraphicalEditPart, Point)</code> is now deprecated. Use
diff --git a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
index dd5f01d299..5838b7a78d 100644
--- a/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
+++ b/plugins/org.eclipse.sirius.doc/doc/Release Notes.textile
@@ -8,7 +8,8 @@ h2(#sirius2.0.0). Changes in Sirius 2.0.0 (from Sirius 1.0.0)
h3. User-Visible Changes
-* It is now possible to select element that intersects the selection rectangle and not that is completely contained by the selection rectangle. This new behavior is enabled when user selects elements from right to left. The normal mode (previous mode) remains when the user selects elements from left to right.
+* It is now possible to select element that intersects the selection rectangle and not that is completely contained by the selection rectangle. This new behavior is enabled when user selects elements from right to left. The normal mode (previous mode) remains when the user selects elements from left to right.
+* The edges appearance is now kept, as much as possible, when one of its extremity is moved. A move of an extremity should move only the closest segment of the edge.
h3. API Changes
@@ -26,12 +27,15 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@
* The method @org.eclipse.sirius.diagram.ui.business.internal.query.DNodeContainerQuery.getDefaultDimension()@ has been added to compute the default size of a DNodeContainer.
* The parameter @additionalFiguresForConflictDetection@ has been added to several methods of @org.eclipse.sirius.diagram.ui.tools.api.figure.locator.DBorderItemLocator@. This parameter is used in case of simultaneous border nodes moves. This list corresponds to the already known border nodes feedbacks. They are used to detect conflicts with other moved nodes.
+* @org.eclipse.sirius.diagram.ui.business.api.query.ConnectionEditPartQuery@ now provides two new methods @isEdgeWithRectilinearRoutingStyle()@ and @isEdgeWithObliqueRoutingStyle()@ that respectively checks if an edge has a rectilinear routing style or an oblique routing style.
+* @org.eclipse.sirius.diagram.ui.business.api.query.ConnectionQuery@ now provides two new methods @getAbsoluteBendpointsConstraint()@ and @getRelativeBendpointsConstraint()@ that returns an option of list of @Bendpoint@ of a connection whether they are respectively @AbsoluteBendpoint@ or @RelatveBendpoint@.
+* @org.eclipse.sirius.diagram.ui.business.api.query.EdgeQuery@ also provides two new methods @isEdgeWithRectilinearRoutingStyle()@ and @isEdgeWithObliqueRoutingStyle()@ that respectively checks if an edge has a rectilinear routing style or an oblique routing style.
h4. Changes in @org.eclipse.sirius.ext.gmf.runtime@
* Several utilities have been added in @org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper@:
-** @applyZoomOnPoint(IGraphicalEditPart, Point)@: Apply the current zoom (of @IGraphicalEditPart@'s diagram) on the @Point@.
-** @applyInverseZoomOnPoint(IGraphicalEditPart, Point)@: Apply the inverse of the current zoom (of @IGraphicalEditPart@'s diagram) on the @Point@.
+** @applyZoomOnPoint(IGraphicalEditPart, Point)@: Apply the current zoom (of @IGraphicalEditPart@'s diagram) on the @Point@ and return the @Point@ for convenience.
+** @applyInverseZoomOnPoint(IGraphicalEditPart, Point)@: Apply the inverse of the current zoom (of @IGraphicalEditPart@'s diagram) on the @Point@ and return the @Point@ for convenience.
** @appliedZoomOnRelativePoint(IGraphicalEditPart, Point)@ is now deprecated. Use @applyZoomOnPoint(IGraphicalEditPart, Point)@ instead.
** @getAnchorPoint(IGraphicalEditPart parent, Anchor anchor)@: Get the @Point@ (absolute draw2d coordinates) corresponding to this @Anchor@.
** @getAnchorPoint(IGraphicalEditPart parent, IdentityAnchor anchor)@: Get the @Point@ (absolute draw2d coordinates) corresponding to this @IdentityAnchor@.
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
index 25fe94e58b..7658e77aa4 100644
--- a/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/META-INF/MANIFEST.MF
@@ -26,4 +26,5 @@ Import-Package: com.google.common.base;version="10.0.1",
org.eclipse.swt.events,
org.eclipse.swt.widgets
Export-Package: org.eclipse.sirius.ext.gmf.runtime.diagram.ui.tools;version="2.0.0",
+ org.eclipse.sirius.ext.gmf.runtime.draw2d.ui.geometry,
org.eclipse.sirius.ext.gmf.runtime.editparts;version="2.0.0"
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/draw2d/ui/geometry/LineSegQuery.java b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/draw2d/ui/geometry/LineSegQuery.java
new file mode 100644
index 0000000000..449b0dbd92
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/draw2d/ui/geometry/LineSegQuery.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2014 THALES GLOBAL SERVICES.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.ext.gmf.runtime.draw2d.ui.geometry;
+
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+
+/**
+ * A class aggregating for queries on {@link LineSeg} elements.
+ *
+ * @author <a href="mailto:steve.monnier@obeo.fr">Steve Monnier</a>
+ */
+public class LineSegQuery {
+
+ private LineSeg lineseg;
+
+ /**
+ * Create a new query.
+ *
+ * @param lineseg
+ * the {@link LineSeg} used by the query.
+ */
+ public LineSegQuery(LineSeg lineseg) {
+ super();
+ this.lineseg = lineseg;
+ }
+
+ /**
+ * Determines if this is a horizontal segment (or at least more horizontal
+ * than vertical).
+ *
+ * @return <code>boolean</code> <code>true</code> if horizontal,
+ * <code>false</code> otherwise.
+ */
+ public boolean isHorizontal() {
+ boolean isHorizontal = lineseg.isHorizontal();
+ boolean isVertical = lineseg.isVertical();
+ if (!isHorizontal && !isVertical) {
+ // We are in case where the bendpoints does not represent
+ // exactly a rectilinear edge
+ int xDifference = lineseg.getOrigin().x - lineseg.getTerminus().x;
+ int yDifference = lineseg.getOrigin().y - lineseg.getTerminus().y;
+ if (xDifference < 0 && yDifference < 0) {
+ isHorizontal = xDifference < yDifference;
+ } else {
+ isHorizontal = xDifference > yDifference;
+ }
+ }
+ return isHorizontal;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
index 95c0b21c5d..21d131f118 100644
--- a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
+++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java
@@ -90,7 +90,7 @@ public final class GraphicalHelper {
}
/**
- * Applied zoom on a point.<BR>
+ * Applies zoom on a point and returns this point for convenience.<BR>
* For example:
* <UL>
* <LI>For a zoom of 200%, the result of this method for the point (100,
@@ -103,18 +103,20 @@ public final class GraphicalHelper {
* the current part
* @param point
* a point
+ * @return <code>point</code> for convenience
*/
- public static void applyZoomOnPoint(IGraphicalEditPart part, Point point) {
+ public static Point applyZoomOnPoint(IGraphicalEditPart part, Point point) {
double zoom = getZoom(part);
if (point instanceof PrecisionPoint) {
((PrecisionPoint) point).setPreciseLocation(point.preciseX() * zoom, point.preciseY() * zoom);
} else {
point.setLocation((int) (point.x * zoom), (int) (point.y * zoom));
}
+ return point;
}
/**
- * Apply inverse zoom on a point.<BR>
+ * Applies inverse zoom on a point and returns this point for convenience.<BR>
* For example:
* <UL>
* <LI>For a zoom of 200%, the result of this method for the point (100,
@@ -127,14 +129,16 @@ public final class GraphicalHelper {
* the current part
* @param point
* a point
+ * @return <code>point</code> for convenience
*/
- public static void applyInverseZoomOnPoint(IGraphicalEditPart part, Point point) {
+ public static Point applyInverseZoomOnPoint(IGraphicalEditPart part, Point point) {
double zoom = getZoom(part);
if (point instanceof PrecisionPoint) {
((PrecisionPoint) point).setPreciseLocation(point.preciseX() / zoom, point.preciseY() / zoom);
} else {
point.setLocation((int) (point.x / zoom), (int) (point.y / zoom));
}
+ return point;
}
/**

Back to the top