Search in sources :

Example 1 with Triple

use of org.eclipse.elk.core.util.Triple in project elk by eclipse.

the class Issue682Test method testGraph.

public Triple<ElkNode, ElkNode, ElkLabel> testGraph() {
    ElkNode graph = ElkGraphUtil.createGraph();
    graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    graph.setProperty(LayeredOptions.DIRECTION, layoutDirection);
    graph.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(21, 32, 43, 54));
    ElkNode parent = ElkGraphUtil.createNode(graph);
    parent.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.NODE_LABELS));
    parent.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter());
    ElkLabel label = ElkGraphUtil.createLabel("foobar", parent);
    // Arbitrary
    label.setWidth(23);
    label.setHeight(22);
    return new Triple<>(graph, parent, label);
}
Also used : Triple(org.eclipse.elk.core.util.Triple) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 2 with Triple

use of org.eclipse.elk.core.util.Triple in project elk by eclipse.

the class DisCoGraphRenderer method renderPolyominoes.

// added by mic
/**
 * Paints all polyominoes that fall into the given dirty area.
 *
 * @param polys
 *            the polyominoes 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 renderPolyominoes(final ElkNode parent, final List<DCPolyomino> polys, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha, final int fillingAlpha, final int levelNumber) {
    for (DCPolyomino poly : polys) {
        KVector polyCorner = poly.getMinCornerOnCanvas();
        double topLeftCornerX = polyCorner.x;
        double topLeftCornerY = polyCorner.y;
        double cellSizeX = poly.getCellSizeX();
        double cellSizeY = poly.getCellSizeY();
        double bottomRightCornerX = topLeftCornerX + cellSizeX * poly.getWidth();
        double bottomRightCornerY = topLeftCornerY + cellSizeY * poly.getHeight();
        for (int x = 0; x < poly.getWidth(); x++) {
            for (int y = 0; y < poly.getHeight(); y++) {
                Triple<Polyomino, Integer, Integer> polyoCell = new Triple<Polyomino, Integer, Integer>(poly, x, y);
                PaintRectangle rect = polyominoMap.get(polyoCell);
                if (rect == null) {
                    rect = new PaintRectangle(topLeftCornerX, topLeftCornerY, cellSizeX, cellSizeY, x, y, offset, getScale());
                    polyominoMap.put(polyoCell, rect);
                }
                if (!rect.painted && rect.intersects(area)) {
                    // paint this node
                    graphics.setAlpha(fillingAlpha);
                    if (configurator.getPolyominoFillColor() != null && poly.isBlocked(x, y)) {
                        graphics.setBackground(configurator.getPolyominoFillColor());
                        graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
                        if (configurator.getNodeLabelFont() != null) {
                            graphics.setFont(configurator.getNodeLabelFont());
                        }
                        graphics.setAlpha(nodeAlpha);
                        graphics.setForeground(configurator.getPolyominoBorderTextColor());
                        if (state.drawLabels()) {
                            String levelprefix = levelNumber + "_";
                            if (state.removeLvl()) {
                                levelprefix = "";
                            }
                            graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
                        }
                    }
                    if (configurator.getPolyominoFillColor() != null && poly.isWeaklyBlocked(x, y)) {
                        // CHECKSTYLEOFF MagicNumber
                        graphics.setBackgroundPattern(patterns.getPolyominoExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
                        // CHECKSTYLEON MagicNumber
                        graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
                        graphics.setAlpha(nodeAlpha);
                        graphics.setForeground(configurator.getPolyominoWeaklyBlockedBorderTextColor());
                        graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
                        if (configurator.getNodeLabelFont() != null) {
                            graphics.setFont(configurator.getNodeLabelFont());
                        }
                        graphics.setAlpha(nodeAlpha);
                        if (state.drawLabels()) {
                            String levelprefix = levelNumber + "_";
                            if (state.removeLvl()) {
                                levelprefix = "";
                            }
                            graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
                        }
                    }
                    graphics.setAlpha(nodeAlpha);
                    if (configurator.getPolyominoBorderTextColor() != null && !poly.isWeaklyBlocked(x, y)) {
                        graphics.setForeground(configurator.getPolyominoBorderTextColor());
                        if (state.drawPolyLinesBlack()) {
                            graphics.setForeground(configurator.getBlack());
                        }
                        graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
                    }
                    rect.painted = true;
                }
            }
        }
        if (state.markTheCenter()) {
            int x = poly.getCenterX();
            int y = poly.getCenterY();
            PaintRectangle centerRect = polyominoCenterMap.get(poly);
            if (centerRect == null) {
                centerRect = new PaintRectangle(topLeftCornerX, topLeftCornerY, cellSizeX, cellSizeY, x, y, offset, getScale());
                polyominoCenterMap.put(poly, centerRect);
            }
            if (configurator.getPolyominoFillColor() != null) {
                // CHECKSTYLEOFF MagicNumber
                graphics.setBackgroundPattern(patterns.getPolyominoCenterPattern(state.makeSolid() ? 255 : fillingAlpha));
                // CHECKSTYLEON MagicNumber
                graphics.fillRectangle(centerRect.x, centerRect.y, centerRect.width, centerRect.height);
                graphics.setAlpha(nodeAlpha);
            }
        }
        for (UniqueTriple<Direction, Integer, Integer> ext : poly.getPolyominoExtensions()) {
            PaintRectangle rect = polyominoExtensionMap.get(ext);
            if (rect == null) {
                Direction dir = ext.getFirst();
                int extStart = ext.getSecond();
                int extEnd = ext.getThird();
                switch(dir) {
                    case NORTH:
                        rect = new PaintRectangle(topLeftCornerX + extStart * cellSizeX, 0, (extEnd - extStart + 1) * cellSizeX, topLeftCornerY, offset, getScale());
                        break;
                    case SOUTH:
                        rect = new PaintRectangle(topLeftCornerX + extStart * cellSizeX, bottomRightCornerY, (extEnd - extStart + 1) * cellSizeX, parent.getHeight() - bottomRightCornerY, offset, getScale());
                        break;
                    case WEST:
                        rect = new PaintRectangle(0, topLeftCornerY + extStart * cellSizeY, topLeftCornerX, (extEnd - extStart + 1) * cellSizeY, offset, getScale());
                        break;
                    default:
                        // EAST
                        rect = new PaintRectangle(bottomRightCornerX, topLeftCornerY + extStart * cellSizeY, parent.getWidth() - bottomRightCornerX, (extEnd - extStart + 1) * cellSizeY, offset, getScale());
                        break;
                }
                // Maybe not unique in extreme cases where extensions
                // are very close to each other, but it doesn't matter
                // for the drawing
                polyominoExtensionMap.put(ext, rect);
            }
            graphics.setAlpha(fillingAlpha);
            // CHECKSTYLEOFF MagicNumber
            graphics.setBackgroundPattern(patterns.getPolyominoExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
            // CHECKSTYLEON MagicNumber
            graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
            graphics.setAlpha(nodeAlpha);
            graphics.setForeground(configurator.getPolyominoWeaklyBlockedBorderTextColor());
            graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
            if (configurator.getNodeLabelFont() != null) {
                graphics.setFont(configurator.getNodeLabelFont());
            }
            graphics.setAlpha(nodeAlpha);
            if (state.drawLabels()) {
                String levelprefix = levelNumber + "_";
                if (state.removeLvl()) {
                    levelprefix = "";
                }
                graphics.drawString(levelprefix + Integer.toString(poly.getId()), rect.x, rect.y, true);
            }
        }
    }
}
Also used : Triple(org.eclipse.elk.core.util.Triple) UniqueTriple(org.eclipse.elk.alg.common.utils.UniqueTriple) DCPolyomino(org.eclipse.elk.alg.disco.structures.DCPolyomino) KVector(org.eclipse.elk.core.math.KVector) Direction(org.eclipse.elk.alg.common.polyomino.structures.Direction) DCDirection(org.eclipse.elk.alg.disco.graph.DCDirection) DCPolyomino(org.eclipse.elk.alg.disco.structures.DCPolyomino) Polyomino(org.eclipse.elk.alg.common.polyomino.structures.Polyomino)

Example 3 with Triple

use of org.eclipse.elk.core.util.Triple in project elk by eclipse.

the class Issue680Test method testGraph.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
public Triple<ElkNode, ElkNode, ElkNode> testGraph() {
    ElkNode graph = ElkGraphUtil.createGraph();
    graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    graph.setProperty(LayeredOptions.DIRECTION, Direction.DOWN);
    ElkNode parent = ElkGraphUtil.createNode(graph);
    parent.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    parent.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    parent.setProperty(LayeredOptions.DIRECTION, Direction.DOWN);
    ElkPort p1 = ElkGraphUtil.createPort(parent);
    p1.setWidth(15);
    p1.setHeight(165);
    p1.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -20.0);
    ElkPort p2 = ElkGraphUtil.createPort(parent);
    p2.setWidth(15);
    p2.setHeight(166);
    p2.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -22.0);
    ElkNode child = ElkGraphUtil.createNode(parent);
    child.setWidth(40.265625);
    child.setHeight(75.5);
    ElkPort childP1 = ElkGraphUtil.createPort(child);
    childP1.setWidth(15);
    childP1.setHeight(33);
    childP1.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -8.0);
    ElkPort childP2 = ElkGraphUtil.createPort(child);
    childP2.setWidth(15);
    childP2.setHeight(34);
    childP2.setProperty(LayeredOptions.PORT_BORDER_OFFSET, -8.0);
    ElkGraphUtil.createSimpleEdge(p1, childP1);
    ElkGraphUtil.createSimpleEdge(childP2, p2);
    return new Triple<>(graph, parent, child);
}
Also used : Triple(org.eclipse.elk.core.util.Triple) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort)

Aggregations

Triple (org.eclipse.elk.core.util.Triple)3 ElkNode (org.eclipse.elk.graph.ElkNode)2 Direction (org.eclipse.elk.alg.common.polyomino.structures.Direction)1 Polyomino (org.eclipse.elk.alg.common.polyomino.structures.Polyomino)1 UniqueTriple (org.eclipse.elk.alg.common.utils.UniqueTriple)1 DCDirection (org.eclipse.elk.alg.disco.graph.DCDirection)1 DCPolyomino (org.eclipse.elk.alg.disco.structures.DCPolyomino)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 KVector (org.eclipse.elk.core.math.KVector)1 ElkLabel (org.eclipse.elk.graph.ElkLabel)1 ElkPort (org.eclipse.elk.graph.ElkPort)1