Search in sources :

Example 96 with LPort

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

the class SwitchDecider method notifyOfSwitch.

/**
 * Notifies in-layer counter of node switch for efficiency reasons.
 *
 * @param upperNode
 *            a node
 * @param lowerNode
 *            a node
 */
public void notifyOfSwitch(final LNode upperNode, final LNode lowerNode) {
    leftInLayerCounter.switchNodes(upperNode, lowerNode, PortSide.WEST);
    rightInLayerCounter.switchNodes(upperNode, lowerNode, PortSide.EAST);
    if (countCrossingsCausedByPortSwitch) {
        LPort upperPort = (LPort) upperNode.getProperty(InternalProperties.ORIGIN);
        LPort lowerPort = (LPort) lowerNode.getProperty(InternalProperties.ORIGIN);
        parentCrossCounter.switchPorts(upperPort, lowerPort);
    }
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 97 with LPort

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

the class AbstractBarycenterPortDistributorTest method distributePortsOfGraph_GivenCrossOnBothSides_ShouldRemoveCrossin.

/**
 * <pre>
 * *  ___  *
 *  \/| |\/
 *  /\| |/\
 * *  |_|  *
 * </pre>
 */
@Test
public void distributePortsOfGraph_GivenCrossOnBothSides_ShouldRemoveCrossin() {
    LNode[] leftNodes = addNodesToLayer(2, makeLayer(getGraph()));
    LNode middleNode = addNodeToLayer(makeLayer(getGraph()));
    LNode[] rightNodes = addNodesToLayer(2, makeLayer(getGraph()));
    eastWestEdgeFromTo(middleNode, rightNodes[1]);
    eastWestEdgeFromTo(middleNode, rightNodes[0]);
    eastWestEdgeFromTo(leftNodes[0], middleNode);
    eastWestEdgeFromTo(leftNodes[1], middleNode);
    setUpIds();
    List<LPort> expectedPortOrderMiddleNode = copyPortsInIndexOrder(middleNode, 1, 0, 3, 2);
    distributePortsInCompleteGraph(8);
    assertThat(middleNode.getPorts(), is(expectedPortOrderMiddleNode));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

Example 98 with LPort

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

the class AbstractBarycenterPortDistributorTest method distributePortsOnSide_GivenCrossOnWesternSide_ShouldRemoveCrossing.

// CHECKSTYLEOFF javadoc
// CHECKSTYLEOFF MagicNumber
// CHECKSTYLEOFF MethodName
/**
 * <pre>
 * *  ___
 *  \/| |
 *  /\| |
 * *  |_|
 * </pre>
 */
@Test
public void distributePortsOnSide_GivenCrossOnWesternSide_ShouldRemoveCrossing() {
    LNode[] leftNodes = addNodesToLayer(2, makeLayer(getGraph()));
    LNode rightNode = addNodeToLayer(makeLayer(getGraph()));
    eastWestEdgeFromTo(leftNodes[0], rightNode);
    eastWestEdgeFromTo(leftNodes[1], rightNode);
    List<LPort> expectedPortOrderRightNode = Lists.newArrayList(rightNode.getPorts().get(1), rightNode.getPorts().get(0));
    distributePortsInCompleteGraph(4);
    assertThat(rightNode.getPorts(), is(expectedPortOrderRightNode));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Test(org.junit.Test)

Example 99 with LPort

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

the class AbstractBarycenterPortDistributorTest method distributePortsOnSide_partlyCrossHierarchicalEdges_CrossHierarchyStaysOuterChanges.

/**
 * <pre>
 * ____
 * | *+--  *
 * |  |  \/
 * |  |\ /\
 * | *+-x  *
 * |__|  \
 *        -*
 * </pre>
 */
// TODO this is a problem which currently cannot be solved by our algorithm :-(
@Ignore
public void distributePortsOnSide_partlyCrossHierarchicalEdges_CrossHierarchyStaysOuterChanges() {
    LNode leftOuterNode = addNodeToLayer(makeLayer());
    LNode[] rightNodes = addNodesToLayer(3, makeLayer());
    LPort[] leftOuterPorts = addPortsOnSide(3, leftOuterNode, PortSide.EAST);
    LGraph leftInnerGraph = nestedGraph(leftOuterNode);
    LNode[] leftInnerNodes = addNodesToLayer(2, makeLayer(leftInnerGraph));
    LNode[] leftInnerDummyNodes = new LNode[2];
    Layer dummyLayer = makeLayer();
    leftInnerDummyNodes[0] = addExternalPortDummyNodeToLayer(dummyLayer, leftOuterPorts[0]);
    leftInnerDummyNodes[1] = addExternalPortDummyNodeToLayer(dummyLayer, leftOuterPorts[2]);
    eastWestEdgeFromTo(leftInnerNodes[0], leftInnerDummyNodes[0]);
    eastWestEdgeFromTo(leftInnerNodes[1], leftInnerDummyNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[0], rightNodes[1]);
    eastWestEdgeFromTo(leftOuterPorts[1], rightNodes[2]);
    eastWestEdgeFromTo(leftOuterPorts[2], rightNodes[0]);
    // leftOuterNode.setProperty(InternalProperties.HAS_HIERARCHICAL_AND_NORMAL_PORTS, true);
    setPortOrderFixed(leftOuterNode);
    setUpIds();
    List<LPort> expectedOrder = Lists.newArrayList(switchOrderInArray(1, 2, leftOuterPorts));
    distributePortsInCompleteGraph(8);
    assertThat(leftOuterNode.getPorts(), is(expectedOrder));
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) Ignore(org.junit.Ignore)

Example 100 with LPort

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

the class AbstractBarycenterPortDistributorTest method distributePortsWhileSweeping_givenSimpleCross_ShouldRemoveCrossing.

/**
 * <pre>
 * ___  ____
 * | |\/|  |
 * |_|/\|  |
 *      |--|
 * </pre>
 */
@Test
public void distributePortsWhileSweeping_givenSimpleCross_ShouldRemoveCrossing() {
    LNode leftNode = addNodeToLayer(makeLayer(getGraph()));
    LNode rightNode = addNodeToLayer(makeLayer(getGraph()));
    eastWestEdgeFromTo(leftNode, rightNode);
    eastWestEdgeFromTo(leftNode, rightNode);
    List<LPort> expectedPortRightNode = copyPortsInIndexOrder(rightNode, 1, 0);
    setUpIds();
    LNode[][] nodeArray = graph.toNodeArray();
    ISweepPortDistributor portDist = new LayerTotalPortDistributor(nodeArray.length);
    IInitializable.init(Arrays.asList(portDist), nodeArray);
    portDist.distributePortsWhileSweeping(nodeArray, 1, true);
    assertThat(rightNode.getPorts(), is(expectedPortRightNode));
}
Also used : LayerTotalPortDistributor(org.eclipse.elk.alg.layered.p3order.LayerTotalPortDistributor) ISweepPortDistributor(org.eclipse.elk.alg.layered.p3order.ISweepPortDistributor) 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