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