Search in sources :

Example 1 with DotTransformationData

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

the class GraphvizLayoutProvider method layout.

@Override
public void layout(final ElkNode parentNode, final IElkProgressMonitor progressMonitor) {
    if (command == Command.INVALID) {
        throw new IllegalStateException("The Graphviz layout provider is not initialized.");
    }
    progressMonitor.begin("Graphviz layout (" + command + ")", 2);
    if (parentNode.getChildren().isEmpty()) {
        // return if there is nothing in this node
        progressMonitor.done();
        return;
    }
    boolean debugMode = parentNode.getProperty(CoreOptions.DEBUG_MODE);
    myCallNo = ++serialCallNo;
    // start the graphviz process, or retrieve the previously used process
    graphvizTool.initialize();
    // create an Xtext resource set for parsing and serialization
    XtextResourceSet resourceSet = (XtextResourceSet) dotResourceSetProvider.createResourceSet();
    // create the dot exporter we'll be using
    DotExporter dotExporter = new LayoutDotExporter();
    // translate the KGraph to Graphviz and write to the process
    IDotTransformationData<ElkNode, GraphvizModel> transData = new DotTransformationData<ElkNode, GraphvizModel>();
    transData.setSourceGraph(parentNode);
    transData.setProperty(DotExporter.COMMAND, command);
    dotExporter.transform(transData);
    GraphvizModel graphvizInput = transData.getTargetGraphs().get(0);
    writeDotGraph(graphvizInput, progressMonitor.subTask(1), debugMode, resourceSet);
    try {
        // read Graphviz output and apply layout information to the KGraph
        GraphvizModel graphvizOutput = readDotGraph(progressMonitor.subTask(1), debugMode, resourceSet);
        transData.getTargetGraphs().set(0, graphvizOutput);
        dotExporter.transferLayout(transData);
    } finally {
        boolean reuseProcess = GraphvizLayouterPreferenceStoreAccess.getUISaveBoolean(PREF_GRAPHVIZ_REUSE_PROCESS, REUSE_PROCESS_DEFAULT);
        graphvizTool.cleanup(reuseProcess ? Cleanup.NORMAL : Cleanup.STOP);
        progressMonitor.done();
    }
}
Also used : GraphvizModel(org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel) ElkNode(org.eclipse.elk.graph.ElkNode) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) DotTransformationData(org.eclipse.elk.alg.graphviz.dot.transform.DotTransformationData) IDotTransformationData(org.eclipse.elk.alg.graphviz.dot.transform.IDotTransformationData) DotExporter(org.eclipse.elk.alg.graphviz.dot.transform.DotExporter)

Aggregations

GraphvizModel (org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel)1 DotExporter (org.eclipse.elk.alg.graphviz.dot.transform.DotExporter)1 DotTransformationData (org.eclipse.elk.alg.graphviz.dot.transform.DotTransformationData)1 IDotTransformationData (org.eclipse.elk.alg.graphviz.dot.transform.IDotTransformationData)1 ElkNode (org.eclipse.elk.graph.ElkNode)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1