]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Add some useful method in containers to extend the services to execute remotely pytho...
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 7 Aug 2014 13:15:19 +0000 (15:15 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 7 Aug 2014 13:15:19 +0000 (15:15 +0200)
idl/SALOME_Component.idl
idl/SALOME_PyNode.idl
src/Container/Container_i.cxx
src/Container/SALOME_Container_i.hxx
src/Container/SALOME_PyNode.py

index f399b33086ed94bae5b7fe87bd0866e2a4721516..f645e2219911e93fadbd17dc31e370a5255242fb 100644 (file)
@@ -222,12 +222,18 @@ module Engines
      */
     PyNode createPyNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
 
+    //! Retrieves the last created PyNode instance with createPyNode.
+    PyNode getDefaultPyNode();
+
     //! Create a PyScriptNode in the container
     /*!
       \param nodeName the name of the PyScriptNode
       \param code python code as text to load in the node
      */
     PyScriptNode createPyScriptNode(in string nodeName, in string code)  raises(SALOME::SALOME_Exception);
+
+    //! Retrieves the last created PyScriptNode instance with createPyScriptNode.
+    PyScriptNode getDefaultPyScriptNode();
   };
 
   /*! \brief Interface to pass data files from the client side to the SALOME Container.
index 97c419d3cfdadbaec74d83b347c78a46cc70ca06..401b3b0e906e828aaf66f91bed50d5ffcbe15c45 100644 (file)
@@ -53,6 +53,11 @@ module Engines
 
   interface PyScriptNode : SALOME::GenericObj
   {
+    /*!
+    This methode executes the python code in \a codeStr and can append/remove symboles in context to make them available or not for future call of execute on this.
+    \param [in] codeStr - the python code (without statement) to be executed, that can modify the context initialized at initialization.
+     */
+    void executeAnotherPieceOfCode(in string codeStr)  raises (SALOME::SALOME_Exception);
 
     /*! \brief execute a python script defined in the node
 
index a8a5f01473bc53a12d5d23a4128f023fd5342a3a..5552a5df55c5a4b5181f1152c1750556e6d6ce7d 100644 (file)
@@ -1646,6 +1646,7 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons
       {
         CORBA::Object_var obj = _orb->string_to_object(astr.c_str());
         node = Engines::PyNode::_narrow(obj);
+        _dftPyNode = node;
         return node._retn();
       }
     else
@@ -1658,6 +1659,19 @@ Engines::PyNode_ptr Engines_Container_i::createPyNode(const char* nodeName, cons
 
 }
 
+//=============================================================================
+/*! \brief Retrieves the last created PyNode instance with createPyNode.
+ *
+ */
+//=============================================================================
+Engines::PyNode_ptr  Engines_Container_i::getDefaultPyNode()
+{
+  if(!CORBA::is_nil(_dftPyNode))
+    return Engines::PyNode::_duplicate(_dftPyNode);
+  else
+    return Engines::PyNode::_nil();
+}
+
 //=============================================================================
 /*! \brief create a PyScriptNode object to execute remote python code
  * \param nodeName the name of the node
@@ -1695,6 +1709,7 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
       {
         CORBA::Object_var obj = _orb->string_to_object(astr.c_str());
         node = Engines::PyScriptNode::_narrow(obj);
+        _dftPyScriptNode = node;
         return node._retn();
       }
     else
@@ -1706,6 +1721,19 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
       }
 }
 
+//=============================================================================
+/*! \brief Retrieves the last created PyScriptNode instance with createPyScriptNode.
+ *
+ */
+//=============================================================================
+Engines::PyScriptNode_ptr Engines_Container_i::getDefaultPyScriptNode()
+{
+  if(!CORBA::is_nil(_dftPyScriptNode))
+    return Engines::PyScriptNode::_duplicate(_dftPyScriptNode);
+  else
+    return Engines::PyScriptNode::_nil();
+}
+
 //=============================================================================
 /* int checkifexecutable(const char *filename)
 *
index 5a48dc9c037b3880f6696746747cbbaf9fe52c54..494d563b5eec1f8a017f211db8a83a8940b60be9 100644 (file)
@@ -106,7 +106,9 @@ public:
   virtual Engines::Salome_file_ptr createSalome_file(const char* origFileName);
   void copyFile(Engines::Container_ptr container, const char* remoteFile, const char* localFile);
   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
+  Engines::PyNode_ptr  getDefaultPyNode();
   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
+  Engines::PyScriptNode_ptr getDefaultPyScriptNode();
   // --- local C++ methods
 
   Engines::EngineComponent_ptr
@@ -154,6 +156,8 @@ protected:
   std::map<std::string,Engines::EngineComponent_var> _listInstances_map;
   std::map<std::string,Engines::fileRef_var> _fileRef_map;
   std::map<std::string,Engines::Salome_file_var> _Salome_file_map;
+  Engines::PyScriptNode_var _dftPyScriptNode;
+  Engines::PyNode_var _dftPyNode;
   std::list<std::string> _tmp_files;
   Engines::fileTransfer_var _fileTransfer;
 
index 04ce26b7ab26ce79d5f76325730808610df146ba..2f8418fab82fc6e5542bbeda8755434c9251c68e 100644 (file)
@@ -90,6 +90,14 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic):
     self.context={}
     self.context["my_container"] = self.my_container
 
+  def executeAnotherPieceOfCode(self,code):
+    """Called for initialization of container lodging self."""
+    try:
+      ccode=compile(code,self.nodeName,'exec')
+      exec ccode in self.context
+    except:
+      raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"","PyScriptNode (%s) : code to be executed \"%s\"" %(self.nodeName,code),0))
+
   def execute(self,outargsname,argsin):
     """Execute the script stored in attribute ccode with pickled args (argsin)"""
     try: