Search in sources :

Example 11 with ElkBendPoint

use of org.eclipse.elk.graph.ElkBendPoint in project elk by eclipse.

the class Issue502Test method testLargeEnoughNode.

private void testLargeEnoughNode(final ElkNode node) {
    ElkRectangle requiredSize = new ElkRectangle();
    for (ElkNode child : node.getChildren()) {
        ElkRectangle childRect = new ElkRectangle(child.getX(), child.getY(), child.getWidth(), child.getHeight());
        requiredSize.union(childRect);
    }
    for (ElkEdge edge : node.getContainedEdges()) {
        for (ElkEdgeSection section : edge.getSections()) {
            for (ElkBendPoint bendPoint : section.getBendPoints()) {
                requiredSize.width = Math.max(requiredSize.width, bendPoint.getX());
                requiredSize.height = Math.max(requiredSize.height, bendPoint.getY());
            }
        }
    }
    assertTrue("Node not large enough for content. Size required: (" + requiredSize.width + ", " + requiredSize.height + "). " + "Actual size: (" + node.getWidth() + ", " + node.getHeight() + ")", node.getWidth() >= requiredSize.width && node.getHeight() >= requiredSize.height);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 12 with ElkBendPoint

use of org.eclipse.elk.graph.ElkBendPoint 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

ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)12 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)8 ElkNode (org.eclipse.elk.graph.ElkNode)6 ElkEdge (org.eclipse.elk.graph.ElkEdge)5 ElkLabel (org.eclipse.elk.graph.ElkLabel)5 KVector (org.eclipse.elk.core.math.KVector)4 ListIterator (java.util.ListIterator)2 KVectorChain (org.eclipse.elk.core.math.KVectorChain)2 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)2 ElkPort (org.eclipse.elk.graph.ElkPort)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)1 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Label (org.eclipse.sirius.components.diagrams.Label)1 Node (org.eclipse.sirius.components.diagrams.Node)1 Position (org.eclipse.sirius.components.diagrams.Position)1 ELKConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.ELKConvertedDiagram)1 Point (org.eclipse.swt.graphics.Point)1