use of org.eclipse.elk.alg.graphviz.dot.transform.DotExporter 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();
}
}
Aggregations