From f0e5c0ddd11cff6cc32b5ab6d76631f9fc38de4e Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Tue, 30 Jul 2024 11:55:51 +0200 Subject: [PATCH] [426] Handle border nodes more precisely Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/426 --- .../ui/internal/refresh/GMFHelper.java | 20 ++++++---- .../CanonicalDBorderItemLocator.java | 38 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) 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 3d52accd6e..7ff0908f58 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 @@ -165,11 +165,13 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { Point location = new Point(0, 0); LayoutConstraint layoutConstraint = node.getLayoutConstraint(); - if (layoutConstraint instanceof Bounds && !(new ViewQuery(node).isRegion())) { + if (layoutConstraint instanceof Bounds gmfBounds && !(new ViewQuery(node).isRegion())) { // The bounds is computed for horizontal or vertical regions, even if it is stored in GMF data - Bounds gmfBounds = (Bounds) layoutConstraint; location.setX(gmfBounds.getX()); location.setY(gmfBounds.getY()); + } + ViewQuery viewQuery = new ViewQuery(node); + if (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 +188,6 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { } } } - ViewQuery viewQuery = new ViewQuery(node); if (viewQuery.isListCompartment()) { // Translate the compartment to be just below the the title, the x coordinate is also the same (same parent // insets) @@ -242,7 +243,7 @@ public static Point getAbsoluteLocation(Node node, boolean insetsAware) { Rectangle previousChildBounds = getAbsoluteBounds(getPreviousChild(node), true); location.translate(previousChildBounds.preciseX() + previousChildBounds.preciseWidth(), previousChildBounds.preciseY()); } - } + } } else if (node.eContainer() instanceof Node container) { Point parentNodeLocation = getAbsoluteLocation(container, insetsAware); location.translate(parentNodeLocation); @@ -377,7 +378,7 @@ private static Dimension getBottomRightInsets(Node container) { result.setWidth(result.width() + borderSize.width()); result.setHeight(result.height() + borderSize.height()); } else if (new DDiagramElementContainerExperimentalQuery(ddec).isRegion()) { - // No margin, except the border size + // No margin, except the border size Dimension borderSize = getBorderSize(ddec); result.setWidth(result.width() + borderSize.width()); result.setHeight(result.height() + borderSize.height()); @@ -921,9 +922,12 @@ private static void replaceAutoSize(Node node, PrecisionRectangle bounds, boolea Dimension bottomRightInsets = getBottomRightInsets(node); // Do not add bottom right insets and shadow if there is at least one border node on the corresponding // side - int borderNodesSides = getBorderNodesSides(node, childrenBounds); - boolean isBorderNodeOnRightSide = recursive && (PositionConstants.RIGHT & borderNodesSides) == PositionConstants.RIGHT; - boolean isBorderNodeOnBottomSide = recursive && (PositionConstants.BOTTOM & borderNodesSides) == PositionConstants.BOTTOM; + int borderNodesSides = PositionConstants.NONE; + if (recursive) { + borderNodesSides = getBorderNodesSides(node, childrenBounds); + } + boolean isBorderNodeOnRightSide = (PositionConstants.RIGHT & borderNodesSides) == PositionConstants.RIGHT; + boolean isBorderNodeOnBottomSide = (PositionConstants.BOTTOM & borderNodesSides) == PositionConstants.BOTTOM; childrenBounds.resize(isBorderNodeOnRightSide ? 0 : bottomRightInsets.width() + shadowBorderSize, isBorderNodeOnBottomSide ? 0 : bottomRightInsets.height() + shadowBorderSize); // Replace -1 by the new computed values if (bounds.width == -1) { 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 609a0e589d..846e5db4fc 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2021 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -669,26 +669,28 @@ private Option conflicts(final Point recommendedLocation, final Dimen final ListIterator iterator = borderItems.listIterator(); while (iterator.hasNext()) { final Node borderItem = (Node) iterator.next(); - boolean takeIntoAccount = true; - // Does not consider label that is not on border. - ViewQuery viewQuery = new ViewQuery(borderItem); - NodeQuery nodeQuery = new NodeQuery(borderItem); - if (!nodeQuery.isBorderedNode() && !viewQuery.isForNameEditPartOnBorder()) { - takeIntoAccount = false; - } - if (isVisible(borderItem) && takeIntoAccount) { - LayoutConstraint borderItemLayoutConstraint = borderItem.getLayoutConstraint(); - if (borderItemLayoutConstraint instanceof Bounds) { - Dimension extendedDimension = getExtendedDimension(borderItem); + if (!portsNodesToIgnore.contains(borderItem)) { + boolean takeIntoAccount = true; + // Does not consider label that is not on border. + ViewQuery viewQuery = new ViewQuery(borderItem); + NodeQuery nodeQuery = new NodeQuery(borderItem); + if (!nodeQuery.isBorderedNode() && !viewQuery.isForNameEditPartOnBorder()) { + takeIntoAccount = false; + } + if (isVisible(borderItem) && takeIntoAccount) { + LayoutConstraint borderItemLayoutConstraint = borderItem.getLayoutConstraint(); + if (borderItemLayoutConstraint instanceof Bounds) { + Dimension extendedDimension = getExtendedDimension(borderItem); - Rectangle borderItemBounds = GMFHelper.getAbsoluteBounds(borderItem, true); + Rectangle borderItemBounds = GMFHelper.getAbsoluteBounds(borderItem, true); - if (extendedDimension != null) { - borderItemBounds = PortLayoutHelper.getUncollapseCandidateLocation(extendedDimension, borderItemBounds, getParentBorder()); - } + if (extendedDimension != null) { + borderItemBounds = PortLayoutHelper.getUncollapseCandidateLocation(extendedDimension, borderItemBounds, getParentBorder()); + } - if (!(portsNodesToIgnore.contains(borderItem)) && borderItemBounds.intersects(recommendedRect)) { - return Options.newSome(borderItemBounds); + if (borderItemBounds.intersects(recommendedRect)) { + return Options.newSome(borderItemBounds); + } } } }