Search in sources :

Example 1 with MapPropertyHolder

use of org.eclipse.elk.graph.properties.MapPropertyHolder in project sirius-components by eclipse-sirius.

the class SiriusWebLayoutConfigurator method overrideWith.

private SiriusWebLayoutConfigurator overrideWith(SiriusWebLayoutConfigurator layoutConfigurator) {
    super.overrideWith(layoutConfigurator);
    for (Map.Entry<String, MapPropertyHolder> entry : layoutConfigurator.idIndex.entrySet()) {
        MapPropertyHolder thisHolder = this.idIndex.get(entry.getKey());
        if (thisHolder == null) {
            thisHolder = new MapPropertyHolder();
            this.idIndex.put(entry.getKey(), thisHolder);
        }
        thisHolder.copyProperties(entry.getValue());
    }
    for (Map.Entry<String, MapPropertyHolder> entry : layoutConfigurator.typeIndex.entrySet()) {
        MapPropertyHolder thisHolder = this.typeIndex.get(entry.getKey());
        if (thisHolder == null) {
            thisHolder = new MapPropertyHolder();
            this.typeIndex.put(entry.getKey(), thisHolder);
        }
        thisHolder.copyProperties(entry.getValue());
    }
    return this;
}
Also used : MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MapPropertyHolder

use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.

the class LayoutConfigurator method configure.

/**
 * Add and return a property holder for the given element class. If such a property holder is
 * already present, the previous instance is returned.
 *
 * It is possible to configure options for every graph element by using {@code KGraphElement.class}
 * as argument. Such options are overridden if a more specific type is configured as well,
 * for instance {@code KNode.class}.
 */
public IPropertyHolder configure(final Class<? extends ElkGraphElement> elementClass) {
    MapPropertyHolder result = classOptionMap.get(elementClass);
    if (result == null) {
        result = new MapPropertyHolder();
        classOptionMap.put(elementClass, result);
    }
    return result;
}
Also used : MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder)

Example 3 with MapPropertyHolder

use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.

the class DotImporter method transform.

/*---------- Transformation Dot to KGraph ----------*/
/**
 * Transform a Dot graph to a KNode.
 *
 * @param statements
 *            a list of Dot statements
 * @param parent
 *            a KNode
 * @param transData
 *            transformation data instance
 * @param nodeProps
 *            properties that are applied to all nodes
 * @param edgeProps
 *            properties that are applied to all edges
 */
private void transform(final List<Statement> statements, final ElkNode parent, final IDotTransformationData<GraphvizModel, ElkNode> transData, final IPropertyHolder nodeProps, final IPropertyHolder edgeProps) {
    DotSwitch<Object> statementSwitch = new DotSwitch<Object>() {

        public Object caseNodeStatement(final NodeStatement statement) {
            transformNode(statement, parent, transData, nodeProps);
            return null;
        }

        public Object caseEdgeStatement(final EdgeStatement statement) {
            transformEdge(statement, parent, transData, edgeProps);
            return null;
        }

        public Object caseSubgraph(final Subgraph subgraph) {
            ElkNode subElkNode = parent;
            if (subgraph.getName() != null && subgraph.getName().startsWith("cluster")) {
                subElkNode = transformNode(subgraph.getName(), parent, transData);
                if (subElkNode.getProperty(PROP_STATEMENT) != null) {
                    transData.log("Discarding cluster subgraph \"" + subgraph.getName() + "\" since its id is already used.");
                    return null;
                } else {
                    // the subgraph inherits all settings of its parent
                    subElkNode.copyProperties(parent);
                    subElkNode.setProperty(PROP_STATEMENT, subgraph);
                }
            }
            MapPropertyHolder subNodeProps = new MapPropertyHolder();
            subNodeProps.copyProperties(nodeProps);
            MapPropertyHolder subEdgeProps = new MapPropertyHolder();
            subEdgeProps.copyProperties(edgeProps);
            transform(subgraph.getStatements(), subElkNode, transData, subNodeProps, subEdgeProps);
            return null;
        }

        public Object caseAttributeStatement(final AttributeStatement statement) {
            switch(statement.getType()) {
                case GRAPH:
                    for (Attribute attr : statement.getAttributes()) {
                        caseAttribute(attr);
                    }
                    break;
                case NODE:
                    for (Attribute attr : statement.getAttributes()) {
                        transformAttribute(nodeProps, attr, transData);
                    }
                    break;
                case EDGE:
                    for (Attribute attr : statement.getAttributes()) {
                        transformAttribute(edgeProps, attr, transData);
                    }
                    break;
            }
            return null;
        }

        public Object caseAttribute(final Attribute attribute) {
            if (Attributes.MARGIN.equals(attribute.getName())) {
                ElkPadding padding = parent.getProperty(CoreOptions.PADDING);
                if (attribute.getValue().indexOf(',') >= 0) {
                    KVector value = new KVector();
                    try {
                        value.parse(attribute.getValue());
                        padding.setLeft((float) value.x);
                        padding.setRight((float) value.x);
                        padding.setTop((float) value.y);
                        padding.setBottom((float) value.y);
                    } catch (IllegalArgumentException exception) {
                        transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
                    }
                } else {
                    try {
                        float value = Float.parseFloat(trimValue(attribute));
                        padding.setLeft(value);
                        padding.setRight(value);
                        padding.setTop(value);
                        padding.setBottom(value);
                    } catch (NumberFormatException exception) {
                        transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
                    }
                }
            } else {
                transformAttribute(parent, attribute, transData);
            }
            return null;
        }
    };
    for (Statement statement : statements) {
        statementSwitch.doSwitch(statement);
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) Statement(org.eclipse.elk.alg.graphviz.dot.dot.Statement) MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) DotSwitch(org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch)

