Search in sources :

Example 1 with OverlapsUpdater

use of org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater 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 OverlapsUpdater

use of org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater in project sirius-components by eclipse-sirius.

the class IncrementalLayoutEngine method layoutNode.

private void layoutNode(Optional<IDiagramEvent> optionalDiagramElementEvent, NodeLayoutData node, ISiriusWebLayoutConfigurator layoutConfigurator) {
    Bounds initialNodeBounds = Bounds.newBounds().position(node.getPosition()).size(node.getSize()).build();
    // first layout child nodes
    for (NodeLayoutData childNode : node.getChildrenNodes()) {
        this.layoutNode(optionalDiagramElementEvent, childNode, layoutConfigurator);
    }
    // compute the node size according to what has been done in the previous steps
    Size size = this.nodeSizeProvider.getSize(optionalDiagramElementEvent, node, layoutConfigurator);
    if (!this.getRoundedSize(size).equals(this.getRoundedSize(node.getSize()))) {
        node.setSize(size);
        node.setChanged(true);
    }
    // recompute the node position
    Position position = this.nodePositionProvider.getPosition(optionalDiagramElementEvent, node);
    if (!position.equals(node.getPosition())) {
        node.setPosition(position);
        node.setChanged(true);
        node.setPinned(true);
    }
    // resolve overlaps due to previous changes
    new OverlapsUpdater().update(node);
    // resize / change position according to the content
    new ContainmentUpdater().update(node);
    // update the border node once the current node bounds are updated
    Bounds newBounds = Bounds.newBounds().position(node.getPosition()).size(node.getSize()).build();
    List<BorderNodesOnSide> borderNodesOnSide = this.layoutBorderNodes(optionalDiagramElementEvent, node.getBorderNodes(), initialNodeBounds, newBounds, layoutConfigurator);
    // recompute the label
    if (node.getLabel() != null) {
        node.getLabel().setPosition(this.nodeLabelPositionProvider.getPosition(node, node.getLabel(), borderNodesOnSide));
    }
}
Also used : ContainmentUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Bounds(org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds) OverlapsUpdater(org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater) NodeLayoutData(org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)

Aggregations

NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)2 ContainmentUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.ContainmentUpdater)2 OverlapsUpdater (org.eclipse.sirius.components.diagrams.layout.incremental.updater.OverlapsUpdater)2 Position (org.eclipse.sirius.components.diagrams.Position)1 Size (org.eclipse.sirius.components.diagrams.Size)1 EdgeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.EdgeLayoutData)1 BorderNodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.BorderNodeLabelPositionProvider)1 EdgeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.EdgeLabelPositionProvider)1 NodeLabelPositionProvider (org.eclipse.sirius.components.diagrams.layout.incremental.provider.NodeLabelPositionProvider)1 Bounds (org.eclipse.sirius.components.diagrams.layout.incremental.utils.Bounds)1