Search in sources :

Example 6 with LayerConstraint

use of org.eclipse.elk.alg.layered.options.LayerConstraint 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 7 with LayerConstraint

use of org.eclipse.elk.alg.layered.options.LayerConstraint 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)

Example 8 with LayerConstraint

use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.

the class EdgeAndLayerConstraintEdgeReverserTest method testLayerConstraints.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(EdgeAndLayerConstraintEdgeReverser.class)
public void testLayerConstraints(Object graph) {
    for (LNode node : ((LGraph) graph).getLayerlessNodes()) {
        LayerConstraint constr = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
        if (constr == LayerConstraint.FIRST) {
            // either no incoming edges or only from FIRST_SEPARATE nodes
            for (LEdge inc : node.getIncomingEdges()) {
                LNode src = inc.getSource().getNode();
                assertTrue(src.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT) == LayerConstraint.FIRST_SEPARATE);
            }
        } else if (constr == LayerConstraint.LAST) {
            // either no outgoing edges or only to LAST_SEPARATE nodes
            for (LEdge inc : node.getOutgoingEdges()) {
                LNode src = inc.getTarget().getNode();
                assertTrue(src.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT) == LayerConstraint.LAST_SEPARATE);
            }
        } else if (constr == LayerConstraint.FIRST_SEPARATE) {
            assertTrue(Iterables.isEmpty(node.getIncomingEdges()));
        } else if (constr == LayerConstraint.LAST_SEPARATE) {
            assertTrue(Iterables.isEmpty(node.getOutgoingEdges()));
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Example 9 with LayerConstraint

use of org.eclipse.elk.alg.layered.options.LayerConstraint in project elk by eclipse.

the class LayerConstraintProcessorTest method testLayerConstraints.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
/**
 * If the first layer contains {@link LayerConstraint#FIRST_SEPARATE} no other type is allowed there. All
 * {@link LayerConstraint#FIRST} constraints must be in the next layer. Similar for
 * {@link LayerConstraint#LAST_SEPARATE} and {@link LayerConstraint#LAST}.
 */
@TestAfterProcessor(LayerConstraintPostprocessor.class)
public void testLayerConstraints(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    Multimap<LayerConstraint, Integer> constraintMap = HashMultimap.create();
    int nextLayerId = 0;
    for (Layer layer : lGraph) {
        layer.id = nextLayerId++;
        for (LNode node : layer) {
            constraintMap.put(node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT), layer.id);
        }
    }
    // if FIRST_SEPARATE nodes are available
    if (constraintMap.containsKey(LayerConstraint.FIRST_SEPARATE)) {
        // FIRST_SEPARATE must only occur in the first layer
        Collection<Integer> firstSep = constraintMap.get(LayerConstraint.FIRST_SEPARATE);
        assertTrue(firstSep.size() == 1 && firstSep.contains(0));
        // first layer must not contain a NONE node
        assertTrue(!constraintMap.get(LayerConstraint.NONE).contains(0));
        // all FIRST nodes have to be at position 1
        Collection<Integer> first = constraintMap.get(LayerConstraint.FIRST);
        if (!first.isEmpty()) {
            assertTrue(first.size() == 1 && first.contains(1));
        }
    } else {
        // all FIRST nodes must be at position 0
        Collection<Integer> first = constraintMap.get(LayerConstraint.FIRST);
        if (!first.isEmpty()) {
            assertTrue(first.size() == 1 && first.contains(0));
        }
    }
    int lastLayer = lGraph.getLayers().size() - 1;
    // if LAST_SEPARATE nodes are available
    if (constraintMap.containsKey(LayerConstraint.LAST_SEPARATE)) {
        // LAST_SEPARATE must only occur in the last layer
        Collection<Integer> lastSep = constraintMap.get(LayerConstraint.LAST_SEPARATE);
        assertTrue(lastSep.size() == 1 && lastSep.contains(lastLayer));
        // last layer must not contain a NONE node
        assertTrue(!constraintMap.get(LayerConstraint.NONE).contains(lastLayer));
        // all LAST nodes have to be at position lastLayer - 1
        Collection<Integer> last = constraintMap.get(LayerConstraint.LAST);
        if (!last.isEmpty()) {
            assertTrue(last.size() == 1 && last.contains(lastLayer - 1));
        }
    } else {
        // all LAST nodes must be at position lastLayer
        Collection<Integer> last = constraintMap.get(LayerConstraint.LAST);
        if (!last.isEmpty()) {
            assertTrue(last.size() == 1 && last.contains(lastLayer));
        }
    }
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Aggregations

LayerConstraint (org.eclipse.elk.alg.layered.options.LayerConstraint)9 LNode (org.eclipse.elk.alg.layered.graph.LNode)7 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)3 LPort (org.eclipse.elk.alg.layered.graph.LPort)2 EdgeConstraint (org.eclipse.elk.alg.layered.options.EdgeConstraint)2 InLayerConstraint (org.eclipse.elk.alg.layered.options.InLayerConstraint)2 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 ArrayList (java.util.ArrayList)1 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)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 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)1 ElkMargin (org.eclipse.elk.core.math.ElkMargin)1 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)1 ElkNode (org.eclipse.elk.graph.ElkNode)1