class MyRandomLayout : public IlvGraphLayout { public: MyRandomLayout() { } protected: void layout(); }; |
void MyRandomLayout::layout() { // obtain the graph model IlvGraphModel* graphModel = getGraphModel(); // obtain the layout report IlvGraphLayoutReport* layoutReport = getLayoutReport(); IlBoolean atLeastOneNodeMoved = IlFalse; // obtain the layout region IlvRect rect; getLayoutRegion(rect); IlvPos xMin = rect.x(); IlvPos yMin = rect.y(); IlvPos xMax = rect.right(); IlvPos yMax = rect.bottom(); // initialize the random generator IlvRandom* random = (isUseSeedValueForRandomGenerator()) ? new IlvRandom(getSeedValueForRandomGenerator()) : new IlvRandom(); // get the objects in the grapher IlList* nodes = graphModel->getNodes(); // browse the objects in the grapher IlLink* l = nodes->getFirst(); while (l) { IlAny node = l->getValue(); l = l->getNext(); // skip fixed nodes if (isPreserveFixedNodes() && isFixed(node)) continue; // compute coordinates IlvPos x = xMin + (IlvPos)((xMax - xMin) * random->nextFloat()); IlvPos y = yMin + (IlvPos)((yMax - yMin) * random->nextFloat()); // move the node to the computed position graphModel->moveNode(node, x, y, IlFalse); atLeastOneNodeMoved = IlTrue; // notify listeners on layout events layoutStepPerformed(); } delete random; // set the layout report code if (atLeastOneNodeMoved) layoutReport->setCode(IlvLayoutReportLayoutDone); else layoutReport->setCode(IlvLayoutReportNoMoveableNode); } |
IlvGraphModel* graphModel = getGraphModel(); |
IlvGraphLayoutReport* layoutReport = getLayoutReport(); |
IlvRect rect; getLayoutRegion(rect); |
IlvRandom* random = (isUseSeedValueForRandomGenerator()) ? new IlvRandom(getSeedValueForRandomGenerator()) : new IlvRandom(); |
IlList* nodes = graphModel->getNodes(); |
// browse the objects in the grapher IlLink* l = nodes->getFirst(); while (l) { IlAny node = l->getValue(); // ... |
graphModel->moveNode(node, x, y, IlFalse); atLeastOneNodeMoved = IlTrue; |
layoutStepPerformed(); |
if (atLeastOneNodeMoved) layoutReport->setCode(IlvLayoutReportLayoutDone); else layoutReport->setCode(IlvLayoutReportNoMoveableNode); |