Search in sources :

Example 1 with IElkProgressMonitor

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

the class LabelAndNodeSizeProcessor method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Node and Port Label Placement and Node Sizing", 1);
    NodeDimensionCalculation.calculateLabelAndNodeSizes(LGraphAdapters.adapt(layeredGraph, true, true, node -> node.getType() == NodeType.NORMAL));
    // which is the reason why we haven't handed them to the label and node size processing code
    if (layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
        Set<PortLabelPlacement> portLabelPlacement = layeredGraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT);
        boolean placeNextToPort = portLabelPlacement.contains(PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE);
        boolean treatAsGroup = layeredGraph.getProperty(LayeredOptions.PORT_LABELS_TREAT_AS_GROUP);
        for (Layer layer : layeredGraph.getLayers()) {
            layer.getNodes().stream().filter(node -> node.getType() == NodeType.EXTERNAL_PORT).forEach(dummy -> placeExternalPortDummyLabels(dummy, portLabelPlacement, placeNextToPort, treatAsGroup));
        }
    }
    monitor.done();
}
Also used : NodeDimensionCalculation(org.eclipse.elk.alg.common.nodespacing.NodeDimensionCalculation) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Layer(org.eclipse.elk.alg.layered.graph.Layer) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) KVector(org.eclipse.elk.core.math.KVector) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Set(java.util.Set) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LGraphAdapters(org.eclipse.elk.alg.layered.graph.LGraphAdapters) LNode(org.eclipse.elk.alg.layered.graph.LNode) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 2 with IElkProgressMonitor

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

the class FinalSplineBendpointsCalculator method process.

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    this.edgeEdgeSpacing = graph.getProperty(LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS);
    this.edgeNodeSpacing = graph.getProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS);
    this.splineRoutingMode = graph.getProperty(LayeredOptions.EDGE_ROUTING_SPLINES_MODE);
    this.compactionStrategy = graph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_STRATEGY);
    // assign indices to nodes to efficiently query neighbors within the same layer
    indexNodesPerLayer(graph);
    // collect all edges that represent the first segment of a spline
    List<LEdge> startEdges = graph.getLayers().stream().flatMap(l -> l.getNodes().stream()).flatMap(n -> StreamSupport.stream(n.getOutgoingEdges().spliterator(), false)).filter(e -> !e.isSelfLoop()).filter(e -> e.hasProperty(InternalProperties.SPLINE_ROUTE_START)).collect(Collectors.toList());
    // first determine the NUB control points
    for (LEdge e : startEdges) {
        List<SplineSegment> spline = e.getProperty(InternalProperties.SPLINE_ROUTE_START);
        spline.forEach(s -> calculateControlPoints(s));
        e.setProperty(InternalProperties.SPLINE_ROUTE_START, null);
    }
    // ... then convert them to bezier splines
    for (LEdge e : startEdges) {
        // may be null
        LEdge survivingEdge = e.getProperty(InternalProperties.SPLINE_SURVIVING_EDGE);
        List<LEdge> edgeChain = e.getProperty(InternalProperties.SPLINE_EDGE_CHAIN);
        calculateBezierBendPoints(edgeChain, survivingEdge);
        // clear property
        e.setProperty(InternalProperties.SPLINE_EDGE_CHAIN, null);
    }
}
Also used : Layer(org.eclipse.elk.alg.layered.graph.Layer) SplinesMath(org.eclipse.elk.alg.layered.p5edges.splines.SplinesMath) PortSide(org.eclipse.elk.core.options.PortSide) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) KVectorChain(org.eclipse.elk.core.math.KVectorChain) NubSpline(org.eclipse.elk.alg.layered.p5edges.splines.NubSpline) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) StreamSupport(java.util.stream.StreamSupport) Iterator(java.util.Iterator) EdgeInformation(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment.EdgeInformation) KVector(org.eclipse.elk.core.math.KVector) Collectors(java.util.stream.Collectors) LMargin(org.eclipse.elk.alg.layered.graph.LMargin) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) HorizontalGraphCompactor(org.eclipse.elk.alg.layered.intermediate.compaction.HorizontalGraphCompactor) ElkMath(org.eclipse.elk.core.math.ElkMath) SplineRoutingMode(org.eclipse.elk.alg.layered.options.SplineRoutingMode) List(java.util.List) SplineEdgeRouter(org.eclipse.elk.alg.layered.p5edges.splines.SplineEdgeRouter) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) SplineSegment(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment) Collections(java.util.Collections) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) SplineSegment(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment)

