Search in sources :

Example 6 with LPort

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

the class InvertedPortProcessor method setLongEdgeSourceAndTarget.

/**
 * Properly sets the
 * {@link org.eclipse.elk.alg.layered.options.LayeredOptions#LONG_EDGE_SOURCE} and
 * {@link org.eclipse.elk.alg.layered.options.LayeredOptions#LONG_EDGE_TARGET} properties for
 * the given long edge dummy. This is required for the
 * {@link org.eclipse.elk.alg.layered.intermediate.HyperedgeDummyMerger} to work correctly.
 *
 * @param longEdgeDummy
 *            the long edge dummy whose properties to set.
 * @param dummyInputPort
 *            the dummy node's input port.
 * @param dummyOutputPort
 *            the dummy node's output port.
 * @param oddPort
 *            the odd port that prompted the dummy to be created.
 */
private void setLongEdgeSourceAndTarget(final LNode longEdgeDummy, final LPort dummyInputPort, final LPort dummyOutputPort, final LPort oddPort) {
    // There's exactly one edge connected to the input and output port
    LPort sourcePort = dummyInputPort.getIncomingEdges().get(0).getSource();
    LNode sourceNode = sourcePort.getNode();
    NodeType sourceNodeType = sourceNode.getType();
    LPort targetPort = dummyOutputPort.getOutgoingEdges().get(0).getTarget();
    LNode targetNode = targetPort.getNode();
    NodeType targetNodeType = targetNode.getType();
    // Set the LONG_EDGE_SOURCE property
    if (sourceNodeType == NodeType.LONG_EDGE) {
        // The source is a LONG_EDGE node; use its LONG_EDGE_SOURCE
        longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_SOURCE, sourceNode.getProperty(InternalProperties.LONG_EDGE_SOURCE));
    } else {
        // The target is the original node; use it
        longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_SOURCE, sourcePort);
    }
    // Set the LONG_EDGE_TARGET property
    if (targetNodeType == NodeType.LONG_EDGE) {
        // The target is a LONG_EDGE node; use its LONG_EDGE_TARGET
        longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_TARGET, targetNode.getProperty(InternalProperties.LONG_EDGE_TARGET));
    } else {
        // The target is the original node; use it
        longEdgeDummy.setProperty(InternalProperties.LONG_EDGE_TARGET, targetPort);
    }
}
Also used : NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 7 with LPort

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

the class InvertedPortProcessor method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Inverted port preprocessing", 1);
    // Retrieve the layers in the graph
    List<Layer> layers = layeredGraph.getLayers();
    // Iterate through the layers and for each layer create a list of dummy nodes
    // that were created, but not yet assigned to the layer (to avoid concurrent
    // modification exceptions)
    ListIterator<Layer> layerIterator = layers.listIterator();
    Layer currentLayer = null;
    List<LNode> unassignedNodes = Lists.newArrayList();
    while (layerIterator.hasNext()) {
        // Update previous and current layers
        Layer previousLayer = currentLayer;
        currentLayer = layerIterator.next();
        // If the previous layer had unassigned nodes, assign them now and clear the list
        for (LNode node : unassignedNodes) {
            node.setLayer(previousLayer);
        }
        unassignedNodes.clear();
        // Iterate through the layer's nodes
        for (LNode node : currentLayer) {
            // Skip dummy nodes
            if (node.getType() != NodeType.NORMAL) {
                continue;
            }
            // port side problem won't appear)
            if (!node.getProperty(LayeredOptions.PORT_CONSTRAINTS).isSideFixed()) {
                continue;
            }
            // Look for input ports on the right side
            for (LPort port : node.getPorts(PortType.INPUT, PortSide.EAST)) {
                // For every edge going into this port, insert dummy nodes (do this using
                // a copy of the current list of edges, since the edges are modified when
                // dummy nodes are created)
                List<LEdge> edges = port.getIncomingEdges();
                LEdge[] edgeArray = LGraphUtil.toEdgeArray(edges);
                for (LEdge edge : edgeArray) {
                    createEastPortSideDummies(layeredGraph, port, edge, unassignedNodes);
                }
            }
            // Look for ports on the left side connected to edges going to higher layers
            for (LPort port : node.getPorts(PortType.OUTPUT, PortSide.WEST)) {
                // For every edge going out of this port, insert dummy nodes (do this using
                // a copy of the current list of edges, since the edges are modified when
                // dummy nodes are created)
                List<LEdge> edges = port.getOutgoingEdges();
                LEdge[] edgeArray = LGraphUtil.toEdgeArray(edges);
                for (LEdge edge : edgeArray) {
                    createWestPortSideDummies(layeredGraph, port, edge, unassignedNodes);
                }
            }
        }
    }
    // There may be unassigned nodes left
    for (LNode node : unassignedNodes) {
        node.setLayer(currentLayer);
    }
    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 8 with LPort

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

