Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgolubev2014-11-12 04:00:17 +0000
committermgolubev2014-11-12 04:00:17 +0000
commit6c6a703b82e35849da1a3ba753eb4c9043bcb625 (patch)
tree36a37d785a778bd0f9e0ac619dbb371ff2139bd1
parentc40b89941ba2a5c702cae4a188a2fab837857007 (diff)
downloadorg.eclipse.papyrus-6c6a703b82e35849da1a3ba753eb4c9043bcb625.tar.gz
org.eclipse.papyrus-6c6a703b82e35849da1a3ba753eb4c9043bcb625.tar.xz
org.eclipse.papyrus-6c6a703b82e35849da1a3ba753eb4c9043bcb625.zip
Fixes 443229: Move anchors when user explicitly operates on bendpoints,
move bendpoints when user operates on anchors Change-Id: I3fc4693e81023075ffe0b0b33da1db989ea67c9e Signed-off-by: mgolubev <golubev@montages.com>
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/LinksLFConnectionBendpointEditPolicy.java25
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/HintedOrthogonalRouter.java60
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java233
3 files changed, 210 insertions, 108 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/LinksLFConnectionBendpointEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/LinksLFConnectionBendpointEditPolicy.java
index 8692ec28374..1702699c850 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/LinksLFConnectionBendpointEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/editpolicies/LinksLFConnectionBendpointEditPolicy.java
@@ -5,6 +5,7 @@ import java.util.List;
import org.eclipse.draw2d.AbsoluteBendpoint;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
@@ -12,9 +13,11 @@ import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.SnapToHelper;
import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.BendpointRequest;
import org.eclipse.gef.requests.LocationRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
@@ -28,6 +31,8 @@ import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.LineMode;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.papyrus.infra.gmfdiag.common.linklf.editpolicies.notformars.ConnectionBendpointEditPolicy3;
+import org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.HintedOrthogonalRouter;
+import org.eclipse.papyrus.infra.gmfdiag.common.linklf.router.HintedOrthogonalRouter.EndRoutingHint;
public class LinksLFConnectionBendpointEditPolicy extends ConnectionBendpointEditPolicy3 {
@@ -211,4 +216,24 @@ public class LinksLFConnectionBendpointEditPolicy extends ConnectionBendpointEdi
point.setLocation(snapped);
}
+ @Override
+ public void showSourceFeedback(Request request) {
+ ConnectionRouter router = getConnection().getConnectionRouter();
+ if (router instanceof HintedOrthogonalRouter) {
+ HintedOrthogonalRouter routerImpl = (HintedOrthogonalRouter) router;
+ EndRoutingHint hint = request instanceof BendpointRequest ? EndRoutingHint.FixBendpointMoveAnchor : EndRoutingHint.FixAnchorMoveBendpoint;
+ routerImpl.setEndRoutingHint(getConnection(), hint);
+ }
+ super.showSourceFeedback(request);
+ }
+
+ @Override
+ public void eraseSourceFeedback(Request request) {
+ ConnectionRouter router = getConnection().getConnectionRouter();
+ if (router instanceof HintedOrthogonalRouter) {
+ ((HintedOrthogonalRouter) router).setEndRoutingHint(getConnection(), null);
+ }
+ super.eraseSourceFeedback(request);
+ }
+
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/HintedOrthogonalRouter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/HintedOrthogonalRouter.java
new file mode 100644
index 00000000000..0bdd53bd9b4
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/HintedOrthogonalRouter.java
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * 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.linklf.router;
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.OrthogonalRouter;
+import org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter;
+
+/**
+ * When connection anchor and first/last bendpoint are not aligned vertically / horizontally,
+ * the {@link OrthogonalRouter} has to decide whether the first / last segment of link will
+ * go:
+ * <ul>
+ * <li>from bendpoint to some point different to anchor</li>
+ * <li>from anchor to some point different to bendpoint</li>
+ * </ul>
+ * The default {@link RectilinearRouter} always prefers the first choice.
+ * <p>
+ * This router extends the {@link OrthogonalRouter} with ability to specify the
+ * hint for this choice externally, on the per-connection basis.
+ */
+public interface HintedOrthogonalRouter extends OrthogonalRouter {
+
+ /**
+ * Specifies 2 possible strategy for the routing of the first / last link segment.
+ * <ul>
+ * <li> {@link EndRoutingHint#FixBendpointMoveAnchor} is default behavior.
+ * It will route the segment from bendpoint to some point different to anchor</li>
+ * <li> {@link EndRoutingHint#FixAnchorMoveBendpoint} will route from anchor
+ * to some point different to bendpoint</li>
+ * </ul>
+ */
+ public static enum EndRoutingHint {
+ FixAnchorMoveBendpoint, //
+ FixBendpointMoveAnchor;
+ }
+
+ /**
+ * Returns default strategy for this router which will be used when hint is not specified.
+ */
+ public EndRoutingHint getDefaultEndRoutingStrategy();
+
+ /**
+ * Asks router to use specified strategy for given connection.
+ * @param hint desired hint or <code>null</code> to revert connection back to default strategy.
+ */
+ public void setEndRoutingHint(Connection conn, EndRoutingHint hint);
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java
index 4980be8b6d0..aa41ed08786 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/linklf/router/SnapToGridRectilinearRouter.java
@@ -1,6 +1,7 @@
package org.eclipse.papyrus.infra.gmfdiag.common.linklf.router;
-import java.util.Arrays;
+import java.util.IdentityHashMap;
+import java.util.Map;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionAnchor;
@@ -13,7 +14,6 @@ import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.SnapToGrid;
-import org.eclipse.gmf.runtime.diagram.ui.internal.commands.MakeDiagramUnmodifiableCommand;
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.draw2d.ui.figures.OrthogonalConnectionAnchor;
import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
@@ -23,14 +23,20 @@ import org.eclipse.papyrus.infra.gmfdiag.common.linklf.DiagramGridSpec;
import org.eclipse.papyrus.infra.gmfdiag.common.linklf.SlidableSnapToGridAnchor;
@SuppressWarnings("restriction")
-public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
+public class SnapToGridRectilinearRouter extends RectilinearRouter2 implements HintedOrthogonalRouter {
+
+ private final Map<Connection, EndRoutingHint> myEndRoutingHints = new IdentityHashMap<Connection, EndRoutingHint>();
private DiagramGridSpec myGridSpec;
-
+
public SnapToGridRectilinearRouter() {
super();
}
+ public EndRoutingHint getDefaultEndRoutingStrategy() {
+ return EndRoutingHint.FixAnchorMoveBendpoint;
+ }
+
public void setEditPartViewer(EditPartViewer viewer) {
if (myGridSpec != null && myGridSpec.getViewer() == viewer) {
return;
@@ -41,11 +47,22 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
myGridSpec = viewer == null ? null : new DiagramGridSpec(viewer);
}
+ public void setEndRoutingHint(Connection conn, EndRoutingHint hint) {
+ if (hint == getDefaultEndRoutingStrategy()) {
+ hint = null;
+ }
+ if (hint == null) {
+ myEndRoutingHints.remove(conn);
+ } else {
+ myEndRoutingHints.put(conn, hint);
+ }
+ }
+
@Override
public void routeLine(Connection conn, int nestedRoutingDepth, PointList newLine) {
super.routeLine(conn, nestedRoutingDepth, newLine);
}
-
+
/**
* @see org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter#resetEndPointsToEdge(org.eclipse.draw2d.Connection, org.eclipse.draw2d.geometry.PointList)
*
@@ -59,79 +76,79 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
* If the connection doesn't have a shape as a source or target we'll
* let the oblique router to do the work. The connection doesn't need to
* be rectilinear at this point. There is no support for making a rectilinear
- * connection for which one of the ends is not connected to anything.
+ * connection for which one of the ends is not connected to anything.
*/
super.resetEndPointsToEdge(conn, line);
return;
}
- PrecisionRectangle source = sourceBoundsRelativeToConnection2(conn);
- PrecisionRectangle target = targetBoundsRelativeToConnection2(conn);
- int offSourceDirection = PositionConstants.NONE;
- int offTargetDirection = PositionConstants.NONE;
+ PrecisionRectangle source = sourceBoundsRelativeToConnection2(conn);
+ PrecisionRectangle target = targetBoundsRelativeToConnection2(conn);
+ int offSourceDirection = PositionConstants.NONE;
+ int offTargetDirection = PositionConstants.NONE;
int sourceAnchorRelativeLocation = PositionConstants.NONE;
int targetAnchorRelativeLocation = PositionConstants.NONE;
-
+
SnapToGrid snapper = getSnapper();
-
- if (line.size() == 0) {
- /*
- * No valid bend points. We can't call super, so we will do the work from RouterHelper ourselves
- */
- PrecisionPoint sourceReference = new PrecisionPoint(conn.getTargetAnchor().getReferencePoint());
- PrecisionPoint sourceAnchorPoint = new PrecisionPoint(conn.getSourceAnchor().getLocation(sourceReference));
- PrecisionPoint targetAnchorPoint = new PrecisionPoint(conn.getTargetAnchor().getLocation(sourceAnchorPoint));
- conn.translateToRelative(sourceAnchorPoint);
- conn.translateToRelative(targetAnchorPoint);
-
- line.addPoint(sourceAnchorPoint);
- line.addPoint(targetAnchorPoint);
-
- sourceAnchorRelativeLocation = getAnchorOffRectangleDirection2(sourceAnchorPoint, source);
- targetAnchorRelativeLocation = getAnchorOffRectangleDirection2(targetAnchorPoint, target);
-
- insertPointsProducingNotAlignedRectilinearSegments(conn, line, sourceAnchorRelativeLocation, targetAnchorRelativeLocation, snapper);
-
- offSourceDirection = getOffShapeDirection2(sourceAnchorRelativeLocation);
- offTargetDirection = getOffShapeDirection2(targetAnchorRelativeLocation);
- } else {
- Point start = line.getFirstPoint();
- Point end = line.getLastPoint();
- if (conn.getSourceAnchor() instanceof OrthogonalConnectionAnchor) {
- addSegmentToSourceAnchor(line, conn, (OrthogonalConnectionAnchor)conn.getSourceAnchor());
- } else {
- /*
- * If anchor is not supporting orthogonal connections we'll use the oblique connection
- * anchors and then convert it to rectilinear.
- */
- PrecisionPoint reference = new PrecisionPoint(start);
- conn.getSourceAnchor().getOwner().translateToAbsolute(reference);
- PrecisionPoint anchorLocation = new PrecisionPoint(conn.getSourceAnchor().getLocation(reference));
+
+ if (line.size() == 0) {
+ /*
+ * No valid bend points. We can't call super, so we will do the work from RouterHelper ourselves
+ */
+ PrecisionPoint sourceReference = new PrecisionPoint(conn.getTargetAnchor().getReferencePoint());
+ PrecisionPoint sourceAnchorPoint = new PrecisionPoint(conn.getSourceAnchor().getLocation(sourceReference));
+ PrecisionPoint targetAnchorPoint = new PrecisionPoint(conn.getTargetAnchor().getLocation(sourceAnchorPoint));
+ conn.translateToRelative(sourceAnchorPoint);
+ conn.translateToRelative(targetAnchorPoint);
+
+ line.addPoint(sourceAnchorPoint);
+ line.addPoint(targetAnchorPoint);
+
+ sourceAnchorRelativeLocation = getAnchorOffRectangleDirection2(sourceAnchorPoint, source);
+ targetAnchorRelativeLocation = getAnchorOffRectangleDirection2(targetAnchorPoint, target);
+
+ insertPointsProducingNotAlignedRectilinearSegments(conn, line, sourceAnchorRelativeLocation, targetAnchorRelativeLocation, snapper);
+
+ offSourceDirection = getOffShapeDirection2(sourceAnchorRelativeLocation);
+ offTargetDirection = getOffShapeDirection2(targetAnchorRelativeLocation);
+ } else {
+ Point start = line.getFirstPoint();
+ Point end = line.getLastPoint();
+ if (conn.getSourceAnchor() instanceof OrthogonalConnectionAnchor) {
+ addSegmentToSourceAnchor(line, conn, (OrthogonalConnectionAnchor) conn.getSourceAnchor());
+ } else {
+ /*
+ * If anchor is not supporting orthogonal connections we'll use the oblique connection
+ * anchors and then convert it to rectilinear.
+ */
+ PrecisionPoint reference = new PrecisionPoint(start);
+ conn.getSourceAnchor().getOwner().translateToAbsolute(reference);
+ PrecisionPoint anchorLocation = new PrecisionPoint(conn.getSourceAnchor().getLocation(reference));
conn.translateToRelative(anchorLocation);
line.insertPoint(anchorLocation, 0);
- }
- if (conn.getTargetAnchor() instanceof OrthogonalConnectionAnchor) {
- addSegmentToTargetAnchor(line, conn, (OrthogonalConnectionAnchor)conn.getTargetAnchor());
- } else {
- /*
- * If anchor is not supporting orthogonal connections we'll use the oblique connection
- * anchors and then convert it to rectilinear.
- */
- PrecisionPoint reference = new PrecisionPoint(end);
- conn.getSourceAnchor().getOwner().translateToAbsolute(reference);
- PrecisionPoint anchorLocation = new PrecisionPoint(conn.getTargetAnchor().getLocation(reference));
+ }
+ if (conn.getTargetAnchor() instanceof OrthogonalConnectionAnchor) {
+ addSegmentToTargetAnchor(line, conn, (OrthogonalConnectionAnchor) conn.getTargetAnchor());
+ } else {
+ /*
+ * If anchor is not supporting orthogonal connections we'll use the oblique connection
+ * anchors and then convert it to rectilinear.
+ */
+ PrecisionPoint reference = new PrecisionPoint(end);
+ conn.getSourceAnchor().getOwner().translateToAbsolute(reference);
+ PrecisionPoint anchorLocation = new PrecisionPoint(conn.getTargetAnchor().getLocation(reference));
conn.translateToRelative(anchorLocation);
line.addPoint(anchorLocation);
- }
- sourceAnchorRelativeLocation = getAnchorOffRectangleDirection2(line.getFirstPoint(), source);
- offSourceDirection = getOffShapeDirection2(sourceAnchorRelativeLocation);
- targetAnchorRelativeLocation = getAnchorOffRectangleDirection2(line.getLastPoint(), target);
- offTargetDirection = getOffShapeDirection2(targetAnchorRelativeLocation);
- }
-
- /*
- * Convert the polyline to rectilinear. If the connection is rectilinear already then the
- * connection will remain as it is.
- */
+ }
+ sourceAnchorRelativeLocation = getAnchorOffRectangleDirection2(line.getFirstPoint(), source);
+ offSourceDirection = getOffShapeDirection2(sourceAnchorRelativeLocation);
+ targetAnchorRelativeLocation = getAnchorOffRectangleDirection2(line.getLastPoint(), target);
+ offTargetDirection = getOffShapeDirection2(targetAnchorRelativeLocation);
+ }
+
+ /*
+ * Convert the polyline to rectilinear. If the connection is rectilinear already then the
+ * connection will remain as it is.
+ */
OrthogonalRouterUtilities.transformToOrthogonalPointList(line, offSourceDirection, offTargetDirection);
removeRedundantPoints(line);
}
@@ -145,7 +162,7 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
* such that when the polyline is converted to rectilinear from oblique we won't have
* rectilinear line segments alligned with source or target shapes edges.
* <p/>
- * Copy-pasted from {@link RectilinearRouter} lines 416.
+ * Copy-pasted from {@link RectilinearRouter} lines 416.
*/
@Deprecated
public static void insertPointsProducingNotAlignedRectilinearSegments(PointList line, int sourceAnchorRelativeLocation, int targetAnchorRelativeLocation) {
@@ -161,7 +178,7 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
public static void insertPointsProducingNotAlignedRectilinearSegments(Connection conn, PointList line, int sourceAnchorRelativeLocation, int targetAnchorRelativeLocation, SnapToGrid snapper) {
insertPointsProducingNotAlignedRectilinearSegments(line, sourceAnchorRelativeLocation, targetAnchorRelativeLocation);
if (asVerticalOrHorizontal(sourceAnchorRelativeLocation) != asVerticalOrHorizontal(targetAnchorRelativeLocation)) {
- //for "|_"-like routing we don't need snapping, the added bendpoint is determined fully by anchors
+ // for "|_"-like routing we don't need snapping, the added bendpoint is determined fully by anchors
return;
}
// so we are in "_|~"-like routing
@@ -173,10 +190,10 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
PrecisionPoint addedForTarget = new PrecisionPoint(line.getPoint(2));
PrecisionPoint addedForTargetAbs = makeAbsolute(conn, addedForTarget.getPreciseCopy());
PrecisionPoint snappedForTargetAbs = addedForTargetAbs.getPreciseCopy();
-
+
snapper.snapPoint(null, asVerticalOrHorizontal(sourceAnchorRelativeLocation), addedForSourceAbs, snappedForSourceAbs);
snapper.snapPoint(null, asVerticalOrHorizontal(targetAnchorRelativeLocation), addedForTargetAbs, snappedForTargetAbs);
-
+
PrecisionPoint snappedForSource = makeRelative(conn, snappedForSourceAbs.getPreciseCopy());
PrecisionPoint snappedForTarget = makeRelative(conn, snappedForTargetAbs.getPreciseCopy());
@@ -199,54 +216,46 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
public static void removeRedundantPoints(PointList line) {
removeRedundantPoints2(line);
}
-
+
protected SnapToGrid getSnapper() {
if (myGridSpec == null || myGridSpec.getAbsoluteGridSpec() == null) {
return null;
}
return new SnapToGrid((GraphicalEditPart) myGridSpec.getViewer().getContents());
}
-
+
protected void addSegmentToSourceAnchor(PointList line, Connection conn, OrthogonalConnectionAnchor anchor) {
- Point start = line.getFirstPoint();
- LineSeg fromFigureToStart = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, start);
- Point atFigureNotAnchor = fromFigureToStart.getOrigin();
-
- int orientation = getOrientationAgainst(anchor, start);
- switch(orientation) {
- case PositionConstants.VERTICAL:
- start.setX(anchor.getReferencePoint().x);
- break;
- case PositionConstants.HORIZONTAL:
- start.setY(anchor.getReferencePoint().y);
- break;
- }
-
- fromFigureToStart = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, start);
- atFigureNotAnchor = fromFigureToStart.getOrigin();
- line.insertPoint(atFigureNotAnchor, 0);
+ Point firstBend = line.getFirstPoint();
+ Point atFigure = computeEndPoint(conn, anchor, firstBend);
+ line.insertPoint(atFigure, 0);
}
-
+
protected void addSegmentToTargetAnchor(PointList line, Connection conn, OrthogonalConnectionAnchor anchor) {
- Point end = line.getLastPoint();
- LineSeg fromFigureToEnd = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, end);
- Point atFigureNotAnchor = fromFigureToEnd.getOrigin();
-
- int orientation = getOrientationAgainst(anchor, end);
- switch(orientation) {
- case PositionConstants.VERTICAL:
- end.setX(anchor.getReferencePoint().x);
- break;
- case PositionConstants.HORIZONTAL:
- end.setY(anchor.getReferencePoint().y);
- break;
+ Point lastBend = line.getLastPoint();
+ Point atFigure = computeEndPoint(conn, anchor, lastBend);
+ line.addPoint(atFigure);
+ }
+
+ protected Point computeEndPoint(Connection conn, OrthogonalConnectionAnchor anchor, Point bendpoint) {
+ LineSeg fromFigureToBendpoint = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, bendpoint);
+ Point result = fromFigureToBendpoint.getOrigin();
+ EndRoutingHint hint = findEndRoutingHint(conn, anchor);
+ if (hint == EndRoutingHint.FixAnchorMoveBendpoint) {
+ int orientation = getOrientationAgainst(anchor, bendpoint);
+ switch (orientation) {
+ case PositionConstants.VERTICAL:
+ bendpoint.setX(anchor.getReferencePoint().x);
+ break;
+ case PositionConstants.HORIZONTAL:
+ bendpoint.setY(anchor.getReferencePoint().y);
+ break;
+ }
+ fromFigureToBendpoint = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, bendpoint);
+ result = fromFigureToBendpoint.getOrigin();
}
-
- fromFigureToEnd = OrthogonalRouterUtilities.getOrthogonalLineSegToAnchorLoc(conn, anchor, end);
- atFigureNotAnchor = fromFigureToEnd.getOrigin();
- line.addPoint(atFigureNotAnchor);
+ return result;
}
-
+
private int getOrientationAgainst(ConnectionAnchor anchor, Point orthoReference) {
PrecisionPoint ownReference = new PrecisionPoint(anchor.getReferencePoint());
PrecisionRectangle bounds = new PrecisionRectangle(FigureUtilities.getAnchorableFigureBounds(anchor.getOwner()));
@@ -279,4 +288,12 @@ public class SnapToGridRectilinearRouter extends RectilinearRouter2 {
return orientation;
}
+ protected EndRoutingHint findEndRoutingHint(Connection conn, OrthogonalConnectionAnchor anchor) {
+ EndRoutingHint result = myEndRoutingHints.get(conn);
+ if (result == null) {
+ result = getDefaultEndRoutingStrategy();
+ }
+ return result;
+ }
+
}

Back to the top