Search in sources :

Example 26 with PortSide

use of org.eclipse.elk.core.options.PortSide in project elk by eclipse.

the class LabelPlacer method assignTwoSidesCornerSideAndAlignment.

private void assignTwoSidesCornerSideAndAlignment(final SelfHyperLoop slLoop) {
    // The side and alignment depends on where the leftmost and rightmost port is. If the leftmost port is north,
    // the loop goes towards the eastern side and we can left-align the label on the nortern side. The other cases
    // are similar.
    PortSide leftmostPortSide = slLoop.getLeftmostPort().getLPort().getSide();
    PortSide rightmostPortSide = slLoop.getRightmostPort().getLPort().getSide();
    if (leftmostPortSide == PortSide.NORTH) {
        assignSideAndAlignment(slLoop, PortSide.NORTH, Alignment.LEFT, slLoop.getLeftmostPort());
    } else if (rightmostPortSide == PortSide.NORTH) {
        assignSideAndAlignment(slLoop, PortSide.NORTH, Alignment.RIGHT, slLoop.getRightmostPort());
    } else if (leftmostPortSide == PortSide.SOUTH) {
        assignSideAndAlignment(slLoop, PortSide.SOUTH, Alignment.RIGHT, slLoop.getLeftmostPort());
    } else if (rightmostPortSide == PortSide.SOUTH) {
        assignSideAndAlignment(slLoop, PortSide.SOUTH, Alignment.LEFT, slLoop.getRightmostPort());
    } else {
        assert false;
    }
}
Also used : PortSide(org.eclipse.elk.core.options.PortSide)

Example 27 with PortSide

use of org.eclipse.elk.core.options.PortSide in project elk by eclipse.

the class LabelPlacer method assignFourSidesSideAndAlignment.

private void assignFourSidesSideAndAlignment(final SelfHyperLoop slLoop) {
    // There are basically just two cases that we need to distinguish: the loop covers the whole northern side, or
    // the loop covers the whole southern side. We always center its label on the side that's completely covered.
    // A side is not completely covered if either the leftmost or the rightmost port is placed on that side, so
    // that's easy to distinguish
    PortSide leftmostPortSide = slLoop.getLeftmostPort().getLPort().getSide();
    PortSide rightmostPortSide = slLoop.getLeftmostPort().getLPort().getSide();
    if (leftmostPortSide == PortSide.NORTH || rightmostPortSide == PortSide.NORTH) {
        assignSideAndAlignment(slLoop, PortSide.SOUTH, Alignment.CENTER, null);
    } else {
        assignSideAndAlignment(slLoop, PortSide.NORTH, Alignment.CENTER, null);
    }
}
Also used : PortSide(org.eclipse.elk.core.options.PortSide)

Example 28 with PortSide

use of org.eclipse.elk.core.options.PortSide in project elk by eclipse.

the class OrthogonalSelfLoopRouter method computeRoutingSlotPositions.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Routing Slot Positions
/**
 * Computes the position of each routing slot on each side, taking care to leave enough space for labels between
 * adjacent routing slots on the north and south sides.
 */
private double[][] computeRoutingSlotPositions(final SelfLoopHolder slHolder, final double edgeEdgeDistance, final double edgeLabelDistance, final double nodeSLDistance) {
    // Initialize array
    double[][] positions = new double[PortSide.values().length][];
    for (PortSide portSide : PortSide.values()) {
        positions[portSide.ordinal()] = new double[slHolder.getRoutingSlotCount()[portSide.ordinal()]];
    }
    // To know how much space we need to leave between adjacent routing slots, we have to find the size of labels
    // first (for north and south sides, that is)
    initializeWithMaxLabelHeight(positions, slHolder, PortSide.NORTH);
    initializeWithMaxLabelHeight(positions, slHolder, PortSide.SOUTH);
    // Compute the positions for each side
    computePositions(positions, slHolder, PortSide.NORTH, edgeEdgeDistance, edgeLabelDistance, nodeSLDistance);
    computePositions(positions, slHolder, PortSide.EAST, edgeEdgeDistance, edgeLabelDistance, nodeSLDistance);
    computePositions(positions, slHolder, PortSide.SOUTH, edgeEdgeDistance, edgeLabelDistance, nodeSLDistance);
    computePositions(positions, slHolder, PortSide.WEST, edgeEdgeDistance, edgeLabelDistance, nodeSLDistance);
    return positions;
}
Also used : PortSide(org.eclipse.elk.core.options.PortSide)

