Search in sources :

Example 1 with IGraphLayoutEngine

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;
}
Also used : IGraphLayoutEngine(org.eclipse.elk.core.IGraphLayoutEngine) ElkNode(org.eclipse.elk.graph.ElkNode) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) IncrementalLayoutConvertedDiagram(org.eclipse.sirius.components.diagrams.layout.incremental.IncrementalLayoutConvertedDiagram) Diagram(org.eclipse.sirius.components.diagrams.Diagram)

Example 2 with IGraphLayoutEngine

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);
}
Also used : IGraphLayoutEngine(org.eclipse.elk.core.IGraphLayoutEngine) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine)

Aggregations

IGraphLayoutEngine (org.eclipse.elk.core.IGraphLayoutEngine)2 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)2 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)2 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)1 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)1 ElkNode (org.eclipse.elk.graph.ElkNode)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Diagram (org.eclipse.sirius.components.diagrams.Diagram)1 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)1 IncrementalLayoutConvertedDiagram (org.eclipse.sirius.components.diagrams.layout.incremental.IncrementalLayoutConvertedDiagram)1