Search in sources :

Example 1 with ISiriusWebLayoutConfigurator

use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.

the class NodeSizeProviderTests method testNodeSizeWithExistingSize.

@Test
public void testNodeSizeWithExistingSize() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
    ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
    Size size = nodeSizeProvider.getSize(Optional.empty(), this.createNodeLayoutData(Size.of(WIDTH_80, HEIGHT_50)), layoutConfigurator);
    assertThat(size).extracting(Size::getHeight).isEqualTo(Double.valueOf(HEIGHT_50));
    assertThat(size).extracting(Size::getWidth).isEqualTo(Double.valueOf(WIDTH_80));
    imageSizeProvider.dispose();
}
Also used : ISiriusWebLayoutConfigurator(org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator) Size(org.eclipse.sirius.components.diagrams.Size) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) Test(org.junit.jupiter.api.Test)

Example 2 with ISiriusWebLayoutConfigurator

use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator 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
}
Also used : Geometry(org.eclipse.sirius.components.diagrams.layout.incremental.utils.Geometry) CoreOptions(org.eclipse.elk.core.options.CoreOptions) Size(org.eclipse.sirius.components.diagrams.Size) Ratio(org.eclipse.sirius.components.diagrams.Ratio) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) ArrayList(java.util.ArrayList) EdgeRoutingPointsProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeRoutingPointsProvider) Geometry(org.eclipse.sirius.components.diagrams.layout.incremental.utils.Geometry) BigDecimal(java.math.BigDecimal) NodePositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodePositionProvider) Service(org.springframework.stereotype.Service) OverlapsUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) Bounds(org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds) RoundingMode(java.math.RoundingMode) EdgeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) ISiriusWebLayoutConfigurator(org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator) EnumMap(java.util.EnumMap) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent) ContainmentUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater) IContainerLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.IContainerLayoutData) Collectors(java.util.stream.Collectors) DoublePositionEvent(org.eclipse.sirius.components.diagrams.events.DoublePositionEvent) MoveEvent(org.eclipse.sirius.components.diagrams.events.MoveEvent) Objects(java.util.Objects) List(java.util.List) BorderNodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider) RectangleSide(org.eclipse.sirius.components.diagrams.layout.incremental.utils.RectangleSide) Optional(java.util.Optional) EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) PointOnRectangleInfo(org.eclipse.sirius.components.diagrams.layout.incremental.utils.PointOnRectangleInfo) Bounds(org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds) PointOnRectangleInfo(org.eclipse.sirius.components.diagrams.layout.incremental.utils.PointOnRectangleInfo) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) RectangleSide(org.eclipse.sirius.components.diagrams.layout.incremental.utils.RectangleSide) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 3 with ISiriusWebLayoutConfigurator

use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.

the class NodeSizeProviderTests method testNodeSize.

@Test
public void testNodeSize() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
    ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
    Size size = nodeSizeProvider.getSize(Optional.empty(), this.createNodeLayoutData(Size.UNDEFINED), layoutConfigurator);
    assertThat(size).extracting(Size::getHeight).isEqualTo(Double.valueOf(HEIGHT_70));
    assertThat(size).extracting(Size::getWidth).isEqualTo(Double.valueOf(WIDTH_150));
    imageSizeProvider.dispose();
}
Also used : ISiriusWebLayoutConfigurator(org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator) Size(org.eclipse.sirius.components.diagrams.Size) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) Test(org.junit.jupiter.api.Test)

Example 4 with ISiriusWebLayoutConfigurator

use of org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator in project sirius-components by eclipse-sirius.

the class NodeSizeProviderTests method testResizeNodeEvent.

@Test
public void testResizeNodeEvent() {
    Size initialNodeSize = Size.of(200, 100);
    NodeLayoutData nodeLayoutData = this.createNodeLayoutData(initialNodeSize);
    NodeLayoutData nodeLayoutData2 = this.createNodeLayoutData(initialNodeSize);
    Size newSize = Size.of(100, 50);
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(imageSizeProvider);
    Optional<IDiagramEvent> optionalEvent = Optional.of(new ResizeEvent(nodeLayoutData.getId(), Position.UNDEFINED, newSize));
    ISiriusWebLayoutConfigurator layoutConfigurator = new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator();
    Size newSizeFromProvider = nodeSizeProvider.getSize(optionalEvent, nodeLayoutData, layoutConfigurator);
    Size newSizeFromProvider2 = nodeSizeProvider.getSize(optionalEvent, nodeLayoutData2, layoutConfigurator);
    assertThat(newSizeFromProvider).isEqualTo(newSize);
    assertThat(newSizeFromProvider2).isEqualTo(initialNodeSize);
}
Also used : Size(org.eclipse.sirius.components.diagrams.Size) ISiriusWebLayoutConfigurator(org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) IDiagramEvent(org.eclipse.sirius.components.diagrams.events.IDiagramEvent) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Size (org.eclipse.sirius.components.diagrams.Size)4 ISiriusWebLayoutConfigurator (org.eclipse.sirius.components.diagrams.layout.ISiriusWebLayoutConfigurator)4 NodeSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider)4 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)3 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)3 Test (org.junit.jupiter.api.Test)3 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)2 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)2 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)2 BigDecimal (java.math.BigDecimal)1 RoundingMode (java.math.RoundingMode)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CoreOptions (org.eclipse.elk.core.options.CoreOptions)1 Position (org.eclipse.sirius.components.diagrams.Position)1 Ratio (org.eclipse.sirius.components.diagrams.Ratio)1