Search in sources :

Example 16 with ElkEdgeSection

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

the class Issue546Test method testEdgeStartsAtPort.

@Test
public void testEdgeStartsAtPort(final ElkNode graph) {
    // We'll look at all edges
    LinkedList<ElkNode> nodeQueue = new LinkedList<>();
    nodeQueue.add(graph);
    while (!nodeQueue.isEmpty()) {
        ElkNode currNode = nodeQueue.poll();
        nodeQueue.addAll(currNode.getChildren());
        // edge is connected to ports
        for (ElkEdge edge : currNode.getContainedEdges()) {
            // Retrieve absolute port rectangle, slightly enlarged
            ElkPort srcPort = ElkGraphUtil.connectableShapeToPort(edge.getSources().get(0));
            KVector srcPortPos = ElkUtil.absolutePosition(srcPort);
            Rectangle2D.Double srcPortRect = new Rectangle2D.Double(srcPortPos.x - TOLERANCE, srcPortPos.y - TOLERANCE, srcPort.getWidth() + 2 * TOLERANCE, srcPort.getHeight() + 2 * TOLERANCE);
            // Retrieve absolut edge source position
            ElkEdgeSection section = edge.getSections().get(0);
            KVector srcPoint = new KVector(section.getStartX(), section.getStartY());
            ElkUtil.toAbsolute(srcPoint, currNode);
            // Ensure that the source point is roughly on the port anchor
            assertTrue("Source point " + srcPoint + " is not close enough to port " + srcPortRect, srcPortRect.contains(srcPoint.x, srcPoint.y));
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) Rectangle2D(java.awt.geom.Rectangle2D) KVector(org.eclipse.elk.core.math.KVector) LinkedList(java.util.LinkedList) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge) Test(org.junit.Test)

Example 17 with ElkEdgeSection

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

the class ElkGraphLayoutTransferrer method applyEdgeLayout.

/**
 * Applies layout information computed for the given edge.
 *
 * @param ledge
 *            the edge that has the layout information.
 * @param routing
 *            the kind of routing applied to edges.
 * @param offset
 *            offset to add to coordinates.
 * @param additionalPadding
 *            the additional insets that may have to be taken into account for hierarchical that go
 *            into the bowels of their source node. These are already included in the offset, but
 *            are required separately.
 */
private void applyEdgeLayout(final LEdge ledge, final EdgeRouting routing, final KVector offset, final LPadding additionalPadding) {
    ElkEdge elkedge = (ElkEdge) ledge.getProperty(InternalProperties.ORIGIN);
    // untouched if another routing algorithm is selected.
    if (elkedge == null) {
        return;
    }
    KVectorChain bendPoints = ledge.getBendPoints();
    // The standard offset may need to be modified if the edge needs to end up in a coordinate system of
    // a graph in a higher hierarchy level
    KVector edgeOffset = new KVector(offset);
    edgeOffset.add(calculateHierarchicalOffset(ledge));
    // Adapt the offset value and add the source port position to the vector chain
    KVector sourcePoint;
    if (LGraphUtil.isDescendant(ledge.getTarget().getNode(), ledge.getSource().getNode())) {
        // The external port's anchor position, relative to the node's top left corner
        LPort sourcePort = ledge.getSource();
        sourcePoint = KVector.sum(sourcePort.getPosition(), sourcePort.getAnchor());
        // The source point will later have the passed offset added to it, which it doesn't actually
        // need, so we subtract it now (notice that the external port's position was already relative
        // to its node's top left corner, while adding the offset now would mean that it was relative
        // to the top left corner + its insets area)
        sourcePoint.sub(offset);
    } else {
        sourcePoint = ledge.getSource().getAbsoluteAnchor();
    }
    bendPoints.addFirst(sourcePoint);
    // Add the target port position to the vector chain, including additional offset
    KVector targetPoint = ledge.getTarget().getAbsoluteAnchor();
    if (ledge.getProperty(InternalProperties.TARGET_OFFSET) != null) {
        targetPoint.add(ledge.getProperty(InternalProperties.TARGET_OFFSET));
    }
    bendPoints.addLast(targetPoint);
    // Translate the bend points by the offset and apply the bend points
    bendPoints.offset(edgeOffset);
    // Give the edge a proper edge section to store routing information
    ElkEdgeSection elkedgeSection = ElkGraphUtil.firstEdgeSection(elkedge, true, true);
    elkedgeSection.setIncomingShape(elkedge.getSources().get(0));
    elkedgeSection.setOutgoingShape(elkedge.getTargets().get(0));
    ElkUtil.applyVectorChain(bendPoints, elkedgeSection);
    // Apply layout to labels
    for (LLabel llabel : ledge.getLabels()) {
        ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
        elklabel.setWidth(llabel.getSize().x);
        elklabel.setHeight(llabel.getSize().y);
        elklabel.setLocation(llabel.getPosition().x + edgeOffset.x, llabel.getPosition().y + edgeOffset.y);
        elklabel.setProperty(LabelDummySwitcher.INCLUDE_LABEL, llabel.getProperty(LabelDummySwitcher.INCLUDE_LABEL));
    }
    // Copy junction points
    KVectorChain junctionPoints = ledge.getProperty(LayeredOptions.JUNCTION_POINTS);
    if (junctionPoints != null) {
        junctionPoints.offset(edgeOffset);
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, junctionPoints);
    } else {
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
    }
    // Mark the edge with information about its routing
    if (routing == EdgeRouting.SPLINES) {
        // SPLINES means that bend points shall be interpreted as control points for splines
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.SPLINES);
    } else {
        // null means that bend points shall be interpreted as bend points
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, null);
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVectorChain(org.eclipse.elk.core.math.KVectorChain) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 18 with ElkEdgeSection

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