Example 4 with MapPropertyHolder

use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.

the class DotImporter method transform.

/**
 * Transform the GraphViz model into a KGraph.
 *
 * @param transData
 *            the transformation data instance that holds the source graph and is enriched with
 *            the new target graphs
 */
public void transform(final IDotTransformationData<GraphvizModel, ElkNode> transData) {
    for (Graph graph : transData.getSourceGraph().getGraphs()) {
        ElkNode parent = ElkGraphUtil.createGraph();
        Map<String, ElkNode> nodeIdMap = Maps.newHashMap();
        transData.setProperty(NODE_ID_MAP, nodeIdMap);
        Map<Pair<ElkNode, String>, ElkPort> portIdMap = Maps.newHashMap();
        transData.setProperty(PORT_ID_MAP, portIdMap);
        transform(graph.getStatements(), parent, transData, new MapPropertyHolder(), new MapPropertyHolder());
        transData.getTargetGraphs().add(parent);
        parent.setProperty(PROP_GRAPH, graph);
    }
}
Also used : Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder) Pair(org.eclipse.elk.core.util.Pair)

Example 5 with MapPropertyHolder

use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.

the class CompoundGraphPreprocessor method createExternalPortProperties.

/**
 * Create suitable port properties for dummy external ports.
 *
 * @param graph
 *            the graph for which the dummy external port is created
 * @return properties to apply to the dummy port
 */
private static IPropertyHolder createExternalPortProperties(final LGraph graph) {
    IPropertyHolder propertyHolder = new MapPropertyHolder();
    // FIXME No idea why ...
    double offset = graph.getProperty(LayeredOptions.SPACING_EDGE_EDGE) / 2;
    propertyHolder.setProperty(LayeredOptions.PORT_BORDER_OFFSET, offset);
    return propertyHolder;
}
Also used : MapPropertyHolder(org.eclipse.elk.graph.properties.MapPropertyHolder) IPropertyHolder(org.eclipse.elk.graph.properties.IPropertyHolder)

Aggregations

MapPropertyHolder (org.eclipse.elk.graph.properties.MapPropertyHolder)8 Map (java.util.Map)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 HashMap (java.util.HashMap)1 Attribute (org.eclipse.elk.alg.graphviz.dot.dot.Attribute)1 AttributeStatement (org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)1 EdgeStatement (org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)1 Graph (org.eclipse.elk.alg.graphviz.dot.dot.Graph)1 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)1 Statement (org.eclipse.elk.alg.graphviz.dot.dot.Statement)1 Subgraph (org.eclipse.elk.alg.graphviz.dot.dot.Subgraph)1 DotSwitch (org.eclipse.elk.alg.graphviz.dot.dot.util.DotSwitch)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 KVector (org.eclipse.elk.core.math.KVector)1 Pair (org.eclipse.elk.core.util.Pair)1 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)1 ElkPort (org.eclipse.elk.graph.ElkPort)1 IPropertyHolder (org.eclipse.elk.graph.properties.IPropertyHolder)1