Search in sources :

Example 1 with ELKConvertedDiagram

use of org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram 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 2 with ELKConvertedDiagram

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

use of org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram 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)

Example 4 with ELKConvertedDiagram

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

the class LayoutedDiagramProviderTests method testLayoutedDiagramProvider.

@Test
public void testLayoutedDiagramProvider() {
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = Node.newNode(diagramBuilder.getNode(FIRST_NODE_ID)).build();
    Edge edge = Edge.newEdge(diagramBuilder.getEdge(FIRST_EDGE_ID, node.getId(), node.getId())).build();
    Diagram originalDiagram = Diagram.newDiagram(diagramBuilder.getDiagram(DIAGRAM_ID)).nodes(List.of(node)).edges(List.of(edge)).build();
    // @formatter:on
    ELKConvertedDiagram convertedDiagram = this.getConvertedDiagram(originalDiagram);
    Diagram layoutedDiagram = new ELKLayoutedDiagramProvider().getLayoutedDiagram(originalDiagram, convertedDiagram.getElkDiagram(), convertedDiagram.getId2ElkGraphElements());
    assertThat(layoutedDiagram).hasBounds(0, 0, 0, 0);
    assertThat(layoutedDiagram.getNodes()).hasSizeGreaterThan(0);
    assertThat(layoutedDiagram.getNodes().get(0)).hasBounds(NODE_X, NODE_Y, NODE_WIDTH, NODE_HEIGHT);
    assertThat(layoutedDiagram).matchesRecursively(originalDiagram, IdPolicy.WITH_ID, LayoutPolicy.WITHOUT_LAYOUT);
}
Also used : ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) TestDiagramBuilder(org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ELKLayoutedDiagramProvider(org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider) 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) Test(org.junit.jupiter.api.Test)

Example 5 with ELKConvertedDiagram

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

the class DiagramConverterTests method testDiagramOneImageNode.

@Test
public void testDiagramOneImageNode() {
    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();
    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);
    Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
    assertThat(id2ElkGraphElements.get(node.getId().toString())).isInstanceOf(ElkNode.class);
    assertThat(id2ElkGraphElements.get(node.getLabel().getId().toString())).isInstanceOf(ElkLabel.class);
    ElkNode elkNode = (ElkNode) id2ElkGraphElements.get(node.getId().toString());
    this.assertSize(elkNode, TEXT_WIDTH, TEXT_HEIGHT);
    assertThat(elkNode.getChildren().size()).isEqualTo(1);
    ElkNode elkImage = elkNode.getChildren().get(0);
    this.assertSize(elkImage, IMAGE_WIDTH, IMAGE_HEIGHT);
    assertThat(elkNode.getLabels().size()).isEqualTo(1);
    ElkLabel elkLabel = elkNode.getLabels().get(0);
    this.assertSize(elkLabel, TEXT_WIDTH, TEXT_HEIGHT);
    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) ElkLabel(org.eclipse.elk.graph.ElkLabel) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ImageSizeProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Aggregations

ElkNode (org.eclipse.elk.graph.ElkNode)7 Node (org.eclipse.sirius.components.diagrams.Node)7 ELKConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram)7 Diagram (org.eclipse.sirius.components.diagrams.Diagram)6 TestDiagramBuilder (org.eclipse.sirius.components.diagrams.tests.TestDiagramBuilder)6 Test (org.junit.jupiter.api.Test)6 ELKDiagramConverter (org.eclipse.sirius.components.diagrams.layout.ELKDiagramConverter)5 ImageSizeProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.ImageSizeProvider)5 ElkEdge (org.eclipse.elk.graph.ElkEdge)4 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)3 ElkLabel (org.eclipse.elk.graph.ElkLabel)3 Edge (org.eclipse.sirius.components.diagrams.Edge)3 HashMap (java.util.HashMap)1 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)1 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)1 ElkPort (org.eclipse.elk.graph.ElkPort)1 ELKLayoutedDiagramProvider (org.eclipse.sirius.components.diagrams.layout.ELKLayoutedDiagramProvider)1