Search in sources :

Example 6 with InternalRelationship

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

the class AbstractLayoutAlgorithm method createInternalRelationships.

/**
 * Creates a list of InternalRelationship objects from the given list of LayoutRelationship objects.
 * @param rels
 * @return List of internal relationships
 */
private InternalRelationship[] createInternalRelationships(LayoutRelationship[] rels) {
    ArrayList listOfInternalRelationships = new ArrayList(rels.length);
    for (int i = 0; i < rels.length; i++) {
        LayoutRelationship relation = rels[i];
        InternalNode src = (InternalNode) relation.getSourceInLayout().getLayoutInformation();
        InternalNode dest = (InternalNode) relation.getDestinationInLayout().getLayoutInformation();
        if ((src != null) && (dest != null)) {
            InternalRelationship internalRelationship = new InternalRelationship(relation, src, dest);
            listOfInternalRelationships.add(internalRelationship);
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new RuntimeException("Error creating internal relationship, one of the nodes is null: src=" + src + ", dest=" + dest);
        }
    }
    InternalRelationship[] internalRelationships = new InternalRelationship[listOfInternalRelationships.size()];
    listOfInternalRelationships.toArray(internalRelationships);
    return internalRelationships;
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship)

Example 7 with InternalRelationship

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

the class AbstractLayoutAlgorithm method updateBendPoints.

/**
 * Update external bend points from the internal bendpoints list. Save the
 * source and destination points for later use in scaling and translating
 * @param relationshipsToConsider
 */
protected void updateBendPoints(InternalRelationship[] relationshipsToConsider) {
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        List bendPoints = relationship.getBendPoints();
        if (bendPoints.size() > 0) {
            // We will assume that source/dest coordinates are for center of node
            BendPoint[] externalBendPoints = new BendPoint[bendPoints.size() + 2];
            InternalNode sourceNode = relationship.getSource();
            externalBendPoints[0] = new BendPoint(sourceNode.getInternalX(), sourceNode.getInternalY());
            InternalNode destNode = relationship.getDestination();
            externalBendPoints[externalBendPoints.length - 1] = new BendPoint(destNode.getInternalX(), destNode.getInternalY());
            for (int j = 0; j < bendPoints.size(); j++) {
                BendPoint bp = (BendPoint) bendPoints.get(j);
                externalBendPoints[j + 1] = new BendPoint(bp.x, bp.y, bp.getIsControlPoint());
            }
            relationship.getLayoutRelationship().setBendPoints(externalBendPoints);
        }
    }
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) ArrayList(java.util.ArrayList) List(java.util.List) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) BasicEntityConstraint(org.eclipse.zest.layouts.constraints.BasicEntityConstraint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint) DisplayIndependentPoint(org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint) BendPoint(org.eclipse.zest.layouts.dataStructures.BendPoint)

Example 8 with InternalRelationship

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

the class TreeLayoutAlgorithm method findRootObjectRecursive.

/**
 * Finds the root node that can be treated as the root of a tree.
 * The found root node should be one of the unmarked nodes.
 */
private InternalNode findRootObjectRecursive(InternalNode currentEntity, Set seenAlready, InternalRelationship[] relationshipsToConsider) {
    InternalNode rootEntity = null;
    InternalRelationship rel = findRelationship(currentEntity, AS_DESTINATION, relationshipsToConsider);
    if (rel == null) {
        rootEntity = currentEntity;
    } else {
        InternalNode parentEntity = rel.getSource();
        if (!seenAlready.contains(parentEntity)) {
            seenAlready.add(parentEntity);
            rootEntity = findRootObjectRecursive(parentEntity, seenAlready, relationshipsToConsider);
        } else {
            rootEntity = currentEntity;
        }
    }
    return rootEntity;
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode)

Example 9 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship 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 10 with InternalRelationship

use of org.eclipse.zest.layouts.dataStructures.InternalRelationship 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)

Aggregations

InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)11 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)9 Iterator (java.util.Iterator)5 BasicEntityConstraint (org.eclipse.zest.layouts.constraints.BasicEntityConstraint)5 BendPoint (org.eclipse.zest.layouts.dataStructures.BendPoint)5 DisplayIndependentPoint (org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)3 List (java.util.List)3 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)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 DisplayIndependentRectangle (org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle)1