use of org.eclipse.elk.alg.layered.p5edges.orthogonal.OrthogonalRoutingGenerator in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method routeEdges.
// /////////////////////////////////////////////////////////////////////////////
// STEP 3: EDGE ROUTING
/**
* Routes nothern and southern hierarchical port edges and ajusts the graph's height and
* offsets accordingly.
*
* @param monitor the progress monitor we're using.
* @param layeredGraph the layered graph.
* @param northSouthDummies the collection of restored northern and southern port dummies.
*/
private void routeEdges(final IElkProgressMonitor monitor, final LGraph layeredGraph, final Iterable<LNode> northSouthDummies) {
// Prepare south and target layers for northern and southern routing
Set<LNode> northernSourceLayer = Sets.newLinkedHashSet();
Set<LNode> northernTargetLayer = Sets.newLinkedHashSet();
Set<LNode> southernSourceLayer = Sets.newLinkedHashSet();
Set<LNode> southernTargetLayer = Sets.newLinkedHashSet();
// Find some routing parameters
double nodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE_NODE).doubleValue();
double edgeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_EDGE).doubleValue();
// connected to
for (LNode hierarchicalPortDummy : northSouthDummies) {
PortSide portSide = hierarchicalPortDummy.getProperty(InternalProperties.EXT_PORT_SIDE);
if (portSide == PortSide.NORTH) {
northernTargetLayer.add(hierarchicalPortDummy);
for (LEdge edge : hierarchicalPortDummy.getIncomingEdges()) {
northernSourceLayer.add(edge.getSource().getNode());
}
} else if (portSide == PortSide.SOUTH) {
southernTargetLayer.add(hierarchicalPortDummy);
for (LEdge edge : hierarchicalPortDummy.getIncomingEdges()) {
southernSourceLayer.add(edge.getSource().getNode());
}
}
}
// Northern routing
if (!northernSourceLayer.isEmpty()) {
// Route the edges using a south-to-north orthogonal edge router
OrthogonalRoutingGenerator routingGenerator = new OrthogonalRoutingGenerator(RoutingDirection.SOUTH_TO_NORTH, edgeSpacing, "extnorth");
int slots = routingGenerator.routeEdges(monitor, layeredGraph, northernSourceLayer, 0, northernTargetLayer, -nodeSpacing - layeredGraph.getOffset().y);
// If anything was routed, adjust the graph's offset and height
if (slots > 0) {
northernExtPortEdgeRoutingHeight = nodeSpacing + (slots - 1) * edgeSpacing;
layeredGraph.getOffset().y += northernExtPortEdgeRoutingHeight;
layeredGraph.getSize().y += northernExtPortEdgeRoutingHeight;
}
}
// Southern routing
if (!southernSourceLayer.isEmpty()) {
// Route the edges using a north-to-south orthogonal edge router
OrthogonalRoutingGenerator routingGenerator = new OrthogonalRoutingGenerator(RoutingDirection.NORTH_TO_SOUTH, edgeSpacing, "extsouth");
int slots = routingGenerator.routeEdges(monitor, layeredGraph, southernSourceLayer, 0, southernTargetLayer, layeredGraph.getSize().y + nodeSpacing - layeredGraph.getOffset().y);
// Adjust graph height.
if (slots > 0) {
layeredGraph.getSize().y += nodeSpacing + (slots - 1) * edgeSpacing;
}
}
}
use of org.eclipse.elk.alg.layered.p5edges.orthogonal.OrthogonalRoutingGenerator in project elk by eclipse.
the class OrthogonalEdgeRouter method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
monitor.begin("Orthogonal edge routing", 1);
// Retrieve some generic values
double nodeNodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS).doubleValue();
double edgeEdgeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS).doubleValue();
double edgeNodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS).doubleValue();
// Prepare for iteration!
OrthogonalRoutingGenerator routingGenerator = new OrthogonalRoutingGenerator(RoutingDirection.WEST_TO_EAST, edgeEdgeSpacing, "phase5");
float xpos = 0.0f;
ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
Layer leftLayer = null;
Layer rightLayer = null;
List<LNode> leftLayerNodes = null;
List<LNode> rightLayerNodes = null;
int leftLayerIndex = -1;
int rightLayerIndex = -1;
// Iterate!
do {
int slotsCount;
// Fetch the next layer, if any
rightLayer = layerIter.hasNext() ? layerIter.next() : null;
rightLayerNodes = rightLayer == null ? null : rightLayer.getNodes();
rightLayerIndex = layerIter.previousIndex();
// Place the left layer's nodes, if any
if (leftLayer != null) {
LGraphUtil.placeNodesHorizontally(leftLayer, xpos);
xpos += leftLayer.getSize().x;
}
// Route edges between the two layers
double startPos = leftLayer == null ? xpos : xpos + edgeNodeSpacing;
slotsCount = routingGenerator.routeEdges(monitor, layeredGraph, leftLayerNodes, leftLayerIndex, rightLayerNodes, startPos);
boolean isLeftLayerExternal = leftLayer == null || Iterables.all(leftLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
boolean isRightLayerExternal = rightLayer == null || Iterables.all(rightLayerNodes, PolylineEdgeRouter.PRED_EXTERNAL_WEST_OR_EAST_PORT);
if (slotsCount > 0) {
// Compute routing area's width
double routingWidth = (slotsCount - 1) * edgeEdgeSpacing;
if (leftLayer != null) {
routingWidth += edgeNodeSpacing;
}
if (rightLayer != null) {
routingWidth += edgeNodeSpacing;
}
// If we are between two layers, make sure their minimal spacing is preserved
if (routingWidth < nodeNodeSpacing && !isLeftLayerExternal && !isRightLayerExternal) {
routingWidth = nodeNodeSpacing;
}
xpos += routingWidth;
} else if (!isLeftLayerExternal && !isRightLayerExternal) {
// If all edges are straight, use the usual spacing
xpos += nodeNodeSpacing;
}
leftLayer = rightLayer;
leftLayerNodes = rightLayerNodes;
leftLayerIndex = rightLayerIndex;
} while (rightLayer != null);
layeredGraph.getSize().x = xpos;
monitor.done();
}
Aggregations