Search in sources :

Example 1 with DCGraph

use of org.eclipse.elk.alg.disco.graph.DCGraph in project elk by eclipse.

the class ElkGraphTransformer method importGraph.

// /////////////////////////////////////////////////////////////////////////////
// Implementation of interface methods
@Override
public DCGraph importGraph(final ElkNode graph) {
    parent = graph;
    // Split graph into components
    List<List<ElkNode>> components = ElkGraphComponentsProcessor.split(graph);
    // This list of lists is used to construct the DCGraph from its smallest units, so called DCElements.
    List<List<DCElement>> result = Lists.newArrayList();
    for (List<ElkNode> component : components) {
        // Each of the subResult lists will represent a connected component in the DCGraph.
        List<DCElement> subResult = Lists.newArrayList();
        result.add(subResult);
        Set<ElkEdge> edgeSet = Sets.newHashSet();
        for (ElkNode node : component) {
            // "true" indicates - we need to consider the position of ElkNodes when applying the new layout of the
            // DCGraph back to the KGraph.
            DCElement componentNode = importElkShape(node, true, 0.0f, 0.0f);
            subResult.add(componentNode);
            // Compute offset for labels (used for computing absolute position)
            double nodeX = node.getX();
            double nodeY = node.getY();
            // For use in the Debugview only
            componentNode.setParentCoords(new KVector(nodeX, nodeY));
            // next look at all labels of this ElkNode ...
            List<ElkLabel> labels = node.getLabels();
            for (ElkLabel label : labels) {
                // "false" indicates - ElkLabels belonging to nodes have coordinates relative to their ElkNode. So
                // don't
                // adjust their position when applying the layout of the DCGraph back to the KGraph.
                DCElement componentLabel = importElkShape(label, false, nodeX, nodeY);
                subResult.add(componentLabel);
            }
            // ... then the ports of the ElkNode
            List<ElkPort> ports = node.getPorts();
            for (ElkPort port : ports) {
                // "false" - ElkPorts have coordinates relative to their ElkNode
                DCElement componentPort = importElkShape(port, false, nodeX, nodeY);
                subResult.add(componentPort);
                // ElkPorts can have labels, too!
                // Compute offset for labels of ElkPorts
                double portX = port.getX() + nodeX;
                double portY = port.getY() + nodeY;
                labels = port.getLabels();
                for (ElkLabel label : labels) {
                    // false - ElkLabels have coordinates relative to their ElkPort
                    DCElement componentLabel = importElkShape(label, false, portX, portY);
                    subResult.add(componentLabel);
                }
            }
            edgeSet.addAll(Sets.newHashSet(ElkGraphUtil.allIncidentEdges(node)));
        }
        importElkEdges(edgeSet, subResult);
    }
    // Finally create the DCGraph
    transformedGraph = new DCGraph(result, componentSpacing / 2);
    // Don't forget to copy properties of parent ElkNode to the DCGraph
    transformedGraph.copyProperties(graph);
    return transformedGraph;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) DCElement(org.eclipse.elk.alg.disco.graph.DCElement) ElkLabel(org.eclipse.elk.graph.ElkLabel) DCGraph(org.eclipse.elk.alg.disco.graph.DCGraph) List(java.util.List) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 2 with DCGraph

use of org.eclipse.elk.alg.disco.graph.DCGraph in project elk by eclipse.

the class DisCoGraphRenderer method renderRecursively.

