Search in sources :

Example 56 with LEdge

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

the class SplineEdgeRouter method findAndAddSuccessor.

/**
 * Finds the predecessor {@link LEdge} of given edge. It is assumed that the source node of an
 * edge with a predecessor only has one incoming edge. Otherwise the first incoming edge of the
 * source node is added as the predecessor.
 *
 * @param edge The {@link LEdge} those predecessor to find.
 */
private void findAndAddSuccessor(final LEdge edge) {
    final LNode targetNode = edge.getTarget().getNode();
    // if target node is a normal node there is no successor
    if (isNormalNode(targetNode)) {
        return;
    }
    // otherwise take the first outgoing edge of target node
    final Iterator<LEdge> iter = targetNode.getOutgoingEdges().iterator();
    if (iter.hasNext()) {
        successingEdge.put(edge, iter.next());
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 57 with LEdge

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

the class SplineEdgeRouter method createSplineSegments.

/**
 * Creates a "one-edge" hyper-edge for each edges in the collection. The hyper-edges are added to the hyperEdges
 * collection.
 *
 * @param edges
 *            The edges to process.
 * @param leftPorts
 *            The left ports of the current situation.
 * @param rightPorts
 *            The right ports of the current situation.
 * @param hyperEdges
 *            The new hyper-edges will be added to this collection.
 */
private void createSplineSegments(final List<LEdge> edges, final Set<LPort> leftPorts, final Set<LPort> rightPorts, final List<SplineSegment> hyperEdges) {
    for (final LEdge edge : edges) {
        final LPort sourcePort = edge.getSource();
        SideToProcess sourceSide;
        if (leftPorts.contains(sourcePort)) {
            sourceSide = SideToProcess.LEFT;
        } else if (rightPorts.contains(sourcePort)) {
            sourceSide = SideToProcess.RIGHT;
        } else {
            throw new IllegalArgumentException("Source port must be in one of the port sets.");
        }
        SideToProcess targetSide;
        final LPort targetPort = edge.getTarget();
        if (leftPorts.contains(targetPort)) {
            targetSide = SideToProcess.LEFT;
        } else if (rightPorts.contains(targetPort)) {
            targetSide = SideToProcess.RIGHT;
        } else {
            throw new IllegalArgumentException("Target port must be in one of the port sets.");
        }
        SplineSegment seg = new SplineSegment(edge, sourceSide, targetSide);
        edgeToSegmentMap.put(edge, seg);
        hyperEdges.add(seg);
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 58 with LEdge

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

the class SplineEdgeRouter method getSplinePath.

private List<SplineSegment> getSplinePath(final LEdge start) {
    List<SplineSegment> segmentChain = Lists.newArrayList();
    LEdge current = start;
    do {
        SplineSegment segment = edgeToSegmentMap.get(current);
        segment.sourcePort = current.getSource();
        segment.targetPort = current.getTarget();
        segmentChain.add(segment);
        current = successingEdge.get(current);
    } while (current != null);
    SplineSegment initialSegment = segmentChain.get(0);
    initialSegment.initialSegment = true;
    initialSegment.sourceNode = initialSegment.edges.iterator().next().getSource().getNode();
    SplineSegment lastSegment = segmentChain.get(segmentChain.size() - 1);
    lastSegment.lastSegment = true;
    lastSegment.targetNode = lastSegment.edges.iterator().next().getTarget().getNode();
    return segmentChain;
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Example 59 with LEdge

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

the class SplineEdgeRouter method clearThenFillMappings.

/**
 * Initially fills the mappings, collection and sets for a pair of layers.
 *
 * @param leftLayer The current left layer.
 * @param RightLayer The current right layer.
 */
private void clearThenFillMappings(final Layer leftLayer, final Layer rightLayer) {
    // clear the mappings
    leftPortsLayer.clear();
    rightPortsLayer.clear();
    edgesRemainingLayer.clear();
    splineSegmentsLayer.clear();
    selfLoopsLayer.clear();
    // iterate over all outgoing edges on the left layer.
    if (leftLayer != null) {
        for (final LNode node : leftLayer.getNodes()) {
            for (final LPort sourcePort : node.getPorts(PortSide.EAST)) {
                leftPortsLayer.add(sourcePort);
                for (final LEdge edge : sourcePort.getOutgoingEdges()) {
                    // Self-loops are handled in the right-layer section below.
                    if (edge.isSelfLoop()) {
                        continue;
                    }
                    // Add edge to set of all edges and find it's successor
                    edgesRemainingLayer.add(edge);
                    findAndAddSuccessor(edge);
                    // Check if edge is a startingEdge
                    if (isQualifiedAsStartingNode(edge.getSource().getNode())) {
                        startEdges.add(edge);
                    }
                    // Check port-side of target port
                    final LPort targetPort = edge.getTarget();
                    final Layer targetLayer = targetPort.getNode().getLayer();
                    if (targetLayer.equals(rightLayer)) {
                        rightPortsLayer.add(targetPort);
                    } else if (targetLayer.equals(leftLayer)) {
                        leftPortsLayer.add(targetPort);
                    } else {
                        // Unhandled situation. Probably there are incoming and outgoing edges on
                        // the same port. This is not supported.
                        edgesRemainingLayer.remove(edge);
                    }
                }
            }
        }
    }
    if (rightLayer != null) {
        for (final LNode node : rightLayer.getNodes()) {
            // handle all self-loops, no matter on witch port-side they are.
            for (final LPort port : node.getPorts()) {
                for (final LEdge edge : port.getOutgoingEdges()) {
                    if (edge.isSelfLoop()) {
                        selfLoopsLayer.add(edge);
                    }
                }
            }
            // iterate over all outgoing edges on the right layer
            for (final LPort sourcePort : node.getPorts(PortSide.WEST)) {
                rightPortsLayer.add(sourcePort);
                for (final LEdge edge : sourcePort.getOutgoingEdges()) {
                    // self-loops have been handled before
                    if (edge.isSelfLoop()) {
                        continue;
                    }
                    // Add edge to set of all edges and find it's successor
                    edgesRemainingLayer.add(edge);
                    findAndAddSuccessor(edge);
                    // Check if edge is a startingEdge
                    if (isQualifiedAsStartingNode(edge.getSource().getNode())) {
                        startEdges.add(edge);
                    }
                    // Check port-side of target port
                    final LPort targetPort = edge.getTarget();
                    final Layer targetLayer = targetPort.getNode().getLayer();
                    if (targetLayer.equals(rightLayer)) {
                        rightPortsLayer.add(targetPort);
                    } else if (targetLayer.equals(leftLayer)) {
                        leftPortsLayer.add(targetPort);
                    } else {
                        // Unhandled situation. Probably there are incoming and outgoing edges on
                        // the same port. This is not supported.
                        edgesRemainingLayer.remove(edge);
                    }
                }
            }
        }
    }
}
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 60 with LEdge

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

the class SouthToNorthRoutingStrategy method calculateBendPoints.

@Override
public void calculateBendPoints(final HyperEdgeSegment segment, final double startPos, final double edgeSpacing) {
    // We don't do anything with dummy segments; they are dealt with when their partner is processed
    if (segment.isDummy()) {
        return;
    }
    // Calculate coordinates for each port's bend points
    double segmentY = startPos - segment.getRoutingSlot() * edgeSpacing;
    for (LPort port : segment.getPorts()) {
        double sourceX = port.getAbsoluteAnchor().x;
        for (LEdge edge : port.getOutgoingEdges()) {
            if (!edge.isSelfLoop()) {
                LPort target = edge.getTarget();
                double targetX = target.getAbsoluteAnchor().x;
                if (Math.abs(sourceX - targetX) > OrthogonalRoutingGenerator.TOLERANCE) {
                    // We'll update these if we find that the segment was split
                    double currentY = segmentY;
                    HyperEdgeSegment currentSegment = segment;
                    KVector bend = new KVector(sourceX, currentY);
                    edge.getBendPoints().add(bend);
                    addJunctionPointIfNecessary(edge, currentSegment, bend, false);
                    // If this segment was split, we need two additional bend points
                    HyperEdgeSegment splitPartner = segment.getSplitPartner();
                    if (splitPartner != null) {
                        double splitX = splitPartner.getIncomingConnectionCoordinates().get(0);
                        bend = new KVector(splitX, currentY);
                        edge.getBendPoints().add(bend);
                        addJunctionPointIfNecessary(edge, currentSegment, bend, false);
                        // Advance to the split partner's routing slot
                        currentY = startPos - splitPartner.getRoutingSlot() * edgeSpacing;
                        currentSegment = splitPartner;
                        bend = new KVector(splitX, currentY);
                        edge.getBendPoints().add(bend);
                        addJunctionPointIfNecessary(edge, currentSegment, bend, false);
                    }
                    bend = new KVector(targetX, currentY);
                    edge.getBendPoints().add(bend);
                    addJunctionPointIfNecessary(edge, currentSegment, bend, false);
                }
            }
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) HyperEdgeSegment(org.eclipse.elk.alg.layered.p5edges.orthogonal.HyperEdgeSegment) KVector(org.eclipse.elk.core.math.KVector)

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