Search in sources :

Example 1 with LayoutConfigurator

use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.

the class LayoutConfigurationManager method createConfigurator.

/**
 * Create a layout configurator and initialize it with the option values from the given layout
 * configuration store provider.
 */
public <T> LayoutConfigurator createConfigurator(final LayoutMapping layoutMapping) {
    LayoutConfigurator result = new LayoutConfigurator();
    if (configProvider != null) {
        configureElement(layoutMapping.getLayoutGraph(), layoutMapping, result);
        Iterator<ElkGraphElement> allElements = Iterators.filter(layoutMapping.getLayoutGraph().eAllContents(), ElkGraphElement.class);
        while (allElements.hasNext()) {
            ElkGraphElement element = allElements.next();
            configureElement(element, layoutMapping, result);
        }
    }
    return result;
}
Also used : ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator)

Example 2 with LayoutConfigurator

use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.

the class BasicConsiderModelOrderTest method preferEdgesConfigurator.

@ConfiguratorProvider
public LayoutConfigurator preferEdgesConfigurator() {
    LayoutConfigurator config = new LayoutConfigurator();
    config.configure(ElkNode.class).setProperty(LayeredOptions.CROSSING_MINIMIZATION_STRATEGY, CrossingMinimizationStrategy.LAYER_SWEEP);
    config.configure(ElkNode.class).setProperty(LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.PREFER_EDGES);
    return config;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) ConfiguratorProvider(org.eclipse.elk.alg.test.framework.annotations.ConfiguratorProvider)

Example 3 with LayoutConfigurator

use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.

the class InvertedPortProcessorTest method configurator.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Configuration
@ConfiguratorProvider
public LayoutConfigurator configurator() {
    LayoutConfigurator config = new LayoutConfigurator();
    config.configure(ElkNode.class).setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    return config;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) ConfiguratorProvider(org.eclipse.elk.alg.test.framework.annotations.ConfiguratorProvider)

Example 4 with LayoutConfigurator

use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.

the class DiagramLayoutEngine method layout.

/**
 * Perform layout on the given layout graph mapping. If zero or one layout configurator is
 * passed, the layout engine is executed exactly once. If multiple layout configurators are
 * passed, the layout engine is executed accordingly often, but the resulting layout is applied
 * only once. This is useful for composition of multiple algorithms that process only parts of
 * the graph. Layout listeners are notified before and after the layout has been computed.
 *
 * @param mapping
 *            a mapping for the layout graph
 * @param progressMonitor
 *            a progress monitor to which progress of the layout algorithm is reported
 * @param params
 *            layout parameters
 * @return a status indicating success or failure
 */
public IStatus layout(final LayoutMapping mapping, final IElkProgressMonitor progressMonitor, final Parameters params) {
    mapping.setProperty(MAPPING_CONNECTOR, connector);
    handleAncestors(mapping, params);
    LinkedList<IGraphElementVisitor> visitors = new LinkedList<IGraphElementVisitor>();
    visitors.add(algorithmResolver);
    // Set up graph validators
    if (params.getGlobalSettings().getProperty(CoreOptions.VALIDATE_OPTIONS)) {
        visitors.add(layoutOptionValidatorProvider.get());
    }
    if (params.getGlobalSettings().getProperty(CoreOptions.VALIDATE_GRAPH)) {
        visitors.add(graphValidatorProvider.get());
    }
    // Notify listeners of the to-be-executed layout
    LayoutConnectorsService.getInstance().fireLayoutAboutToStart(mapping, progressMonitor);
    IStatus status = null;
    if (params.configurators.isEmpty()) {
        // Perform layout without any extra configuration
        IGraphElementVisitor[] visitorsArray = visitors.toArray(new IGraphElementVisitor[visitors.size()]);
        status = layout(mapping, progressMonitor, visitorsArray);
    } else if (params.configurators.size() == 1) {
        // Perform layout once with an extra configuration
        visitors.addFirst(params.configurators.get(0));
        IGraphElementVisitor[] visitorsArray = visitors.toArray(new IGraphElementVisitor[visitors.size()]);
        status = layout(mapping, progressMonitor, visitorsArray);
    } else {
        // Perform layout multiple times with different configurations
        progressMonitor.begin("Diagram layout engine", params.configurators.size());
        ListIterator<IGraphElementVisitor> configIter = params.configurators.listIterator();
        while (configIter.hasNext()) {
            visitors.addFirst(configIter.next());
            IGraphElementVisitor[] visitorsArray = visitors.toArray(new IGraphElementVisitor[visitors.size()]);
            status = layout(mapping, progressMonitor, visitorsArray);
            if (!status.isOK()) {
                break;
            }
            visitors.removeFirst();
            // If an additional layout configurator is attached to the graph, consider it in the future
            LayoutConfigurator addConfig = mapping.getLayoutGraph().getProperty(LayoutConfigurator.ADD_LAYOUT_CONFIG);
            if (addConfig != null) {
                ListIterator<IGraphElementVisitor> configIter2 = params.configurators.listIterator(configIter.nextIndex());
                while (configIter2.hasNext()) {
                    IGraphElementVisitor c = configIter2.next();
                    if (c instanceof LayoutConfigurator) {
                        ((LayoutConfigurator) c).overrideWith(addConfig);
                    }
                }
            }
        }
        progressMonitor.done();
        // Log the final result to be displayed in our debug views
        progressMonitor.logGraph(mapping.getLayoutGraph(), "Result");
    }
    mapping.setProperty(MAPPING_STATUS, status);
    // Notify listeners of the executed layout
    LayoutConnectorsService.getInstance().fireLayoutDone(mapping, progressMonitor);
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator)

Example 5 with LayoutConfigurator

use of org.eclipse.elk.core.LayoutConfigurator in project elk by eclipse.

the class BasicCycleBreakerTest method modelOrderPreferEdgesConfigurator.

@ConfiguratorProvider
public LayoutConfigurator modelOrderPreferEdgesConfigurator() {
    LayoutConfigurator config = configuratorFor(CycleBreakingStrategy.MODEL_ORDER);
    config.configure(ElkNode.class).setProperty(LayeredOptions.CONSIDER_MODEL_ORDER_STRATEGY, OrderingStrategy.PREFER_EDGES);
    return config;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) ConfiguratorProvider(org.eclipse.elk.alg.test.framework.annotations.ConfiguratorProvider)

Aggregations

LayoutConfigurator (org.eclipse.elk.core.LayoutConfigurator)27 ElkNode (org.eclipse.elk.graph.ElkNode)22 ConfiguratorProvider (org.eclipse.elk.alg.test.framework.annotations.ConfiguratorProvider)10 Test (org.junit.Test)6 IGraphElementVisitor (org.eclipse.elk.core.util.IGraphElementVisitor)3 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)3 ElkPort (org.eclipse.elk.graph.ElkPort)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ListIterator (java.util.ListIterator)1 IStatus (org.eclipse.core.runtime.IStatus)1 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)1 UnsupportedConfigurationException (org.eclipse.elk.core.UnsupportedConfigurationException)1 LayoutAlgorithmResolver (org.eclipse.elk.core.data.LayoutAlgorithmResolver)1 NullElkProgressMonitor (org.eclipse.elk.core.util.NullElkProgressMonitor)1 ElkEdge (org.eclipse.elk.graph.ElkEdge)1 IPropertyHolder (org.eclipse.elk.graph.properties.IPropertyHolder)1 FrameworkMethod (org.junit.runners.model.FrameworkMethod)1