Search in sources :

Example 31 with InternalNode

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

the class HorizontalTreeLayoutAlgorithm method postLayoutAlgorithm.

@Override
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider) {
    // swap x->y and width->height
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode entity = entitiesToLayout[i];
        entity.setInternalLocation(entity.getInternalY(), entity.getInternalX());
        entity.setInternalSize(entity.getInternalWidth(), entity.getInternalHeight());
    }
    super.postLayoutAlgorithm(entitiesToLayout, relationshipsToConsider);
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 32 with InternalNode

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

the class SpringLayoutAlgorithm method preCompute.

private void preCompute(InternalNode[] entitiesToLayout) {
    // count number of relationships between all nodes and the average
    // weight between them
    srcDestToNumRels = new int[entitiesToLayout.length][entitiesToLayout.length];
    srcDestToRelsAvgWeight = new double[entitiesToLayout.length][entitiesToLayout.length];
    for (int i = 0; i < entitiesToLayout.length - 1; i++) {
        InternalNode layoutEntity1 = entitiesToLayout[i];
        for (int j = i + 1; j < entitiesToLayout.length; j++) {
            InternalNode layoutEntity2 = entitiesToLayout[j];
            srcDestToNumRels[i][j] = numRelations(layoutEntity1, layoutEntity2);
            srcDestToNumRels[i][j] += numRelations(layoutEntity2, layoutEntity1);
            srcDestToRelsAvgWeight[i][j] = avgWeight(layoutEntity1, layoutEntity2);
        }
    }
    if (sprRandom)
        // put vertices in random places
        placeRandomly(entitiesToLayout);
    else
        convertToUnitCoordinates(entitiesToLayout);
    iteration = 1;
    largestMovement = Double.MAX_VALUE;
}
Also used : InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 33 with InternalNode

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

the class SpringLayoutAlgorithm method computeForces.

// /////////////////////////////////////////////////////////////////
// /// Protected Methods /////
// /////////////////////////////////////////////////////////////////
/**
 * Computes the force for each node in this SpringLayoutAlgorithm. The
 * computed force will be stored in the data repository
 */
protected void computeForces(InternalNode[] entitiesToLayout) {
    // initialize all forces to zero
    for (int i = 0; i < entitiesToLayout.length; i++) {
        forcesX[i] = 0.0;
        forcesY[i] = 0.0;
    }
    for (int i = 0; i < entitiesToLayout.length - 1; i++) {
        InternalNode sourceEntity = entitiesToLayout[i];
        double srcLocationX = tempLocationsX[i];
        double srcLocationY = tempLocationsY[i];
        // force in x direction
        double fx = forcesX[i];
        // force in y direction
        double fy = forcesY[i];
        for (int j = i + 1; j < entitiesToLayout.length; j++) {
            InternalNode destinationEntity = entitiesToLayout[j];
            if (!destinationEntity.equals(sourceEntity)) {
                double destLocationX = tempLocationsX[j];
                double destLocationY = tempLocationsY[j];
                double dx = srcLocationX - destLocationX;
                double dy = srcLocationY - destLocationY;
                double distance = Math.sqrt(dx * dx + dy * dy);
                double distance_sq = distance * distance;
                // make sure distance and distance squared not too small
                distance = Math.max(MIN_DISTANCE, distance);
                // If there are relationships between srcObj and destObj
                // then decrease force on srcObj (a pull) in direction of destObj
                // If no relation between srcObj and destObj then increase
                // force on srcObj (a push) from direction of destObj.
                int numRels = srcDestToNumRels[i][j];
                double avgWeight = srcDestToRelsAvgWeight[i][j];
                if (numRels > 0) {
                    // nodes are pulled towards each other
                    double f = sprStrain * Math.log(distance / sprLength) * numRels * avgWeight;
                    fx = fx - (f * dx / distance);
                    fy = fy - (f * dy / distance);
                } else {
                    // nodes are repelled from each other
                    // double f = Math.min(100, sprGravitation / (distance*distance));
                    double f = sprGravitation / (distance_sq);
                    fx = fx + (f * dx / distance);
                    fy = fy + (f * dy / distance);
                }
                // According to Newton, "for every action, there is an equal
                // and opposite reaction."
                // so give the dest an opposite force
                forcesX[j] = forcesX[j] - fx;
                forcesY[j] = forcesY[j] - fy;
            }
        }
        /*
             * //make sure forces aren't too big if (fx > 0 ) fx = Math.min(fx,
             * 10*sprMove); else fx = Math.max(fx, -10*sprMove); if (fy > 0) fy =
             * Math.min(fy, 10*sprMove); else fy = Math.max(fy, -10*sprMove);
             */
        forcesX[i] = fx;
        forcesY[i] = fy;
    // Remove the src object from the list of destinations since
    // we've already calculated the force from it on all other
    // objects.
    // dests.remove(srcObj);
    }
}
Also used : 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