use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class PolylineEdgeRouter method processNode.
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Actual Edge Routing Code
/**
* Inserts bend points for edges incident to this node. The bend points are inserted such that
* the segments that cross the layer's area are straight or pretty much straight. A bend point
* is only added if it's necessary: if the bend point to be inserted differs from the edge's end
* point.
*
* @param node
* the node whose incident edges to insert bend points for.
* @param layerLeftXPos
* the x position of the node's layer.
* @param maxAcceptableXDiff
* the maximum space between node and layer boundary before bend points need to be inserted.
*/
private void processNode(final LNode node, final double layerLeftXPos, final double maxAcceptableXDiff) {
// The right side of the layer
final double layerRightXPos = layerLeftXPos + node.getLayer().getSize().x;
for (LPort port : node.getPorts()) {
KVector absolutePortAnchor = port.getAbsoluteAnchor();
if (node.getType() == NodeType.NORTH_SOUTH_PORT) {
// North/south ports require special handling (also see #515):
// The dummy node that represents the north/south port will have been placed at:
// - the very left x-coordinate of the currently processed layer for incoming edges
// - the very right x-coordinate for outgoing edges
// However, the actual x-coordinate of the port itself is very likely to have a different x-coordinate.
// The code below introduces bendpoints that prevent edge/node overlaps based on a condition that
// checks that a node's position is "far enough away" from the left-most x-coordinate of the layer.
// Consequently, we have to use the north/south port's x-coordinate instead of the dummy node's one.
LPort correspondingPort = (LPort) port.getProperty(InternalProperties.ORIGIN);
absolutePortAnchor.x = correspondingPort.getAbsoluteAnchor().x;
// While it makes sense either way, it is important to move the dummy node to the correct location
// as well. Otherwise the #addBendPoint(...) method won't add the computed bendpoint as it
// thinks it's superfluous.
node.getPosition().x = absolutePortAnchor.x;
}
KVector bendPoint = new KVector(0, absolutePortAnchor.y);
if (port.getSide() == PortSide.EAST) {
bendPoint.x = layerRightXPos;
} else if (port.getSide() == PortSide.WEST) {
bendPoint.x = layerLeftXPos;
} else {
// We only know what to do with eastern and western ports
continue;
}
// If the port's absolute anchor equals the bend point, we don't want to insert anything
// (unless the node represents an in-layer dummy)
double xDistance = Math.abs(absolutePortAnchor.x - bendPoint.x);
if (xDistance <= maxAcceptableXDiff && !isInLayerDummy(node)) {
continue;
}
// Whether to add a junction point or not
boolean addJunctionPoint = port.getOutgoingEdges().size() + port.getIncomingEdges().size() > 1;
// Iterate over the edges and add bend (and possibly junction) points
for (LEdge e : port.getConnectedEdges()) {
LPort otherPort = e.getSource() == port ? e.getTarget() : e.getSource();
if (Math.abs(otherPort.getAbsoluteAnchor().y - bendPoint.y) > MIN_VERT_DIFF) {
// Insert bend point
addBendPoint(e, bendPoint, addJunctionPoint, port);
}
}
}
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class PolylineEdgeRouter method calculateWestInLayerEdgeYDiff.
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Utility Methods
/**
* Calculates the maximum vertical span of any in-layer edge connecting west-side ports of nodes
* in the given layer.
*
* @param layer
* the layer to iterate over.
* @return maximum vertical span of west-side in-layer edges.
*/
private double calculateWestInLayerEdgeYDiff(final Layer layer) {
double maxYDiff = 0.0;
for (LNode node : layer) {
for (LEdge outgoingEdge : node.getOutgoingEdges()) {
if (layer == outgoingEdge.getTarget().getNode().getLayer() && outgoingEdge.getSource().getSide() == PortSide.WEST) {
double sourcePos = outgoingEdge.getSource().getAbsoluteAnchor().y;
double targetPos = outgoingEdge.getTarget().getAbsoluteAnchor().y;
maxYDiff = Math.max(maxYDiff, Math.abs(targetPos - sourcePos));
}
}
}
return maxYDiff;
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class ReversedEdgeRestorer method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
monitor.begin("Restoring reversed edges", 1);
// Iterate through the layers
for (Layer layer : layeredGraph) {
// Iterate through the nodes
for (LNode node : layer) {
// Iterate over all the ports, looking for outgoing edges that should be reversed
for (LPort port : node.getPorts()) {
// Iterate over a copy of the edges to avoid concurrent modification exceptions
LEdge[] edgeArray = LGraphUtil.toEdgeArray(port.getOutgoingEdges());
for (LEdge edge : edgeArray) {
if (edge.getProperty(InternalProperties.REVERSED)) {
edge.reverse(layeredGraph, false);
}
}
}
}
}
monitor.done();
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class SelfLoopPostProcessor method restoreEdge.
private void restoreEdge(final LNode lNode, final SelfLoopEdge slEdge) {
LEdge lEdge = slEdge.getLEdge();
lEdge.setSource(slEdge.getSLSource().getLPort());
lEdge.setTarget(slEdge.getSLTarget().getLPort());
lEdge.getBendPoints().offset(lNode.getPosition());
}
use of org.eclipse.elk.alg.layered.graph.LEdge in project elk by eclipse.
the class SortByInputModelProcessor method longEdgeTargetNodePreprocessing.
/**
* Calculate long edge target of port and saves it and adds a map of all long edge targets to the node.
* @param node the node
* @return A map of all long edge targets of a node
*/
public static Map<LNode, Integer> longEdgeTargetNodePreprocessing(LNode node) {
Map<LNode, Integer> targetNodeModelOrder = new HashMap<>();
if (node.hasProperty(InternalProperties.TARGET_NODE_MODEL_ORDER)) {
return node.getProperty(InternalProperties.TARGET_NODE_MODEL_ORDER);
}
node.getPorts().stream().filter(p -> !p.getOutgoingEdges().isEmpty()).forEach(p -> {
LNode targetNode = getTargetNode(p);
p.setProperty(InternalProperties.LONG_EDGE_TARGET_NODE, targetNode);
if (targetNode != null) {
int previousOrder = Integer.MAX_VALUE;
if (targetNodeModelOrder.containsKey(targetNode)) {
previousOrder = targetNodeModelOrder.get(targetNode);
}
LEdge edge = p.getOutgoingEdges().get(0);
if (!edge.getProperty(InternalProperties.REVERSED)) {
targetNodeModelOrder.put(targetNode, Math.min(edge.getProperty(InternalProperties.MODEL_ORDER), previousOrder));
}
}
});
node.setProperty(InternalProperties.TARGET_NODE_MODEL_ORDER, targetNodeModelOrder);
return targetNodeModelOrder;
}
Aggregations