Search in sources :

Example 6 with ELKConvertedDiagram

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

the class DiagramConverterTests method testDiagramOneRectangularNode.

@Test
public void testDiagramOneRectangularNode() {
    ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
    ELKDiagramConverter diagramConverter = new ELKDiagramConverter(this.textBoundsService, imageSizeProvider);
    // @formatter:off
    TestDiagramBuilder diagramBuilder = new TestDiagramBuilder();
    Node node = diagramBuilder.getNode(FIRST_NODE_ID);
    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.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)

Example 7 with ELKConvertedDiagram

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

the class LayoutedDiagramProviderTests method getConvertedDiagram.

private ELKConvertedDiagram getConvertedDiagram(Diagram originalDiagram) {
    Map<String, ElkGraphElement> id2ElkGraphElements = new HashMap<>();
    ElkNode elkDiagram = ElkGraphFactory.eINSTANCE.createElkNode();
    elkDiagram.setIdentifier(originalDiagram.getId().toString());
    Node node = originalDiagram.getNodes().get(0);
    ElkNode elkNode = ElkGraphFactory.eINSTANCE.createElkNode();
    elkNode.setIdentifier(node.getId().toString());
    elkNode.setDimensions(NODE_WIDTH, NODE_HEIGHT);
    elkNode.setX(NODE_X);
    elkNode.setY(NODE_Y);
    elkNode.setParent(elkDiagram);
    ElkLabel elkLabel = ElkGraphFactory.eINSTANCE.createElkLabel();
    elkLabel.setIdentifier(node.getLabel().getId().toString());
    elkLabel.setDimensions(LABEL_WIDTH, LABEL_HEIGHT);
    elkLabel.setX(LABEL_X);
    elkLabel.setY(LABEL_Y);
    elkLabel.setParent(elkNode);
    id2ElkGraphElements.put(elkLabel.getIdentifier(), elkLabel);
    id2ElkGraphElements.put(elkNode.getIdentifier(), elkNode);
    String edgeId = originalDiagram.getEdges().get(0).getId();
    ElkEdge elkEdge = ElkGraphFactory.eINSTANCE.createElkEdge();
    elkEdge.setIdentifier(edgeId.toString());
    elkEdge.getSources().add(elkNode);
    elkEdge.getTargets().add(elkNode);
    elkEdge.setContainingNode(elkDiagram);
    ElkEdgeSection section = ElkGraphFactory.eINSTANCE.createElkEdgeSection();
    section.setStartX(NODE_X);
    section.setStartY(NODE_Y);
    ElkBendPoint bendPoint = ElkGraphFactory.eINSTANCE.createElkBendPoint();
    bendPoint.setX(EDGE_BENDPOINT_X);
    bendPoint.setY(EDGE_BENDPOINT_Y);
    section.getBendPoints().add(bendPoint);
    section.setEndX(NODE_X);
    section.setEndY(NODE_Y);
    elkEdge.getSections().add(section);
    id2ElkGraphElements.put(elkEdge.getIdentifier(), elkEdge);
    return new ELKConvertedDiagram(elkDiagram, id2ElkGraphElements);
}
Also used : ELKConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram) ElkNode(org.eclipse.elk.graph.ElkNode) HashMap(java.util.HashMap) ElkLabel(org.eclipse.elk.graph.ElkLabel) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

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