Salome HOME
Use tempfile.mkdtemp to create temporary directory
[modules/yacs.git] / src / engine / VisitorSaveState.cxx
index 088c102ec905f595bb910d483aae066a50d79d26..440f09feb31ce94239f098c87a0ce353c2f3c383 100644 (file)
@@ -1,8 +1,27 @@
+// Copyright (C) 2006-2022  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, or (at your option) any later version.
+//
+// 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 "ElementaryNode.hxx"
 #include "Bloc.hxx"
 #include "Proc.hxx"
 #include "ForEachLoop.hxx"
+#include "OptimizerLoop.hxx"
 #include "Loop.hxx"
 #include "ForLoop.hxx"
 #include "WhileLoop.hxx"
@@ -10,7 +29,9 @@
 #include "InputPort.hxx"
 #include "InlineNode.hxx"
 #include "ServiceNode.hxx"
+#include "ServerNode.hxx"
 #include "ServiceInlineNode.hxx"
+#include "DataNode.hxx"
 
 #include "VisitorSaveState.hxx"
 
@@ -25,7 +46,7 @@ using namespace std;
 
 VisitorSaveState::VisitorSaveState(ComposedNode *root): Visitor(root)
 {
-  _nodeStateName[YACS::INITED] ="INITED";
+  _nodeStateName[YACS::READY] ="READY";
   _nodeStateName[YACS::TOLOAD] ="TOLOAD";
   _nodeStateName[YACS::LOADED] ="LOADED";
   _nodeStateName[YACS::TOACTIVATE] ="TOACTIVATE";
@@ -51,7 +72,7 @@ VisitorSaveState::~VisitorSaveState()
     }
 }
 
-void VisitorSaveState::openFileDump(std::string xmlDump) throw(Exception)
+void VisitorSaveState::openFileDump(const std::string& xmlDump)
 {
   _out.open(xmlDump.c_str(), ios::out);
   if (!_out)
@@ -98,6 +119,26 @@ void VisitorSaveState::visitElementaryNode(ElementaryNode *node)
         }
       _out << "    </inputPort>" << endl;
     }
+
+  list<OutputPort *> setOfOutputPort = node->getSetOfOutputPort();
+  list<OutputPort *>::iterator oiter;
+  for(oiter = setOfOutputPort.begin(); oiter != setOfOutputPort.end(); oiter++)
+    {
+      _out << "    <outputPort>" << endl;
+      _out << "      <name>" << (*oiter)->getName() << "</name>" << endl;
+      try
+        {
+          _out << "      ";
+          _out << (*oiter)->dump();
+        }
+      catch (YACS::Exception &e)
+        {
+          DEBTRACE("caught YACS:Exception: " << e.what());
+          _out << "<value><error><![CDATA[" << e.what() << "]]></error></value>" << endl;
+        }
+      _out << "    </outputPort>" << endl;
+    }
+
   _out << "  </node>" << endl;
 }
 
@@ -143,6 +184,38 @@ void VisitorSaveState::visitForEachLoop(ForEachLoop *node)
   _out << "  </node>" << endl;
 }
 
+void VisitorSaveState::visitForEachLoopDyn(ForEachLoopDyn *node)
+{
+  node->ComposedNode::accept(this);
+  if (!_out) throw Exception("No file open for dump state");
+  string name = _root->getName();
+  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
+  DEBTRACE("VisitorSaveState::visitForEachLoopDyn ------ " << name);
+  _out << "  <node type='forEachLoopDyn'>" << endl;
+  _out << "    <name>" << name << "</name>" << endl;
+  _out << "    <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
+  _out << "  </node>" << endl;
+}
+
+void VisitorSaveState::visitOptimizerLoop(OptimizerLoop *node)
+{
+  node->ComposedNode::accept(this);
+  if (!_out) throw Exception("No file open for dump state");
+  string name = _root->getName();
+  if (static_cast<ComposedNode*>(node) != _root) name = _root->getChildName(node);
+  DEBTRACE("VisitorSaveState::visitOptimizerLoop ------ " << name);
+  _out << "  <node type='optimizerLoop'>" << endl;
+  _out << "    <name>" << name << "</name>" << endl;
+  _out << "    <state>" << _nodeStateName[node->getState()] << "</state>" << endl;
+
+  _out << "  </node>" << endl;
+}
+
+void VisitorSaveState::visitDynParaLoop(DynParaLoop *node)
+{
+  node->ComposedNode::accept(this);
+}
+
 void VisitorSaveState::visitLoop(Loop *node)
 {
   node->ComposedNode::accept(this);
@@ -193,9 +266,11 @@ void VisitorSaveState::visitWhileLoop(WhileLoop *node)
   InputPort * ip = node->edGetConditionPort();
   if (ip->isEmpty())
     throw Exception("condition in WhileLoop empty, case not handled yet...");
-  Any *val = static_cast<Any*>(ip->get());
-  bool condition = val->getBoolValue();
-  _out << "    <condition>" << condition << "</condition>" << endl;
+  if ( ConditionInputPort* cip = dynamic_cast<ConditionInputPort*>(ip) )
+  {
+    bool condition = cip->getValue();
+    _out << "    <condition>" << condition << "</condition>" << endl;
+  }
 
   _out << "  </node>" << endl;
 }
@@ -235,8 +310,32 @@ void VisitorSaveState::visitServiceNode(ServiceNode *node)
   visitElementaryNode(node);
 }
 
+void VisitorSaveState::visitServerNode(ServerNode *node)
+{
+  visitElementaryNode(node);
+}
 
 void VisitorSaveState::visitServiceInlineNode(ServiceInlineNode *node)
 {
   visitElementaryNode(node);
 }
+
+void VisitorSaveState::visitPresetNode(DataNode *node)
+{
+  visitElementaryNode(node);
+}
+
+void VisitorSaveState::visitOutNode(DataNode *node)
+{
+  visitElementaryNode(node);
+}
+
+void VisitorSaveState::visitStudyInNode(DataNode *node)
+{
+  visitElementaryNode(node);
+}
+
+void VisitorSaveState::visitStudyOutNode(DataNode *node)
+{
+  visitElementaryNode(node);
+}