the class ElkGraphUtil method firstEdgeSection.

/**
 * Returns the edge's first edge section or creates one if there is none.
 *
 * @param edge the edge whose first edge section to retrieve.
 * @param resetSection {@code true} if all bend points should be removed and the location reset on the section
 *                     before it is returned.
 * @param removeOtherSections {@code true} if all the other edge sections, if any, should be removed.
 * @return the first edge section.
 */
public static ElkEdgeSection firstEdgeSection(final ElkEdge edge, final boolean resetSection, final boolean removeOtherSections) {
    if (edge.getSections().isEmpty()) {
        // Create and return a new section
        return createEdgeSection(edge);
    } else {
        // Retrieve the first section
        ElkEdgeSection section = edge.getSections().get(0);
        if (resetSection) {
            section.getBendPoints().clear();
            section.setStartLocation(0, 0);
            section.setEndLocation(0, 0);
        }
        if (removeOtherSections) {
            List<ElkEdgeSection> sections = edge.getSections();
            while (sections.size() > 1) {
                sections.remove(sections.size() - 1);
            }
        }
        return section;
    }
}
Also used : ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection)

Example 19 with ElkEdgeSection

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

the class OverallLayoutTest method testEdgeOrthogonality.

/**
 * Tests if the edge routing produced perfectly orthogonal edges. This test only makes sense if
 * the orthogonal edge router is used.
 */
@Test
public void testEdgeOrthogonality() {
    LinkedList<KVector> bendPoints = new LinkedList<>();
    for (ElkEdge edge : simpleGraph.getContainedEdges()) {
        for (ElkEdgeSection section : edge.getSections()) {
            // Assemble list of bend points
            bendPoints.clear();
            bendPoints.add(new KVector(section.getStartX(), section.getStartY()));
            section.getBendPoints().stream().map(bp -> new KVector(bp.getX(), bp.getY())).forEach(vec -> bendPoints.add(vec));
            bendPoints.add(new KVector(section.getEndX(), section.getEndY()));
            if (bendPoints.size() >= 2) {
                // Check whether the bend points run orthogonally
                Iterator<KVector> bendPointIterator = bendPoints.iterator();
                KVector prevBendPoint = bendPointIterator.next();
                while (bendPointIterator.hasNext()) {
                    KVector currBendPoint = bendPointIterator.next();
                    assertTrue(prevBendPoint.x == currBendPoint.x || prevBendPoint.y == currBendPoint.y);
                    prevBendPoint = currBendPoint;
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) PlainJavaInitialization(org.eclipse.elk.alg.test.PlainJavaInitialization) KVector(org.eclipse.elk.core.math.KVector) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Assert.assertTrue(org.junit.Assert.assertTrue) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Test(org.junit.Test) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) ElkNode(org.eclipse.elk.graph.ElkNode) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) LinkedList(java.util.LinkedList) Before(org.junit.Before) KVector(org.eclipse.elk.core.math.KVector) LinkedList(java.util.LinkedList) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge) Test(org.junit.Test)

Example 20 with ElkEdgeSection

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

the class GmfDiagramLayoutConnector method setEdgeLayout.

/**
 * Stores the layout information of the given connection edit part into an edge layout.
 *
 * @param edge
 *            an edge layout
 * @param connection
 *            a connection edit part
 * @param offset
 *            offset to be subtracted from coordinates
 */
protected void setEdgeLayout(final ElkEdge edge, final ConnectionEditPart connection, final KVector offset) {
    Connection figure = connection.getConnectionFigure();
    PointList pointList = figure.getPoints();
    // our edge will have exactly one edge section
    ElkEdgeSection edgeSection = ElkGraphUtil.createEdgeSection(edge);
    // source point
    Point firstPoint = pointList.getPoint(0);
    edgeSection.setStartX(firstPoint.x - offset.x);
    edgeSection.setStartY(firstPoint.y - offset.y);
    // bend points
    for (int i = 1; i < pointList.size() - 1; i++) {
        Point point = pointList.getPoint(i);
        ElkGraphUtil.createBendPoint(edgeSection, point.x - offset.x, point.y - offset.y);
    }
    // target point
    Point lastPoint = pointList.getPoint(pointList.size() - 1);
    edgeSection.setEndX(lastPoint.x - offset.x);
    edgeSection.setEndY(lastPoint.y - offset.y);
// We would set the modified flag to false here, but that doesn't exist anymore
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)37 KVector (org.eclipse.elk.core.math.KVector)23 ElkEdge (org.eclipse.elk.graph.ElkEdge)21 ElkNode (org.eclipse.elk.graph.ElkNode)21 ElkLabel (org.eclipse.elk.graph.ElkLabel)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)13 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)11 ElkPort (org.eclipse.elk.graph.ElkPort)10 LinkedList (java.util.LinkedList)6 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)6 ArrayList (java.util.ArrayList)4 ElkPadding (org.eclipse.elk.core.math.ElkPadding)4 PointList (org.eclipse.draw2d.geometry.PointList)3 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)3 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)3 Test (org.junit.Test)3 ListIterator (java.util.ListIterator)2 Point (org.eclipse.draw2d.geometry.Point)2 DCDirection (org.eclipse.elk.alg.disco.graph.DCDirection)2 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)2