Salome HOME
Work in progress save and load state.
[modules/yacs.git] / src / engine / ComposedNode.cxx
index 3f0e559d207130744025981e477ad1aff0fd94c5..71576cd2bd823ae5dddfee5159f4b3faa827de2b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -241,8 +241,7 @@ std::vector<Task *> ComposedNode::getNextTasks(bool& isMore)
  * Calls ComposedNode::updateStateFrom to update state from task to root node
  */
 void ComposedNode::notifyFrom(const Task *sender, //* I : task emitting event
-                              YACS::Event event,   //* I : event emitted
-                              const Executor *execInst
+                              YACS::Event event   //* I : event emitted
                               )
 {
   DEBTRACE("ComposedNode::notifyFrom " << event);
@@ -252,12 +251,12 @@ void ComposedNode::notifyFrom(const Task *sender, //* I : task emitting event
   ComposedNode *curLevelNode=taskTyped->_father;
   if(!curLevelNode)//Specific case of loop when 0 turn is specified without any enclosing bloc.
     return ;
-  curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent,execInst);
+  curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent);
   while(curEvent!=YACS::NOEVENT && curLevelNode!=this)
     {
       lminus1LevelNode=curLevelNode;
       curLevelNode=curLevelNode->_father;
-      curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent,execInst);
+      curEvent=curLevelNode->updateStateFrom(lminus1LevelNode,curEvent);
     }
 }
 
@@ -1045,7 +1044,7 @@ void ComposedNode::checkInMyDescendance(Node *nodeToTest) const throw(YACS::Exce
  */
 ComposedNode *ComposedNode::getLowestCommonAncestor(Node *node1, Node *node2) throw(YACS::Exception)
 {
-  const char what[]="2 nodes does not share the same genealogy";
+  const char what[]="The two nodes do not share the same genealogy";
   if(node1==0 || node2==0)
     throw Exception(what);
   ComposedNode *temp;
@@ -1075,6 +1074,45 @@ ComposedNode *ComposedNode::getLowestCommonAncestor(Node *node1, Node *node2) th
   return *iter;
 }
 
+/*!
+ * Same as getLowestCommonAncestor method except that absolute string representation is considered here instead of instances.
+ */
+std::string ComposedNode::getLowestCommonAncestorStr(const std::string& node1, const std::string& node2)
+{
+  std::string ret;
+  std::size_t it1_b(0),it1_e(0),it2_b(0),it2_e(0);
+  while(it1_b!=std::string::npos && it2_b!=std::string::npos)
+    {
+      it1_e=node1.find(SEP_CHAR_BTW_LEVEL,it1_b);
+      it2_e=node2.find(SEP_CHAR_BTW_LEVEL,it2_b);
+      if(it1_e!=it2_e && it1_e!=std::string::npos && it2_e!=std::string::npos)
+        break;
+      std::string elt1(node1.substr(it1_b,it1_e-it1_b)),elt2(node2.substr(it2_b,it2_e-it2_b));
+      if(elt1!=elt2)
+        break;
+      if(!ret.empty())
+        ret+=SEP_CHAR_BTW_LEVEL;
+      ret+=elt1;
+      it1_b=node1.find_first_not_of(SEP_CHAR_BTW_LEVEL,it1_e);
+      it2_b=node2.find_first_not_of(SEP_CHAR_BTW_LEVEL,it2_e);
+    }
+  return ret;
+}
+
+/*!
+ * This method recursively all redundant control links in this.
+ */
+void ComposedNode::removeRecursivelyRedundantCL()
+{
+  std::list<Node *> dd(edGetDirectDescendants());
+  for(std::list<Node *>::const_iterator it=dd.begin();it!=dd.end();it++)
+    {
+      ComposedNode *elt(dynamic_cast<ComposedNode *>(*it));
+      if(elt)
+        elt->removeRecursivelyRedundantCL();
+    }
+}
+
 list<ElementaryNode *> ComposedNode::getRecursiveConstituents() const
 {
   list<ElementaryNode *> ret;
@@ -1131,6 +1169,24 @@ list<Node *> ComposedNode::getAllRecursiveNodes()
   return ret;
 }
 
+
+//! Get the progress weight for all elementary nodes
+/*!
+ * Only elementary nodes have weight. A simple composed node only sum up weight of all his descendants
+ * (working is different for loop or switch nodes)
+ */
+list<ProgressWeight> ComposedNode::getProgressWeight() const
+{
+  list<ProgressWeight> ret;
+  list<Node *> setOfNode=edGetDirectDescendants();
+  for(list<Node *>::const_iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
+    {
+      list<ProgressWeight> myCurrentSet=((ComposedNode*)(*iter))->getProgressWeight();
+      ret.insert(ret.end(),myCurrentSet.begin(),myCurrentSet.end());
+    }
+  return ret;
+}
+
 //! Get the input port name 
 /*!
  * get the input port name used by the current node, recursively built with children names.
@@ -1319,8 +1375,7 @@ OutputDataStreamPort *ComposedNode::getOutputDataStreamPort(const std::string& n
  * Called by ComposedNode::notifyFrom
  */
 YACS::Event ComposedNode::updateStateFrom(Node *node,        //* I : node emitting event
-                                          YACS::Event event,  //* I : event emitted
-                                          const Executor *execInst
+                                          YACS::Event event  //* I : event emitted
                                           )
 {
   DEBTRACE("updateStateFrom: " << node->getName() << " " << event);
@@ -1335,7 +1390,7 @@ YACS::Event ComposedNode::updateStateFrom(Node *node,        //* I : node emitti
           return updateStateOnFinishedEventFrom(node);
           break;
         case YACS::ABORT:
-          return updateStateOnFailedEventFrom(node,execInst);
+          return updateStateOnFailedEventFrom(node);
           break;
         default:
           return YACS::NOEVENT;//TODO unexpected type of event
@@ -1377,7 +1432,7 @@ YACS::Event ComposedNode::updateStateOnStartEventFrom(Node *node)
 }
 
 //! Method used to notify the node that a child node has failed
-YACS::Event ComposedNode::updateStateOnFailedEventFrom(Node *node, const Executor *execInst)
+YACS::Event ComposedNode::updateStateOnFailedEventFrom(Node *node)
 {
    setState(YACS::FAILED);
    return YACS::ABORT;