Search in sources :

Example 61 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class PolylineEdgeRouter method processNode.

// //////////////////////////////////////////////////////////////////////////////////////////////////
// Actual Edge Routing Code
/**
 * Inserts bend points for edges incident to this node. The bend points are inserted such that
 * the segments that cross the layer's area are straight or pretty much straight. A bend point
 * is only added if it's necessary: if the bend point to be inserted differs from the edge's end
 * point.
 *
 * @param node
 *            the node whose incident edges to insert bend points for.
 * @param layerLeftXPos
 *            the x position of the node's layer.
 * @param maxAcceptableXDiff
 *            the maximum space between node and layer boundary before bend points need to be inserted.
 */
private void processNode(final LNode node, final double layerLeftXPos, final double maxAcceptableXDiff) {
    // The right side of the layer
    final double layerRightXPos = layerLeftXPos + node.getLayer().getSize().x;
    for (LPort port : node.getPorts()) {
        KVector absolutePortAnchor = port.getAbsoluteAnchor();
        if (node.getType() == NodeType.NORTH_SOUTH_PORT) {
            // North/south ports require special handling (also see #515):
            // The dummy node that represents the north/south port will have been placed at:
            // - the very left x-coordinate of the currently processed layer for incoming edges
            // - the very right x-coordinate for outgoing edges
            // However, the actual x-coordinate of the port itself is very likely to have a different x-coordinate.
            // The code below introduces bendpoints that prevent edge/node overlaps based on a condition that
            // checks that a node's position is "far enough away" from the left-most x-coordinate of the layer.
            // Consequently, we have to use the north/south port's x-coordinate instead of the dummy node's one.
            LPort correspondingPort = (LPort) port.getProperty(InternalProperties.ORIGIN);
            absolutePortAnchor.x = correspondingPort.getAbsoluteAnchor().x;
            // While it makes sense either way, it is important to move the dummy node to the correct location
            // as well. Otherwise the #addBendPoint(...) method won't add the computed bendpoint as it
            // thinks it's superfluous.
            node.getPosition().x = absolutePortAnchor.x;
        }
        KVector bendPoint = new KVector(0, absolutePortAnchor.y);
        if (port.getSide() == PortSide.EAST) {
            bendPoint.x = layerRightXPos;
        } else if (port.getSide() == PortSide.WEST) {
            bendPoint.x = layerLeftXPos;
        } else {
            // We only know what to do with eastern and western ports
            continue;
        }
        // If the port's absolute anchor equals the bend point, we don't want to insert anything
        // (unless the node represents an in-layer dummy)
        double xDistance = Math.abs(absolutePortAnchor.x - bendPoint.x);
        if (xDistance <= maxAcceptableXDiff && !isInLayerDummy(node)) {
            continue;
        }
        // Whether to add a junction point or not
        boolean addJunctionPoint = port.getOutgoingEdges().size() + port.getIncomingEdges().size() > 1;
        // Iterate over the edges and add bend (and possibly junction) points
        for (LEdge e : port.getConnectedEdges()) {
            LPort otherPort = e.getSource() == port ? e.getTarget() : e.getSource();
            if (Math.abs(otherPort.getAbsoluteAnchor().y - bendPoint.y) > MIN_VERT_DIFF) {
                // Insert bend point
                addBendPoint(e, bendPoint, addJunctionPoint, port);
            }
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector)

Example 62 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class PolylineEdgeRouter method calculateWestInLayerEdgeYDiff.

// //////////////////////////////////////////////////////////////////////////////////////////////////
// Utility Methods
/**
 * Calculates the maximum vertical span of any in-layer edge connecting west-side ports of nodes
 * in the given layer.
 *
 * @param layer
 *            the layer to iterate over.
 * @return maximum vertical span of west-side in-layer edges.
 */
private double calculateWestInLayerEdgeYDiff(final Layer layer) {
    double maxYDiff = 0.0;
    for (LNode node : layer) {
        for (LEdge outgoingEdge : node.getOutgoingEdges()) {
            if (layer == outgoingEdge.getTarget().getNode().getLayer() && outgoingEdge.getSource().getSide() == PortSide.WEST) {
                double sourcePos = outgoingEdge.getSource().getAbsoluteAnchor().y;
                double targetPos = outgoingEdge.getTarget().getAbsoluteAnchor().y;
                maxYDiff = Math.max(maxYDiff, Math.abs(targetPos - sourcePos));
            }
        }
    }
    return maxYDiff;
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 63 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class ReversedEdgeRestorer method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Restoring reversed edges", 1);
    // Iterate through the layers
    for (Layer layer : layeredGraph) {
        // Iterate through the nodes
        for (LNode node : layer) {
            // Iterate over all the ports, looking for outgoing edges that should be reversed
            for (LPort port : node.getPorts()) {
                // Iterate over a copy of the edges to avoid concurrent modification exceptions
                LEdge[] edgeArray = LGraphUtil.toEdgeArray(port.getOutgoingEdges());
                for (LEdge edge : edgeArray) {
                    if (edge.getProperty(InternalProperties.REVERSED)) {
                        edge.reverse(layeredGraph, false);
                    }
                }
            }
        }
    }
    monitor.done();
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 64 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class SelfLoopPostProcessor method restoreEdge.

private void restoreEdge(final LNode lNode, final SelfLoopEdge slEdge) {
    LEdge lEdge = slEdge.getLEdge();
    lEdge.setSource(slEdge.getSLSource().getLPort());
    lEdge.setTarget(slEdge.getSLTarget().getLPort());
    lEdge.getBendPoints().offset(lNode.getPosition());
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Example 65 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.

the class SortByInputModelProcessor method longEdgeTargetNodePreprocessing.

/**
 * Calculate long edge target of port and saves it and adds a map of all long edge targets to the node.
 * @param node the node
 * @return A map of all long edge targets of a node
 */
public static Map<LNode, Integer> longEdgeTargetNodePreprocessing(LNode node) {
    Map<LNode, Integer> targetNodeModelOrder = new HashMap<>();
    if (node.hasProperty(InternalProperties.TARGET_NODE_MODEL_ORDER)) {
        return node.getProperty(InternalProperties.TARGET_NODE_MODEL_ORDER);
    }
    node.getPorts().stream().filter(p -> !p.getOutgoingEdges().isEmpty()).forEach(p -> {
        LNode targetNode = getTargetNode(p);
        p.setProperty(InternalProperties.LONG_EDGE_TARGET_NODE, targetNode);
        if (targetNode != null) {
            int previousOrder = Integer.MAX_VALUE;
            if (targetNodeModelOrder.containsKey(targetNode)) {
                previousOrder = targetNodeModelOrder.get(targetNode);
            }
            LEdge edge = p.getOutgoingEdges().get(0);
            if (!edge.getProperty(InternalProperties.REVERSED)) {
                targetNodeModelOrder.put(targetNode, Math.min(edge.getProperty(InternalProperties.MODEL_ORDER), previousOrder));
            }
        }
    });
    node.setProperty(InternalProperties.TARGET_NODE_MODEL_ORDER, targetNodeModelOrder);
    return targetNodeModelOrder;
}
Also used : ModelOrderNodeComparator(org.eclipse.elk.alg.layered.intermediate.preserveorder.ModelOrderNodeComparator) Layer(org.eclipse.elk.alg.layered.graph.Layer) PortConstraints(org.eclipse.elk.core.options.PortConstraints) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) HashMap(java.util.HashMap) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Map(java.util.Map) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) ModelOrderPortComparator(org.eclipse.elk.alg.layered.intermediate.preserveorder.ModelOrderPortComparator) Collections(java.util.Collections) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) HashMap(java.util.HashMap) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Aggregations

LEdge (org.eclipse.elk.alg.layered.graph.LEdge)148 LNode (org.eclipse.elk.alg.layered.graph.LNode)107 LPort (org.eclipse.elk.alg.layered.graph.LPort)80 Layer (org.eclipse.elk.alg.layered.graph.Layer)41 KVector (org.eclipse.elk.core.math.KVector)34 KVectorChain (org.eclipse.elk.core.math.KVectorChain)20 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)17 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)16 PortSide (org.eclipse.elk.core.options.PortSide)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 Set (java.util.Set)7 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)7 Map (java.util.Map)6 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)6 Lists (com.google.common.collect.Lists)5 Iterator (java.util.Iterator)5 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)5 Pair (org.eclipse.elk.core.util.Pair)5