Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / Switch.cxx
index 1c6b18ef0b77a0cfefa359425860bc37b2022f21..7db8ce71b074919acb43601cc29fc147cd896de7 100644 (file)
@@ -1,3 +1,21 @@
+//  Copyright (C) 2006-2008  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
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 #include "Switch.hxx"
 #include "Visitor.hxx"
 #include "LinkInfo.hxx"
@@ -6,6 +24,9 @@
 #include <sstream>
 #include <cassert>
 
+//#define _DEVDEBUG_
+#include "YacsTrace.hxx"
+
 using namespace YACS::ENGINE;
 using namespace std;
 
@@ -468,10 +489,18 @@ Node *Switch::edReleaseCase(int caseId) throw(Exception)
       Node *ret=(*iter).second;
       StaticDefinedComposedNode::edRemoveChild(ret);
       _mapOfNode.erase(iter);
+      modified();
       return ret;
     }
 }
 
+Node *Switch::edGetNode(int caseId)
+{
+  if (!_mapOfNode.count(caseId)) return 0;
+  return _mapOfNode[caseId];
+}
+
+
 /*!
  * \param caseId : the case ID chosen to place 'node'
  * \param node   : the node for the specified 'caseId'
@@ -488,10 +517,10 @@ Node *Switch::edSetNode(int caseId, Node *node) throw(Exception)
   checkNoCrossHierachyWith(node);
   node->_father=this;
   map< int , Node * >::iterator iter=_mapOfNode.find(caseId);
-  modified();
   if(iter==_mapOfNode.end())
     {
       _mapOfNode[caseId]=node;
+      modified();
       return 0;
     }
   else
@@ -500,11 +529,26 @@ Node *Switch::edSetNode(int caseId, Node *node) throw(Exception)
         {
           Node *ret=(*iter).second;
           (*iter).second=node;
+          modified();
           return ret;
         }
     }
 }
 
+bool Switch::edAddChild(Node *node) throw(Exception)
+{
+  int aCase = 0;
+  map<int, Node*>::const_iterator it = _mapOfNode.begin();
+  for(; it != _mapOfNode.end(); ++it)
+    if ((*it).first > aCase)
+      aCase = (*it).first;
+  aCase++;
+  DEBTRACE(aCase);
+  bool ret = edSetNode(aCase, node);
+  DEBTRACE(ret);
+  return ret;
+}
+
 YACS::Event Switch::updateStateOnFinishedEventFrom(Node *node)
 {
   setState(YACS::DONE);
@@ -650,6 +694,8 @@ YACS::StatesForNode Switch::getEffectiveState(const Node* node) const
     return YACS::READY;
   if(effectiveState==YACS::DISABLED)
     return YACS::DISABLED;
+  if(!_condition.getValue())
+    return node->getState();
   map< int , Node * >::const_iterator iter=_mapOfNode.find(_condition.getIntValue());
   if(iter!=_mapOfNode.end() && (*iter).second==node)
     return node->getState();