use of org.eclipse.sirius.components.diagrams.layout.incremental.utils.RectangleSide in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method updateBorderNodeAccordingParentResize.
/**
* Move the border node along the side according to the parent Size changes.
*/
private void updateBorderNodeAccordingParentResize(Optional<IDiagramEvent> optionalDiagramElementEvent, Bounds initialNodeBounds, Bounds newNodeBounds, List<BorderNodesOnSide> borderNodesPerSideList, String parentId) {
// @formatter:off
boolean isParentRectangleResized = optionalDiagramElementEvent.filter(ResizeEvent.class::isInstance).map(ResizeEvent.class::cast).map(ResizeEvent::getNodeId).filter(parentId::equals).isPresent();
if (isParentRectangleResized && !initialNodeBounds.equals(newNodeBounds)) {
EnumMap<RectangleSide, Double> sideHomotheticRatio = this.getHomotheticRatio(initialNodeBounds.getSize(), newNodeBounds.getSize());
Size initialSize = initialNodeBounds.getSize();
Size newSize = newNodeBounds.getSize();
for (BorderNodesOnSide borderNodesOnSide : borderNodesPerSideList) {
RectangleSide side = borderNodesOnSide.getSide();
List<NodeLayoutData> borderNodes = borderNodesOnSide.getBorderNodes();
double homotheticRatio = sideHomotheticRatio.get(side);
for (NodeLayoutData borderNodeLayoutData : borderNodes) {
// The border node position is done in the parent node coordinate system
Position position = borderNodeLayoutData.getPosition();
Size size = borderNodeLayoutData.getSize();
if (RectangleSide.NORTH.equals(side)) {
borderNodeLayoutData.setPosition(Position.at((position.getX() + size.getWidth() / 2) * homotheticRatio - size.getWidth() / 2, position.getY()));
} else if (RectangleSide.SOUTH.equals(side)) {
double dySouthShift = newSize.getHeight() - initialSize.getHeight();
borderNodeLayoutData.setPosition(Position.at((position.getX() + size.getWidth() / 2) * homotheticRatio - size.getWidth() / 2, position.getY() + dySouthShift));
} else if (RectangleSide.WEST.equals(side)) {
borderNodeLayoutData.setPosition(Position.at(position.getX(), (position.getY() + size.getHeight() / 2) * homotheticRatio - size.getHeight() / 2));
} else if (RectangleSide.EAST.equals(side)) {
double dxEastShift = newSize.getWidth() - initialSize.getWidth();
borderNodeLayoutData.setPosition(Position.at(position.getX() + dxEastShift, (position.getY() + size.getHeight() / 2) * homotheticRatio - size.getHeight() / 2));
}
}
}
}
}
use of org.eclipse.sirius.components.diagrams.layout.incremental.utils.RectangleSide 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.RectangleSide in project sirius-components by eclipse-sirius.
the class IncrementalLayoutEngine method updateBorderNodeLabel.
private void updateBorderNodeLabel(Optional<IDiagramEvent> optionalDiagramElementEvent, List<BorderNodesOnSide> borderNodesPerSideList) {
for (BorderNodesOnSide borderNodesOnSide : borderNodesPerSideList) {
RectangleSide side = borderNodesOnSide.getSide();
List<NodeLayoutData> borderNodes = borderNodesOnSide.getBorderNodes();
for (NodeLayoutData borderNodeLayoutData : borderNodes) {
this.borderNodeLabelPositionProvider.updateLabelPosition(optionalDiagramElementEvent, side, borderNodeLayoutData);
}
}
}
Aggregations