Salome HOME
Merge branch 'omu/verify_links'
[modules/yacs.git] / src / engine / ComposedNode.cxx
index 1a4ce93caf31719887220887b1f34dbfa2a9f81d..31424ad25dfd8c0aaa9c15c82ee4877a899bb8ad 100644 (file)
@@ -28,6 +28,7 @@
 #include "DataStreamPort.hxx"
 #include "ElementaryNode.hxx"
 #include "ComponentInstance.hxx"
+#include "ForEachLoop.hxx"
 
 #include <iostream>
 #include <set>
@@ -1131,6 +1132,49 @@ list<Node *> ComposedNode::getAllRecursiveNodes()
   return ret;
 }
 
+
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. If a node is in a for each loop, his weight is modified by the size of the loop
+ *
+ */
+list<pair<int,int> > ComposedNode::getProgressWeight()
+{
+       list<pair<int,int> > ret;
+       list<Node *> setOfNode=edGetDirectDescendants();
+       int elemDone, elemTotal;
+       for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+               {
+                       if ( dynamic_cast<ForEachLoop*> (*iter) )
+                               {
+                                       elemDone=((ForEachLoop*)(*iter))->getCurrentIndex();
+                                       elemTotal=((ForEachLoop*)(*iter))->getNbOfElementsToBeProcessed();
+                                       list<pair<int,int> > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
+                                       myCurrentSet.pop_front();
+                                       myCurrentSet.pop_back();
+                                       for(list<pair<int,int> >::iterator iter=myCurrentSet.begin();iter!=myCurrentSet.end();iter++)
+                                               {
+                                                       (*iter).first=(*iter).second*elemDone;
+                                                       (*iter).second*=elemTotal;
+                                               }
+                                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+                               }
+                       else if ( dynamic_cast<ComposedNode*> (*iter) )
+                               {
+                                 list<pair<int,int> > myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
+                                       ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+                               }
+                       else
+                               {
+                                 if ((*iter)->getState() == YACS::DONE)
+                                         ret.push_back(pair<int,int>(1,1));
+                                       else
+                                               ret.push_back(pair<int,int>(0,1));
+                               }
+               }
+  return ret;
+}
+
 //! Get the input port name 
 /*!
  * get the input port name used by the current node, recursively built with children names.