breath first search
| 65 | |
| 66 | //breath first search |
| 67 | void IPProcessGrid::buildQueue() |
| 68 | { |
| 69 | qDebug() << "IPProcessGrid::buildQueue"; |
| 70 | QQueue<IPProcessStep*> tmpQueue; |
| 71 | _processList.clear(); |
| 72 | |
| 73 | // find source processes |
| 74 | int branchID = 0; |
| 75 | for(auto it = _scene->steps()->begin(); it < _scene->steps()->end(); ++it) |
| 76 | { |
| 77 | IPProcessStep* step = (IPProcessStep*) *it; |
| 78 | IPLProcess* process = step->process(); |
| 79 | |
| 80 | // attach property changed event handler |
| 81 | process->registerPropertyChangedEventHandler(this); |
| 82 | process->registerOutputsChangedEventHandler(this); |
| 83 | |
| 84 | if(process->isSource()) |
| 85 | { |
| 86 | step->setTreeDepth(0); |
| 87 | step->setBranchID(branchID++); |
| 88 | _processList.push_back(step); |
| 89 | tmpQueue.enqueue(step); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // add all other process steps with BFS |
| 94 | int counter = 0; |
| 95 | int limit = 100; |
| 96 | while(!tmpQueue.isEmpty() && counter < limit) |
| 97 | { |
| 98 | IPProcessStep* step = tmpQueue.dequeue(); |
| 99 | |
| 100 | for(auto it = step->edgesOut()->begin(); it < step->edgesOut()->end(); ++it) |
| 101 | { |
| 102 | IPProcessEdge* edge = (IPProcessEdge*) *it; |
| 103 | IPProcessStep* nextStep = edge->to(); |
| 104 | |
| 105 | // set depth |
| 106 | nextStep->setTreeDepth(step->treeDepth()+1); |
| 107 | |
| 108 | // set branch ID |
| 109 | nextStep->setBranchID(step->branchID()); |
| 110 | |
| 111 | // add to queue and list |
| 112 | tmpQueue.enqueue(nextStep); |
| 113 | |
| 114 | // unique |
| 115 | if(!_processList.contains(nextStep)) |
| 116 | { |
| 117 | _processList.push_back(nextStep); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // sort by depth |
| 123 | qSort(_processList.begin(), _processList.end(), IPProcessGrid::sortTreeDepthLessThan); |
| 124 |
nothing calls this directly
no test coverage detected