the class LabelDummyInserter method createLabelDummy.

/**
 * Creates a label dummy for the given edge.
 *
 * @param layeredGraph
 *            graph the dummy will later be placed in.
 * @param edge
 *            the edge the label dummy is created for.
 * @param thickness
 *            the edge's thickness.
 * @param representedLabels
 *            currently empty list of labels represented by the new label dummy. This is set on the edge as a
 *            property and will later be filled with the represented labels by the calling method.
 */
private LNode createLabelDummy(final LGraph layeredGraph, final LEdge edge, final double thickness, final List<LLabel> representedLabels) {
    LNode dummyNode = new LNode(layeredGraph);
    dummyNode.setType(NodeType.LABEL);
    dummyNode.setProperty(InternalProperties.ORIGIN, edge);
    dummyNode.setProperty(InternalProperties.REPRESENTED_LABELS, representedLabels);
    dummyNode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
    dummyNode.setProperty(InternalProperties.LONG_EDGE_SOURCE, edge.getSource());
    dummyNode.setProperty(InternalProperties.LONG_EDGE_TARGET, edge.getTarget());
    // Actually split the edge
    LongEdgeSplitter.splitEdge(edge, dummyNode);
    // Place ports at the edge's center
    double portPos = Math.floor(thickness / 2);
    for (LPort dummyPort : dummyNode.getPorts()) {
        dummyPort.getPosition().y = portPos;
    }
    return dummyNode;
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 9 with LPort

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

the class LabelDummySwitcher method swapNodes.

/**
 * Swaps the two given label dummy with the given long edge dummy. The dummies are assumed to be part of the same
 * long edge. The label dummy's new layer's width in the {@link #layerWidths} array is enlarged if the label dummy
 * is wider than the layer currently is.
 */
private void swapNodes(final LNode labelDummy, final LNode longEdgeDummy) {
    // Find the layers and the positions inside the layers of the dummy nodes. We need the positions later since
    // we run after crossing minimization and have to keep the order of nodes the same. An alternative for this
    // method would be not to change the layers and connections of the two nodes but to switch all of their
    // properties instead, but we reckon that might actually be more work
    Layer layer1 = labelDummy.getLayer();
    Layer layer2 = longEdgeDummy.getLayer();
    int dummy1LayerPosition = layer1.getNodes().indexOf(labelDummy);
    int dummy2LayerPosition = layer2.getNodes().indexOf(longEdgeDummy);
    // Detect incoming and outgoing ports of the nodes (this of course assumes that there's just one of each kind,
    // which should be true for long edge and label dummy nodes)
    LPort inputPort1 = labelDummy.getPorts(PortType.INPUT).iterator().next();
    LPort outputPort1 = labelDummy.getPorts(PortType.OUTPUT).iterator().next();
    LPort inputPort2 = longEdgeDummy.getPorts(PortType.INPUT).iterator().next();
    LPort outputPort2 = longEdgeDummy.getPorts(PortType.OUTPUT).iterator().next();
    // Store incoming and outgoing edges
    LEdge[] incomingEdges1 = LGraphUtil.toEdgeArray(inputPort1.getIncomingEdges());
    LEdge[] outgoingEdges1 = LGraphUtil.toEdgeArray(outputPort1.getOutgoingEdges());
    LEdge[] incomingEdges2 = LGraphUtil.toEdgeArray(inputPort2.getIncomingEdges());
    LEdge[] outgoingEdges2 = LGraphUtil.toEdgeArray(outputPort2.getOutgoingEdges());
    // Put first dummy into second dummy's layer and reroute second dummy's edges to first dummy
    labelDummy.setLayer(dummy2LayerPosition, layer2);
    for (LEdge edge : incomingEdges2) {
        edge.setTarget(inputPort1);
    }
    for (LEdge edge : outgoingEdges2) {
        edge.setSource(outputPort1);
    }
    // Put second dummy into first dummy's layer and reroute first dummy's edges to second dummy
    longEdgeDummy.setLayer(dummy1LayerPosition, layer1);
    for (LEdge edge : incomingEdges1) {
        edge.setTarget(inputPort2);
    }
    for (LEdge edge : outgoingEdges1) {
        edge.setSource(outputPort2);
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 10 with LPort

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

the class LabelManagementProcessor method manageNonCenterLabels.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Everything Except Center Edge Labels
/**
 * Calls label management on all labels that are not edge center labels.
 */
private void manageNonCenterLabels(final LGraph lGraph, final ILabelManager labelManager, final double labelLabelSpacing) {
    boolean verticalLayout = lGraph.getProperty(LayeredOptions.DIRECTION).isVertical();
    // Iterate over the layers
    for (Layer layer : lGraph) {
        // Apply label management to node and port labels
        for (LNode node : layer) {
            if (node.getType() == NodeType.NORMAL) {
                // Handle node labels
                doManageLabels(labelManager, node.getLabels(), MIN_WIDTH_NODE_LABELS, labelLabelSpacing, verticalLayout);
                // Handle ports
                List<LPort> ports = node.getPorts();
                for (LPort port : ports) {
                    doManageLabels(labelManager, port.getLabels(), MIN_WIDTH_PORT_LABELS, labelLabelSpacing, verticalLayout);
                }
                // Handle attached comments
                if (node.hasProperty(InternalProperties.TOP_COMMENTS)) {
                    doManageAttachedCommentLabels(labelManager, node.getProperty(InternalProperties.TOP_COMMENTS), MIN_WIDTH_NODE_LABELS, verticalLayout);
                }
                if (node.hasProperty(InternalProperties.BOTTOM_COMMENTS)) {
                    doManageAttachedCommentLabels(labelManager, node.getProperty(InternalProperties.BOTTOM_COMMENTS), MIN_WIDTH_NODE_LABELS, verticalLayout);
                }
            }
            // point, only head and tail labels remain)
            for (LEdge edge : node.getOutgoingEdges()) {
                doManageLabels(labelManager, edge.getLabels(), MIN_WIDTH_EDGE_LABELS, 0, verticalLayout);
            }
        }
    }
}
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)

Aggregations

LPort (org.eclipse.elk.alg.layered.graph.LPort)270 LNode (org.eclipse.elk.alg.layered.graph.LNode)187 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)78 Test (org.junit.Test)66 Layer (org.eclipse.elk.alg.layered.graph.Layer)62 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)46 KVector (org.eclipse.elk.core.math.KVector)36 PortSide (org.eclipse.elk.core.options.PortSide)29 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)23 KVectorChain (org.eclipse.elk.core.math.KVectorChain)18 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)15 List (java.util.List)12 ArrayList (java.util.ArrayList)8 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 PortConstraints (org.eclipse.elk.core.options.PortConstraints)7 Set (java.util.Set)6 ElkLabel (org.eclipse.elk.graph.ElkLabel)6 EnumSet (java.util.EnumSet)5 SelfHyperLoop (org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoop)5 Lists (com.google.common.collect.Lists)4