use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class InteractiveLayeredGraphVisitor method setInteractiveOptionsAndPseudoPositions.
/**
* Sets pseudo positions and interactive strategies for the given graph.
*
* @param root
* Root of the graph
*/
private void setInteractiveOptionsAndPseudoPositions(final ElkNode root) {
if (!root.getChildren().isEmpty()) {
String algorithm = root.getProperty(CoreOptions.ALGORITHM);
if (algorithm == null || LayeredOptions.ALGORITHM_ID.endsWith(algorithm)) {
// LayerChoiceConstraints
for (ElkNode node : root.getChildren()) {
if (node.hasProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT)) {
LayerConstraint constraint = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
node.setProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT, LayerConstraint.NONE);
switch(constraint) {
case FIRST:
if (node.getProperty(LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT) == -1) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT, 0);
}
break;
case LAST:
if (node.getProperty(LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT) == -1) {
node.setProperty(LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT, LAST_LAYER_INDEX);
}
break;
}
}
setCoordinates(root);
setInteractiveStrategies(root);
}
}
}
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class EdgeAndLayerConstraintEdgeReverser method canReverseIncomingEdge.
/**
* Checks whether or not a given edge incoming edge can actually be reversed. It cannot be reversed if it already
* has been, or if it connects a node in the {@code FIRST} layer to either a node in the {@code FIRST_SEPARATE}
* layer or to a label dummy node.
*
* @param targetNodeLayerConstraint
* the target node's layer constraint.
* @param edge
* the edge to possibly be reversed.
* @return {@code true} if it's okay to reverse the edge.
*/
private boolean canReverseIncomingEdge(final LayerConstraint targetNodeLayerConstraint, final LEdge edge) {
// The layer constraint that gets passed to us
assert targetNodeLayerConstraint == edge.getTarget().getNode().getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
// If the edge is already reversed, we don't want to reverse it again
if (edge.getProperty(InternalProperties.REVERSED)) {
return false;
}
LNode sourceNode = edge.getSource().getNode();
// If the node is supposed to be in the FIRST layer...
if (targetNodeLayerConstraint == LayerConstraint.FIRST) {
// FIRST_SEPARATE and the FIRST layer
if (sourceNode.getType() == NodeType.LABEL) {
return false;
}
}
// If the source is a node in the FIRST_SEPARATE layer, we won't reverse it
LayerConstraint sourceLayerConstraint = sourceNode.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (sourceLayerConstraint == LayerConstraint.FIRST_SEPARATE) {
return false;
}
return true;
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class EdgeAndLayerConstraintEdgeReverser method canReverseOutgoingEdge.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Reversal Testing
/**
* Checks whether or not a given edge outgoing edge can actually be reversed. It cannot be reversed if it already
* has been, or if it connects a node in the {@code LAST} layer to either a node in the {@code LAST_SEPARATE} layer
* or to a label dummy node.
*
* @param sourceNodeLayerConstraint
* the source node's layer constraint.
* @param edge
* the edge to possibly be reversed.
* @return {@code true} if it's okay to reverse the edge.
*/
private boolean canReverseOutgoingEdge(final LayerConstraint sourceNodeLayerConstraint, final LEdge edge) {
// The layer constraint that gets passed to us
assert sourceNodeLayerConstraint == edge.getSource().getNode().getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
// If the edge is already reversed, we don't want to reverse it again
if (edge.getProperty(InternalProperties.REVERSED)) {
return false;
}
LNode targetNode = edge.getTarget().getNode();
// If the node is supposed to be in the lAST layer...
if (sourceNodeLayerConstraint == LayerConstraint.LAST) {
// LAST and the LAST_SEPARATE layer
if (targetNode.getType() == NodeType.LABEL) {
return false;
}
}
// If the target is a node in the LAST_SEPARATE layer, we won't reverse it
LayerConstraint targetLayerConstraint = targetNode.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (targetLayerConstraint == LayerConstraint.LAST_SEPARATE) {
return false;
}
return true;
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class EdgeAndLayerConstraintEdgeReverser method handleOuterNodes.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Outer Nodes
/**
* Ensures that edges incident to outer nodes are correct.
*
* @return list of those nodes that are not outer nodes.
*/
private List<LNode> handleOuterNodes(final LGraph layeredGraph) {
List<LNode> remainingNodes = new ArrayList<>(layeredGraph.getLayerlessNodes().size());
for (LNode node : layeredGraph.getLayerlessNodes()) {
// Check if there is a layer constraint
LayerConstraint layerConstraint = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
EdgeConstraint edgeConstraint = null;
switch(layerConstraint) {
case FIRST:
case FIRST_SEPARATE:
edgeConstraint = EdgeConstraint.OUTGOING_ONLY;
break;
case LAST:
case LAST_SEPARATE:
edgeConstraint = EdgeConstraint.INCOMING_ONLY;
break;
}
if (edgeConstraint != null) {
// Set the edge constraint on the node
node.setProperty(InternalProperties.EDGE_CONSTRAINT, EdgeConstraint.OUTGOING_ONLY);
if (edgeConstraint == EdgeConstraint.INCOMING_ONLY) {
reverseEdges(layeredGraph, node, layerConstraint, PortType.INPUT);
} else if (edgeConstraint == EdgeConstraint.OUTGOING_ONLY) {
reverseEdges(layeredGraph, node, layerConstraint, PortType.OUTPUT);
}
} else {
// Remember this node for the next loop
remainingNodes.add(node);
}
}
return remainingNodes;
}
use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.
the class EdgeAndLayerConstraintEdgeReverser method handleInnerNodes.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Inner Nodes
/**
* @param remainingNodes
*/
private void handleInnerNodes(final LGraph layeredGraph, final List<LNode> remainingNodes) {
// Iterate over the remaining nodes
for (LNode node : remainingNodes) {
// Check if there is a layer constraint
LayerConstraint layerConstraint = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
EdgeConstraint edgeConstraint = null;
switch(layerConstraint) {
case FIRST:
case FIRST_SEPARATE:
edgeConstraint = EdgeConstraint.OUTGOING_ONLY;
break;
case LAST:
case LAST_SEPARATE:
edgeConstraint = EdgeConstraint.INCOMING_ONLY;
break;
}
if (edgeConstraint != null) {
// Set the edge constraint on the node
node.setProperty(InternalProperties.EDGE_CONSTRAINT, EdgeConstraint.OUTGOING_ONLY);
if (edgeConstraint == EdgeConstraint.INCOMING_ONLY) {
reverseEdges(layeredGraph, node, layerConstraint, PortType.INPUT);
} else if (edgeConstraint == EdgeConstraint.OUTGOING_ONLY) {
reverseEdges(layeredGraph, node, layerConstraint, PortType.OUTPUT);
}
} else {
// port dummy with FIRST_SEPARATE and an inverted ports on the target node's EAST side.
if (node.getProperty(LayeredOptions.PORT_CONSTRAINTS).isSideFixed() && !node.getPorts().isEmpty()) {
boolean allPortsReversed = true;
for (LPort port : node.getPorts()) {
// reversed.
if (!(port.getSide() == PortSide.EAST && port.getNetFlow() > 0 || port.getSide() == PortSide.WEST && port.getNetFlow() < 0)) {
allPortsReversed = false;
break;
}
// no LAST or LAST_SEPARATE allowed for the target of outgoing edges
for (LEdge e : port.getOutgoingEdges()) {
LayerConstraint lc = e.getTarget().getNode().getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (lc == LayerConstraint.LAST || lc == LayerConstraint.LAST_SEPARATE) {
allPortsReversed = false;
break;
}
}
// no FIRST or FIRST_SEPARATE allowed for the source of incoming edgs
for (LEdge e : port.getIncomingEdges()) {
LayerConstraint lc = e.getSource().getNode().getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (lc == LayerConstraint.FIRST || lc == LayerConstraint.FIRST_SEPARATE) {
allPortsReversed = false;
break;
}
}
}
if (allPortsReversed) {
// Reverse all kinds of edges
reverseEdges(layeredGraph, node, layerConstraint, PortType.UNDEFINED);
}
}
}
}
}
Aggregations