Search in sources :

Example 6 with GraphProperties

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

the class ElkGraphLayoutTransferrer method applyParentNodeLayout.

/**
 * Applies layout information computed for the given graph.
 *
 * @param lgraph
 *            the edge that has the layout information.
 */
private void applyParentNodeLayout(final LGraph lgraph) {
    ElkNode elknode = (ElkNode) lgraph.getProperty(InternalProperties.ORIGIN);
    boolean sizeConstraintsIncludedPortLabels = elknode.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.PORT_LABELS);
    if (lgraph.getParentNode() == null) {
        Set<GraphProperties> graphProps = lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
        KVector actualGraphSize = lgraph.getActualSize();
        if (graphProps.contains(GraphProperties.EXTERNAL_PORTS)) {
            // Ports have positions assigned, the graph's size is final
            elknode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
            ElkUtil.resizeNode(elknode, actualGraphSize.x, actualGraphSize.y, false, true);
        } else {
            // Ports have not been positioned yet - leave this for next layouter
            ElkUtil.resizeNode(elknode, actualGraphSize.x, actualGraphSize.y, true, true);
        }
    }
    // consideration for their labels.
    if (sizeConstraintsIncludedPortLabels) {
        elknode.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.PORT_LABELS));
    } else {
        elknode.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) KVector(org.eclipse.elk.core.math.KVector)

Example 7 with GraphProperties

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

the class ElkGraphImporter method transformNode.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Transformation
/**
 * Transforms the given node and its contained ports.
 *
 * @param elknode
 *            the node to transform
 * @param lgraph
 *            the layered graph into which the transformed node is put
 * @return the transformed node
 */
private LNode transformNode(final ElkNode elknode, final LGraph lgraph) {
    // add a new node to the layered graph, copying its position
    LNode lnode = new LNode(lgraph);
    lnode.copyProperties(elknode);
    lnode.setProperty(InternalProperties.ORIGIN, elknode);
    lnode.getSize().x = elknode.getWidth();
    lnode.getSize().y = elknode.getHeight();
    lnode.getPosition().x = elknode.getX();
    lnode.getPosition().y = elknode.getY();
    lgraph.getLayerlessNodes().add(lnode);
    nodeAndPortMap.put(elknode, lnode);
    // check if the node is a compound node in the original graph
    if (!elknode.getChildren().isEmpty() || elknode.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_ACTIVATE)) {
        lnode.setProperty(InternalProperties.COMPOUND_NODE, true);
    }
    Set<GraphProperties> graphProperties = lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
    // port constraints and sides cannot be undefined
    PortConstraints portConstraints = lnode.getProperty(LayeredOptions.PORT_CONSTRAINTS);
    if (portConstraints == PortConstraints.UNDEFINED) {
        lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
    } else if (portConstraints != PortConstraints.FREE) {
        // if the port constraints are not free, set the appropriate graph property
        graphProperties.add(GraphProperties.NON_FREE_PORTS);
    }
    // transform the ports
    Direction direction = lgraph.getProperty(LayeredOptions.DIRECTION);
    for (ElkPort elkport : elknode.getPorts()) {
        if (!elkport.getProperty(LayeredOptions.NO_LAYOUT)) {
            transformPort(elkport, lnode, graphProperties, direction, portConstraints);
        }
    }
    // add the node's labels
    for (ElkLabel elklabel : elknode.getLabels()) {
        if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
            lnode.getLabels().add(transformLabel(elklabel));
        }
    }
    if (lnode.getProperty(LayeredOptions.COMMENT_BOX)) {
        graphProperties.add(GraphProperties.COMMENTS);
    }
    // if we have a hypernode without ports, create a default input and output port
    if (lnode.getProperty(LayeredOptions.HYPERNODE)) {
        graphProperties.add(GraphProperties.HYPERNODES);
        graphProperties.add(GraphProperties.HYPEREDGES);
        lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
    }
    return lnode;
}
Also used : GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Direction(org.eclipse.elk.core.options.Direction)

Example 8 with GraphProperties

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

the class LGraphUtil method computeGraphProperties.

// /////////////////////////////////////////////////////////////////////////////
// Graph Properties
/**
 * Compute the graph properties of the given layered graph. These properties are important
 * to determine which intermediate processors are included in the layout run.
 * Ideally the properties are computed during the import of the source format into {@link LGraph},
 * e.g. as done in {@code KGraphImporter}. This method is offered only for convenience.
 * <p>
 * The nodes are expected to be in the {@link LGraph#getLayerlessNodes()} list.
 * </p>
 *
 * @param layeredGraph a layered graph
 */
