Search in sources :

Example 1 with InLayerConstraint

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;
        }
    }
}
Also used : InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 2 with InLayerConstraint

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);
    }
}
Also used : InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint)

Example 3 with InLayerConstraint

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();
}
Also used : InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint)

Example 4 with InLayerConstraint

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());
            }
        }
    }
}
Also used : ElkMargin(org.eclipse.elk.core.math.ElkMargin) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Function(com.google.common.base.Function) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Optional(com.google.common.base.Optional) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkMargin(org.eclipse.elk.core.math.ElkMargin) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint)

Aggregations

InLayerConstraint (org.eclipse.elk.alg.layered.options.InLayerConstraint)4 LNode (org.eclipse.elk.alg.layered.graph.LNode)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)2 Layer (org.eclipse.elk.alg.layered.graph.Layer)2 LayerConstraint (org.eclipse.elk.alg.layered.options.LayerConstraint)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)1 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)1 ElkMargin (org.eclipse.elk.core.math.ElkMargin)1 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)1