Search in sources :

Example 36 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class EndLabelPreprocessor method placeLabels.

/**
 * Places the edge end labels that are to be placed near the given port.
 */
private void placeLabels(final LPort port, final LabelCell labelCell, final double edgeLabelSpacing) {
    // Some necessary position information
    ElkRectangle labelCellRect = labelCell.getCellRectangle();
    KVector nodeSize = port.getNode().getSize();
    LMargin nodeMargin = port.getNode().getMargin();
    KVector portPos = port.getPosition();
    KVector portAnchor = KVector.sum(portPos, port.getAnchor());
    // Calculate cell position depending on port side
    switch(port.getSide()) {
        case NORTH:
            labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
            labelCellRect.y = -nodeMargin.top - edgeLabelSpacing - labelCellRect.height;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
                labelCellRect.x = portAnchor.x - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.width;
            } else {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
                labelCellRect.x = portAnchor.x + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case EAST:
            labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
            labelCellRect.x = nodeSize.x + nodeMargin.right + edgeLabelSpacing;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
                labelCellRect.y = portAnchor.y - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.height;
            } else {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
                labelCellRect.y = portAnchor.y + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case SOUTH:
            labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
            labelCellRect.y = nodeSize.y + nodeMargin.bottom + edgeLabelSpacing;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
                labelCellRect.x = portAnchor.x - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.width;
            } else {
                labelCell.setHorizontalAlignment(HorizontalLabelAlignment.LEFT);
                labelCellRect.x = portAnchor.x + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
        case WEST:
            labelCell.setHorizontalAlignment(HorizontalLabelAlignment.RIGHT);
            labelCellRect.x = -nodeMargin.left - edgeLabelSpacing - labelCellRect.width;
            if (getLabelSide(labelCell) == LabelSide.ABOVE) {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.BOTTOM);
                labelCellRect.y = portAnchor.y - maxEdgeThickness(port) - edgeLabelSpacing - labelCellRect.height;
            } else {
                labelCell.setVerticalAlignment(VerticalLabelAlignment.TOP);
                labelCellRect.y = portAnchor.y + maxEdgeThickness(port) + edgeLabelSpacing;
            }
            break;
    }
}
Also used : LMargin(org.eclipse.elk.alg.layered.graph.LMargin) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector)

Example 37 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class DCComponent method update.

// /////////////////////////////////////////////////////////////////////////////
// Private method for updating internal state
/**
 * Updates the position and the dimensions of the bounding rectangle of this {@link DCComponent}. To be called
 * whenever the component has been modified and properties of the bounding rectangle are being requested.
 */
private void update() {
    changed = false;
    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (DCElement elem : shapes) {
        ElkRectangle elemBounds = elem.getBounds();
        minX = Math.min(minX, elemBounds.x);
        maxX = Math.max(maxX, elemBounds.x + elemBounds.width);
        minY = Math.min(minY, elemBounds.y);
        maxY = Math.max(maxY, elemBounds.y + elemBounds.height);
        for (DCExtension ext : elem.getExtensions()) {
            DCDirection dir = ext.getDirection();
            double minPos, maxPos;
            if (dir.isHorizontal()) {
                minPos = elemBounds.y + ext.getOffset().y;
                maxPos = minPos + ext.getWidth();
                minY = Math.min(minY, minPos);
                maxY = Math.max(maxY, maxPos);
            } else {
                minPos = elemBounds.x + ext.getOffset().x;
                maxPos = minPos + ext.getWidth();
                minX = Math.min(minX, minPos);
                maxX = Math.max(maxX, maxPos);
            }
        }
    }
    bounds = new KVector(maxX - minX, maxY - minY);
    minCornerOfBoundingRectangle = new KVector(minX + offset.x, minY + offset.y);
}
Also used : ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector)

Example 38 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle in project elk by eclipse.

the class DisCoGraphRenderer method renderComponentGraph.

// added by mic
/**
 * Paints all elements of the DCGraph that fall into the given dirty area.
 *
 * @param componentGraph
 *            The DCGraph to paint
 * @param graphics
 *            the graphics context used to paint
 * @param area
 *            dirty area that needs painting
 * @param offset
 *            offset to be added to relative coordinates
 * @param nodeAlpha
 *            alpha value for nodes
 * @param fillingAlpha
 *            alpha value for node fillings
 */
