use of org.eclipse.elk.alg.layered.options.InLayerConstraint in project elk by eclipse.
the class InLayerConstraintProcessorTest method testValidNodeOrder.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(InLayerConstraintProcessor.class)
public void testValidNodeOrder(final Object graph) {
LGraph lGraph = (LGraph) graph;
for (Layer layer : lGraph) {
InLayerConstraint lastConstraint = null;
for (LNode node : layer) {
InLayerConstraint currentConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (lastConstraint != null && currentConstraint != lastConstraint) {
// if the value changes check valid transitions
String error = "Invalid constraint transition: " + lastConstraint.name() + " -> " + currentConstraint.name();
if (currentConstraint == InLayerConstraint.NONE) {
assertTrue(error, lastConstraint == InLayerConstraint.TOP);
} else if (currentConstraint == InLayerConstraint.BOTTOM) {
assertTrue(error, lastConstraint == InLayerConstraint.TOP || lastConstraint == InLayerConstraint.NONE);
}
lastConstraint = currentConstraint;
}
lastConstraint = currentConstraint;
}
}
}
use of org.eclipse.elk.alg.layered.options.InLayerConstraint in project elk by eclipse.
the class GraphTransformer method transposeLayerConstraint.
/**
* The layer constraint and in-layer constraint set on a node. A node with layer constraint
* {@link LayerConstraint#FIRST_SEPARATE} will end up with an in-layer constraint
* {@link InLayerConstraint#TOP}. This is only meant for external port dummy nodes and only
* supports the cases that can occur with them.
*
* @param node the node whose layer constraint to mirror.
*/
private void transposeLayerConstraint(final LNode node) {
LayerConstraint layerConstraint = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
InLayerConstraint inLayerConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (layerConstraint == LayerConstraint.FIRST_SEPARATE) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.NONE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.TOP);
} else if (layerConstraint == LayerConstraint.LAST_SEPARATE) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.NONE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.BOTTOM);
} else if (inLayerConstraint == InLayerConstraint.TOP) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.FIRST_SEPARATE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.NONE);
} else if (inLayerConstraint == InLayerConstraint.BOTTOM) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.LAST_SEPARATE);
node.setProperty(InternalProperties.IN_LAYER_CONSTRAINT, InLayerConstraint.NONE);
}
}
use of org.eclipse.elk.alg.layered.options.InLayerConstraint in project elk by eclipse.
the class InLayerConstraintProcessor method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
monitor.begin("Layer constraint edge reversal", 1);
// Iterate through each layer
for (Layer layer : layeredGraph) {
/* We'll go through the layer's nodes, remembering two things:
* 1. Once we reach the first non-top-constrained node, we remember its
* index. Top-constrained nodes encountered afterwards must be inserted
* at that point.
* 2. A list of bottom-constrained nodes we have encountered. They will
* afterwards be moved to the end of the list, keeping the order in
* which we've encountered them.
*/
int topInsertionIndex = -1;
List<LNode> bottomConstrainedNodes = Lists.newArrayList();
// Iterate through an array of its nodes
LNode[] nodes = LGraphUtil.toNodeArray(layer.getNodes());
for (int i = 0; i < nodes.length; i++) {
InLayerConstraint constraint = nodes[i].getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (topInsertionIndex == -1) {
// See if this node is the first non-top-constrained node
if (constraint != InLayerConstraint.TOP) {
topInsertionIndex = i;
}
} else {
// We have already encountered non-top-constrained nodes before
if (constraint == InLayerConstraint.TOP) {
// Move the node to the top insertion point
nodes[i].setLayer(null);
nodes[i].setLayer(topInsertionIndex++, layer);
}
}
// Put BOTTOM-constrained nodes into the corresponding list
if (constraint == InLayerConstraint.BOTTOM) {
bottomConstrainedNodes.add(nodes[i]);
}
}
// Append the bottom-constrained nodes
for (LNode node : bottomConstrainedNodes) {
node.setLayer(null);
node.setLayer(layer);
}
}
monitor.done();
}
use of org.eclipse.elk.alg.layered.options.InLayerConstraint in project elk by eclipse.
the class InteractiveExternalPortPositioner method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
// if the graph does not contain any external ports ...
if (!layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
// ... nothing we can do about it
return;
}
// find the minimum and maximum x coordinates of the graph
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() == NodeType.NORMAL) {
ElkMargin margins = node.getProperty(LayeredOptions.MARGINS);
minX = Math.min(minX, node.getPosition().x - margins.left);
maxX = Math.max(maxX, node.getPosition().x + node.getSize().x + margins.right);
minY = Math.min(minY, node.getPosition().y - margins.top);
maxY = Math.max(maxY, node.getPosition().y + node.getSize().y + margins.bottom);
}
}
// assign reasonable coordinates to external port dummies
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() != NodeType.NORMAL) {
switch(node.getType()) {
// SUPPRESS CHECKSTYLE NEXT 50 InnerAssignment
case EXTERNAL_PORT:
LayerConstraint lc = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (lc == LayerConstraint.FIRST_SEPARATE) {
// it's a WEST port
node.getPosition().x = minX - ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getTarget().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
if (lc == LayerConstraint.LAST_SEPARATE) {
// it's a EAST port
node.getPosition().x = maxX + ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getSource().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
InLayerConstraint ilc = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (ilc == InLayerConstraint.TOP) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = minY - ARBITRARY_SPACING;
break;
}
if (ilc == InLayerConstraint.BOTTOM) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = maxY + ARBITRARY_SPACING;
break;
}
break;
default:
throw new IllegalArgumentException("The node type " + node.getType() + " is not supported by the " + this.getClass());
}
}
}
}
Aggregations