use of org.eclipse.elk.core.options.PortLabelPlacement in project elk by eclipse.
the class HierarchicalPortOrthogonalEdgeRouter method restoreDummy.
/**
* Restores the given dummy.
*/
private void restoreDummy(final LNode dummy, final LGraph graph) {
// Depending on the hierarchical port's side, we set the port side of the dummy's ports
// to be able to route properly (northern dummies must have a southern port)
PortSide portSide = dummy.getProperty(InternalProperties.EXT_PORT_SIDE);
LPort dummyPort = dummy.getPorts().get(0);
if (portSide == PortSide.NORTH) {
dummyPort.setSide(PortSide.SOUTH);
} else if (portSide == PortSide.SOUTH) {
dummyPort.setSide(PortSide.NORTH);
}
// are not set acoordingly. That needs to be fixed (if port labels are to be taken into consideration)
if (graph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.PORT_LABELS)) {
// The ElkGraphImporter has set the relevant spacings on the dummy node
double portLabelSpacing = dummy.getProperty(LayeredOptions.SPACING_LABEL_PORT);
double labelLabelSpacing = dummy.getProperty(LayeredOptions.SPACING_LABEL_LABEL);
Set<PortLabelPlacement> portLabelPlacement = graph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT);
if (portLabelPlacement.contains(PortLabelPlacement.INSIDE)) {
double currentY = portLabelSpacing;
double xCenterRelativeToPort = dummy.getSize().x / 2 - dummyPort.getPosition().x;
for (LLabel label : dummyPort.getLabels()) {
label.getPosition().y = currentY;
label.getPosition().x = xCenterRelativeToPort - label.getSize().x / 2;
currentY += label.getSize().y + labelLabelSpacing;
}
} else if (portLabelPlacement.contains(PortLabelPlacement.OUTSIDE)) {
// Port labels have a vertical size of 0, but we need to set their x coordinate
for (LLabel label : dummyPort.getLabels()) {
label.getPosition().x = portLabelSpacing + dummy.getSize().x - dummyPort.getPosition().x;
}
}
// Calculate margins
NodeDimensionCalculation.getNodeMarginCalculator(LGraphAdapters.adapt(graph, false)).processNode(LGraphAdapters.adapt(dummy, false));
}
}
use of org.eclipse.elk.core.options.PortLabelPlacement 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();
}
use of org.eclipse.elk.core.options.PortLabelPlacement in project elk by eclipse.
the class ElkGraphImporter method checkExternalPorts.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// External Port Transformation
/**
* Checks if external ports processing should be active. This is the case if the parent node has
* ports and at least one of the following conditions is true:
* <ul>
* <li>
* Port label placement is set to {@code INSIDE} and at least one of the ports has a label.
* </li>
* <li>
* At least one of the ports has an edge that connects to the insides of the parent node.
* </li>
* <li>
* There is a self-loop that should be routed inside the node.
* </li>
* </ul>
*
* @param elkgraph
* a KGraph we want to check for external ports.
* @param graphProperties
* the set of graph properties to store our results in.
*/
private void checkExternalPorts(final ElkNode elkgraph, final Set<GraphProperties> graphProperties) {
final boolean enableSelfLoops = elkgraph.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_ACTIVATE);
final Set<PortLabelPlacement> portLabelPlacement = elkgraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT);
// We're iterating over the ports until we've determined that we have both external ports and
// hyperedges, or if there are no more ports left
boolean hasExternalPorts = false;
boolean hasHyperedges = false;
final Iterator<ElkPort> portIterator = elkgraph.getPorts().iterator();
while (portIterator.hasNext() && (!hasExternalPorts || !hasHyperedges)) {
final ElkPort elkport = portIterator.next();
// Find out if there are edges connected to external ports of the graph (this is the case
// for inside self loops as well as for edges connected to children)
int externalPortEdges = 0;
for (ElkEdge elkedge : ElkGraphUtil.allIncidentEdges(elkport)) {
boolean isInsideSelfLoop = enableSelfLoops && elkedge.isSelfloop() && elkedge.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_YO);
boolean connectsToChild = elkedge.getSources().contains(elkport) ? elkgraph == ElkGraphUtil.connectableShapeToNode(elkedge.getTargets().get(0)).getParent() : elkgraph == ElkGraphUtil.connectableShapeToNode(elkedge.getSources().get(0)).getParent();
if (isInsideSelfLoop || connectsToChild) {
externalPortEdges++;
if (externalPortEdges > 1) {
break;
}
}
}
// External ports?
if (externalPortEdges > 0) {
hasExternalPorts = true;
} else if (portLabelPlacement.contains(PortLabelPlacement.INSIDE) && elkport.getLabels().size() > 0) {
hasExternalPorts = true;
}
// Hyperedges, even?
if (externalPortEdges > 1) {
hasHyperedges = true;
}
}
// Update graph properties
if (hasExternalPorts) {
graphProperties.add(GraphProperties.EXTERNAL_PORTS);
}
if (hasHyperedges) {
graphProperties.add(GraphProperties.HYPEREDGES);
}
}
Aggregations