Example 29 with PortSide

use of org.eclipse.elk.core.options.PortSide in project elk by eclipse.

the class SelfHyperLoop method computePortsPerSide.

/**
 * Fills our {@link #slPortsBySide} multimap and determines this self loop's type. This method is called by
 * {@link PortRestorer} right before it gets to work since it has to know which ports are on which side.
 */
public void computePortsPerSide() {
    assert slPortsBySide == null;
    // Remember ports for each side
    slPortsBySide = ArrayListMultimap.create(PortSide.values().length, slPorts.size());
    for (SelfLoopPort slPort : slPorts) {
        PortSide portSide = slPort.getLPort().getSide();
        assert portSide != PortSide.UNDEFINED;
        slPortsBySide.put(portSide, slPort);
    }
    // Determine this self loop's loop type
    selfLoopType = SelfLoopType.fromPortSides(slPortsBySide.keySet());
}
Also used : PortSide(org.eclipse.elk.core.options.PortSide)

Example 30 with PortSide

use of org.eclipse.elk.core.options.PortSide in project elk by eclipse.

the class PortRestorer method processOneSideLoops.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Self Loop Placement (One Side)
private void processOneSideLoops(final SelfLoopOrderingStrategy ordering) {
    for (SelfHyperLoop slLoop : slLoopsByType.get(SelfLoopType.ONE_SIDE)) {
        // Obtain the port side
        PortSide side = slLoop.getSLPorts().get(0).getLPort().getSide();
        // We want ports with more outgoing edges to be to the left of ports with more incoming edges, so we need
        // a sorted list of ports
        List<SelfLoopPort> sortedPorts = new ArrayList<>(slLoop.getSLPorts());
        sortedPorts.sort((slPort1, slPort2) -> Integer.compare(slPort1.getSLNetFlow(), slPort2.getSLNetFlow()));
        switch(ordering) {
            case SEQUENCED:
                // Simply add all ports according to our list
                addToTargetArea(sortedPorts, side, PortSideArea.MIDDLE, AddMode.APPEND);
                break;
            case STACKED:
                // Compute which ports we want to have in the first group and which in the second group
                int splitIndex = computePortListSplitIndex(sortedPorts);
                // Prepend the first group to the middle list, and append the second group to that same list
                addToTargetArea(sortedPorts.subList(0, splitIndex), side, PortSideArea.MIDDLE, AddMode.PREPEND);
                addToTargetArea(sortedPorts.subList(splitIndex, sortedPorts.size()), side, PortSideArea.MIDDLE, AddMode.APPEND);
                break;
            default:
                assert false;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SelfLoopPort(org.eclipse.elk.alg.layered.intermediate.loops.SelfLoopPort) PortSide(org.eclipse.elk.core.options.PortSide) SelfHyperLoop(org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoop)

Aggregations

PortSide (org.eclipse.elk.core.options.PortSide)71 LPort (org.eclipse.elk.alg.layered.graph.LPort)24 LNode (org.eclipse.elk.alg.layered.graph.LNode)23 KVector (org.eclipse.elk.core.math.KVector)16 SelfHyperLoop (org.eclipse.elk.alg.layered.intermediate.loops.SelfHyperLoop)10 Direction (org.eclipse.elk.core.options.Direction)9 PortConstraints (org.eclipse.elk.core.options.PortConstraints)9 ElkPort (org.eclipse.elk.graph.ElkPort)8 List (java.util.List)7 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)7 ElkLabel (org.eclipse.elk.graph.ElkLabel)7 ArrayList (java.util.ArrayList)6 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)6 Collectors (java.util.stream.Collectors)5 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)5 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 EnumSet (java.util.EnumSet)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)4