Search in sources :

Example 11 with LayoutConfigurator

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

the class LayoutConfiguratorTest method testCombineMultipleClass.

@Test
public void testCombineMultipleClass() {
    Graph g = new Graph();
    LayoutConfigurator lc = new LayoutConfigurator();
    lc.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 42d);
    lc.configure(ElkGraphElement.class).setProperty(CoreOptions.SPACING_EDGE_NODE, 42d);
    ElkUtil.applyVisitors(g.root, lc);
    assertEquals(42d, g.n1.getProperty(CoreOptions.SPACING_NODE_NODE), EPSILON);
    assertEquals(42d, g.n1.getProperty(CoreOptions.SPACING_EDGE_NODE), EPSILON);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Test(org.junit.Test)

Example 12 with LayoutConfigurator

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

the class Issue562Test method test.

@Test
public void test() {
    // Create the basic graph structure
    ElkNode graph = ElkGraphUtil.createGraph();
    ElkNode n1 = ElkGraphUtil.createNode(graph);
    ElkPort p1 = ElkGraphUtil.createPort(n1);
    ElkPort p2 = ElkGraphUtil.createPort(n1);
    ElkEdge e = ElkGraphUtil.createSimpleEdge(p1, p2);
    // Create a layout configurator to apply options, just as it would happen in the DiagramLayoutEngine
    LayoutConfigurator config = new LayoutConfigurator();
    config.configure(n1).setProperty(CoreOptions.INSIDE_SELF_LOOPS_ACTIVATE, true);
    config.configure(e).setProperty(CoreOptions.INSIDE_SELF_LOOPS_YO, true);
    // Apply the configurator and a layout algorithm resolver, just like the DiagramLayoutEngine does
    ElkUtil.applyVisitors(graph, config, new LayoutAlgorithmResolver());
    // Apply layout. We don't want an UnsupportedConfigurationException to be thrown
    try {
        new RecursiveGraphLayoutEngine().layout(graph, new NullElkProgressMonitor());
    } catch (UnsupportedConfigurationException ex) {
        fail(ex.toString());
    }
}
Also used : NullElkProgressMonitor(org.eclipse.elk.core.util.NullElkProgressMonitor) ElkNode(org.eclipse.elk.graph.ElkNode) UnsupportedConfigurationException(org.eclipse.elk.core.UnsupportedConfigurationException) ElkPort(org.eclipse.elk.graph.ElkPort) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) LayoutAlgorithmResolver(org.eclipse.elk.core.data.LayoutAlgorithmResolver) ElkEdge(org.eclipse.elk.graph.ElkEdge) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Test(org.junit.Test)

Example 13 with LayoutConfigurator

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

the class LayoutConfiguratorTest method testPreventOverridingExistingOptions.

@Test
public void testPreventOverridingExistingOptions() {
    Graph g = new Graph();
    g.root.setProperty(CoreOptions.SPACING_NODE_NODE, 13d);
    LayoutConfigurator lc = new LayoutConfigurator();
    lc.configure(ElkNode.class).setProperty(CoreOptions.SPACING_NODE_NODE, 42d);
    lc.addFilter(LayoutConfigurator.NO_OVERWRITE);
    ElkUtil.applyVisitors(g.root, lc);
    assertEquals(13d, g.root.getProperty(CoreOptions.SPACING_NODE_NODE), EPSILON);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Test(org.junit.Test)

Example 14 with LayoutConfigurator

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

the class DiagramLayoutEngine method handleAncestors.

/**
 * Handle the ancestors of the parent element if {@link CoreOptions#LAYOUT_ANCESTORS} is set.
 * For every ancestor node of the parent element (i.e. {@link LayoutMapping#getParentElement()}),
 * all containing elements that are not ancestors are excluded from layout.
 *
 * @param mapping
 *            a mapping for the layout graph
 * @param params
 *            layout parameters
 */
protected void handleAncestors(final LayoutMapping mapping, final Parameters params) {
    boolean layoutAncestors = params.getGlobalSettings().getProperty(CoreOptions.LAYOUT_ANCESTORS);
    if (layoutAncestors) {
        // Mark all parallel areas for exclusion from layout
        ElkGraphElement graphElem = mapping.getGraphMap().inverse().get(mapping.getParentElement());
        if (graphElem instanceof ElkNode && ((ElkNode) graphElem).getParent() != null) {
            if (params.configurators.isEmpty()) {
                params.configurators.add(new LayoutConfigurator());
            }
            ElkNode node = (ElkNode) graphElem;
            do {
                ElkNode parent = node.getParent();
                for (ElkNode child : parent.getChildren()) {
                    if (child != node) {
                        for (IGraphElementVisitor c : params.configurators) {
                            if (c instanceof LayoutConfigurator) {
                                IPropertyHolder childConfig = ((LayoutConfigurator) c).configure(child);
                                // Do not layout the content of the child node
                                childConfig.setProperty(CoreOptions.NO_LAYOUT, true);
                                // Do not change the size of the child node
                                childConfig.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
                                // Do not move the ports of the child node
                                childConfig.setProperty(CoreOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
                            }
                        }
                    }
                }
                node = parent;
            } while (node.getParent() != null);
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) IPropertyHolder(org.eclipse.elk.graph.properties.IPropertyHolder) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor)

Example 15 with LayoutConfigurator

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

the class DiagramLayoutEngine method addDiagramConfig.

/**
 * Create a diagram layout configuration and add it to the setup.
 */
protected void addDiagramConfig(final Parameters params, final LayoutMapping layoutMapping) {
    LayoutConfigurator diagramConfig = configManager.createConfigurator(layoutMapping);
    if (params.configurators.isEmpty()) {
        params.addLayoutRun(diagramConfig);
    } else {
        ListIterator<IGraphElementVisitor> configIter = params.configurators.listIterator();
        while (configIter.hasNext()) {
            boolean isFirstConfig = !configIter.hasPrevious();
            IGraphElementVisitor setupConfig = configIter.next();
            if (setupConfig instanceof LayoutConfigurator) {
                LayoutConfigurator layoutConfigurator = (LayoutConfigurator) setupConfig;
                if (params.overrideDiagramConfig) {
                    if (isFirstConfig || layoutConfigurator.isClearLayout()) {
                        LayoutConfigurator newConfig;
                        if (configIter.hasNext()) {
                            newConfig = new LayoutConfigurator().overrideWith(diagramConfig);
                        } else {
                            newConfig = diagramConfig;
                        }
                        configIter.set(newConfig.overrideWith(layoutConfigurator));
                    }
                } else {
                    layoutConfigurator.overrideWith(diagramConfig);
                }
            }
        }
    }
}
Also used : LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor)

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