Search in sources :

Example 1 with EdgeLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData in project sirius-components by eclipse-sirius.

the class IncrementalLayoutEngine method layout.

public void layout(Optional<IDiagramEvent> optionalDiagramElementEvent, DiagramLayoutData diagram, ISiriusWebLayoutConfigurator layoutConfigurator) {
    this.borderNodeLabelPositionProvider = new BorderNodeLabelPositionProvider();
    this.nodeLabelPositionProvider = new NodeLabelPositionProvider(layoutConfigurator);
    this.edgeLabelPositionProvider = new EdgeLabelPositionProvider(layoutConfigurator);
    // first we layout all the nodes
    for (NodeLayoutData node : diagram.getChildrenNodes()) {
        this.layoutNode(optionalDiagramElementEvent, node, layoutConfigurator);
    }
    // resolve overlaps due to previous changes
    new OverlapsUpdater().update(diagram);
    // resize according to the content
    new ContainmentUpdater().update(diagram);
    // finally we recompute the edges that needs to
    for (EdgeLayoutData edge : diagram.getEdges()) {
        if (this.hasChanged(edge.getSource()) || this.hasChanged(edge.getTarget()) || !this.isLabelPositioned(edge) || !this.isEdgePositioned(edge)) {
            this.layoutEdge(optionalDiagramElementEvent, edge);
        }
    }
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) ContainmentUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater) BorderNodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider) EdgeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider) NodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider) BorderNodeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider) OverlapsUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Example 2 with EdgeLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData in project sirius-components by eclipse-sirius.

the class EdgeLabelPositionProviderTests method createEdgeLayoutData.

private EdgeLayoutData createEdgeLayoutData(DiagramLayoutData diagramLayoutData) {
    EdgeLayoutData edgeLayoutData = new EdgeLayoutData();
    edgeLayoutData.setCenterLabel(this.createLabelLayoutData());
    edgeLayoutData.setId(UUID.randomUUID().toString());
    edgeLayoutData.setSource(this.createNodeLayoutData(Position.at(0, 0), Size.of(200, 200), diagramLayoutData));
    edgeLayoutData.setTarget(this.createNodeLayoutData(Position.at(400, 0), Size.of(200, 200), diagramLayoutData));
    List<Position> routingPoints = Arrays.asList(Position.at(200, 100), Position.at(400, 100));
    edgeLayoutData.setRoutingPoints(routingPoints);
    return edgeLayoutData;
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) Position(org.eclipse.sirius.components.diagrams.Position)

Example 3 with EdgeLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData in project sirius-components by eclipse-sirius.

the class EdgeRoutingPointsProviderTests method createEdgeLayoutData.

private EdgeLayoutData createEdgeLayoutData(DiagramLayoutData diagramLayoutData) {
    EdgeLayoutData edgeLayoutData = new EdgeLayoutData();
    edgeLayoutData.setId(UUID.randomUUID().toString());
    edgeLayoutData.setSource(this.createNodeLayoutData(Position.at(0, 0), Size.of(100, 50), diagramLayoutData));
    edgeLayoutData.setTarget(this.createNodeLayoutData(Position.at(200, 200), Size.of(100, 50), diagramLayoutData));
    List<Position> routingPoints = Arrays.asList(Position.at(200, 100), Position.at(400, 100));
    edgeLayoutData.setRoutingPoints(routingPoints);
    return edgeLayoutData;
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) Position(org.eclipse.sirius.components.diagrams.Position)

Example 4 with EdgeLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData in project sirius-components by eclipse-sirius.

the class EdgeLabelPositionProviderTests method testEdgeLabelBoundsPosition.

@Test
public void testEdgeLabelBoundsPosition() {
    EdgeLayoutData edgeLayoutData = this.createEdgeLayoutData(this.createDiagramLayoutData());
    EdgeLabelPositionProvider labelBoundsProvider = new EdgeLabelPositionProvider(new LayoutConfiguratorRegistry(List.of()).getDefaultLayoutConfigurator());
    Position centerPosition = labelBoundsProvider.getCenterPosition(edgeLayoutData, edgeLayoutData.getCenterLabel());
    assertThat(centerPosition.getX()).isCloseTo(267.539, Offset.offset(0.0001));
    assertThat(centerPosition.getY()).isCloseTo(103, Offset.offset(0.0001));
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) EdgeLabelPositionProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider) LayoutConfiguratorRegistry(org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry) Test(org.junit.jupiter.api.Test)

Example 5 with EdgeLayoutData

use of org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData in project sirius-components by eclipse-sirius.

the class EdgeRoutingPointsProviderTests method testEdgeRoutingPoints.

@Test
public void testEdgeRoutingPoints() {
    EdgeRoutingPointsProvider edgeRoutingPointsProvider = new EdgeRoutingPointsProvider();
    DiagramLayoutData diagramLayoutData = this.createDiagramLayoutData();
    EdgeLayoutData edgeLayoutData = this.createEdgeLayoutData(diagramLayoutData);
    List<Position> routingPoints = edgeRoutingPointsProvider.getRoutingPoints(edgeLayoutData);
    assertThat(routingPoints).hasSize(2);
    Position firstRoutingPoint = routingPoints.get(0);
    assertThat(firstRoutingPoint).extracting(Position::getX).isEqualTo(75.0);
    assertThat(firstRoutingPoint).extracting(Position::getY).isEqualTo(50.0);
    Position secondRoutingPoint = routingPoints.get(1);
    assertThat(secondRoutingPoint).extracting(Position::getX).isEqualTo(225.0);
    assertThat(secondRoutingPoint).extracting(Position::getY).isEqualTo(200.0);
}
Also used : EdgeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData) DiagramLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData) Position(org.eclipse.sirius.components.diagrams.Position) EdgeRoutingPointsProvider(org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeRoutingPointsProvider) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData)7 Position (org.eclipse.sirius.components.diagrams.Position)4 DiagramLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.DiagramLayoutData)2 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)2 EdgeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Edge (org.eclipse.sirius.components.diagrams.Edge)1 Node (org.eclipse.sirius.components.diagrams.Node)1 LayoutConfiguratorRegistry (org.eclipse.sirius.components.diagrams.layout.LayoutConfiguratorRegistry)1 ILayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.ILayoutData)1 BorderNodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider)1 EdgeRoutingPointsProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeRoutingPointsProvider)1 NodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider)1 ContainmentUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater)1 OverlapsUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater)1