private void renderComponentGraph(final ElkNode parent, final DCGraph componentGraph, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha, final int fillingAlpha, final int levelNumber) {
    KVector boundaries = new KVector(parent.getWidth(), parent.getHeight());
    for (DCComponent comp : componentGraph.getComponents()) {
        for (DCElement el : comp.getElements()) {
            PaintPolygon poly = polygonMap.get(el);
            if (poly == null) {
                poly = new PaintPolygon(el, offset, getScale());
                polygonMap.put(el, poly);
            }
            if (!poly.painted && poly.intersects(area)) {
                // paint this node
                graphics.setAlpha(fillingAlpha);
                if (configurator.getDCElementFillColor() != null) {
                    graphics.setBackground(configurator.getDCElementFillColor());
                    graphics.fillPolygon(poly.coordsScaledAndRounded);
                }
                graphics.setAlpha(nodeAlpha);
                if (configurator.getDCElementBorderTextColor() != null) {
                    graphics.setForeground(configurator.getDCElementBorderTextColor());
                    graphics.drawPolygon(poly.coordsScaledAndRounded);
                    if (configurator.getNodeLabelFont() != null) {
                        graphics.setFont(configurator.getNodeLabelFont());
                    }
                    if (state.drawLabels()) {
                        String levelprefix = levelNumber + "_";
                        if (state.removeLvl()) {
                            levelprefix = "";
                        }
                        graphics.drawString(levelprefix + Integer.toString(comp.getId()), poly.coordsScaledAndRounded[0], poly.coordsScaledAndRounded[1], true);
                    }
                }
                poly.painted = true;
            }
            ElkRectangle bounds = el.getBounds();
            Rectangle2D.Double elementBounding = new Rectangle2D.Double(bounds.x, bounds.y, bounds.width, bounds.height);
            double offsetX = elementBounding.getX() + el.getOffset().x;
            double offsetY = elementBounding.getY() + el.getOffset().y;
            elementBounding = new Rectangle2D.Double(offsetX, offsetY, elementBounding.getWidth(), elementBounding.getHeight());
            for (DCExtension ext : el.getExtensions()) {
                PaintRectangle rect = dcExtensionMap.get(ext);
                if (rect == null) {
                    rect = new PaintRectangle(ext, elementBounding, boundaries, offset, getScale());
                    dcExtensionMap.put(ext, rect);
                }
                if (!rect.painted && rect.intersects(area)) {
                    graphics.setAlpha(fillingAlpha);
                    // CHECKSTYLEOFF MagicNumber
                    if (configurator.getDCElementExternalFillColor() != null) {
                        graphics.setBackgroundPattern(patterns.getDCExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
                        graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
                    }
                    // CHECKSTYLEON MagicNumber
                    graphics.setAlpha(nodeAlpha);
                    if (configurator.getNodeBorderColor() != null) {
                        graphics.setForeground(configurator.getDCElementExternalBorderTextColor());
                        graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
                    }
                    if (configurator.getDCElementExternalBorderTextColor() != null) {
                        graphics.setForeground(configurator.getDCElementExternalBorderTextColor());
                        if (configurator.getNodeLabelFont() != null) {
                            graphics.setFont(configurator.getNodeLabelFont());
                        }
                        if (state.drawLabels()) {
                            String levelprefix = levelNumber + "_";
                            if (state.removeLvl()) {
                                levelprefix = "";
                            }
                            graphics.drawString(levelprefix + Integer.toString(comp.getId()), rect.x, rect.y, true);
                        }
                    }
                    rect.painted = true;
                }
            }
        }
    }
}
Also used : DCComponent(org.eclipse.elk.alg.disco.graph.DCComponent) DCExtension(org.eclipse.elk.alg.disco.graph.DCExtension) Rectangle2D(java.awt.geom.Rectangle2D) DCElement(org.eclipse.elk.alg.disco.graph.DCElement) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 39 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle 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 40 with ElkRectangle

use of org.eclipse.elk.core.math.ElkRectangle 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

ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)82 KVector (org.eclipse.elk.core.math.KVector)33 Test (org.junit.Test)27 Direction (org.eclipse.elk.core.options.Direction)18 CGraph (org.eclipse.elk.alg.layered.compaction.oned.CGraph)17 ElkPadding (org.eclipse.elk.core.math.ElkPadding)9 PortContext (org.eclipse.elk.alg.common.nodespacing.internal.PortContext)8 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)7 CGroup (org.eclipse.elk.alg.layered.compaction.oned.CGroup)6 Point (org.eclipse.elk.alg.common.Point)4 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)4 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 ElkNode (org.eclipse.elk.graph.ElkNode)4 RectilinearConvexHull (org.eclipse.elk.alg.common.RectilinearConvexHull)3 AtomicCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.AtomicCell)3 RectangleStripOverlapRemover (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)3 LNode (org.eclipse.elk.alg.layered.graph.LNode)3 Random (java.util.Random)2