From 55b00a0d2b3e4f30c29b90b40b2be1c5dbda415f Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Tue, 30 Jul 2024 17:11:54 +0200 Subject: [PATCH] [426] Fix border nodes tests regression Analysis: It seems that before, the code with comment "manage location of bordered node with closest side", in GMFHelper.getAbsoluteLocation, is called only in specific circumstances. Since recent changes, it was called systematically, but that shouldn't be the case. This commit also reduces the number of getAbsoluBounds methods to ease the impact analysis. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/426 --- .../internal/query/SequenceNodeQuery.java | 2 +- .../FixBendpointsOnCreationCommand.java | 4 +- .../ui/business/api/query/NodeQuery.java | 2 +- ...entationsFileMigrationParticipantV670.java | 7 +- .../edit/commands/StraightenToCommand.java | 2 +- .../AbstractCanonicalSynchronizer.java | 4 +- .../ui/internal/refresh/GMFHelper.java | 153 +++++++++--------- .../CanonicalDBorderItemLocator.java | 2 +- .../AbstractSiriusFormatDataManager.java | 2 +- .../tools/internal/commands/SnapCommand.java | 6 +- .../CanonicalDBorderItemLocatorTest.java | 2 +- .../swtbot/BorderedNodeCreationTest.java | 2 +- ...orderedNodeCreationWithSnapToGridTest.java | 4 +- ...odeCreationPositionWithSnapToGridTest.java | 4 +- .../tests/swtbot/layout/GMFHelperTest.java | 2 +- .../sirius/ui/debug/SiriusDebugView.java | 4 +- 16 files changed, 103 insertions(+), 99 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java index 110a6ae356..08733296d6 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/query/SequenceNodeQuery.java @@ -64,7 +64,7 @@ public Range getVerticalRange() { result = CacheHelper.getViewToRangeCache().get(node); } if (result == null) { - Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node); + Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node, false, false, false, true); int y = absoluteBounds.y; int height = absoluteBounds.height; // GMFHelper.getAbsoluteBounds() use default diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/FixBendpointsOnCreationCommand.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/FixBendpointsOnCreationCommand.java index e2f4ae107d..215c11ba6f 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/FixBendpointsOnCreationCommand.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/refresh/FixBendpointsOnCreationCommand.java @@ -152,7 +152,7 @@ private void updateEdge(DEdge dEdge) { private void computeEdgeDataWithoutEdgeLayoutData() { Point firstClick = new Point(0, 0); - Rectangle sourceBounds = GMFHelper.getAbsoluteBounds((Node) source); + Rectangle sourceBounds = GMFHelper.getAbsoluteBounds((Node) source, false, false, false, true); if (source.getElement() instanceof AbstractDNode) { AbstractDNode sourceDNode = (AbstractDNode) source.getElement(); if (sourceDNode.eContainer() instanceof AbstractDNode) { @@ -181,7 +181,7 @@ private void computeEdgeDataWithoutEdgeLayoutData() { sourceTerminal = "(" + sourceRelativeLocation.preciseX() + "," + sourceRelativeLocation.preciseY() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Point secondClick = new Point(0, 0); - Rectangle targetBounds = GMFHelper.getAbsoluteBounds((Node) target); + Rectangle targetBounds = GMFHelper.getAbsoluteBounds((Node) target, false, false, false, true); if (target.getElement() instanceof AbstractDNode) { AbstractDNode targetDNode = (AbstractDNode) target.getElement(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/NodeQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/NodeQuery.java index 9333a02600..ff4530c158 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/NodeQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/NodeQuery.java @@ -274,7 +274,7 @@ private Option getParentBorder() { * @return The rectangle used for handles */ public Rectangle getHandleBounds() { - return GMFHelper.getAbsoluteBounds(node, true, true); + return GMFHelper.getAbsoluteBounds(node, true, false, false, false); } /** diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/DiagramRepresentationsFileMigrationParticipantV670.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/DiagramRepresentationsFileMigrationParticipantV670.java index c725abbeb4..cd2096292b 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/DiagramRepresentationsFileMigrationParticipantV670.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/DiagramRepresentationsFileMigrationParticipantV670.java @@ -174,7 +174,7 @@ private void avoidOverlaps(Diagram diagram) { Location location = (Location) layoutConstraint; constraint = new Rectangle(location.getX(), location.getY(), -1, -1); } - Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode); + Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, false, false); constraint.translate(parentAbsoluteLocation.x, parentAbsoluteLocation.y); final Point realLocation = borderItemLocator.getValidLocation(constraint, node, otherBorderedNodesToIgnore); final Dimension d = realLocation.getDifference(parentAbsoluteLocation); @@ -215,7 +215,7 @@ private void migrateGraphicalFiltersAndGMFBounds(Diagram diagram) { LayoutConstraint layoutConstraint = node.getLayoutConstraint(); if (layoutConstraint instanceof Bounds) { Bounds bounds = (Bounds) layoutConstraint; - Rectangle rectBounds = GMFHelper.getAbsoluteBounds(node); + Rectangle rectBounds = GMFHelper.getAbsoluteBounds(node, false, false, false, true); // The GMF node size must be stored in collapse // filter (to can set this size // when this node is expanded). @@ -287,6 +287,7 @@ private void migrateChildrenOfCollapsedNode(Diagram diagram) { * */ private static class IsStandardDiagramPredicate implements Predicate { + @Override public boolean apply(Diagram input) { boolean apply = false; if (input.getElement() instanceof DDiagram) { @@ -311,6 +312,7 @@ public boolean apply(Diagram input) { */ private static class IsBorderedNodePredicate implements Predicate { + @Override public boolean apply(Node input) { // Is this node the main view of a DNode and a border // node ? @@ -327,6 +329,7 @@ public boolean apply(Node input) { */ private static class IsDirectlyCollapsedNodePredicate implements Predicate { + @Override public boolean apply(Node input) { boolean apply = false; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java index 7aafb1d649..752d212cda 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/StraightenToCommand.java @@ -667,7 +667,7 @@ private boolean isOverlapped(Node node, StraightenToCommandData data) { // the move. It should be the same as the one stored in GMF but // sometimes, probably caused by some bugs, it could be wrong in // GMF. - Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode); + Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, false, true); Rectangle initialAsboluteConstraint = initialRelativeConstraint.getTranslated(parentAbsoluteLocation); Point validInitialAbsoluteLocation = borderItemLocator.getValidLocation(initialAsboluteConstraint, node, new ArrayList(Arrays.asList(node))); Rectangle validInitialAbsoluteConstraint = initialAsboluteConstraint.getCopy(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java index 304daa7c5e..0346d6baf3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/AbstractCanonicalSynchronizer.java @@ -607,7 +607,7 @@ private LayoutDataResult updateAbstractDNode_ownedBorderedNodes_Bounds(View crea locator.setConstraint(constraint); dummyFigure.setVisible(true); final Rectangle rect = new Rectangle(constraint); - Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, true); + Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, true, false); rect.translate(parentAbsoluteLocation.x, parentAbsoluteLocation.y); dummyFigure.setBounds(rect); final Point realLocation = locator.getValidLocation(rect, createdNode, new ArrayList(Arrays.asList(createdNode))); @@ -666,7 +666,7 @@ private LayoutDataResult updateAbstractDNode_ownedBorderedNodes_Bounds(View crea // CanonicalDBorderItemLocator works with absolute GMF parent // location so we need to translate BorderedNode absolute location. - final org.eclipse.draw2d.geometry.Point parentAbsoluteLocation = GMFHelper.getAbsoluteBounds(parentNode).getTopLeft(); + final org.eclipse.draw2d.geometry.Point parentAbsoluteLocation = GMFHelper.getAbsoluteBounds(parentNode, false, false, false, false).getTopLeft(); final Point realLocation = locator.getValidLocation(new Rectangle(location.getTranslated(parentAbsoluteLocation), size), createdNode, Collections.singleton(createdNode)); // Compute the new relative position to the parent diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java index 04929f6260..cfff7f119e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/GMFHelper.java @@ -139,18 +139,6 @@ private GMFHelper() { // Helper to not instantiate } - /** - * Get the absolute location relative to the origin (Diagram). - * - * @param node - * the GMF Node - * - * @return the absolute location of the node relative to the origin (Diagram) - */ - public static Point getAbsoluteLocation(Node node) { - return getAbsoluteLocation(node, false); - } - /** * Get the absolute location relative to the origin (Diagram). * @@ -159,10 +147,13 @@ public static Point getAbsoluteLocation(Node node) { * @param insetsAware * true to consider the draw2D figures insets. Warning: Those insets are based on the * current Sirius editParts and could become wrong if a developer customizes them. + * @param adaptBorderNodeLocation + * Useful for specific border nodes, like in sequence diagrams, to center the border nodes if the + * coordinate is 0 (x for EAST or WEST side, y for NORTH or SOUTH side) * * @return the absolute location of the node relative to the origin (Diagram) */ - public static Point getAbsoluteLocation(Node node, boolean insetsAware) { + public static Point getAbsoluteLocation(Node node, boolean insetsAware, boolean adaptBorderNodeLocation) { // TODO: Location of title "DNode*NameEditPart", x coordinate, can be wrong according to label alignment. This // problem is not yet handled. @@ -174,7 +165,7 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { location.setY(gmfBounds.getY()); } ViewQuery viewQuery = new ViewQuery(node); - if (viewQuery.isBorderedNode() && layoutConstraint instanceof Bounds gmfBounds) { + if (adaptBorderNodeLocation && viewQuery.isBorderedNode() && layoutConstraint instanceof Bounds gmfBounds) { // manage location of bordered node with closest side if (node.getElement() instanceof DNode && node.getElement().eContainer() instanceof AbstractDNode) { DNode dNode = (DNode) node.getElement(); @@ -186,7 +177,7 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { Bounds parentBounds = (Bounds) parentLayoutConstraint; int position = CanonicalDBorderItemLocator.findClosestSideOfParent(new Rectangle(gmfBounds.getX(), gmfBounds.getY(), gmfBounds.getWidth(), gmfBounds.getHeight()), new Rectangle(parentBounds.getX(), parentBounds.getY(), parentBounds.getWidth(), parentBounds.getHeight())); - updateLocation(location, position, parentBounds, gmfBounds); + centerLocationIfZero(location, position, parentBounds, gmfBounds); } } } @@ -194,61 +185,61 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { if (viewQuery.isListCompartment()) { // Translate the compartment to be just below the the title, the x coordinate is also the same (same parent // insets) - Rectangle titleBounds = getAbsoluteBounds(getPreviousChild(node), true); + Rectangle titleBounds = getAbsoluteBounds(getPreviousChild(node), true, false, false, false); location.translate(titleBounds.preciseX(), titleBounds.preciseY() + titleBounds.preciseHeight()); // Translate from the spacing (5 pixels) location.translate(0, IContainerLabelOffsets.LABEL_OFFSET); } else if (viewQuery.isListItem()) { if (node.eContainer() instanceof Node container) { if (container.getChildren().get(0) == node) { - Point parentNodeLocation = getAbsoluteLocation(container, insetsAware); + Point parentNodeLocation = getAbsoluteLocation(container, insetsAware, false); location.translate(parentNodeLocation); if (insetsAware) { translateWithInsets(location, node); } } else { // Translate from the previous children - Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true); + Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true, false, false, false); location.translate(previousChildBounds.preciseX(), previousChildBounds.preciseY() + previousChildBounds.preciseHeight()); } } } else if (viewQuery.isRegionContainerCompartment()) { // Translate the compartment to be just below the the title, the x coordinate is also the same (same parent // insets) - Rectangle titleBounds = getAbsoluteBounds(getPreviousChild(node), true); + Rectangle titleBounds = getAbsoluteBounds(getPreviousChild(node), true, false, false, false); location.translate(titleBounds.preciseX(), titleBounds.preciseY() + titleBounds.preciseHeight()); // Translate from the spacing (5 pixels) location.translate(0, IContainerLabelOffsets.LABEL_OFFSET); } else if (viewQuery.isVerticalRegion()) { if (node.eContainer() instanceof Node container) { if (container.getChildren().get(0) == node) { - Point parentNodeLocation = getAbsoluteLocation(container, insetsAware); + Point parentNodeLocation = getAbsoluteLocation(container, insetsAware, false); location.translate(parentNodeLocation); if (insetsAware) { translateWithInsets(location, node); } } else { // Translate from the previous children - Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true); + Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true, false, false, false); location.translate(previousChildBounds.preciseX(), previousChildBounds.preciseY() + previousChildBounds.preciseHeight()); } } } else if (viewQuery.isHorizontalRegion()) { if (node.eContainer() instanceof Node container) { if (container.getChildren().get(0) == node) { - Point parentNodeLocation = getAbsoluteLocation(container, insetsAware); + Point parentNodeLocation = getAbsoluteLocation(container, insetsAware, false); location.translate(parentNodeLocation); if (insetsAware) { translateWithInsets(location, node); } } else { // Translate from the previous children - Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true); + Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true, false, false, false); location.translate(previousChildBounds.preciseX() + previousChildBounds.preciseWidth(), previousChildBounds.preciseY()); } } } else if (node.eContainer() instanceof Node container) { - Point parentNodeLocation = getAbsoluteLocation(container, insetsAware); + Point parentNodeLocation = getAbsoluteLocation(container, insetsAware, true); location.translate(parentNodeLocation); if (insetsAware) { translateWithInsets(location, node); @@ -538,10 +529,10 @@ private static void translateWithInsets(Rectangle boundsToTranslate, Node curren */ @Deprecated public static Point getLocation(Node node) { - return getAbsoluteLocation(node, true); + return getAbsoluteLocation(node, true, true); } - private static void updateLocation(Point location, int position, Bounds parentBounds, Bounds gmfBounds) { + private static void centerLocationIfZero(Point location, int position, Bounds parentBounds, Bounds gmfBounds) { switch (position) { case PositionConstants.NORTH: case PositionConstants.SOUTH: @@ -559,50 +550,56 @@ private static void updateLocation(Point location, int position, Bounds parentBo break; } } - - /** - * Get the absolute bounds relative to the origin (Diagram). - * - * @param node - * the GMF Node - * - * @return the absolute bounds of the node relative to the origin (Diagram) - */ - public static Rectangle getAbsoluteBounds(Node node) { - return getAbsoluteBounds(node, false); - } - - /** - * Get the absolute bounds relative to the origin (Diagram). - * - * @param node - * the GMF Node - * @param insetsAware - * true to consider the draw2D figures insets. Warning: Those insets are based on the - * current Sirius editParts and could become wrong if a developer customizes them. - * - * @return the absolute bounds of the node relative to the origin (Diagram) - */ - public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware) { - return getAbsoluteBounds(node, insetsAware, false, false); - } - - /** - * Get the absolute bounds relative to the origin (Diagram). - * - * @param node - * the GMF Node - * @param insetsAware - * true to consider the draw2D figures insets. Warning: Those insets are based on the - * current Sirius editParts and could become wrong if a developer customizes them. - * @param boxForConnection - * true if we want to have the bounds used to compute connection anchor from source or target, false - * otherwise - * @return the absolute bounds of the node relative to the origin (Diagram) - */ - public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection) { - return getAbsoluteBounds(node, insetsAware, boxForConnection, false); - } + // + // /** + // * Get the absolute bounds relative to the origin (Diagram). + // * + // * @param node + // * the GMF Node + // * @param adaptBorderNodeLocation + // * Useful for specific border nodes, like in sequence diagrams, to center the border nodes if the + // * coordinate is 0 (x for EAST or WEST side, y for NORTH or SOUTH side) + // * + // * @return the absolute bounds of the node relative to the origin (Diagram) + // */ + // public static Rectangle getAbsoluteBounds(Node node, boolean adaptBorderNodeLocation) { + // return getAbsoluteBounds(node, false, false, false, adaptBorderNodeLocation); + // } + // /** + // * Get the absolute bounds relative to the origin (Diagram). + // * + // * @param node + // * the GMF Node + // * @param insetsAware + // * true to consider the draw2D figures insets. Warning: Those insets are based on the + // * current Sirius editParts and could become wrong if a developer customizes them. + // * @param adaptBorderNodeLocation + // * Useful for specific border nodes, like in sequence diagrams, to center the border nodes if the + // * coordinate is 0 (x for EAST or WEST side, y for NORTH or SOUTH side) + // * + // * @return the absolute bounds of the node relative to the origin (Diagram) + // */ + // public static Rectangle getAbsoluteBounds2(Node node, boolean insetsAware, boolean adaptBorderNodeLocation) { + // return getAbsoluteBounds(node, insetsAware, false, false, adaptBorderNodeLocation); + // } + // + // /** + // * Get the absolute bounds relative to the origin (Diagram). + // * + // * @param node + // * the GMF Node + // * @param insetsAware + // * true to consider the draw2D figures insets. Warning: Those insets are based on the + // * current Sirius editParts and could become wrong if a developer customizes them. + // * @param boxForConnection + // * true if we want to have the bounds used to compute connection anchor from source or target, false + // * otherwise + // * @return the absolute bounds of the node relative to the origin (Diagram) + // */ + // public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection, boolean + // adaptBorderNodeLocation) { + // return getAbsoluteBounds(node, insetsAware, boxForConnection, false, adaptBorderNodeLocation); + // } /** * Get the absolute bounds relative to the origin (Diagram). @@ -617,9 +614,13 @@ public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolea * otherwise * @param recursiveGetBounds * true if this method is called from a parent "getBounds" call, false otherwise. + * @param adaptBorderNodeLocation + * Useful for specific border nodes, like in sequence diagrams, to center the border nodes if the + * coordinate is 0 (x for EAST or WEST side, y for NORTH or SOUTH side) + * * @return the absolute bounds of the node relative to the origin (Diagram) */ - public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection, boolean recursiveGetBounds) { + public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection, boolean recursiveGetBounds, boolean adaptBorderNodeLocation) { if (!recursiveGetBounds) { boundsCache.clear(); } @@ -627,7 +628,7 @@ public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolea if (boundsCache.containsKey(node)) { result = boundsCache.get(node); } else { - Point location = getAbsoluteLocation(node, insetsAware); + Point location = getAbsoluteLocation(node, insetsAware, adaptBorderNodeLocation); Rectangle bounds = getBounds(node, false, false, boxForConnection, recursiveGetBounds, location); result = new PrecisionRectangle(location.preciseX(), location.preciseY(), bounds.preciseWidth(), bounds.preciseHeight()); if (recursiveGetBounds) { @@ -717,7 +718,7 @@ public static Option getAbsoluteBounds(View view, boolean insetsAware public static Option getAbsoluteBounds(View view, boolean insetsAware, boolean boxForConnection) { Option result = Options.newNone(); if (view instanceof Node) { - result = Options.newSome(getAbsoluteBounds((Node) view, insetsAware, boxForConnection, false)); + result = Options.newSome(getAbsoluteBounds((Node) view, insetsAware, boxForConnection, false, true)); } else if (view instanceof Edge) { result = getAbsoluteBounds((Edge) view, insetsAware, boxForConnection); } @@ -975,7 +976,7 @@ private static int getBorderNodesSides(Node container, Rectangle containerChildr for (Iterator children = Iterators.filter(container.getChildren().iterator(), Node.class); children.hasNext(); /* */) { Node child = children.next(); if (new NodeQuery(child).isBorderedNode()) { - Rectangle borderNodeBounds = getAbsoluteBounds(child, true); + Rectangle borderNodeBounds = getAbsoluteBounds(child, true, false, false, false); if (borderNodeBounds.preciseX() == containerChildrenBounds.preciseX()) { result = result | PositionConstants.LEFT; } @@ -1051,7 +1052,7 @@ private static Rectangle getChildrenBounds(Node container, boolean considerBorde if (containerViewQuery.isListContainer() || containerViewQuery.isListCompartment() || containerViewQuery.isVerticalRegionContainerCompartment()) { if (!container.getChildren().isEmpty()) { Node lastChild = getLastChild(container, considerBorderNodes); - result = getAbsoluteBounds(lastChild, true, false, true); + result = getAbsoluteBounds(lastChild, true, false, true, false); } } else { for (Iterator children = Iterators.filter(container.getChildren().iterator(), Node.class); children.hasNext(); /* */) { @@ -1059,7 +1060,7 @@ private static Rectangle getChildrenBounds(Node container, boolean considerBorde // The border nodes are ignored, except if it is expected to consider it (auto-size of a container with // children having border nodes) if (considerBorderNodes || !(new NodeQuery(child).isBorderedNode())) { - Rectangle childAbsoluteBounds = getAbsoluteBounds(child, true, false, true); + Rectangle childAbsoluteBounds = getAbsoluteBounds(child, true, false, true, false); if (result == null) { result = childAbsoluteBounds.getCopy(); } else { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/borderednode/CanonicalDBorderItemLocator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/borderednode/CanonicalDBorderItemLocator.java index 846e5db4fc..3f2335fd83 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/borderednode/CanonicalDBorderItemLocator.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/refresh/borderednode/CanonicalDBorderItemLocator.java @@ -682,7 +682,7 @@ private Option conflicts(final Point recommendedLocation, final Dimen if (borderItemLayoutConstraint instanceof Bounds) { Dimension extendedDimension = getExtendedDimension(borderItem); - Rectangle borderItemBounds = GMFHelper.getAbsoluteBounds(borderItem, true); + Rectangle borderItemBounds = GMFHelper.getAbsoluteBounds(borderItem, false, false, false, false); if (extendedDimension != null) { borderItemBounds = PortLayoutHelper.getUncollapseCandidateLocation(extendedDimension, borderItemBounds, getParentBorder()); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java index 42cadd22aa..00b901d2db 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java @@ -1021,7 +1021,7 @@ private void applyFormatForBorderedNode(final DSemanticDecorator semanticDecorat final org.eclipse.draw2d.geometry.Point realLocation = locator.getValidLocation(rect, toRestoreView, portsNodesToIgnore); // Compute the new relative position to the parent - final org.eclipse.draw2d.geometry.Point parentAbsoluteLocation = GMFHelper.getAbsoluteBounds(parentNode, true).getTopLeft(); + final org.eclipse.draw2d.geometry.Point parentAbsoluteLocation = GMFHelper.getAbsoluteBounds(parentNode, false, false, false, false).getTopLeft(); locationToApply.setX(realLocation.x); locationToApply.setY(realLocation.y); locationToApply = FormatDataHelper.INSTANCE.getTranslated(locationToApply, parentAbsoluteLocation.negate()); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SnapCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SnapCommand.java index 17776d00b7..eedfb60e6c 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SnapCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SnapCommand.java @@ -183,7 +183,7 @@ private void handleNodeAndContainer(IAbstractDiagramNodeEditPart newEditPart, Co figure.translateToAbsolute(figureBounds); // We compute the new GMF Absolute Location. The SnapToHelper works with absolute coordinates. - Point newGMFAbsoluteLocation = GMFHelper.getAbsoluteLocation((Node) newEditPart.getModel(), true); + Point newGMFAbsoluteLocation = GMFHelper.getAbsoluteLocation((Node) newEditPart.getModel(), true, true); // We convert in screen coordinate as it is expected by the SnapToHelper GraphicalHelper.logical2screen(newGMFAbsoluteLocation, newEditPart); @@ -220,11 +220,11 @@ private void handleBorderNode(IDiagramBorderNodeEditPart newEditPart, CompositeT // We use the CanonicalDBorderItemLocator to compute the new border node location in absolute coordinates Dimension spacing = (Dimension) newEditPart.getViewer().getProperty(SnapToGrid.PROPERTY_GRID_SPACING); CanonicalDBorderItemLocator itemLocator = initCDBIL(node, parentNode, spacing); - Rectangle newGMFAbsoluteBounds = GMFHelper.getAbsoluteBounds(node, true); + Rectangle newGMFAbsoluteBounds = GMFHelper.getAbsoluteBounds(node, true, false, false, true); Point newValidLocation = itemLocator.getValidLocation(newGMFAbsoluteBounds, node, Collections.singleton(node)); // We compute the new relative coordinates - Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, true); + Point parentAbsoluteLocation = GMFHelper.getAbsoluteLocation(parentNode, true, false); Point newValidRelativeLocation = newValidLocation.getTranslated(parentAbsoluteLocation.getNegated()); // We compute the move delta by calculating the difference between the current figure relative location and diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/CanonicalDBorderItemLocatorTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/CanonicalDBorderItemLocatorTest.java index e97b2403cf..1ab081fb06 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/CanonicalDBorderItemLocatorTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/CanonicalDBorderItemLocatorTest.java @@ -89,7 +89,7 @@ public boolean apply(EObject arg0) { Node node = (Node) iterator.next(); CanonicalDBorderItemLocator locator = new CanonicalDBorderItemLocator((Node) node.eContainer(), PositionConstants.NSEW); locator.setBorderItemOffset(IBorderItemOffsets.DEFAULT_OFFSET); - Rectangle expectedBounds = GMFHelper.getAbsoluteBounds(node); + Rectangle expectedBounds = GMFHelper.getAbsoluteBounds(node, false, false, false, true); Point location = locator.getValidLocation(expectedBounds, node, Collections.singletonList(node)); assertEquals("The border node should not be in conflict", expectedBounds.getLocation(), location); } diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java index 49967a9386..21e4d900be 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java @@ -637,7 +637,7 @@ protected void assertBorderedNodeAtLocation(String borderedNodeLabel, Point expe errorMessage = "the BorderedNode has been created at wrong location (for near collapsed bordered node case)."; } // Check GMF - Point gmfNodeLocation = GMFHelper.getAbsoluteLocation((Node) borderNodePart.getModel(), true); + Point gmfNodeLocation = GMFHelper.getAbsoluteLocation((Node) borderNodePart.getModel(), true, true); assertSameLocation("For GMF, " + errorMessage, expectedLocation, gmfNodeLocation, parentLocation, creationLocation, parentPart); // Check Draw2d assertSameLocation("For Draw2d, " + errorMessage, expectedLocation, nodeLocation, parentLocation, creationLocation, parentPart); diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java index fb2c771111..d59b008650 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java @@ -89,8 +89,8 @@ public void testCreateTwoBorderNodesAtSameLocation() { assertFalse("Second border node should not overlap the first one (draw2d).", firstNewNodeAbsoluteBounds.intersects(secondNewNodeAbsoluteLocation)); - Rectangle firstNewNodeGMFBounds = GMFHelper.getAbsoluteBounds((Node) firstNewNode.part().getModel()); - Rectangle secondNewNodeGMFBounds = GMFHelper.getAbsoluteBounds((Node) secondNewNode.part().getModel()); + Rectangle firstNewNodeGMFBounds = GMFHelper.getAbsoluteBounds((Node) firstNewNode.part().getModel(), false, false, false, true); + Rectangle secondNewNodeGMFBounds = GMFHelper.getAbsoluteBounds((Node) secondNewNode.part().getModel(), false, false, false, true); assertFalse("Second border node should not overlap the first one (GMF).", firstNewNodeGMFBounds.intersects(secondNewNodeGMFBounds)); diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeWithBorderNodeCreationPositionWithSnapToGridTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeWithBorderNodeCreationPositionWithSnapToGridTest.java index c53b8590f4..7a1692b63e 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeWithBorderNodeCreationPositionWithSnapToGridTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/EdgeWithBorderNodeCreationPositionWithSnapToGridTest.java @@ -87,14 +87,14 @@ public String getFailureMessage() { Point draw2DSourceBNLocation = GraphicalHelper.getAbsoluteBoundsIn100Percent(source, true).getTopLeft(); assertTrue("For starting point (" + draw2DSourceBNLocation.preciseX() + ", " + draw2DSourceBNLocation.preciseY() + "), the x or y coordinate should be on the grid (step=" + gridStep + ") or at least one should be the same as parent: " + parentSourceBounds + ".", checkLocation(draw2DSourceBNLocation, parentSourceBounds)); - Point gmfSourceBNLocation = GMFHelper.getAbsoluteLocation((Node) source.getModel(), true); + Point gmfSourceBNLocation = GMFHelper.getAbsoluteLocation((Node) source.getModel(), true, true); assertEquals("The computing starting point from GMF data should be the same than draw2D", draw2DSourceBNLocation, gmfSourceBNLocation); Rectangle parentTargetBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(target, true); Point draw2DTargetBNLocation = GraphicalHelper.getAbsoluteBoundsIn100Percent(target, true).getTopLeft(); assertTrue("For ending point (" + draw2DTargetBNLocation.preciseX() + ", " + draw2DTargetBNLocation.preciseY() + "), the x or y coordinate should be on the grid (step=" + gridStep + ") or at least one should be the same as parent: " + parentTargetBounds + ".", checkLocation(draw2DTargetBNLocation, parentTargetBounds)); - Point gmfTargetBNLocation = GMFHelper.getAbsoluteLocation((Node) target.getModel(), true); + Point gmfTargetBNLocation = GMFHelper.getAbsoluteLocation((Node) target.getModel(), true, true); assertEquals("The computing starting point from GMF data should be the same than draw2D", draw2DTargetBNLocation, gmfTargetBNLocation); // Contrary to super class, the checkSide are not done because // snapToGrid is enabled and has effect on the side. diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/GMFHelperTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/GMFHelperTest.java index 822067eb92..995e952e50 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/GMFHelperTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/layout/GMFHelperTest.java @@ -273,7 +273,7 @@ private void testContainerBounds(String representationName, String elementToChec // It's strange, the above method does not return absolute bounds. To check in another commit. And the method // GraphicalHelper.getAbsoluteBoundsIn100Percent consider handleBounds and this is not what is expected here. ((GraphicalEditPart) swtBotEditPart.part()).getFigure().translateToAbsolute(draw2DAbsoluteBounds); - Rectangle gmfAbsoluteBounds = GMFHelper.getAbsoluteBounds((Node) swtBotEditPart.part().getModel(), true); + Rectangle gmfAbsoluteBounds = GMFHelper.getAbsoluteBounds((Node) swtBotEditPart.part().getModel(), true, false, false, false); assertEquals("The GMF width of " + elementToCheckName + " in " + representationName + " does not correspond to the Draw2D one.", draw2DAbsoluteBounds.preciseWidth(), gmfAbsoluteBounds.preciseWidth()); assertEquals("The GMF height of " + elementToCheckName + " in " + representationName + " does not correspond to the Draw2D one.", draw2DAbsoluteBounds.preciseHeight(), diff --git a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/SiriusDebugView.java b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/SiriusDebugView.java index 25ba6cc0a5..23c2bbddb8 100644 --- a/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/SiriusDebugView.java +++ b/plugins/org.eclipse.sirius.ui.debug/src/org/eclipse/sirius/ui/debug/SiriusDebugView.java @@ -306,10 +306,10 @@ private void appendBoundsDetails(IGraphicalEditPart part, StringBuilder sb) { sb.append("Location (GMF): Location(" + location.getX() + ", " + location.getY() + ")\n"); } - Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node, true); + Rectangle absoluteBounds = GMFHelper.getAbsoluteBounds(node, true, false, false, false); sb.append("Bounds (GMF absolute - insets): " + absoluteBounds + "\n"); - absoluteBounds = GMFHelper.getAbsoluteBounds(node, false); + absoluteBounds = GMFHelper.getAbsoluteBounds(node, true, false, false, false); sb.append("Bounds (GMF absolute - no insets): " + absoluteBounds + "\n"); Option elt = ISequenceElementAccessor.getISequenceElement(part.getNotationView());