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);
}
}
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);
}
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;
}
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));
}
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));
}
Aggregations