diff options
author | Bob Brodt | 2015-05-05 11:06:04 +0000 |
---|---|---|
committer | Bob Brodt | 2015-05-05 11:06:04 +0000 |
commit | 1fc11e03f6164d2a6ecee8c6d8096dfdf09d791a (patch) | |
tree | 63b66a2e0e9e5974710c7bb3c5702d3297ec1670 | |
parent | c5704a9eb76947ca855dcb250910550d9f6167a0 (diff) | |
download | org.eclipse.bpmn2-modeler-1fc11e03f6164d2a6ecee8c6d8096dfdf09d791a.tar.gz org.eclipse.bpmn2-modeler-1fc11e03f6164d2a6ecee8c6d8096dfdf09d791a.tar.xz org.eclipse.bpmn2-modeler-1fc11e03f6164d2a6ecee8c6d8096dfdf09d791a.zip |
https://bugzilla.redhat.com/show_bug.cgi?id=1181215 - Arrows are changed unexpectedly when Node is moved on the canvas
3 files changed, 77 insertions, 7 deletions
diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java index 90a7b1d1..ee8122eb 100644 --- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java +++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/DefaultConnectionRouter.java @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.bpmn2.BaseElement; import org.eclipse.bpmn2.Lane; +import org.eclipse.bpmn2.Participant; import org.eclipse.bpmn2.di.BPMNShape; import org.eclipse.bpmn2.modeler.core.preferences.ShapeStyle; import org.eclipse.bpmn2.modeler.core.preferences.ShapeStyle.RoutingStyle; @@ -241,7 +242,8 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter { boolean ignore = false; // only Lanes can be siblings to other Lanes within a container // which may be either another Lane or a Pool. - if (BusinessObjectUtil.containsElementOfType(shape, Lane.class)) { + BaseElement be = BusinessObjectUtil.getFirstBaseElement(shape); + if (be instanceof Lane) { EObject ancestor = shape.eContainer(); while (!(ancestor instanceof Diagram)) { if (ancestors.contains(ancestor)) { @@ -251,6 +253,25 @@ public class DefaultConnectionRouter extends AbstractConnectionRouter { ancestor = ancestor.eContainer(); } } + // Yet another hack for dealing with imported files. + // Here we have a poorly laid out diagram such that + // a Pool overlaps another Pool almost completely. + // This is an indication that the tool used to create + // the file is rendering Pools on separate pages, even + // though there is only a single BPMNDiagram. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=463205 + // for an example of this. + if (be instanceof Lane || be instanceof Participant) { + for (ContainerShape ancestor : ancestors) { + if (GraphicsUtil.intersects(shape, ancestor)) { + ignore = true; + break; + } + } + } + // check if any ancestors overlaps this Lane or Pool + // this is a special case + if (!ignore) { allShapes.add(shape); } diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java index f73f69f1..c7695815 100644 --- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java +++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/features/ManhattanConnectionRouter.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Hashtable; import java.util.List; +import java.util.Map; import org.eclipse.bpmn2.modeler.core.utils.AnchorSite; import org.eclipse.bpmn2.modeler.core.utils.AnchorType; @@ -45,7 +46,7 @@ import org.eclipse.graphiti.services.Graphiti; public class ManhattanConnectionRouter extends BendpointConnectionRouter { /** The Constant offset. */ - static final int margin = 10; + static final int margin = 20; /** The test route solver. */ static boolean testRouteSolver = false; @@ -258,11 +259,35 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter { boolean changed = false; if (connection instanceof FreeFormConnection) { + // This is yet another hack to deal with imported diagrams: + // we need to respect the original source/target anchor locations + // of connections that are not being routed. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=463205 + // for an example of this. + Map<Anchor,Point> initialSourceAnchorLocations = AnchorUtil.saveAnchorLocations(source); + Map<Anchor,Point> initialTargetAnchorLocations = AnchorUtil.saveAnchorLocations(target); + // this will normalize the locations of the source and target + // anchors by ensuring that single anchors are in the middle + // of an edge and multiple anchors are evenly spaced out + // along the edge of a shape. + AnchorUtil.adjustAnchors(source); + AnchorUtil.adjustAnchors(target); + // of course now the locations of the source and target anchors + // MAY have changed, so these need to be updated... + oldPoints[0] = GraphicsUtil.createPoint(ffc.getStart()); + oldPoints[oldPoints.length-1] = GraphicsUtil.createPoint(ffc.getEnd()); + ConnectionRoute route = calculateRoute(); if (route!=null) { changed = isRouteChanged(route); applyRoute(route); } + + initialSourceAnchorLocations.remove(ffc.getStart()); + initialTargetAnchorLocations.remove(ffc.getEnd()); + AnchorUtil.restoreAnchorLocations(source, initialSourceAnchorLocations); + AnchorUtil.restoreAnchorLocations(target, initialTargetAnchorLocations); + dispose(); } @@ -270,7 +295,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter { Hashtable<AnchorSite, List<FixPointAnchor>> targetAnchorsAfter = AnchorUtil.countAnchors(target); boolean repeat = false; - int iterations=0; + int iterations = 0; do { repeat = false; for (AnchorSite site : AnchorSite.values()) { @@ -322,6 +347,7 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter { return super.calculateRoute(); GraphicsUtil.debug = false; + GraphicsUtil.dump("\n===========================================\nRouting ", ffc); boolean initialUpdate = (peService.getPropertyValue(ffc, GraphitiConstants.INITIAL_UPDATE) != null); if (initialUpdate) { @@ -485,10 +511,10 @@ public class ManhattanConnectionRouter extends BendpointConnectionRouter { // to an anchor on the shape) we have to change the p3 = oldPoints[length-2]; if (isHorizontal(p3, p1)) { - p1.setX(p2.getX()); + p1.setY(p2.getY()); } else { - p1.setY(p2.getY()); + p1.setX(p2.getX()); } } else { diff --git a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java index f7eadc25..7397c8b2 100644 --- a/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java +++ b/plugins/org.eclipse.bpmn2.modeler.core/src/org/eclipse/bpmn2/modeler/core/utils/AnchorUtil.java @@ -15,6 +15,7 @@ package org.eclipse.bpmn2.modeler.core.utils; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; @@ -26,6 +27,7 @@ import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.ecore.EObject; import org.eclipse.graphiti.datatypes.IDimension; import org.eclipse.graphiti.datatypes.ILocation; +import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Rectangle; import org.eclipse.graphiti.mm.algorithms.styles.Point; import org.eclipse.graphiti.mm.pictograms.Anchor; @@ -208,7 +210,6 @@ public class AnchorUtil { return; } if (parent instanceof Shape) { - EObject bo = BusinessObjectUtil.getBusinessObjectForPictogramElement(parent); p = GraphicsUtil.createPoint(p); // make a copy ILocation loc = peService.getLocationRelativeToDiagram((Shape)parent); LineSegment edge = GraphicsUtil.findNearestEdge((Shape)parent, p); @@ -393,7 +394,29 @@ public class AnchorUtil { } return result; } - + + public static Map<Anchor,Point> saveAnchorLocations(AnchorContainer ac) { + Map<Anchor, Point> points = new Hashtable<Anchor,Point>(); + for (Anchor a : ac.getAnchors()) { + if (a instanceof FixPointAnchor) { + Point p = GraphicsUtil.createPoint(((FixPointAnchor) a).getLocation()); + points.put(a, p); + } + } + return points; + } + + public static void restoreAnchorLocations(AnchorContainer ac, Map<Anchor,Point> points) { + for (Anchor a : ac.getAnchors()) { + if (a instanceof FixPointAnchor) { + Point p = points.get(a); + if (p!=null) { + ((FixPointAnchor) a).setLocation(p); + } + } + } + } + ///////////////////////////////////////////////////////////////////// // Private API ///////////////////////////////////////////////////////////////////// |