Search in sources :

Example 6 with NodeType

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

the class HyperedgeDummyMerger method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Hyperedge merging", 1);
    identifyHyperedges(layeredGraph);
    // Iterate through the layers
    ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
    while (layerIter.hasNext()) {
        Layer layer = layerIter.next();
        List<LNode> nodes = layer.getNodes();
        // If there are no nodes anyway, just move on to the next layer
        if (nodes.isEmpty()) {
            continue;
        }
        LNode currNode = null;
        NodeType currNodeType = null;
        LNode lastNode = null;
        NodeType lastNodeType = null;
        // Iterate through the remaining nodes
        for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++) {
            // Get the next node
            currNode = nodes.get(nodeIndex);
            currNodeType = currNode.getType();
            // We're only interested if the current and last nodes are long edge dummies
            if (currNodeType == NodeType.LONG_EDGE && lastNodeType == NodeType.LONG_EDGE) {
                // If the source or the target are identical and we are allowed to merge, merge the current node
                // into the last
                MergeState state = checkMergeAllowed(currNode, lastNode);
                if (state.allowMerge) {
                    mergeNodes(currNode, lastNode, state.sameSource, state.sameTarget);
                    // Remove the current node and make the last node the current node
                    nodes.remove(nodeIndex);
                    nodeIndex--;
                    currNode = lastNode;
                    currNodeType = lastNodeType;
                }
            }
            // Remember this node for the next iteration
            lastNode = currNode;
            lastNodeType = currNodeType;
        }
    }
    monitor.done();
}
Also used : NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Aggregations

NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)6 LNode (org.eclipse.elk.alg.layered.graph.LNode)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)2 Layer (org.eclipse.elk.alg.layered.graph.Layer)2