Search in sources :

Example 11 with IElkProgressMonitor

use of org.eclipse.elk.core.util.IElkProgressMonitor 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)

Example 12 with IElkProgressMonitor

use of org.eclipse.elk.core.util.IElkProgressMonitor in project elk by eclipse.

the class SemiInteractiveCrossMinProcessor method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Semi-Interactive Crossing Minimization Processor", 1);
    boolean addedConstraints = false;
    for (Layer l : layeredGraph) {
        // #1 extract relevant nodes
        // #2 sort them with ascending y coordinate
        // #3 introduce pair-wise in-layer constraints
        Optional<LNode> reduced = l.getNodes().stream().filter(n -> n.getType() == NodeType.NORMAL).filter(n -> n.getAllProperties().containsKey(LayeredOptions.POSITION)).sorted((n1, n2) -> {
            KVector origPos1 = n1.getProperty(LayeredOptions.POSITION);
            KVector origPos2 = n2.getProperty(LayeredOptions.POSITION);
            return Double.compare(origPos1.y, origPos2.y);
        }).reduce((prev, cur) -> {
            prev.getProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS).add(cur);
            return cur;
        });
        addedConstraints |= reduced.isPresent();
    }
    // If we added in-layer successor constraints, make subsequent phases aware
    if (addedConstraints) {
        layeredGraph.setProperty(InternalProperties.IN_LAYER_SUCCESSOR_CONSTRAINTS_BETWEEN_NON_DUMMIES, true);
    }
    progressMonitor.done();
}
Also used : Layer(org.eclipse.elk.alg.layered.graph.Layer) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) KVector(org.eclipse.elk.core.math.KVector) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Optional(java.util.Optional) LNode(org.eclipse.elk.alg.layered.graph.LNode) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 13 with IElkProgressMonitor

use of org.eclipse.elk.core.util.IElkProgressMonitor in project elk by eclipse.

the class InteractiveExternalPortPositioner method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
    // if the graph does not contain any external ports ...
    if (!layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
        // ... nothing we can do about it
        return;
    }
    // find the minimum and maximum x coordinates of the graph
    for (LNode node : layeredGraph.getLayerlessNodes()) {
        if (node.getType() == NodeType.NORMAL) {
            ElkMargin margins = node.getProperty(LayeredOptions.MARGINS);
            minX = Math.min(minX, node.getPosition().x - margins.left);
            maxX = Math.max(maxX, node.getPosition().x + node.getSize().x + margins.right);
            minY = Math.min(minY, node.getPosition().y - margins.top);
            maxY = Math.max(maxY, node.getPosition().y + node.getSize().y + margins.bottom);
        }
    }
    // assign reasonable coordinates to external port dummies
    for (LNode node : layeredGraph.getLayerlessNodes()) {
        if (node.getType() != NodeType.NORMAL) {
            switch(node.getType()) {
                // SUPPRESS CHECKSTYLE NEXT 50 InnerAssignment
                case EXTERNAL_PORT:
                    LayerConstraint lc = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
                    if (lc == LayerConstraint.FIRST_SEPARATE) {
                        // it's a WEST port
                        node.getPosition().x = minX - ARBITRARY_SPACING;
                        findYCoordinate(node, (e) -> e.getTarget().getNode()).transform((d) -> node.getPosition().y = d);
                        break;
                    }
                    if (lc == LayerConstraint.LAST_SEPARATE) {
                        // it's a EAST port
                        node.getPosition().x = maxX + ARBITRARY_SPACING;
                        findYCoordinate(node, (e) -> e.getSource().getNode()).transform((d) -> node.getPosition().y = d);
                        break;
                    }
                    InLayerConstraint ilc = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
                    if (ilc == InLayerConstraint.TOP) {
                        findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
                        node.getPosition().y = minY - ARBITRARY_SPACING;
                        break;
                    }
                    if (ilc == InLayerConstraint.BOTTOM) {
                        findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
                        node.getPosition().y = maxY + ARBITRARY_SPACING;
                        break;
                    }
                    break;
                default:
                    throw new IllegalArgumentException("The node type " + node.getType() + " is not supported by the " + this.getClass());
            }
        }
    }
}
Also used : ElkMargin(org.eclipse.elk.core.math.ElkMargin) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Function(com.google.common.base.Function) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Optional(com.google.common.base.Optional) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkMargin(org.eclipse.elk.core.math.ElkMargin) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint)

Example 14 with IElkProgressMonitor

use of org.eclipse.elk.core.util.IElkProgressMonitor in project elk by eclipse.

