Search in sources :

Example 21 with InternalNode

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

the class TreeLayoutAlgorithm method getNumDescendentsAndLevelRecursive.

private void getNumDescendentsAndLevelRecursive(InternalNode layoutEntity, InternalRelationship[] relationships, Set seenAlready, int[] numDescendentsAndLevel, int currentLevel) {
    if (seenAlready.contains(layoutEntity)) {
        return;
    }
    seenAlready.add(layoutEntity);
    numDescendentsAndLevel[NUM_LEVELS_INDEX] = Math.max(numDescendentsAndLevel[NUM_LEVELS_INDEX], currentLevel);
    Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
    for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
        InternalRelationship layoutRel = (InternalRelationship) iter.next();
        InternalNode childEntity = layoutRel.getDestination();
        numDescendentsAndLevel[NUM_DESCENDENTS_INDEX]++;
        getNumDescendentsAndLevelRecursive(childEntity, relationships, seenAlready, numDescendentsAndLevel, currentLevel + 1);
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) Iterator(java.util.Iterator) Collection(java.util.Collection) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 22 with InternalNode

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

the class TreeLayoutAlgorithm method modifyWeightRecursively.

/**
 * Modifies the weight value of the marked node recursively.
 */
private void modifyWeightRecursively(InternalNode layoutEntity, int i, double weight, Set descendentsSeenSoFar, InternalNode[] entities, InternalRelationship[] relationships) {
    // No need to do further computation!
    if (layoutEntity == null) {
        return;
    }
    if (descendentsSeenSoFar.contains(layoutEntity)) {
        // No need to do further computation.
        return;
    }
    descendentsSeenSoFar.add(layoutEntity);
    // No need to do further computation!
    if (weight < weights[i]) {
        return;
    }
    weights[i] = weight;
    Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
    for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
        InternalRelationship tmpRel = (InternalRelationship) iter.next();
        InternalNode tmpEntity = tmpRel.getDestination();
        int tmpEntityIndex = indexOfInternalNode(entities, tmpEntity);
        modifyWeightRecursively(tmpEntity, tmpEntityIndex, weight + 1, descendentsSeenSoFar, entities, relationships);
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) Iterator(java.util.Iterator) Collection(java.util.Collection) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 23 with InternalNode

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

the class TreeLayoutAlgorithm method getMaxiumWeightRecursive.

/**
 * Gets the maxium weight of a tree in the forest of this TreeLayoutAlgorithm.
 */
private double getMaxiumWeightRecursive(InternalNode layoutEntity, int i, Set seenAlready, InternalNode[] entities) {
    double result = 0;
    if (seenAlready.contains(layoutEntity)) {
        return result;
    }
    seenAlready.add(layoutEntity);
    List children = childrenLists[i];
    if (children.isEmpty()) {
        result = weights[i];
    } else {
        // TODO: SLOW
        for (Iterator iter = children.iterator(); iter.hasNext(); ) {
            InternalNode childEntity = (InternalNode) iter.next();
            int childEntityIndex = indexOfInternalNode(entities, childEntity);
            result = Math.max(result, getMaxiumWeightRecursive(childEntity, childEntityIndex, seenAlready, entities));
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 24 with InternalNode

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

the class TreeLayoutAlgorithm method computePositions.

/**
 * Computes positions for each node in this TreeLayoutAlgorithm by
 * referencing the forest that holds those nodes.
 */
private void computePositions(List roots, InternalNode[] entities) {
    // No need to do further computation!
    if (roots.size() == 0) {
        return;
    }
    int totalLeafCount = 0;
    double maxWeight = 0;
    for (int i = 0; i < roots.size(); i++) {
        InternalNode rootEntity = (InternalNode) roots.get(i);
        int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
        totalLeafCount = totalLeafCount + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
        maxWeight = Math.max(maxWeight, getMaxiumWeightRecursive(rootEntity, rootEntityIndex, new HashSet(), entities) + 1.0);
    }
    double width = 1.0 / totalLeafCount;
    double height = 1.0 / maxWeight;
    int leafCountSoFar = 0;
    // TODO: SLOW!
    for (int i = 0; i < roots.size(); i++) {
        InternalNode rootEntity = (InternalNode) roots.get(i);
        int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
        computePositionRecursively(rootEntity, rootEntityIndex, leafCountSoFar, width, height, new HashSet(), entities);
        leafCountSoFar = leafCountSoFar + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
    }
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) HashSet(java.util.HashSet)

Example 25 with InternalNode

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

the class TreeLayoutAlgorithm method computePositionRecursively.

/**
 * Computes positions recursively until the leaf nodes are reached.
 */
private void computePositionRecursively(InternalNode layoutEntity, int i, int relativePosition, double width, double height, Set seenAlready, InternalNode[] entities) {
    if (seenAlready.contains(layoutEntity)) {
        return;
    }
    seenAlready.add(layoutEntity);
    double level = getLevel(layoutEntity, i, entities);
    int breadth = getNumberOfLeaves(layoutEntity, i, entities);
    double absHPosition = relativePosition + breadth / 2.0;
    double absVPosition = (level + 0.5);
    double posx = absHPosition * width;
    double posy = absVPosition * height;
    double weight = weights[i];
    posy = posy + height * (weight - level);
    layoutEntity.setInternalLocation(posx, posy);
    int relativeCount = 0;
    List children = childrenLists[i];
    // TODO: Slow
    for (Iterator iter = children.iterator(); iter.hasNext(); ) {
        InternalNode childEntity = (InternalNode) iter.next();
        int childEntityIndex = indexOfInternalNode(entities, childEntity);
        computePositionRecursively(childEntity, childEntityIndex, relativePosition + relativeCount, width, height, seenAlready, entities);
        relativeCount = relativeCount + getNumberOfLeaves(childEntity, childEntityIndex, entities);
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) 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