Search in sources :

Example 6 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class RadialLayoutAlgorithm method determineCenterPoint.

/**
 * Find the center point between the roots
 */
private DisplayIndependentPoint determineCenterPoint(List roots) {
    double totalX = 0, totalY = 0;
    for (Iterator iterator = roots.iterator(); iterator.hasNext(); ) {
        InternalNode entity = (InternalNode) iterator.next();
        totalX += entity.getInternalX();
        totalY += entity.getInternalY();
    }
    return new DisplayIndependentPoint(totalX / roots.size(), totalY / roots.size());
}
Also used : DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) Iterator(java.util.Iterator) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 7 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class RadialLayoutAlgorithm method computeRadialPositions.

/**
 * Take the tree and make it round.  This is done by determining the location of each entity in terms
 * of its percentage in the tree layout.  Then apply that percentage to the radius and distance from
 * the center.
 */
protected void computeRadialPositions(InternalNode[] entities, DisplayIndependentRectangle bounds2) {
    // TODO TODO TODO
    DisplayIndependentRectangle bounds = new DisplayIndependentRectangle(getLayoutBounds(entities, true));
    bounds.height = bounds2.height;
    bounds.y = bounds2.y;
    for (int i = 0; i < entities.length; i++) {
        InternalNode entity = entities[i];
        double percentTheta = (entity.getInternalX() - bounds.x) / bounds.width;
        double distance = (entity.getInternalY() - bounds.y) / bounds.height;
        double theta = startDegree + Math.abs(endDegree - startDegree) * percentTheta;
        double newX = distance * Math.cos(theta);
        double newY = distance * Math.sin(theta);
        entity.setInternalLocation(newX, newY);
    }
}
Also used : DisplayIndependentRectangle(org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)

Example 8 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.

@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    HashMap mapping = new HashMap(entitiesToLayout.length);
    DirectedGraph graph = new DirectedGraph();
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode internalNode = entitiesToLayout[i];
        Node node = new Node(internalNode);
        node.setSize(new Dimension(10, 10));
        mapping.put(internalNode, node);
        graph.nodes.add(node);
    }
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        Node source = (Node) mapping.get(relationship.getSource());
        Node dest = (Node) mapping.get(relationship.getDestination());
        Edge edge = new Edge(relationship, source, dest);
        graph.edges.add(edge);
    }
    DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
    directedGraphLayout.visit(graph);
    for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
        Node node = (Node) iterator.next();
        InternalNode internalNode = (InternalNode) node.data;
        // For horizontal layout transpose the x and y coordinates
        if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
            internalNode.setInternalLocation(node.y, node.x);
        } else {
            internalNode.setInternalLocation(node.x, node.y);
        }
    }
    updateLayoutLocations(entitiesToLayout);
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) DirectedGraphLayout(org.eclipse.draw2d.graph.DirectedGraphLayout) HashMap(java.util.HashMap) Node(org.eclipse.draw2d.graph.Node) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Iterator(java.util.Iterator) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Dimension(org.eclipse.draw2d.geometry.Dimension) Edge(org.eclipse.draw2d.graph.Edge)

Example 9 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class SpringLayoutAlgorithm method convertToUnitCoordinates.

/**
 * Converts the position for each node in this SpringLayoutAlgorithm
 * to unit coordinates in double precision. The computed positions will be
 * still stored in the data repository.
 */
protected void convertToUnitCoordinates(InternalNode[] entitiesToLayout) {
    double minX = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = Double.MIN_VALUE;
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode layoutEntity = entitiesToLayout[i];
        minX = Math.min(minX, layoutEntity.getInternalX());
        minY = Math.min(minY, layoutEntity.getInternalY());
        maxX = Math.max(maxX, layoutEntity.getInternalX());
        maxY = Math.max(maxY, layoutEntity.getInternalY());
    }
    double spanX = maxX - minX;
    double spanY = maxY - minY;
    double maxSpan = Math.max(spanX, spanY);
    if (maxSpan > EPSILON) {
        for (int i = 0; i < entitiesToLayout.length; i++) {
            InternalNode layoutEntity = entitiesToLayout[i];
            double x = (layoutEntity.getInternalX() - minX) / spanX;
            double y = (layoutEntity.getInternalY() - minY) / spanY;
            tempLocationsX[i] = x;
            tempLocationsY[i] = y;
        }
    } else {
        placeRandomly(entitiesToLayout);
    }
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 10 with InternalNode

use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.

the class SpringLayoutAlgorithm method checkPreferredLocation.

private void checkPreferredLocation(InternalNode[] entitiesToLayout, DisplayIndependentRectangle realBounds) {
    // use 10% for the border - 5% on each side
    double borderWidth = Math.min(realBounds.width, realBounds.height) / 10.0;
    DisplayIndependentRectangle screenBounds = new DisplayIndependentRectangle(realBounds.x + borderWidth / 2.0, realBounds.y + borderWidth / 2.0, realBounds.width - borderWidth, realBounds.height - borderWidth);
    DisplayIndependentRectangle layoutBounds = getLayoutBoundsTemp(entitiesToLayout, false);
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode layoutEntity = entitiesToLayout[i];
        if (layoutEntity.hasPreferredLocation()) {
            convertNodePositionsBack(i, layoutEntity, layoutEntity.getPreferredX(), layoutEntity.getPreferredY(), screenBounds.width, screenBounds.height, layoutBounds);
        }
    }
}
Also used : DisplayIndependentRectangle(org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Aggregations

InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)33 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)11 List (java.util.List)10 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)9 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)9 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)9 DisplayIndependentRectangle (org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle)5 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)3 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 DirectedGraph (org.eclipse.draw2d.graph.DirectedGraph)1 DirectedGraphLayout (org.eclipse.draw2d.graph.DirectedGraphLayout)1 Edge (org.eclipse.draw2d.graph.Edge)1 Node (org.eclipse.draw2d.graph.Node)1 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)1