private void renderRecursively(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha, final int fillingAlpha, final int levelNumber) {
    /**
     * by mic: the associated graph of connected components
     */
    DCGraph componentGraph = (DCGraph) parent.getProperty(DisCoOptions.DEBUG_DISCO_GRAPH);
    int lowerLvl = state.getLowerLvl();
    int upperLvl = state.getUpperLvl();
    if ((paintElkGraph && levelNumber >= lowerLvl && levelNumber <= upperLvl) || (state.drawGhostParent() && levelNumber == 0)) {
        Set<ElkEdge> edgeSet = new HashSet<ElkEdge>();
        // render the nodes and ports
        if (lowerLvl > 0 && state.drawGhostParent() && levelNumber == 0) {
            renderNodeChildren(parent, graphics, area, offset, edgeSet, nodeAlpha, 0);
        } else {
            renderNodeChildren(parent, graphics, area, offset, edgeSet, nodeAlpha, fillingAlpha);
        }
        // render the edges
        for (ElkEdge edge : edgeSet) {
            renderEdge(parent, edge, graphics, area, offset, nodeAlpha);
        }
    }
    if (paintDCGraph && componentGraph != null && levelNumber >= lowerLvl && levelNumber <= upperLvl) {
        renderComponentGraph(parent, componentGraph, graphics, area, offset, nodeAlpha, fillingAlpha, levelNumber);
    }
    if (paintPolys && levelNumber >= lowerLvl && levelNumber <= upperLvl) {
        // by mic: low resolution polyominos generated from the graph of
        // connected components
        @SuppressWarnings("unchecked") List<DCPolyomino> polys = (List<DCPolyomino>) parent.getProperty(DisCoOptions.DEBUG_DISCO_POLYS);
        if (polys != null) {
            renderPolyominoes(parent, polys, graphics, area, offset, nodeAlpha, fillingAlpha, levelNumber);
        }
    }
    for (ElkNode child : parent.getChildren()) {
        // compute the offset required to make the children's
        KVector contentOffset = new KVector(child.getX() * getScale(), child.getY() * getScale());
        contentOffset.add(offset);
        renderRecursively(child, graphics, area, contentOffset, nodeAlpha, fillingAlpha, levelNumber + 1);
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) DCGraph(org.eclipse.elk.alg.disco.graph.DCGraph) DCPolyomino(org.eclipse.elk.alg.disco.structures.DCPolyomino) List(java.util.List) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge) HashSet(java.util.HashSet)

Example 3 with DCGraph

use of org.eclipse.elk.alg.disco.graph.DCGraph in project elk by eclipse.

the class DisCoGraphRenderer method render.

// ////////////////////////////////////////////////////////////////////////////////////////////////
// Rendering Code
/**
 * Paints the contained layout graph onto the given graphics object.
 *
 * @param parentNode
 *            the parent node that shall be rendered
 * @param graphics
 *            the graphics context used to paint
 * @param area
 *            the area to fill
 */
public void render(final ElkNode parentNode, final GC graphics, final Rectangle area) {
    int oldLineWidth = graphics.getLineWidth();
    graphics.setLineWidth((int) (scale * state.getThicknessScale()));
    /**
     * by mic: the associated graph of connected components
     */
    DCGraph componentGraph = (DCGraph) parentNode.getProperty(DisCoOptions.DEBUG_DISCO_GRAPH);
    if (mostRecentlyDrawnGraph != parentNode) {
        flushCache();
        mostRecentlyDrawnGraph = parentNode;
    }
    // activate interpolation
    graphics.setInterpolation(SWT.HIGH);
    // determine an overall alpha value for nodes, depending on the
    // maximal node depth
    int maxDepth = Math.max(maxDepth(parentNode), 1);
    state.setDepth(maxDepth);
    // CHECKSTYLEOFF MagicNumber
    int nodeAlpha = 200 / maxDepth + 55;
    // by mic: all elements drawn will be quite transparent, so that the
    // user can see the different layers (graph, DCCGraph und polyomino
    // cells) stacked on top of each other.
    int fillingAlpha = 40 / maxDepth + 55;
    if (state.makeSolid()) {
        nodeAlpha = 0xff;
    }
    if (componentGraph == null) {
        savePaintDCGraph = Boolean.valueOf(paintDCGraph);
        paintDCGraph = false;
        savePaintPolys = Boolean.valueOf(paintPolys);
        paintPolys = false;
    } else {
        if (savePaintDCGraph != null) {
            paintDCGraph = savePaintDCGraph.booleanValue();
            savePaintDCGraph = null;
        }
        if (savePaintPolys != null) {
            paintPolys = savePaintPolys.booleanValue();
            savePaintPolys = null;
        }
    }
    renderRecursively(parentNode, graphics, area, baseOffset, nodeAlpha, fillingAlpha, 0);
    if (componentGraph == null) {
        graphics.setForeground(configurator.getBlack());
        graphics.drawString("No layout algorithm for connected components has been used.", 0, 0, true);
    }
    graphics.setLineWidth(oldLineWidth);
}
Also used : DCGraph(org.eclipse.elk.alg.disco.graph.DCGraph)

Aggregations

DCGraph (org.eclipse.elk.alg.disco.graph.DCGraph)3 List (java.util.List)2 KVector (org.eclipse.elk.core.math.KVector)2 ElkEdge (org.eclipse.elk.graph.ElkEdge)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 HashSet (java.util.HashSet)1 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)1 DCPolyomino (org.eclipse.elk.alg.disco.structures.DCPolyomino)1 ElkLabel (org.eclipse.elk.graph.ElkLabel)1 ElkPort (org.eclipse.elk.graph.ElkPort)1