Example 3 with IElkProgressMonitor

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

the class MaxSTPhase method process.

@Override
public void process(final Graph graph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Maximum spanning tree construction", 1);
    // inverted cost function
    ICostFunction invertedCF = e -> {
        return -graph.costFunction.cost(e);
    };
    KVector root;
    if (graph.preferredRoot != null) {
        root = graph.preferredRoot.vertex;
    } else {
        root = graph.vertices.get(0).vertex;
    }
    Tree<KVector> tree;
    if (graph.getProperty(InternalProperties.DEBUG_SVG)) {
        tree = NaiveMinST.createSpanningTree(graph.tEdges, root, invertedCF, ElkUtil.debugFolderPath("spore") + "20minst");
    } else {
        tree = NaiveMinST.createSpanningTree(graph.tEdges, root, invertedCF);
    }
    // convert result to a Tree that can be used in the execution phase
    convert(tree, graph);
    progressMonitor.done();
}
Also used : ICostFunction(org.eclipse.elk.alg.common.ICostFunction) ElkUtil(org.eclipse.elk.core.util.ElkUtil) NaiveMinST(org.eclipse.elk.alg.common.NaiveMinST) KVector(org.eclipse.elk.core.math.KVector) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) ICostFunction(org.eclipse.elk.alg.common.ICostFunction) Tree(org.eclipse.elk.alg.common.Tree) Graph(org.eclipse.elk.alg.spore.graph.Graph) InternalProperties(org.eclipse.elk.alg.common.spore.InternalProperties) KVector(org.eclipse.elk.core.math.KVector)

Example 4 with IElkProgressMonitor

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

the class MonitoredOperation method runOperation.

/**
 * Runs the operation after synchronization with the UI handler.
 *
 * @param display the current display
 * @param monitor the progress monitor wrapper
 * @param status the returned status
 */
private void runOperation(final Display display, final Maybe<IProgressMonitor> monitor, final Maybe<IStatus> status) {
    try {
        synchronized (monitor) {
            while (monitor.get() == null && !isCanceled()) {
                try {
                    monitor.wait();
                } catch (InterruptedException exception) {
                // ignore exception
                }
            }
        }
        if (status.get() == null && !isCanceled()) {
            IPreferenceStore prefStore = ElkServicePlugin.getInstance().getPreferenceStore();
            IElkProgressMonitor monAdapt = new ProgressMonitorAdapter(monitor.get(), MAX_PROGRESS_LEVELS).withLogging(prefStore.getBoolean(DiagramLayoutEngine.PREF_DEBUG_LOGGING)).withExecutionTimeMeasurement(prefStore.getBoolean(DiagramLayoutEngine.PREF_DEBUG_EXEC_TIME));
            status.set(execute(monAdapt));
            assert status.get() != null;
        }
    } finally {
        synchronized (status) {
            if (status.get() == null) {
                status.set(Status.OK_STATUS);
            }
            display.wake();
        }
    }
}
Also used : IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 5 with IElkProgressMonitor

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

the class ElkLayered method doCompoundLayout.

// //////////////////////////////////////////////////////////////////////////////
// Compound Graph Layout
/**
 * Does a layout on the given compound graph. Connected components processing is currently not
 * supported.
 *
 * @param lgraph the graph to layout
 * @param monitor a progress monitor to show progress information in, or {@code null}
 */
public void doCompoundLayout(final LGraph lgraph, final IElkProgressMonitor monitor) {
    IElkProgressMonitor theMonitor = monitor;
    if (theMonitor == null) {
        theMonitor = new BasicProgressMonitor().withMaxHierarchyLevels(0);
    }
    // SUPPRESS CHECKSTYLE MagicNumber
    theMonitor.begin("Layered layout", 2);
    // Preprocess the compound graph by splitting cross-hierarchy edges
    notifyProcessorReady(lgraph, compoundGraphPreprocessor);
    compoundGraphPreprocessor.process(lgraph, theMonitor.subTask(1));
    notifyProcessorFinished(lgraph, compoundGraphPreprocessor);
    hierarchicalLayout(lgraph, theMonitor.subTask(1));
    // Postprocess the compound graph by combining split cross-hierarchy edges
    notifyProcessorReady(lgraph, compoundGraphPostprocessor);
    compoundGraphPostprocessor.process(lgraph, theMonitor.subTask(1));
    notifyProcessorFinished(lgraph, compoundGraphPostprocessor);
    theMonitor.done();
}
Also used : IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor)

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