Search in sources :

Example 1 with Graph

use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.

the class DotExporter method transform.

/**
 * Transforms the KGraph instance to a Dot instance using the given command.
 *
 * @param transData the transformation data instance
 */
public void transform(final IDotTransformationData<ElkNode, GraphvizModel> transData) {
    BiMap<String, ElkGraphElement> graphElems = HashBiMap.create();
    transData.setProperty(GRAPH_ELEMS, graphElems);
    ElkNode elkgraph = transData.getSourceGraph();
    GraphvizModel graphvizModel = DotFactory.eINSTANCE.createGraphvizModel();
    Graph graph = DotFactory.eINSTANCE.createGraph();
    graph.setType(GraphType.DIGRAPH);
    graphvizModel.getGraphs().add(graph);
    transformNodes(elkgraph, graph.getStatements(), new KVector(), transData);
    transformEdges(elkgraph, graph.getStatements(), transData);
    transData.getTargetGraphs().add(graphvizModel);
}
Also used : GraphvizModel(org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel) Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) ElkNode(org.eclipse.elk.graph.ElkNode) KVector(org.eclipse.elk.core.math.KVector) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement)

Example 2 with Graph

use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.

the class DotExporter method transferLayout.

/**
 * Applies the layout information attached to the given Dot instance to the KGraph instance
 * using the mapping created by a previous call to {@code transform}. Has to be called after a
 * call to {@code transform}.
 *
 * @param transData the transformation data instance
 */
public void transferLayout(final IDotTransformationData<ElkNode, GraphvizModel> transData) {
    ElkPadding padding = transData.getSourceGraph().getProperty(CoreOptions.PADDING);
    Graph graph = transData.getTargetGraphs().get(0).getGraphs().get(0);
    // process nodes and subgraphs
    KVector baseOffset = new KVector();
    applyLayout(transData.getSourceGraph(), graph.getStatements(), baseOffset, padding, transData);
    // finally process the edges
    LinkedList<Statement> statements = new LinkedList<Statement>(graph.getStatements());
    KVector edgeOffset = baseOffset.add(padding.getLeft(), padding.getTop());
    while (!statements.isEmpty()) {
        Statement statement = statements.removeFirst();
        if (statement instanceof EdgeStatement) {
            applyEdgeLayout((EdgeStatement) statement, edgeOffset, transData);
        } else if (statement instanceof Subgraph) {
            statements.addAll(((Subgraph) statement).getStatements());
        }
    }
}
Also used : Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) 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) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) LinkedList(java.util.LinkedList) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)

Example 3 with Graph

use of org.eclipse.elk.alg.graphviz.dot.dot.Graph 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 4 with Graph

use of org.eclipse.elk.alg.graphviz.dot.dot.Graph in project elk by eclipse.

the class AbstractGraphvizDotSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == DotPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case DotPackage.ATTRIBUTE:
                if (rule == grammarAccess.getStatementRule() || rule == grammarAccess.getAttributeRule()) {
                    sequence_Attribute(context, (Attribute) semanticObject);
                    return;
                } else if (rule == grammarAccess.getListAttributeRule()) {
                    sequence_ListAttribute(context, (Attribute) semanticObject);
                    return;
                } else
                    break;
            case DotPackage.ATTRIBUTE_STATEMENT:
                sequence_AttributeStatement(context, (AttributeStatement) semanticObject);
                return;
            case DotPackage.EDGE_STATEMENT:
                sequence_EdgeStatement(context, (EdgeStatement) semanticObject);
                return;
            case DotPackage.EDGE_TARGET:
                sequence_EdgeTarget(context, (EdgeTarget) semanticObject);
                return;
            case DotPackage.GRAPH:
                sequence_Graph(context, (Graph) semanticObject);
                return;
            case DotPackage.GRAPHVIZ_MODEL:
                sequence_GraphvizModel(context, (GraphvizModel) semanticObject);
                return;
            case DotPackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
            case DotPackage.NODE_STATEMENT:
                sequence_NodeStatement(context, (NodeStatement) semanticObject);
                return;
            case DotPackage.PORT:
                sequence_Port(context, (Port) semanticObject);
                return;
            case DotPackage.SUBGRAPH:
                sequence_Subgraph(context, (Subgraph) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Attribute(org.eclipse.elk.alg.graphviz.dot.dot.Attribute) NodeStatement(org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement) Node(org.eclipse.elk.alg.graphviz.dot.dot.Node) Port(org.eclipse.elk.alg.graphviz.dot.dot.Port) EdgeStatement(org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement) EPackage(org.eclipse.emf.ecore.EPackage) GraphvizModel(org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel) Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) AttributeStatement(org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement) EdgeTarget(org.eclipse.elk.alg.graphviz.dot.dot.EdgeTarget) Subgraph(org.eclipse.elk.alg.graphviz.dot.dot.Subgraph) Parameter(org.eclipse.xtext.Parameter)

Aggregations

Graph (org.eclipse.elk.alg.graphviz.dot.dot.Graph)4 AttributeStatement (org.eclipse.elk.alg.graphviz.dot.dot.AttributeStatement)2 EdgeStatement (org.eclipse.elk.alg.graphviz.dot.dot.EdgeStatement)2 GraphvizModel (org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel)2 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)2 Subgraph (org.eclipse.elk.alg.graphviz.dot.dot.Subgraph)2 KVector (org.eclipse.elk.core.math.KVector)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 LinkedList (java.util.LinkedList)1 Attribute (org.eclipse.elk.alg.graphviz.dot.dot.Attribute)1 EdgeTarget (org.eclipse.elk.alg.graphviz.dot.dot.EdgeTarget)1 Node (org.eclipse.elk.alg.graphviz.dot.dot.Node)1 Port (org.eclipse.elk.alg.graphviz.dot.dot.Port)1 Statement (org.eclipse.elk.alg.graphviz.dot.dot.Statement)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 Pair (org.eclipse.elk.core.util.Pair)1 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)1 ElkPort (org.eclipse.elk.graph.ElkPort)1 MapPropertyHolder (org.eclipse.elk.graph.properties.MapPropertyHolder)1 EPackage (org.eclipse.emf.ecore.EPackage)1