Search in sources :

Example 1 with ElkGraphUtil

use of org.eclipse.elk.graph.util.ElkGraphUtil in project elk by eclipse.

the class ElkGraphImporter method transformPort.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Port Transformation
/**
 * Transforms the given port. The new port will be added to the given node and will be
 * registered with the {@code transformMap}.
 *
 * @param elkport
 *            the port to transform.
 * @param parentLNode
 *            the node the port should be added to.
 * @param graphProperties
 *            the graph properties of the graph the transformed port will be part of. The graph
 *            properties are modified depending on the port's properties.
 * @param layoutDirection
 *            the layout direction in the graph the port will be part of.
 * @param portConstraints
 *            the port constraints of the port's node.
 * @return the transformed port.
 */
private LPort transformPort(final ElkPort elkport, final LNode parentLNode, final Set<GraphProperties> graphProperties, final Direction layoutDirection, final PortConstraints portConstraints) {
    // create layered port, copying its position
    LPort lport = new LPort();
    lport.copyProperties(elkport);
    lport.setSide(elkport.getProperty(LayeredOptions.PORT_SIDE));
    lport.setProperty(InternalProperties.ORIGIN, elkport);
    lport.setNode(parentLNode);
    KVector portSize = lport.getSize();
    portSize.x = elkport.getWidth();
    portSize.y = elkport.getHeight();
    KVector portPos = lport.getPosition();
    portPos.x = elkport.getX();
    portPos.y = elkport.getY();
    nodeAndPortMap.put(elkport, lport);
    // check if the original port has any outgoing connections to descendants of its node
    boolean connectionsToDescendants = elkport.getOutgoingEdges().stream().flatMap(edge -> edge.getTargets().stream()).map(ElkGraphUtil::connectableShapeToNode).anyMatch(targetNode -> ElkGraphUtil.isDescendant(targetNode, elkport.getParent()));
    // there could be yet incoming connections from descendants
    if (!connectionsToDescendants) {
        // check if the original port has any incoming connections from descendants of its node
        connectionsToDescendants = elkport.getIncomingEdges().stream().flatMap(edge -> edge.getSources().stream()).map(ElkGraphUtil::connectableShapeToNode).anyMatch(sourceNode -> ElkGraphUtil.isDescendant(sourceNode, elkport.getParent()));
    }
    // if there are still no connections to descendants, there might yet be inside self loops involved
    if (!connectionsToDescendants) {
        // check if the original port has any incoming connections from descendants of its node
        connectionsToDescendants = elkport.getOutgoingEdges().stream().anyMatch(edge -> edge.isSelfloop() && edge.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_YO));
    }
    // if we have found connections to / from descendants, mark the port accordingly
    lport.setProperty(InternalProperties.INSIDE_CONNECTIONS, connectionsToDescendants);
    // initialize the port's side, offset, and anchor point
    LGraphUtil.initializePort(lport, portConstraints, layoutDirection, elkport.getProperty(LayeredOptions.PORT_ANCHOR));
    // create the port's labels
    for (ElkLabel elklabel : elkport.getLabels()) {
        if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
            lport.getLabels().add(transformLabel(elklabel));
        }
    }
    switch(layoutDirection) {
        case LEFT:
        case RIGHT:
            if (lport.getSide() == PortSide.NORTH || lport.getSide() == PortSide.SOUTH) {
                graphProperties.add(GraphProperties.NORTH_SOUTH_PORTS);
            }
            break;
        case UP:
        case DOWN:
            if (lport.getSide() == PortSide.EAST || lport.getSide() == PortSide.WEST) {
                graphProperties.add(GraphProperties.NORTH_SOUTH_PORTS);
            }
            break;
    }
    return lport;
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) PortSide(org.eclipse.elk.core.options.PortSide) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) UnsupportedGraphException(org.eclipse.elk.core.UnsupportedGraphException) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ElkGraphAdapters(org.eclipse.elk.core.util.adapters.ElkGraphAdapters) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) Map(java.util.Map) GraphAdapter(org.eclipse.elk.core.util.adapters.GraphAdapters.GraphAdapter) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling) EnumSet(java.util.EnumSet) CycleBreakingStrategy(org.eclipse.elk.alg.layered.options.CycleBreakingStrategy) Set(java.util.Set) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) CrossingMinimizationStrategy(org.eclipse.elk.alg.layered.options.CrossingMinimizationStrategy) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) PortType(org.eclipse.elk.alg.layered.options.PortType) Direction(org.eclipse.elk.core.options.Direction) NodeAdapter(org.eclipse.elk.core.util.adapters.GraphAdapters.NodeAdapter) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) LPort(org.eclipse.elk.alg.layered.graph.LPort) OrderingStrategy(org.eclipse.elk.alg.layered.options.OrderingStrategy) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkEdge(org.eclipse.elk.graph.ElkEdge) Queue(java.util.Queue) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) NodeLabelAndSizeCalculator(org.eclipse.elk.alg.common.nodespacing.NodeLabelAndSizeCalculator) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) KVectorChain(org.eclipse.elk.core.math.KVectorChain) ElkUtil(org.eclipse.elk.core.util.ElkUtil) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ElkPadding(org.eclipse.elk.core.math.ElkPadding) LayeredSpacings(org.eclipse.elk.alg.layered.options.LayeredSpacings) NodePlacementStrategy(org.eclipse.elk.alg.layered.options.NodePlacementStrategy) Iterator(java.util.Iterator) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Maps(com.google.common.collect.Maps) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) LGraphElement(org.eclipse.elk.alg.layered.graph.LGraphElement) LGraphUtil(org.eclipse.elk.alg.layered.graph.LGraphUtil) LPadding(org.eclipse.elk.alg.layered.graph.LPadding) LabelManagementOptions(org.eclipse.elk.core.labels.LabelManagementOptions) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) ElkLabel(org.eclipse.elk.graph.ElkLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 EnumSet (java.util.EnumSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 NodeLabelAndSizeCalculator (org.eclipse.elk.alg.common.nodespacing.NodeLabelAndSizeCalculator)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LGraphElement (org.eclipse.elk.alg.layered.graph.LGraphElement)1 LGraphUtil (org.eclipse.elk.alg.layered.graph.LGraphUtil)1 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPadding (org.eclipse.elk.alg.layered.graph.LPadding)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 CrossingMinimizationStrategy (org.eclipse.elk.alg.layered.options.CrossingMinimizationStrategy)1 CycleBreakingStrategy (org.eclipse.elk.alg.layered.options.CycleBreakingStrategy)1 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)1