Search in sources :

Example 1 with ImageSizeProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider in project sirius-components by eclipse-sirius.

the class NodeResizeTests method createDiagramCreationService.

private TestDiagramCreationService createDiagramCreationService(Diagram diagram) {
    IRepresentationDescriptionSearchService.NoOp representationDescriptionSearchService = new IRepresentationDescriptionSearchService.NoOp() {

        @Override
        public Optional<IRepresentationDescription> findById(IEditingContext editingContext, UUID representationDescriptionId) {
            DiagramDescription diagramDescription = NodeResizeTests.this.defaultTestDiagramDescriptionProvider.getDefaultDiagramDescription(diagram);
            return Optional.of(diagramDescription);
        }
    };
    NodeSizeProvider nodeSizeProvider = new NodeSizeProvider(new ImageSizeProvider());
    IncrementalLayoutEngine incrementalLayoutEngine = new IncrementalLayoutEngine(nodeSizeProvider);
    LayoutService layoutService = new LayoutService(new IELKDiagramConverter.NoOp(), new IncrementalLayoutDiagramConverter(), new LayoutConfiguratorRegistry(List.of()), new ELKLayoutedDiagramProvider(), new IncrementalLayoutedDiagramProvider(), representationDescriptionSearchService, incrementalLayoutEngine);
    return new TestDiagramCreationService(this.objectService, representationDescriptionSearchService, layoutService);
}
Also used : TestDiagramCreationService(org.eclipse.sirius.components.diagrams.layout.services.TestDiagramCreationService) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) IELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.IELKDiagramConverter) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ELKLayoutedDiagramProvider(org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider) NodeSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider) LayoutService(org.eclipse.sirius.components.diagrams.layout.LayoutService) UUID(java.util.UUID) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)

Example 2 with ImageSizeProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider 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 3 with ImageSizeProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneNodeAndOneBorderNode.

@Test
public void testDiagramOneNodeAndOneBorderNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node borderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node node = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(borderNode)).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    ElkNode elkNode = elkDiagram.getChildren().get(0);
    assertThat(elkNode.getPorts().size()).isEqualTo(1);
    ElkPort elkPort = elkNode.getPorts().get(0);
    assertThat(elkPort.getIdentifier()).isEqualTo(borderNode.getId().toString());
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) ElkPort(org.eclipse.elk.graph.ElkPort) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 4 with ImageSizeProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneEdgeBetweenTwoBorderNodes.

@Test
public void testDiagramOneEdgeBetweenTwoBorderNodes() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node firstBorderNode = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node secondBorderNode = Node.newNode(diagramBuilder.getNode(SECOND_NODE_ID)).style(diagramBuilder.getRectangularNodeStyle()).build();
    Node node = Node.newNode(diagramBuilder.getNode(THIRD_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).borderNodes(List.of(firstBorderNode, secondBorderNode)).build();
    Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, firstBorderNode.getId(), secondBorderNode.getId())).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getChildren().size()).isEqualTo(1);
    assertThat(elkDiagram.getChildren().get(0)).isInstanceOf(ElkNode.class);
    assertThat(elkDiagram.getContainedEdges().size()).isEqualTo(1);
    assertThat(elkDiagram.getContainedEdges().get(0)).isInstanceOf(ElkEdge.class);
    ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
    assertThat(elkEdge.getSources().size()).isEqualTo(1);
    assertThat(elkEdge.getSources().get(0).getIdentifier()).isEqualTo(firstBorderNode.getId().toString());
    assertThat(elkEdge.getTargets().size()).isEqualTo(1);
    assertThat(elkEdge.getTargets().get(0).getIdentifier()).isEqualTo(secondBorderNode.getId().toString());
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) Edge(org.eclipse.sirius.components.diagrams.Edge) ElkEdge(org.eclipse.elk.graph.ElkEdge) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ElkEdge(org.eclipse.elk.graph.ElkEdge) Test(org.junit.jupiter.api.Test)

Example 5 with ImageSizeProvider

use of org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider in project sirius-components by eclipse-sirius.

the class DiagramConverterTests method testDiagramOneNodeAndOneEdge.

@Test
public void testDiagramOneNodeAndOneEdge() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).style(diagramBuilder.getImageNodeStyle()).build();
    Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, node.getId(), node.getId())).build();
    Diagram diagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = diagramConverter.convert(diagram);
    ElkNode elkDiagram = convertedDiagram.getElkDiagram();
    assertThat(elkDiagram.getContainedEdges().size()).isEqualTo(1);
    ElkEdge elkEdge = elkDiagram.getContainedEdges().get(0);
    assertThat(elkEdge.getIdentifier()).isEqualTo(edge.getId().toString());
    imageSizeProvider.dispose();
}
Also used : ELKDiagramConverter(org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) Edge(org.eclipse.sirius.components.diagrams.Edge) ElkEdge(org.eclipse.elk.graph.ElkEdge) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ElkEdge(org.eclipse.elk.graph.ElkEdge) Test(org.junit.jupiter.api.Test)

Aggregations

ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)19 Test (org.junit.jupiter.api.Test)15 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)14 NodeSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeSizeProvider)14 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)8 IDiagramEvent (org.eclipse.sirius.components.diagrams.events.IDiagramEvent)7 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)7 ELKDiagramConverter (org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter)6 ElkNode (org.eclipse.elk.graph.ElkNode)5 Diagram (org.eclipse.sirius.components.diagrams.Diagram)5 Node (org.eclipse.sirius.components.diagrams.Node)5 ELKConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram)5 TestDiagramBuilder (org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder)5 UUID (java.util.UUID)4 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)4 IRepresentationDescriptionSearchService (org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService)4 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)4 ResizeEvent (org.eclipse.sirius.components.diagrams.events.ResizeEvent)4 ELKLayoutedDiagramProvider (org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider)4 LayoutService (org.eclipse.sirius.components.diagrams.layout.LayoutService)4