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;
}
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);
}
}
}
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;
}
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);
}
}
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);
}
}
Aggregations