Search in sources :

Example 1 with Quadruplet

use of org.eclipse.elk.alg.common.compaction.oned.Quadruplet in project elk by eclipse.

the class LGraphToCGraphTransformer method verticalSegmentToCNode.

private void verticalSegmentToCNode(final VerticalSegment verticalSegment) {
    // create CNode representation for the last segment
    CNode cNode = CNode.of().origin(verticalSegment).type("vs").hitbox(new ElkRectangle(verticalSegment.hitbox)).toStringDelegate(VS_TO_STRING_DELEGATE).create(cGraph);
    // assumption: during creation of LNode representing CNodes, these CNodes have been fitted with their own group
    if (!verticalSegment.potentialGroupParents.isEmpty()) {
        verticalSegment.potentialGroupParents.get(0).cGroup.addCNode(cNode);
    }
    Quadruplet vsLock = new Quadruplet();
    lockMap.put(cNode, vsLock);
    // segments belonging to multiple edges should be locked
    // in the direction that fewer different ports are connected in
    // (only used if LEFT_RIGHT_CONNECTION_LOCKING is active)
    Set<LPort> inc = Sets.newHashSet();
    Set<LPort> out = Sets.newHashSet();
    for (LEdge e : verticalSegment.representedLEdges) {
        inc.add(e.getSource());
        out.add(e.getTarget());
    }
    int difference = inc.size() - out.size();
    if (difference < 0) {
        vsLock.set(true, Direction.LEFT);
        vsLock.set(false, Direction.RIGHT);
    } else if (difference > 0) {
        vsLock.set(false, Direction.LEFT);
        vsLock.set(true, Direction.RIGHT);
    }
    verticalSegment.joined.forEach(other -> verticalSegmentsMap.put(other, cNode));
    verticalSegmentsMap.put(verticalSegment, cNode);
}
Also used : CNode(org.eclipse.elk.alg.common.compaction.oned.CNode) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) Quadruplet(org.eclipse.elk.alg.common.compaction.oned.Quadruplet) LPort(org.eclipse.elk.alg.layered.graph.LPort) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 2 with Quadruplet

use of org.eclipse.elk.alg.common.compaction.oned.Quadruplet in project elk by eclipse.

the class LGraphToCGraphTransformer method transformNodes.

private void transformNodes() {
    for (Layer layer : layeredGraph) {
        for (LNode node : layer) {
            // of other nodes overlapping them after compaction
            if (node.getProperty(LayeredOptions.COMMENT_BOX)) {
                if (!Iterables.isEmpty(node.getConnectedEdges())) {
                    LEdge e = Iterables.get(node.getConnectedEdges(), 0);
                    LNode other = e.getSource().getNode();
                    if (other == node) {
                        other = e.getTarget().getNode();
                    }
                    Pair<LNode, KVector> p = Pair.of(other, node.getPosition().clone().sub(other.getPosition()));
                    commentOffsets.put(node, p);
                    continue;
                }
            }
            ElkRectangle hitbox = new ElkRectangle(node.getPosition().x - node.getMargin().left, node.getPosition().y - node.getMargin().top, node.getSize().x + node.getMargin().left + node.getMargin().right, node.getSize().y + node.getMargin().top + node.getMargin().bottom);
            // create the node in the compaction graph
            CNode cNode = CNode.of().origin(node).hitbox(hitbox).toStringDelegate(NODE_TO_STRING_DELEGATE).create(cGraph);
            // the node lives in its own group
            CGroup.of().nodes(cNode).master(cNode).create(cGraph);
            Quadruplet nodeLock = new Quadruplet();
            lockMap.put(cNode, nodeLock);
            // locking the node for directions that fewer edges are connected in
            // (only used if LEFT_RIGHT_CONNECTION_LOCKING is used)
            int difference = Iterables.size(node.getIncomingEdges()) - Iterables.size(node.getOutgoingEdges());
            if (difference < 0) {
                nodeLock.set(true, Direction.LEFT);
            } else if (difference > 0) {
                nodeLock.set(true, Direction.RIGHT);
            }
            // excluding external port dummies
            if (node.getType() == NodeType.EXTERNAL_PORT) {
                nodeLock.set(false, false, false, false);
            }
            nodesMap.put(node, cNode);
        }
    }
}
Also used : CNode(org.eclipse.elk.alg.common.compaction.oned.CNode) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) Quadruplet(org.eclipse.elk.alg.common.compaction.oned.Quadruplet) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Aggregations

CNode (org.eclipse.elk.alg.common.compaction.oned.CNode)2 Quadruplet (org.eclipse.elk.alg.common.compaction.oned.Quadruplet)2 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)2 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)2 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 KVector (org.eclipse.elk.core.math.KVector)1