use of org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method snapBorderNodes.
/**
* Update the border node by snapping it to the parentRectangle, that is moving it to the closest point of the
* parentRectangle.
*
* @param borderNodesLayoutData
* the border nodes which position is given in the rectangle upper right corner coordinates system
* @return for each side of the given parentRectangle, the list of the updates border node
*/
private List<BorderNodesOnSide> snapBorderNodes(List<NodeLayoutData> borderNodesLayoutData, Size parentRectangle, ISiriusWebLayoutConfigurator layoutConfigurator) {
EnumMap<RectangleSide, List<NodeLayoutData>> borderNodesPerSide = new EnumMap<>(RectangleSide.class);
Geometry geometry = new Geometry();
for (NodeLayoutData borderNodeLayoutData : borderNodesLayoutData) {
double portOffset = layoutConfigurator.configureByType(borderNodeLayoutData.getNodeType()).getProperty(CoreOptions.PORT_BORDER_OFFSET).doubleValue();
Bounds borderNodeRectangle = Bounds.newBounds().position(borderNodeLayoutData.getPosition()).size(borderNodeLayoutData.getSize()).build();
PointOnRectangleInfo borderNodePositionOnSide = geometry.snapBorderNodeOnRectangle(borderNodeRectangle, parentRectangle, portOffset);
// update the border node
borderNodeLayoutData.setPosition(borderNodePositionOnSide.getPosition());
borderNodesPerSide.computeIfAbsent(borderNodePositionOnSide.getSide(), side -> new ArrayList<>());
borderNodesPerSide.get(borderNodePositionOnSide.getSide()).add(borderNodeLayoutData);
}
// @formatter:off
return borderNodesPerSide.entrySet().stream().map(entry -> new BorderNodesOnSide(entry.getKey(), entry.getValue())).collect(Collectors.toList());
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds in project sirius-components by eclipse-sirius.
the class EdgeRoutingPointsProvider method getRoutingPoints.
public List<Position> getRoutingPoints(EdgeLayoutData edge) {
List<Position> positions = List.of();
if (edge.getSource().equals(edge.getTarget())) {
positions = this.getRoutingPointsToMyself(edge.getSource().getPosition(), edge.getSource().getSize().getWidth());
} else {
Bounds sourceBounds = this.getAbsoluteBounds(edge.getSource());
Bounds targetBounds = this.getAbsoluteBounds(edge.getTarget());
this.supportOldDiagramWithExistingEdge(edge);
Position sourceAbsolutePosition = this.toAbsolutePosition(edge.getSourceAnchorRelativePosition(), sourceBounds);
Position targetAbsolutePosition = this.toAbsolutePosition(edge.getTargetAnchorRelativePosition(), targetBounds);
Geometry geometry = new Geometry();
Optional<Position> optionalSourceIntersection = geometry.getIntersection(targetAbsolutePosition, sourceAbsolutePosition, sourceBounds);
Optional<Position> optionalTargetIntersection = geometry.getIntersection(sourceAbsolutePosition, targetAbsolutePosition, targetBounds);
if (optionalSourceIntersection.isPresent() && optionalTargetIntersection.isPresent()) {
positions = List.of(optionalSourceIntersection.get(), optionalTargetIntersection.get());
}
}
return positions;
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method layoutNode.
private void layoutNode(Optional<IDiagramEvent> optionalDiagramElementEvent, NodeLayoutData node, ISiriusWebLayoutConfigurator layoutConfigurator) {
Bounds initialNodeBounds = Bounds.newBounds().position(node.getPosition()).size(node.getSize()).build();
// first layout child nodes
for (NodeLayoutData childNode : node.getChildrenNodes()) {
this.layoutNode(optionalDiagramElementEvent, childNode, layoutConfigurator);
}
// compute the node size according to what has been done in the previous steps
Size size = this.nodeSizeProvider.getSize(optionalDiagramElementEvent, node, layoutConfigurator);
if (!this.getRoundedSize(size).equals(this.getRoundedSize(node.getSize()))) {
node.setSize(size);
node.setChanged(true);
}
// recompute the node position
Position position = this.nodePositionProvider.getPosition(optionalDiagramElementEvent, node);
if (!position.equals(node.getPosition())) {
node.setPosition(position);
node.setChanged(true);
node.setPinned(true);
}
// resolve overlaps due to previous changes
new OverlapsUpdater().update(node);
// resize / change position according to the content
new ContainmentUpdater().update(node);
// update the border node once the current node bounds are updated
Bounds newBounds = Bounds.newBounds().position(node.getPosition()).size(node.getSize()).build();
List<BorderNodesOnSide> borderNodesOnSide = this.layoutBorderNodes(optionalDiagramElementEvent, node.getBorderNodes(), initialNodeBounds, newBounds, layoutConfigurator);
// recompute the label
if (node.getLabel() != null) {
node.getLabel().setPosition(this.nodeLabelPositionProvider.getPosition(node, node.getLabel(), borderNodesOnSide));
}
}
Aggregations