Search in sources :

Example 1 with Direction

use of org.eclipse.elk.alg.common.polyomino.structures.Direction in project elk by eclipse.

the class DCPolyomino method addExtensionsToPoly.

/**
 * Adds extenstions to this polyomino taken from a {@link DCElement} of the component it represents.
 *
 * @param elem
 *            an element of the component this polyomino represents
 */
private void addExtensionsToPoly(final DCElement elem) {
    List<DCExtension> extensions = elem.getExtensions();
    KVector compCorner = representee.getMinCorner();
    KVector polyoOffset = getOffset();
    double baseX = compCorner.x - polyoOffset.x;
    double baseY = compCorner.y - polyoOffset.y;
    ElkRectangle elemPos = elem.getBounds();
    baseX = elemPos.x - baseX;
    baseY = elemPos.y - baseY;
    for (DCExtension extension : extensions) {
        KVector pos = extension.getOffset();
        double xe = baseX + pos.x;
        double ye = baseY + pos.y;
        int xp = (int) (xe / cellSizeX);
        int yp = (int) (ye / cellSizeY);
        DCDirection dir = extension.getDirection();
        Direction polyDir;
        switch(dir) {
            case NORTH:
                polyDir = Direction.NORTH;
                break;
            case EAST:
                polyDir = Direction.EAST;
                break;
            case SOUTH:
                polyDir = Direction.SOUTH;
                break;
            default:
                polyDir = Direction.WEST;
        }
        if (dir.isHorizontal()) {
            int ypPlusWidth = (int) ((ye + extension.getWidth()) / cellSizeY);
            addExtension(polyDir, yp, ypPlusWidth);
            if (dir.equals(DCDirection.WEST)) {
                weaklyBlockArea(0, yp, xp, ypPlusWidth);
            } else {
                // direction is EAST
                weaklyBlockArea(xp, yp, pWidth - 1, ypPlusWidth);
            }
        } else {
            // direction is vertical
            int xpPlusWidth = (int) ((xe + extension.getWidth()) / cellSizeX);
            addExtension(polyDir, xp, xpPlusWidth);
            if (dir.equals(DCDirection.NORTH)) {
                weaklyBlockArea(xp, 0, xpPlusWidth, yp);
            } else {
                // direction is SOUTH
                weaklyBlockArea(xp, yp, xpPlusWidth, pHeight - 1);
            }
        }
    }
}
Also used : DCExtension(org.eclipse.elk.alg.disco.graph.DCExtension) DCDirection(org.eclipse.elk.alg.disco.graph.DCDirection) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) DCDirection(org.eclipse.elk.alg.disco.graph.DCDirection) Direction(org.eclipse.elk.alg.common.polyomino.structures.Direction)

Example 2 with Direction

use of org.eclipse.elk.alg.common.polyomino.structures.Direction 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)

Aggregations

Direction (org.eclipse.elk.alg.common.polyomino.structures.Direction)2 DCDirection (org.eclipse.elk.alg.disco.graph.DCDirection)2 KVector (org.eclipse.elk.core.math.KVector)2 Polyomino (org.eclipse.elk.alg.common.polyomino.structures.Polyomino)1 UniqueTriple (org.eclipse.elk.alg.common.utils.UniqueTriple)1 DCExtension (org.eclipse.elk.alg.disco.graph.DCExtension)1 DCPolyomino (org.eclipse.elk.alg.disco.structures.DCPolyomino)1 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)1 Triple (org.eclipse.elk.core.util.Triple)1