Search in sources :

Example 21 with LPort

use of org.eclipse.elk.alg.layered.graph.LPort 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 22 with LPort

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

the class TestGraphCreator method eastWestEdgeFromTo.

protected void eastWestEdgeFromTo(final LNode left, final LNode right) {
    LPort leftPort = addPortOnSide(left, PortSide.EAST);
    LPort rightPort = addPortOnSide(right, PortSide.WEST);
    addEdgeBetweenPorts(leftPort, rightPort);
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 23 with LPort

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

the class TestGraphCreator method twoEdgesIntoSamePortResolvesCrossingWhenSwitched.

/**
 * <pre>
 * *  *
 *  \/
 *  /\
 * *--*<- Into same port
 * </pre>
 *
 * .
 *
 * @return Graph of the form above.
 */
public LGraph twoEdgesIntoSamePortResolvesCrossingWhenSwitched() {
    Layer leftLayer = makeLayer();
    Layer rightLayer = makeLayer();
    LNode topLeft = addNodeToLayer(leftLayer);
    LNode bottomLeft = addNodeToLayer(leftLayer);
    LNode topRight = addNodeToLayer(rightLayer);
    LNode bottomRight = addNodeToLayer(rightLayer);
    LPort topLeftPort = addPortOnSide(topLeft, PortSide.EAST);
    LPort bottomLeftPort = addPortOnSide(bottomLeft, PortSide.EAST);
    LPort bottomRightPort = addPortOnSide(bottomRight, PortSide.WEST);
    addEdgeBetweenPorts(topLeftPort, bottomRightPort);
    addEdgeBetweenPorts(bottomLeftPort, bottomRightPort);
    eastWestEdgeFromTo(bottomLeft, topRight);
    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 24 with LPort

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

the class InLayerEdgeTwoNodeCrossingCounterTest method multipleEdgesIntoOnePort_ShouldNotCauseCrossing.

/**
 * <pre>
 * *------
 * *---\ |
 * ___ | |
 * | |--/
 * |_|
 * </pre>
 */
@Test
public void multipleEdgesIntoOnePort_ShouldNotCauseCrossing() {
    LNode[] nodes = addNodesToLayer(3, makeLayer(getGraph()));
    final PortSide portSide = PortSide.EAST;
    LPort portOne = addPortOnSide(nodes[0], portSide);
    LPort portTwo = addPortOnSide(nodes[1], portSide);
    LPort portThree = addPortOnSide(nodes[2], portSide);
    addEdgeBetweenPorts(portOne, portThree);
    addEdgeBetweenPorts(portTwo, portThree);
    countCrossingsInLayerForUpperNodeLowerNode(0, 0, 1);
    assertThat("upperLowerCrossings", upperLowerCrossings, is(0));
    assertThat("lowerUpperCrossings", lowerUpperCrossings, is(0));
}
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) Test(org.junit.Test)

Example 25 with LPort

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

the class NorthSouthEdgeNeighbouringNodeCrossingsCounterTest method multipleEdgesInBothDirectionsNSNode.

/**
 * <pre>
 * *===.--*
 *     |
 * *-.====*
 *   | |
 *  _|_|_
 *  |   |
 *  |___|
 * </pre>
 */
@Test
public void multipleEdgesInBothDirectionsNSNode() {
    LNode[] leftLayer = addNodesToLayer(2, makeLayer());
    LNode[] middleLayer = addNodesToLayer(3, makeLayer());
    LNode[] rightLayer = addNodesToLayer(2, makeLayer());
    setFixedOrderConstraint(middleLayer[2]);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[1], leftLayer[1], true);
    LPort normalNodePort = addPortOnSide(rightLayer[1], PortSide.WEST);
    LPort dummyNodePort = addPortOnSide(middleLayer[1], PortSide.EAST);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    LPort originPort = middleLayer[2].getPorts().get(0);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    addNorthSouthEdge(PortSide.NORTH, middleLayer[2], middleLayer[0], rightLayer[0], false);
    normalNodePort = addPortOnSide(rightLayer[0], PortSide.EAST);
    dummyNodePort = addPortOnSide(middleLayer[0], PortSide.WEST);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    addEdgeBetweenPorts(dummyNodePort, normalNodePort);
    originPort = middleLayer[2].getPorts().get(1);
    dummyNodePort.setProperty(InternalProperties.ORIGIN, originPort);
    countCrossingsInLayerBetweenNodes(1, 0, 1);
    assertThat(counter.getUpperLowerCrossings(), is(2));
    // Note that the three other crossings which result from this switch are
    // counted by a
    // different crossings counter.
    assertThat(counter.getLowerUpperCrossings(), is(2));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

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