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);
}
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();
}
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());
}
}
}
}
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();
}
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();
}
Aggregations