public static void computeGraphProperties(final LGraph layeredGraph) {
    Set<GraphProperties> props = layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
    if (!props.isEmpty()) {
        props.clear();
    }
    Direction direction = getDirection(layeredGraph);
    for (LNode node : layeredGraph.getLayerlessNodes()) {
        if (node.getProperty(LayeredOptions.COMMENT_BOX)) {
            props.add(GraphProperties.COMMENTS);
        } else if (node.getProperty(LayeredOptions.HYPERNODE)) {
            props.add(GraphProperties.HYPERNODES);
            props.add(GraphProperties.HYPEREDGES);
        } else if (node.getType() == NodeType.EXTERNAL_PORT) {
            props.add(GraphProperties.EXTERNAL_PORTS);
        }
        PortConstraints portConstraints = node.getProperty(LayeredOptions.PORT_CONSTRAINTS);
        if (portConstraints == PortConstraints.UNDEFINED) {
            // correct the port constraints value
            node.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
        } else if (portConstraints != PortConstraints.FREE) {
            props.add(GraphProperties.NON_FREE_PORTS);
        }
        for (LPort port : node.getPorts()) {
            if (port.getIncomingEdges().size() + port.getOutgoingEdges().size() > 1) {
                props.add(GraphProperties.HYPEREDGES);
            }
            PortSide portSide = port.getSide();
            switch(direction) {
                case UP:
                case DOWN:
                    if (portSide == PortSide.EAST || portSide == PortSide.WEST) {
                        props.add(GraphProperties.NORTH_SOUTH_PORTS);
                    }
                    break;
                default:
                    if (portSide == PortSide.NORTH || portSide == PortSide.SOUTH) {
                        props.add(GraphProperties.NORTH_SOUTH_PORTS);
                    }
            }
            for (LEdge edge : port.getOutgoingEdges()) {
                if (edge.getTarget().getNode() == node) {
                    props.add(GraphProperties.SELF_LOOPS);
                }
                for (LLabel label : edge.getLabels()) {
                    switch(label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT)) {
                        case CENTER:
                            props.add(GraphProperties.CENTER_LABELS);
                            break;
                        case HEAD:
                        case TAIL:
                            props.add(GraphProperties.END_LABELS);
                            break;
                    }
                }
            }
        }
    }
}
Also used : GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) PortSide(org.eclipse.elk.core.options.PortSide) Direction(org.eclipse.elk.core.options.Direction) PortConstraints(org.eclipse.elk.core.options.PortConstraints)

Example 9 with GraphProperties

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

the class TestGraphCreator method addExternalPortDummyNodeToLayer.

protected LNode addExternalPortDummyNodeToLayer(final Layer layer, final LPort port) {
    LNode node = addNodeToLayer(layer);
    node.setProperty(InternalProperties.ORIGIN, port);
    node.setType(NodeType.EXTERNAL_PORT);
    node.setProperty(InternalProperties.EXT_PORT_SIDE, port.getSide());
    port.setProperty(InternalProperties.PORT_DUMMY, node);
    port.setProperty(InternalProperties.INSIDE_CONNECTIONS, true);
    Set<GraphProperties> ps = node.getGraph().getProperty(InternalProperties.GRAPH_PROPERTIES);
    ps.add(GraphProperties.EXTERNAL_PORTS);
    return node;
}
Also used : GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Aggregations

GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)9 LNode (org.eclipse.elk.alg.layered.graph.LNode)4 KVector (org.eclipse.elk.core.math.KVector)4 Direction (org.eclipse.elk.core.options.Direction)4 ElkPort (org.eclipse.elk.graph.ElkPort)4 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)3 PortSide (org.eclipse.elk.core.options.PortSide)3 ElkLabel (org.eclipse.elk.graph.ElkLabel)3 ElkNode (org.eclipse.elk.graph.ElkNode)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)2 LGraphElement (org.eclipse.elk.alg.layered.graph.LGraphElement)2 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)2 LPort (org.eclipse.elk.alg.layered.graph.LPort)2 CrossingMinimizationStrategy (org.eclipse.elk.alg.layered.options.CrossingMinimizationStrategy)2 NodePlacementStrategy (org.eclipse.elk.alg.layered.options.NodePlacementStrategy)2 PortType (org.eclipse.elk.alg.layered.options.PortType)2 UnsupportedGraphException (org.eclipse.elk.core.UnsupportedGraphException)2 KVectorChain (org.eclipse.elk.core.math.KVectorChain)2 HierarchyHandling (org.eclipse.elk.core.options.HierarchyHandling)2 PortConstraints (org.eclipse.elk.core.options.PortConstraints)2