use of org.eclipse.elk.core.IGraphLayoutEngine in project sirius-components by eclipse-sirius.
the class LayoutService method layout.
@Override
public Diagram layout(IEditingContext editingContext, Diagram diagram) {
ELKConvertedDiagram convertedDiagram = this.elkDiagramConverter.convert(diagram);
ElkNode elkDiagram = convertedDiagram.getElkDiagram();
// @formatter:off
var optionalDiagramDescription = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast);
// @formatter:on
ISiriusWebLayoutConfigurator layoutConfigurator;
if (optionalDiagramDescription.isPresent()) {
var diagramDescription = optionalDiagramDescription.get();
elkDiagram = this.layoutConfiguratorRegistry.applyBeforeLayout(elkDiagram, editingContext, diagram, diagramDescription);
layoutConfigurator = this.layoutConfiguratorRegistry.getLayoutConfigurator(diagram, diagramDescription);
} else {
layoutConfigurator = this.layoutConfiguratorRegistry.getDefaultLayoutConfigurator();
}
ElkUtil.applyVisitors(elkDiagram, layoutConfigurator);
IGraphLayoutEngine engine = new RecursiveGraphLayoutEngine();
engine.layout(elkDiagram, new BasicProgressMonitor());
if (optionalDiagramDescription.isPresent()) {
var diagramDescription = optionalDiagramDescription.get();
elkDiagram = this.layoutConfiguratorRegistry.applyAfterLayout(elkDiagram, editingContext, diagram, diagramDescription);
}
Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
Diagram layoutedDiagram = this.elkLayoutedDiagramProvider.getLayoutedDiagram(diagram, elkDiagram, id2ElkGraphElements);
if (this.logger.isDebugEnabled()) {
// @formatter:off
String json = ElkGraphJson.forGraph(elkDiagram).omitLayout(true).omitZeroDimension(true).omitZeroPositions(true).shortLayoutOptionKeys(false).prettyPrint(true).toJson();
// @formatter:on
this.logger.debug(json);
}
return layoutedDiagram;
}
use of org.eclipse.elk.core.IGraphLayoutEngine in project elk by eclipse.
the class LoadGraphAction method layout.
/**
* Perform layout, if requested, and return an {@link ExecutionInfo} that contains information about the layout run.
* That object is not added to the {@link ExecutionInfoModel} by this method.
*/
static ExecutionInfo layout(final String fileName, final boolean performLayout, final ElkNode graph) {
IPreferenceStore prefStore = ElkServicePlugin.getInstance().getPreferenceStore();
IElkProgressMonitor monitor = new BasicProgressMonitor().withMaxHierarchyLevels(0).withLogging(prefStore.getBoolean(DiagramLayoutEngine.PREF_DEBUG_LOGGING)).withLogPersistence(prefStore.getBoolean(DiagramLayoutEngine.PREF_DEBUG_STORE)).withExecutionTimeMeasurement(prefStore.getBoolean(DiagramLayoutEngine.PREF_DEBUG_EXEC_TIME));
monitor.begin(fileName, 1);
// Perform layout using a graph layout engine, if enabled
if (performLayout) {
IGraphLayoutEngine layoutEngine = new RecursiveGraphLayoutEngine();
layoutEngine.layout(graph, monitor.subTask(1));
}
monitor.done();
// We're not going through the DiagramLayoutEngine, but directly through the RecursiveGraphLayoutEngine, which
// means that not layout events will be fired. We'll have to update our model manually.
monitor.logGraph(graph, "Result");
return ExecutionInfo.fromProgressMonitorAndFile(monitor, fileName, performLayout);
}
Aggregations