diff options
| author | Laurent Redor | 2015-08-11 09:46:58 +0000 |
|---|---|---|
| committer | Laurent Redor | 2015-08-19 09:16:04 +0000 |
| commit | 1a5df2d52c19f9b69d9f9dd7226b8b99a3b15426 (patch) | |
| tree | 3e801418eedcbaeb4cd779b3e89921e00eafb3a8 | |
| parent | ff658ab399e4c462eccc1483110d5a62c7ab2061 (diff) | |
| download | org.eclipse.sirius-1a5df2d52c19f9b69d9f9dd7226b8b99a3b15426.tar.gz org.eclipse.sirius-1a5df2d52c19f9b69d9f9dd7226b8b99a3b15426.tar.xz org.eclipse.sirius-1a5df2d52c19f9b69d9f9dd7226b8b99a3b15426.zip | |
[474688] Handle case of bendpoints included in moved node
When the moved node included some bendpoints after the move, these
bendpoints were no longer visible (draw2d), but they existed in GMF
constraint.
Bug: 474688
Change-Id: Ib06c1f3a2bd7d54fc353ab97f55bac8c04cef3f1
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
2 files changed, 218 insertions, 88 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java index 086f068ba1..a7e190e3d8 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SetConnectionBendpointsAccordingToExtremityMoveCommmand.java @@ -16,10 +16,11 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.PrecisionPoint; -import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.draw2d.geometry.PrecisionRectangle; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; @@ -108,46 +109,14 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set */ public static void adaptPointListAndRefPoints(boolean sourceMove, Point moveDelta, org.eclipse.gef.ConnectionEditPart connectionEditPart, Point sourceRefPoint, Point targetRefPoint, PointList connectionPointList) { - // Get the bounds of the moved node - Rectangle bounds; + // Get the bounds of the source and target nodes + PrecisionRectangle sourceBounds = new PrecisionRectangle(GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getSource())); + PrecisionRectangle targetBounds = new PrecisionRectangle(GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getTarget())); + boolean isEdgeWithRectilinearRoutingStyle = new ConnectionEditPartQuery(connectionEditPart).isEdgeWithRectilinearRoutingStyle(); if (sourceMove) { - bounds = GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getSource()); + moveFirstSegmentAndRefPointAccordingToSourcetMove(moveDelta, isEdgeWithRectilinearRoutingStyle, sourceBounds, targetBounds, sourceRefPoint, targetRefPoint, connectionPointList); } else { - bounds = GraphicalHelper.getAbsoluteBoundsIn100Percent((IGraphicalEditPart) connectionEditPart.getTarget()); - } - adaptPointListAndRefPoints(sourceMove, moveDelta, new ConnectionEditPartQuery(connectionEditPart).isEdgeWithRectilinearRoutingStyle(), bounds, sourceRefPoint, targetRefPoint, - connectionPointList); - } - - /** - * Adapt the point list and the source reference point (or target reference - * point) according to a move of the source (or of the target). - * - * @param sourceMove - * true if the source node of edge has been moved, false - * otherwise - * @param moveDelta - * the delta of the move of the extremity (source or target) - * @param isEdgeWithRectilinearRoutingStyle - * True if the edge is rectilinear (one more point is adapted in - * this case), false otherwise - * @param bounds - * The bounds of the moved node - * @param sourceRefPoint - * The source reference point to adapt (only adapted for - * sourceMove true) - * @param targetRefPoint - * The target reference point to adapt (only adapted for - * sourceMove false) - * @param connectionPointList - * The point list to adapt - */ - public static void adaptPointListAndRefPoints(boolean sourceMove, Point moveDelta, boolean isEdgeWithRectilinearRoutingStyle, Rectangle bounds, Point sourceRefPoint, Point targetRefPoint, - PointList connectionPointList) { - if (sourceMove) { - moveFirstSegmentAndRefPointAccordingToSourcetMove(moveDelta, isEdgeWithRectilinearRoutingStyle, bounds, sourceRefPoint, connectionPointList); - } else { - moveLastSegmentAndRefPointAccordingToTargetMove(moveDelta, isEdgeWithRectilinearRoutingStyle, bounds, targetRefPoint, connectionPointList); + moveLastSegmentAndRefPointAccordingToTargetMove(moveDelta, isEdgeWithRectilinearRoutingStyle, sourceBounds, targetBounds, sourceRefPoint, targetRefPoint, connectionPointList); } } @@ -160,15 +129,19 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set * @param isEdgeWithRectilinearRoutingStyle * True if the edge is rectilinear (one more point is adapted in * this case), false otherwise - * @param bounds - * The bounds of the moved node + * @param sourceBounds + * The bounds of the source node + * @param targetBounds + * The bounds of the target node * @param sourceRefPoint * The source reference point to adapt + * @param targetRefPoint + * The target reference point * @param connectionPointList * The point list to adapt */ - private static void moveFirstSegmentAndRefPointAccordingToSourcetMove(Point moveDelta, boolean isEdgeWithRectilinearRoutingStyle, Rectangle bounds, Point sourceRefPoint, - PointList connectionPointList) { + private static void moveFirstSegmentAndRefPointAccordingToSourcetMove(Point moveDelta, boolean isEdgeWithRectilinearRoutingStyle, PrecisionRectangle sourceBounds, PrecisionRectangle targetBounds, + Point sourceRefPoint, Point targetRefPoint, PointList connectionPointList) { // Move reference point sourceRefPoint.performTranslate(moveDelta.x, moveDelta.y); // Move second point in case of rectilinear router @@ -177,17 +150,17 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set if (firstSegment.isHorizontal()) { connectionPointList.setPoint(connectionPointList.getPoint(0).translate(moveDelta.x, moveDelta.y), 0); connectionPointList.setPoint(connectionPointList.getPoint(1).translate(0, moveDelta.y), 1); - normalizeAndStraight(connectionPointList); } else { connectionPointList.setPoint(connectionPointList.getPoint(0).translate(moveDelta.x, moveDelta.y), 0); connectionPointList.setPoint(connectionPointList.getPoint(1).translate(moveDelta.x, 0), 1); - normalizeAndStraight(connectionPointList); } + normalizeAndStraight(connectionPointList); + removePointsInViews(connectionPointList, (PrecisionRectangle) sourceBounds.getTranslated(moveDelta), sourceRefPoint, targetBounds, targetRefPoint); } else { // Compute intersection between the line // (tempSourceRefPoint<-->second point) and the source node // 2-Compute intersection - Option<Point> intersectionPoint = GraphicalHelper.getIntersection(sourceRefPoint, connectionPointList.getPoint(1), bounds.getTranslated(moveDelta), false); + Option<Point> intersectionPoint = GraphicalHelper.getIntersection(sourceRefPoint, connectionPointList.getPoint(1), sourceBounds.getTranslated(moveDelta), false); if (intersectionPoint.some()) { connectionPointList.setPoint(intersectionPoint.get(), 0); } else { @@ -205,15 +178,19 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set * @param isEdgeWithRectilinearRoutingStyle * True if the edge is rectilinear (one more point is adapted in * this case), false otherwise - * @param bounds - * The bounds of the moved node + * @param sourceBounds + * The bounds of the source node + * @param targetBounds + * The bounds of the target node + * @param sourceRefPoint + * The source reference point * @param targetRefPoint * The target reference point to adapt * @param connectionPointList * The point list to adapt */ - private static void moveLastSegmentAndRefPointAccordingToTargetMove(Point moveDelta, boolean isEdgeWithRectilinearRoutingStyle, Rectangle bounds, Point targetRefPoint, - PointList connectionPointList) { + private static void moveLastSegmentAndRefPointAccordingToTargetMove(Point moveDelta, boolean isEdgeWithRectilinearRoutingStyle, PrecisionRectangle sourceBounds, PrecisionRectangle targetBounds, + Point sourceRefPoint, Point targetRefPoint, PointList connectionPointList) { // Move reference point targetRefPoint.performTranslate(moveDelta.x, moveDelta.y); // Move second last point in case of rectilinear router @@ -222,17 +199,18 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set if (lastSegment.isHorizontal()) { connectionPointList.setPoint(connectionPointList.getPoint(connectionPointList.size() - 2).translate(0, moveDelta.y), connectionPointList.size() - 2); connectionPointList.setPoint(connectionPointList.getPoint(connectionPointList.size() - 1).translate(moveDelta.x, moveDelta.y), connectionPointList.size() - 1); - normalizeAndStraight(connectionPointList); } else { connectionPointList.setPoint(connectionPointList.getPoint(connectionPointList.size() - 2).translate(moveDelta.x, 0), connectionPointList.size() - 2); connectionPointList.setPoint(connectionPointList.getPoint(connectionPointList.size() - 1).translate(moveDelta.x, moveDelta.y), connectionPointList.size() - 1); - normalizeAndStraight(connectionPointList); } + normalizeAndStraight(connectionPointList); + removePointsInViews(connectionPointList, sourceBounds, sourceRefPoint, (PrecisionRectangle) targetBounds.getTranslated(moveDelta), targetRefPoint); } else { // Compute intersection between the line // (tempTargetRefPoint<-->second to last point) and the target node // 2-Compute intersection - Option<Point> intersectionPoint = GraphicalHelper.getIntersection(targetRefPoint, connectionPointList.getPoint(connectionPointList.size() - 2), bounds.getTranslated(moveDelta), false); + Option<Point> intersectionPoint = GraphicalHelper.getIntersection(targetRefPoint, connectionPointList.getPoint(connectionPointList.size() - 2), targetBounds.getTranslated(moveDelta), + false); if (intersectionPoint.some()) { connectionPointList.setPoint(intersectionPoint.get(), connectionPointList.size() - 1); } else { @@ -288,6 +266,123 @@ public class SetConnectionBendpointsAccordingToExtremityMoveCommmand extends Set } /** + * Removes consecutive points contained within the source shape and removes + * consecutive points contained within the target shape. If all points have + * been removed an extra point outside source and target shapes will be + * added. Inspired from + * {@link org.eclipse.gmf.runtime.draw2d.ui.internal.routers.RectilinearRouter#removePointsInViews(Connection, PointList, Point, Point)} + * + * @param newLine + * polyline of the connection + * @param source + * The bounds of the source node + * @param start + * old start anchor point + * @param source + * The bounds of the target node + * @param end + * old end anchor point + */ + private static void removePointsInViews(PointList newLine, PrecisionRectangle source, Point start, PrecisionRectangle target, Point end) { + Point lastRemovedFromSource = null; + Point lastRemovedFromTarget = null; + + /* + * Starting from the first point of polyline remove points that are + * contained within the source shape until the first point outside is + * found. Remember the point that was removed from the source shape last + * for a possible case of all points removed from polyline. + */ + PointList sourcePointList = PointListUtilities.createPointsFromRect(source); + if (newLine.size() != 0) { + int nbIncludedPoints = 0; + for (int i = 0; i < newLine.size() && sourcePointList.polygonContainsPoint(newLine.getPoint(i).x, newLine.getPoint(i).y); i++) { + nbIncludedPoints++; + } + // Do nothing if there is only one point inside. This is the first + // point that is on the border. + if (nbIncludedPoints > 1) { + for (int i = 0; i < nbIncludedPoints; i++) { + lastRemovedFromSource = newLine.removePoint(0); + } + } + } + + /* + * Starting from the end point of polyline remove points that are + * contained within the target shape until the first point outside is + * found. Remember the point that was removed from the target shape last + * for a possible case of all points removed from polyline. + */ + PointList targetPointList = PointListUtilities.createPointsFromRect(target); + if (newLine.size() != 0) { + int nbIncludedPoints = 0; + for (int i = newLine.size() - 1; i > 0 && targetPointList.polygonContainsPoint(newLine.getPoint(i).x, newLine.getPoint(i).y); i--) { + nbIncludedPoints++; + } + // Do nothing if there is only one point inside. This is the last + // point that is on the border. + if (nbIncludedPoints > 1) { + for (int i = 0; i < nbIncludedPoints; i++) { + lastRemovedFromTarget = newLine.removePoint(newLine.size() - 1); + } + } + } + + /* + * Handle the special case of all points removed from polyline. + */ + if (newLine.size() == 0) { + Dimension tolerance = new Dimension(1, 0); + int toleranceValue = tolerance.width; + if (lastRemovedFromSource == null) { + lastRemovedFromSource = start; + } + if (lastRemovedFromTarget == null) { + lastRemovedFromTarget = end; + } + /* + * If last point removed from source and the points removed from + * target form a vertical or horizontal line we'll find a point + * located on this line and is outside of source and target shape + * and insert it in the polyline. The check for vertical and + * horizontal segment is using tolerance value, because bend point + * location extracted from RelativeBendpoint can have precision + * errors due to non-integer weight factors. + */ + if (Math.abs(lastRemovedFromSource.x - lastRemovedFromTarget.x) < toleranceValue) { + // Vertical + if (source.preciseY() < target.preciseY()) { + newLine.addPoint(lastRemovedFromSource.x, (source.getBottom().y + target.getTop().y) / 2); + } else { + newLine.addPoint(lastRemovedFromSource.x, (source.getTop().y + target.getBottom().y) / 2); + } + } else if (Math.abs(lastRemovedFromSource.y - lastRemovedFromTarget.y) < toleranceValue) { + // Horizontal + if (source.preciseX() < target.preciseX()) { + newLine.addPoint((source.getRight().x + target.getLeft().x) / 2, lastRemovedFromSource.y); + } else { + newLine.addPoint((source.getLeft().x + target.getRight().x) / 2, lastRemovedFromSource.y); + } + } + } else { + // Add necessary point to complete the first (or last) segment if + // points have been removed from source (or target). + if (lastRemovedFromSource != null) { + Option<Point> optionalIntersection = GraphicalHelper.getIntersection(lastRemovedFromSource, newLine.getFirstPoint(), source, true); + if (optionalIntersection.some()) { + newLine.insertPoint(optionalIntersection.get(), 0); + } + } else if (lastRemovedFromTarget != null) { + Option<Point> optionalIntersection = GraphicalHelper.getIntersection(lastRemovedFromTarget, newLine.getLastPoint(), target, false); + if (optionalIntersection.some()) { + newLine.addPoint(optionalIntersection.get()); + } + } + } + } + + /** * Set if the source is moved, or if the target is moved. * * @param sourceMove diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BendpointsStabilityOnMovesSpecificCasesTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BendpointsStabilityOnMovesSpecificCasesTest.java index 9307197d6e..254405b306 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BendpointsStabilityOnMovesSpecificCasesTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BendpointsStabilityOnMovesSpecificCasesTest.java @@ -16,10 +16,13 @@ import java.util.List; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PointList; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx; import org.eclipse.sirius.diagram.DSemanticDiagram; import org.eclipse.sirius.diagram.ui.edit.api.part.IAbstractDiagramNodeEditPart; import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper; +import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper; import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource; import org.eclipse.sirius.tests.swtbot.support.api.condition.CheckEditPartMoved; @@ -116,7 +119,7 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * points are consistency. */ public void testFirstPointConsistency() { - testFirstPointConsistency(new Point(20, 20), false); + testFirstPointConsistency(new Point(20, 20), false, false); } /** @@ -125,7 +128,15 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * the second one. */ public void testFirstPointConsistencyWithMergeSegment() { - testFirstPointConsistency(new Point(0, 99), true); + testFirstPointConsistency(new Point(0, 99), true, false); + } + + /** + * Test that first point is moved has expected and that draw2d and GMF last + * points are consistency (when the first segment is removed). + */ + public void testFirstPointConsistencyWithFirstSegmentRemoval() { + testFirstPointConsistency(new Point(60, 20), false, true); } /** @@ -133,7 +144,7 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * points are consistency. */ public void testLastPointConsistency() { - testLastPointConsistency(new Point(-20, 50), false); + testLastPointConsistency(new Point(-20, 50), false, false); } /** @@ -142,7 +153,15 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * previous one. */ public void testLastPointConsistencyWithMergeSegment() { - testLastPointConsistency(new Point(0, -139), true); + testLastPointConsistency(new Point(0, -139), true, false); + } + + /** + * Test that last point is moved has expected and that draw2d and GMF last + * points are consistency (when the last segment is removed). + */ + public void testLastPointConsistencyWithLastSegmentRemoval() { + testLastPointConsistency(new Point(-120, 50), false, true); } /** @@ -154,9 +173,12 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * @param segmentMerged * true if the corresponding segment is merged with the next one * (2 points less and segments normalize and straight), false - * otherwise. + * otherwise. Exclusive with segmentRemoved. + * @param segmentRemoved + * true if the corresponding segment is removed (absorbed by the + * moved node), false otherwise. Exclusive with segmentMerged. */ - protected void testLastPointConsistency(Point moveDelta, boolean segmentMerged) { + protected void testLastPointConsistency(Point moveDelta, boolean segmentMerged, boolean segmentRemoved) { String nodeToMoveName = "C2"; editor.reveal(nodeToMoveName); // Step 2: store the previous bendpoints @@ -165,14 +187,15 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS PointList previousPoints = ((PolylineConnectionEx) connectionEditPart.part().getFigure()).getPoints(); // Step 3: Drag node - Point initialLocation = editor.getBounds(editPartToMove).getCenter(); + Rectangle nodeBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent((GraphicalEditPart) editPartToMove.part()); + Point initialLocation = nodeBounds.getCenter(); Point targetLocation = new Point(initialLocation.x + moveDelta.x, initialLocation.y + moveDelta.y); ICondition editPartMovedCondition = new CheckEditPartMoved(editPartToMove); editor.drag(initialLocation, targetLocation); bot.waitUntil(editPartMovedCondition); assertEquals("Drag as failed: selection should be the same before and after drag.", editPartToMove, editor.selectedEditParts().get(0)); // Step 4: Check bendpoints - compareActualBendpointsWithExpected(editor, connectionEditPart, previousPoints, moveDelta, false, segmentMerged); + compareActualBendpointsWithExpected(editor, connectionEditPart, previousPoints, moveDelta, nodeBounds, false, segmentMerged, segmentRemoved); } /** @@ -184,9 +207,12 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS * @param segmentMerged * true if the corresponding segment is merged with the next one * (2 points less and segments normalize and straight), false - * otherwise. + * otherwise. Exclusive with segmentRemoved. + * @param segmentRemoved + * true if the corresponding segment is removed (absorbed by the + * moved node), false otherwise. Exclusive with segmentMerged. */ - protected void testFirstPointConsistency(Point moveDelta, boolean segmentMerged) { + protected void testFirstPointConsistency(Point moveDelta, boolean segmentMerged, boolean segmentRemoved) { String nodeToMoveName = "C1"; editor.reveal(nodeToMoveName); // Step 2: store the previous bendpoints @@ -195,54 +221,63 @@ public class BendpointsStabilityOnMovesSpecificCasesTest extends AbstractSiriusS PointList previousPoints = ((PolylineConnectionEx) connectionEditPart.part().getFigure()).getPoints(); // Step 3: Drag node - Point initialLocation = editor.getBounds(editPartToMove).getCenter(); + Rectangle nodeBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent((GraphicalEditPart) editPartToMove.part()); + Point initialLocation = nodeBounds.getCenter(); Point targetLocation = new Point(initialLocation.x + moveDelta.x, initialLocation.y + moveDelta.y); ICondition editPartMovedCondition = new CheckEditPartMoved(editPartToMove); editor.drag(initialLocation, targetLocation); bot.waitUntil(editPartMovedCondition); assertEquals("Drag as failed: selection should be the same before and after drag.", editPartToMove, editor.selectedEditParts().get(0)); // Step 4: Check bendpoints - compareActualBendpointsWithExpected(editor, connectionEditPart, previousPoints, moveDelta, true, segmentMerged); + compareActualBendpointsWithExpected(editor, connectionEditPart, previousPoints, moveDelta, nodeBounds, true, segmentMerged, segmentRemoved); } - // Check the first or last benpoint of the connection. - private void compareActualBendpointsWithExpected(SWTBotSiriusDiagramEditor diagramEditor, SWTBotGefConnectionEditPart connectionEditPart, PointList expectedBendPoints, Point moveDelta, - boolean firstPoint, boolean segmentMerged) { + // Check the first or last bendpoint of the connection. + private void compareActualBendpointsWithExpected(SWTBotSiriusDiagramEditor diagramEditor, SWTBotGefConnectionEditPart connectionEditPart, PointList previousPoints, Point moveDelta, + Rectangle movedNodeBounds, boolean firstPoint, boolean segmentMerged, boolean segmentRemoved) { List<Point> newGMFBendpointsFromSource = GMFHelper.getPointsFromSource(connectionEditPart.part()); String messagePrefix = "First"; if (!firstPoint) { messagePrefix = "Last"; } if (segmentMerged) { - assertEquals(messagePrefix + " segment must me merged. We should have 2 points less.", expectedBendPoints.size() - 2, newGMFBendpointsFromSource.size()); + assertEquals(messagePrefix + " segment must me merged. We should have 2 GMF points less.", previousPoints.size() - 2, newGMFBendpointsFromSource.size()); + } else if (segmentRemoved) { + assertEquals(messagePrefix + " segment must me removed. We should have 1 GMF point less.", previousPoints.size() - 1, newGMFBendpointsFromSource.size()); } - Point expectedDraw2dPoint; - Point expectedMergedPoint; - Point actualDraw2dPoint; - Point actualGmfPoint; + Point previousDraw2dPoint; + Point previousMergedPoint; + Point currentDraw2dPoint; + Point currentGmfPoint; + int yNodeBorder; PointList actualBendPoints = ((PolylineConnectionEx) connectionEditPart.part().getFigure()).getPoints(); if (firstPoint) { - expectedDraw2dPoint = expectedBendPoints.getFirstPoint(); - expectedMergedPoint = expectedBendPoints.getPoint(2); - actualDraw2dPoint = actualBendPoints.getFirstPoint(); - actualGmfPoint = newGMFBendpointsFromSource.get(0); + previousDraw2dPoint = previousPoints.getFirstPoint(); + previousMergedPoint = previousPoints.getPoint(2); + currentDraw2dPoint = actualBendPoints.getFirstPoint(); + currentGmfPoint = newGMFBendpointsFromSource.get(0); + yNodeBorder = movedNodeBounds.getTranslated(moveDelta).getBottom().y; } else { - expectedDraw2dPoint = expectedBendPoints.getLastPoint(); - expectedMergedPoint = expectedBendPoints.getPoint(expectedBendPoints.size() - 3); - actualDraw2dPoint = actualBendPoints.getLastPoint(); - actualGmfPoint = newGMFBendpointsFromSource.get(newGMFBendpointsFromSource.size() - 1); + previousDraw2dPoint = previousPoints.getLastPoint(); + previousMergedPoint = previousPoints.getPoint(previousPoints.size() - 3); + currentDraw2dPoint = actualBendPoints.getLastPoint(); + currentGmfPoint = newGMFBendpointsFromSource.get(newGMFBendpointsFromSource.size() - 1); + yNodeBorder = movedNodeBounds.getTranslated(moveDelta).y; } // The first (or last) bendpoint should have moved. - assertNotEquals(messagePrefix + " point should have moved", expectedDraw2dPoint, actualDraw2dPoint); + assertNotEquals(messagePrefix + " point should have moved", previousDraw2dPoint, currentDraw2dPoint); if (segmentMerged) { - Point expectedPoint = expectedDraw2dPoint.getTranslated(moveDelta); - Point otherExpectedPoint = new Point(expectedPoint.x, expectedMergedPoint.y); - assertTrue(messagePrefix + " point should have moved at the expected location. expected:<" + expectedPoint + "or " + otherExpectedPoint + "> but was:<" + actualBendPoints + ">", - expectedPoint.equals(actualDraw2dPoint) || otherExpectedPoint.equals(actualDraw2dPoint)); + Point expectedPoint = previousDraw2dPoint.getTranslated(moveDelta); + Point otherExpectedPoint = new Point(expectedPoint.x, previousMergedPoint.y); + assertTrue(messagePrefix + " point should have moved at the expected location. expected:<" + expectedPoint + "or " + otherExpectedPoint + "> but was:<" + currentDraw2dPoint + ">", + expectedPoint.equals(currentDraw2dPoint) || otherExpectedPoint.equals(currentDraw2dPoint)); + } else if (segmentRemoved) { + Point otherExpectedPoint = new Point(previousMergedPoint.x, yNodeBorder); + assertEquals(messagePrefix + " point should have moved at the expected location", otherExpectedPoint, currentDraw2dPoint); } else { - assertEquals(messagePrefix + " point should have moved at the expected location", expectedDraw2dPoint.getTranslated(moveDelta), actualDraw2dPoint); + assertEquals(messagePrefix + " point should have moved at the expected location", previousDraw2dPoint.getTranslated(moveDelta), currentDraw2dPoint); } // The draw2d and GMF point should be the same. - assertEquals(messagePrefix + " draw2d and GMF points should be the same", actualDraw2dPoint, actualGmfPoint); + assertEquals(messagePrefix + " draw2d and GMF points should be the same", currentDraw2dPoint, currentGmfPoint); } } |
