Skip to content

Commit

Permalink
[426] Handle border nodes more precisely
Browse files Browse the repository at this point in the history
Bug: #426
  • Loading branch information
lredor committed Sep 10, 2024
1 parent 01a8883 commit f0e5c0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -669,26 +669,28 @@ private Option<Rectangle> 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);
}
}
}
}
Expand Down

0 comments on commit f0e5c0d

Please sign in to comment.