the class SelfLoopRouter method process.

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Self-Loop routing", 1);
    AbstractSelfLoopRouter router = routerForGraph(graph);
    ILabelManager labelManager = graph.getProperty(LabelManagementOptions.LABEL_MANAGER);
    // Process every node that actually has self loops
    graph.getLayers().stream().flatMap(layer -> layer.getNodes().stream()).filter(lNode -> lNode.getType() == NodeType.NORMAL).filter(lNode -> lNode.hasProperty(InternalProperties.SELF_LOOP_HOLDER)).map(lNode -> lNode.getProperty(InternalProperties.SELF_LOOP_HOLDER)).forEach(slHolder -> processNode(slHolder, labelManager, router, progressMonitor));
    progressMonitor.done();
}
Also used : RoutingDirector(org.eclipse.elk.alg.layered.intermediate.loops.routing.RoutingDirector) LabelPlacer(org.eclipse.elk.alg.layered.intermediate.loops.routing.LabelPlacer) RoutingSlotAssigner(org.eclipse.elk.alg.layered.intermediate.loops.routing.RoutingSlotAssigner) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) OrthogonalSelfLoopRouter(org.eclipse.elk.alg.layered.intermediate.loops.routing.OrthogonalSelfLoopRouter) SplineSelfLoopRouter(org.eclipse.elk.alg.layered.intermediate.loops.routing.SplineSelfLoopRouter) PolylineSelfLoopRouter(org.eclipse.elk.alg.layered.intermediate.loops.routing.PolylineSelfLoopRouter) ILabelManager(org.eclipse.elk.core.labels.ILabelManager) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) SelfLoopHolder(org.eclipse.elk.alg.layered.intermediate.loops.SelfLoopHolder) LabelManagementOptions(org.eclipse.elk.core.labels.LabelManagementOptions) AbstractSelfLoopRouter(org.eclipse.elk.alg.layered.intermediate.loops.routing.AbstractSelfLoopRouter) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) ILabelManager(org.eclipse.elk.core.labels.ILabelManager) AbstractSelfLoopRouter(org.eclipse.elk.alg.layered.intermediate.loops.routing.AbstractSelfLoopRouter)

Example 15 with IElkProgressMonitor

use of org.eclipse.elk.core.util.IElkProgressMonitor in project elk by eclipse.

the class HorizontalGraphCompactor method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
    GraphCompactionStrategy strategy = layeredGraph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_STRATEGY);
    if (strategy == GraphCompactionStrategy.NONE) {
        return;
    }
    progressMonitor.begin("Horizontal Compaction", 1);
    this.lGraph = layeredGraph;
    // the layered graph is transformed into a CGraph that is passed to OneDimensionalCompactor
    LGraphToCGraphTransformer transformer = new LGraphToCGraphTransformer();
    OneDimensionalCompactor odc = new OneDimensionalCompactor(transformer.transform(layeredGraph));
    // consider special spacing requirements of the lgraph's nodes and edges
    odc.setSpacingsHandler(specialSpacingsHandler);
    // -
    switch(layeredGraph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_CONSTRAINTS)) {
        case SCANLINE:
            odc.setConstraintAlgorithm(new EdgeAwareScanlineConstraintCalculation(lGraph));
            break;
        default:
            odc.setConstraintAlgorithm(OneDimensionalCompactor.QUADRATIC_CONSTRAINTS);
    }
    // -
    switch(strategy) {
        case LEFT:
            odc.compact();
            break;
        case RIGHT:
            odc.changeDirection(Direction.RIGHT).compact();
            break;
        case LEFT_RIGHT_CONSTRAINT_LOCKING:
            // lock CNodes if they are not constrained
            odc.compact().changeDirection(Direction.RIGHT).setLockFunction((node, dir) -> node.cGroup.outDegreeReal == 0).compact();
            break;
        case LEFT_RIGHT_CONNECTION_LOCKING:
            // compacting left, locking all CNodes that have fewer connections to the right,
            // then compacting right to shorten unnecessary long edges
            odc.compact().changeDirection(Direction.RIGHT).setLockFunction((node, dir) -> transformer.getLockMap().get(node).get(dir)).compact();
            break;
        case EDGE_LENGTH:
            odc.setCompactionAlgorithm(NETWORK_SIMPLEX_COMPACTION).compact();
            break;
        default:
            // nobody should get here
            break;
    }
    // since changeDirection may transform hitboxes, the final direction has to be LEFT again
    odc.finish();
    // applying the compacted positions to the LGraph and updating its size and offset
    transformer.applyLayout();
    progressMonitor.done();
}
Also used : IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) OneDimensionalCompactor(org.eclipse.elk.alg.common.compaction.oned.OneDimensionalCompactor) ISpacingsHandler(org.eclipse.elk.alg.common.compaction.oned.ISpacingsHandler) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) CNode(org.eclipse.elk.alg.common.compaction.oned.CNode) Spacings(org.eclipse.elk.alg.layered.options.Spacings) ICompactionAlgorithm(org.eclipse.elk.alg.common.compaction.oned.ICompactionAlgorithm) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Direction(org.eclipse.elk.core.options.Direction) LNode(org.eclipse.elk.alg.layered.graph.LNode) Collections(java.util.Collections) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) OneDimensionalCompactor(org.eclipse.elk.alg.common.compaction.oned.OneDimensionalCompactor)

Aggregations

IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)23 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)8 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)8 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)7 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)7 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)7 LNode (org.eclipse.elk.alg.layered.graph.LNode)6 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)6 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 KVector (org.eclipse.elk.core.math.KVector)4 List (java.util.List)3 Set (java.util.Set)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 Layer (org.eclipse.elk.alg.layered.graph.Layer)3 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)3 ElkNode (org.eclipse.elk.graph.ElkNode)3 Sets (com.google.common.collect.Sets)2 Collections (java.util.Collections)2