Search in sources :

Example 26 with LNode

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

the class TestGraphCreator method getCurrentOrder.

/**
 * Returns the nodes in the graph as two-dimensional array of LNodes.
 *
 * @return graph as LNode[][].
 */
public LNode[][] getCurrentOrder() {
    LNode[][] nodeOrder = new LNode[graph.getLayers().size()][];
    List<Layer> layers = graph.getLayers();
    for (int i = 0; i < layers.size(); i++) {
        Layer layer = layers.get(i);
        List<LNode> nodes = layer.getNodes();
        nodeOrder[i] = new LNode[nodes.size()];
        for (int j = 0; j < nodes.size(); j++) {
            nodeOrder[i][j] = nodes.get(j);
        }
    }
    return nodeOrder;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 27 with LNode

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

the class TestGraphCreator method getFixedPortOrderInLayerEdgesDontCrossEachOther.

/**
 * <pre>
 * ____
 * |  |----
 * |__|\  |
 * ____ | |
 * |  |/  |
 * |__|---|
 * .
 * </pre>
 *
 * Port order fixed.
 *
 * @return Graph of the form above.
 */
public LGraph getFixedPortOrderInLayerEdgesDontCrossEachOther() {
    Layer layer = makeLayer();
    LNode[] nodes = addNodesToLayer(2, layer);
    setFixedOrderConstraint(nodes[0]);
    setFixedOrderConstraint(nodes[1]);
    // must add ports and edges manually, due to clockwise port ordering
    LPort upperPortUpperNode = addPortOnSide(nodes[0], PortSide.EAST);
    LPort lowerPortUpperNode = addPortOnSide(nodes[0], PortSide.EAST);
    LPort upperPortLowerNode = addPortOnSide(nodes[1], PortSide.EAST);
    LPort lowerPortLowerNode = addPortOnSide(nodes[1], PortSide.EAST);
    addEdgeBetweenPorts(upperPortUpperNode, lowerPortLowerNode);
    addEdgeBetweenPorts(lowerPortUpperNode, upperPortLowerNode);
    setUpIds();
    return graph;
}
Also used : 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 28 with LNode

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

the class TestGraphCreator method addNorthSouthEdge.

protected void addNorthSouthEdge(final PortSide side, final LNode nodeWithNSPorts, final LNode northSouthDummy, final LNode nodeWithEastWestPorts, final boolean nodeWithEastWestPortsIsOrigin) {
    boolean normalNodeEastOfNsPortNode = nodeWithEastWestPorts.getLayer().getIndex() < nodeWithNSPorts.getLayer().getIndex();
    PortSide direction = normalNodeEastOfNsPortNode ? PortSide.WEST : PortSide.EAST;
    PortSide targetNodePortSide = direction == PortSide.WEST ? PortSide.EAST : PortSide.WEST;
    LPort normalNodePort = addPortOnSide(nodeWithEastWestPorts, targetNodePortSide);
    LPort dummyNodePort = addPortOnSide(northSouthDummy, direction);
    if (nodeWithEastWestPortsIsOrigin) {
        addEdgeBetweenPorts(normalNodePort, dummyNodePort);
    } else {
        addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    }
    northSouthDummy.setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, nodeWithNSPorts);
    northSouthDummy.setProperty(InternalProperties.ORIGIN, nodeWithNSPorts);
    setAsNorthSouthNode(northSouthDummy);
    LPort originPort = addPortOnSide(nodeWithNSPorts, side);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    originPort.setProperty(InternalProperties.PORT_DUMMY, northSouthDummy);
    List<LNode> baryAssoc = Lists.newArrayList(northSouthDummy);
    List<LNode> otherBaryAssocs = nodeWithNSPorts.getProperty(InternalProperties.BARYCENTER_ASSOCIATES);
    if (otherBaryAssocs == null) {
        nodeWithNSPorts.setProperty(InternalProperties.BARYCENTER_ASSOCIATES, baryAssoc);
    } else {
        otherBaryAssocs.addAll(baryAssoc);
    }
    if (side == PortSide.NORTH) {
        northSouthDummy.getProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS).add(nodeWithNSPorts);
    } else {
        nodeWithNSPorts.getProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS).add(northSouthDummy);
    }
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortSide(org.eclipse.elk.core.options.PortSide)

Example 29 with LNode

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

the class TestGraphCreator method multipleInBetweenLayerEdgesIntoNodeWithNoFixedPortOrder.

/**
 * <pre>
 *  ---*
 *  |
 *  | ____
 * *+-|  |
 * *+-|  |
 *   \|__|
 * Port order not fixed.
 * .
 * </pre>
 *
 * @return Graph of the form above.
 */
public LGraph multipleInBetweenLayerEdgesIntoNodeWithNoFixedPortOrder() {
    Layer leftLayer = makeLayer();
    LNode[] leftNodes = addNodesToLayer(2, leftLayer);
    Layer rightLayer = makeLayer();
    LNode[] rightNodes = addNodesToLayer(2, rightLayer);
    addInLayerEdge(rightNodes[0], rightNodes[1], PortSide.WEST);
    eastWestEdgeFromTo(leftNodes[0], rightNodes[1]);
    eastWestEdgeFromTo(leftNodes[0], rightNodes[1]);
    setUpIds();
    return graph;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 30 with LNode

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

the class TestGraphCreator method addNodeToLayer.

protected LNode addNodeToLayer(final Layer layer) {
    LNode node = new LNode(graph);
    node.setType(NodeType.NORMAL);
    node.setProperty(InternalProperties.IN_LAYER_LAYOUT_UNIT, node);
    node.setLayer(layer);
    node.id = nodeId++;
    return node;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode)

Aggregations

LNode (org.eclipse.elk.alg.layered.graph.LNode)471 LPort (org.eclipse.elk.alg.layered.graph.LPort)189 Layer (org.eclipse.elk.alg.layered.graph.Layer)185 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)110 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)91 Test (org.junit.Test)85 KVector (org.eclipse.elk.core.math.KVector)38 PortSide (org.eclipse.elk.core.options.PortSide)28 List (java.util.List)23 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)22 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)16 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)16 KVectorChain (org.eclipse.elk.core.math.KVectorChain)15 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)14 ArrayList (java.util.ArrayList)13 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)13 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)13 PortConstraints (org.eclipse.elk.core.options.PortConstraints)13 Set (java.util.Set)12 CrossingsCounter (org.eclipse.elk.alg.layered.p3order.counting.CrossingsCounter)10