Search in sources :

Example 1 with PortLabelPlacement

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));
    }
}
Also used : PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) PortSide(org.eclipse.elk.core.options.PortSide)

Example 2 with PortLabelPlacement

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();
}
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 3 with PortLabelPlacement

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);
    }
}
Also used : PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) ElkPort(org.eclipse.elk.graph.ElkPort) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Aggregations

PortLabelPlacement (org.eclipse.elk.core.options.PortLabelPlacement)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)2 LPort (org.eclipse.elk.alg.layered.graph.LPort)2 Set (java.util.Set)1 NodeDimensionCalculation (org.eclipse.elk.alg.common.nodespacing.NodeDimensionCalculation)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LGraphAdapters (org.eclipse.elk.alg.layered.graph.LGraphAdapters)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)1 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)1 KVector (org.eclipse.elk.core.math.KVector)1 PortSide (org.eclipse.elk.core.options.PortSide)1 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)1 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)1 ElkEdge (org.eclipse.elk.graph.ElkEdge)1