Search in sources :

Example 1 with SplineRoutingMode

use of org.eclipse.elk.alg.layered.options.SplineRoutingMode in project elk by eclipse.

the class SplineEdgeRouter method process.

// ////////////////////////////////////////////////
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Spline edge routing", 1);
    if (layeredGraph.getLayers().isEmpty()) {
        layeredGraph.getSize().x = 0;
        monitor.done();
        return;
    }
    // Retrieve some generic values
    final double nodeNodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS);
    final double edgeNodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS);
    final double edgeEdgeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS);
    // Find out if splines should be routed thoroughly or sloppy
    final SplineRoutingMode mode = layeredGraph.getProperty(LayeredOptions.EDGE_ROUTING_SPLINES_MODE);
    final boolean sloppyRouting = mode == SplineRoutingMode.SLOPPY;
    final double sloppyLayerSpacingFactor = layeredGraph.getProperty(LayeredOptions.EDGE_ROUTING_SPLINES_SLOPPY_LAYER_SPACING_FACTOR);
    lGraph = layeredGraph;
    startEdges.clear();
    allSplineSegments.clear();
    successingEdge.clear();
    // check if the first and/or last layer are populated with external port dummies
    final Layer firstLayer = layeredGraph.getLayers().get(0);
    final boolean isLeftLayerExternal = Iterables.all(firstLayer.getNodes(), PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
    final Layer lastLayer = layeredGraph.getLayers().get(layeredGraph.getLayers().size() - 1);
    final boolean isRightLayerExternal = Iterables.all(lastLayer.getNodes(), PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
    final Iterator<Layer> layerIterator = layeredGraph.iterator();
    Layer leftLayer = null;
    Layer rightLayer;
    // initial x position
    double xpos = 0.0;
    do {
        rightLayer = layerIterator.hasNext() ? layerIterator.next() : null;
        // fresh start for this pair of layers
        clearThenFillMappings(leftLayer, rightLayer);
        // creation of the SplineSegments
        createSegmentsAndComputeRanking();
        // count the number of required slots for vertical segments
        // (edges to be drawn straight are assigned a rank but must be omitted here)
        final int slotCount = splineSegmentsLayer.stream().filter(e -> !e.isStraight).mapToInt(e -> e.rank + 1).max().orElse(0);
        // the code below ensures that at least nodeNodeSpacing is preserved between a pair of layers
        // if this spacing is larger than what would be required to route the vertical segments in-between
        // a pair of layers, it looks nicer to move the vertical segments halfway between the layers.
        // The xSegmentDelta variable holds the required offset
        double xSegmentDelta = 0;
        double rightLayerPosition = xpos;
        boolean isSpecialLeftLayer = leftLayer == null || (isLeftLayerExternal && leftLayer == firstLayer);
        boolean isSpecialRightLayer = rightLayer == null || (isRightLayerExternal && rightLayer == lastLayer);
        // compute horizontal positions just as for the OrthogonalEdgeRouter
        if (slotCount > 0) {
            // the space between each pair of edge segments, and between nodes and edges
            double increment = 0;
            if (leftLayer != null) {
                increment += edgeNodeSpacing;
            }
            increment += (slotCount - 1) * edgeEdgeSpacing;
            if (rightLayer != null) {
                increment += edgeNodeSpacing;
            }
            // sloppy routing may want to reserve more space in-between a pair of layers
            if (sloppyRouting && rightLayer != null) {
                increment = Math.max(increment, computeSloppySpacing(rightLayer, edgeEdgeSpacing, nodeNodeSpacing, sloppyLayerSpacingFactor));
            }
            // if we are between two layers, make sure their minimal spacing is preserved
            if (increment < nodeNodeSpacing && !isSpecialLeftLayer && !isSpecialRightLayer) {
                xSegmentDelta = (nodeNodeSpacing - increment) / 2d;
                increment = nodeNodeSpacing;
            }
            rightLayerPosition += increment;
        } else if (!isSpecialLeftLayer && !isSpecialRightLayer) {
            // If all edges are straight, use the usual spacing
            rightLayerPosition += nodeNodeSpacing;
        }
        // place right layer's nodes
        if (rightLayer != null) {
            LGraphUtil.placeNodesHorizontally(rightLayer, rightLayerPosition);
        }
        // are determined by the FinalSplineBendpointsCaluclator
        for (final SplineSegment segment : splineSegmentsLayer) {
            segment.boundingBox.x = xpos;
            segment.boundingBox.width = rightLayerPosition - xpos;
            segment.xDelta = xSegmentDelta;
            segment.isWestOfInitialLayer = leftLayer == null;
        }
        allSplineSegments.addAll(splineSegmentsLayer);
        // proceed to the next layer
        xpos = rightLayerPosition;
        if (rightLayer != null) {
            xpos += rightLayer.getSize().x;
        }
        leftLayer = rightLayer;
        isSpecialLeftLayer = isSpecialRightLayer;
    } while (rightLayer != null);
    // control point calculation to be done by a later intermediate processor
    for (LEdge edge : startEdges) {
        List<LEdge> edgeChain = getEdgeChain(edge);
        edge.setProperty(InternalProperties.SPLINE_EDGE_CHAIN, edgeChain);
        List<SplineSegment> spline = getSplinePath(edge);
        edge.setProperty(InternalProperties.SPLINE_ROUTE_START, spline);
    }
    // assign final width of the layering and thus the overall graph
    layeredGraph.getSize().x = xpos;
    lGraph = null;
    monitor.done();
}
Also used : PolylineEdgeRouter(org.eclipse.elk.alg.layered.p5edges.PolylineEdgeRouter) Iterables(com.google.common.collect.Iterables) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Layer(org.eclipse.elk.alg.layered.graph.Layer) ListIterator(java.util.ListIterator) PortSide(org.eclipse.elk.core.options.PortSide) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Random(java.util.Random) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) IntermediateProcessorStrategy(org.eclipse.elk.alg.layered.intermediate.IntermediateProcessorStrategy) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) Map(java.util.Map) Pair(org.eclipse.elk.core.util.Pair) LinkedList(java.util.LinkedList) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) FinalSplineBendpointsCalculator(org.eclipse.elk.alg.layered.intermediate.FinalSplineBendpointsCalculator) LayoutProcessorConfiguration(org.eclipse.elk.core.alg.LayoutProcessorConfiguration) Iterator(java.util.Iterator) Set(java.util.Set) ILayoutPhase(org.eclipse.elk.core.alg.ILayoutPhase) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) LGraphUtil(org.eclipse.elk.alg.layered.graph.LGraphUtil) SplineRoutingMode(org.eclipse.elk.alg.layered.options.SplineRoutingMode) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LayeredPhases(org.eclipse.elk.alg.layered.LayeredPhases) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) SplineRoutingMode(org.eclipse.elk.alg.layered.options.SplineRoutingMode) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 LayeredPhases (org.eclipse.elk.alg.layered.LayeredPhases)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LGraphUtil (org.eclipse.elk.alg.layered.graph.LGraphUtil)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 FinalSplineBendpointsCalculator (org.eclipse.elk.alg.layered.intermediate.FinalSplineBendpointsCalculator)1