]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
PPGP issue.
authoreap <eap@opencascade.com>
Thu, 7 Mar 2013 08:37:57 +0000 (08:37 +0000)
committereap <eap@opencascade.com>
Thu, 7 Mar 2013 08:37:57 +0000 (08:37 +0000)
Make a script valid even if some involved object are not published:
eliminate SetName() and object removal from the scrip

SMESH_2smeshpy::
   ConvertScript(const TCollection_AsciiString&            theScript,
                 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+                std::set< TCollection_AsciiString >&      theRemovedObjIDs,
                 SALOMEDS::Study_ptr&                      theStudy,
                 const bool                                theHistoricalDump);

src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_2smeshpy.hxx
src/SMESH_I/SMESH_DumpPython.cxx
src/SMESH_I/SMESH_PythonDump.hxx

index 6351ac79b15c94ec26de257c3e4ce5bc146dbed2..a3041761100ad5f38ffd3c5a961ead1d68dc3d08 100644 (file)
@@ -179,11 +179,24 @@ namespace {
 
   void CheckObjectPresence( const Handle(_pyCommand)& cmd, set<_pyID> & presentObjects)
   {
+    // either comment or erase a command including NotPublishedObjectName()
     if ( cmd->GetString().Location( TPythonDump::NotPublishedObjectName(), 1, cmd->Length() ))
     {
-      cmd->Comment();
+      bool isResultPublished = false;
+      for ( int i = 0; i < cmd->GetNbResultValues(); i++ )
+      {
+        _pyID objID = cmd->GetResultValue( i+1 );
+        if ( cmd->IsStudyEntry( objID ))
+          isResultPublished = (! theGen->IsNotPublished( objID ));
+        theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
+      }
+      if ( isResultPublished )
+        cmd->Comment();
+      else
+        cmd->Clear();
       return;
     }
+    // comment a command having not created args
     for ( int iArg = cmd->GetNbArgs(); iArg; --iArg )
     {
       const _pyID& arg = cmd->GetArg( iArg );
@@ -197,14 +210,23 @@ namespace {
           cmd->Comment();
           cmd->GetString() += " ### " ;
           cmd->GetString() += *id + " has not been yet created";
+          for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
+            _pyID objID = cmd->GetResultValue( i+1 );
+            theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
+          }
           return;
         }
     }
+    // comment a command having not created Object
     const _pyID& obj = cmd->GetObject();
     if ( !obj.IsEmpty() && cmd->IsStudyEntry( obj ) && !presentObjects.count( obj ))
     {
       cmd->Comment();
       cmd->GetString() += " ### not created object" ;
+      for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
+        _pyID objID = cmd->GetResultValue( i+1 );
+        theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
+      }
     }
     const _pyID& result = cmd->GetResultValue();
     if ( result.IsEmpty() || result.Value( 1 ) == '"' || result.Value( 1 ) == '\'' )
@@ -323,13 +345,15 @@ namespace {
 
 //================================================================================
 /*!
- * \brief Convert python script using commands of smesh.py
-  * \param theScript - Input script
-  * \retval TCollection_AsciiString - Convertion result
-  * \param theToKeepAllCommands - to keep all commands or
-  *        to exclude commands relating to objects removed from study
-  *
-  * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
+ * \brief Convert a python script using commands of smesh.py
+ *  \param theScript - Input script
+ *  \param theEntry2AccessorMethod - returns method names to access to
+ *         objects wrapped with python class
+ *  \param theObjectNames - names of objects
+ *  \param theRemovedObjIDs - entries of objects whose created commands were removed
+ *  \param theHistoricalDump - true means to keep all commands, false means
+ *         to exclude commands relating to objects removed from study
+ *  \retval TCollection_AsciiString - Convertion result
  */
 //================================================================================
 
@@ -337,10 +361,15 @@ TCollection_AsciiString
 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScript,
                               Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                               Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+                              std::set< TCollection_AsciiString >&      theRemovedObjIDs,
                               SALOMEDS::Study_ptr&                      theStudy,
                               const bool                                theToKeepAllCommands)
 {
-  theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames, theStudy, theToKeepAllCommands );
+  theGen = new _pyGen( theEntry2AccessorMethod,
+                       theObjectNames,
+                       theRemovedObjIDs,
+                       theStudy,
+                       theToKeepAllCommands );
 
   // split theScript into separate commands
 
@@ -350,9 +379,9 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScrip
   while ( from < end && ( to = theScript.Location( "\n", from, end )))
   {
     if ( to != from )
-        // cut out and store a command
-        aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
-      from = to + 1;
+      // cut out and store a command
+      aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
+    from = to + 1;
   }
 
   aNoteBook->ReplaceVariables();
@@ -421,12 +450,14 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScrip
 
 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+               std::set< TCollection_AsciiString >&      theRemovedObjIDs,
                SALOMEDS::Study_ptr&                      theStudy,
                const bool                                theToKeepAllCommands)
   : _pyObject( new _pyCommand( "", 0 )),
     myNbCommands( 0 ),
     myID2AccessorMethod( theEntry2AccessorMethod ),
     myObjectNames( theObjectNames ),
+    myRemovedObjIDs( theRemovedObjIDs ),
     myNbFilters( 0 ),
     myToKeepAllCommands( theToKeepAllCommands ),
     myStudy( SALOMEDS::Study::_duplicate( theStudy )),
@@ -792,7 +823,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
       method == "CreateMeshesFromSAUV"||
       method == "CreateMeshesFromGMF" )
   {
-    for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
+    for ( int ind = 0; ind < theCommand->GetNbResultValues(); ind++ )
     {
       _pyID meshID = theCommand->GetResultValue(ind+1);
       if ( !theCommand->IsStudyEntry( meshID ) ) continue;
@@ -1373,6 +1404,19 @@ bool _pyGen::IsNotPublished(const _pyID& theObjID) const
   return true; // SMESH object not in study
 }
 
+//================================================================================
+/*!
+ * \brief Remove object name from myObjectNames that leads to that SetName() for
+ *        this object is not dumped
+ *  \param [in] theObjID - entry of the object whose creation command was eliminated
+ */
+//================================================================================
+
+void _pyGen::ObjectCreationRemoved(const _pyID& theObjID)
+{
+  myRemovedObjIDs.insert( theObjID );
+}
+
 //================================================================================
 /*!
  * \brief Return reader of  hypotheses of plugins
@@ -3189,22 +3233,21 @@ const TCollection_AsciiString & _pyCommand::GetResultValue()
 //================================================================================
 /*!
  * \brief Return number of python command result value ResultValue = Obj.Meth()
-  * \retval const int
  */
 //================================================================================
 
-const int _pyCommand::GetNbResultValues()
+int _pyCommand::GetNbResultValues()
 {
+  int nb     = 0;
   int begPos = 1;
-  int Nb=0;
   int endPos = myString.Location( "=", 1, Length() );
-  TCollection_AsciiString str = "";
-  while ( begPos < endPos) {
-    str = GetWord( myString, begPos, true );
+  while ( begPos < endPos )
+  {
+    _AString str = GetWord( myString, begPos, true );
     begPos = begPos+ str.Length();
-    Nb++;
+    nb++;
   }
-  return (Nb-1);
+  return (nb-1);
 }
 
 
index feb720f5f913d5c8d5d3a633ef4503c74827538d..184a475e4e1d79eae00066b560442e29033de6c4 100644 (file)
@@ -123,7 +123,7 @@ public:
   bool IsEmpty() const { return myString.IsEmpty(); }
   _AString GetIndentation();
   const _AString & GetResultValue();
-  const int GetNbResultValues();
+  int GetNbResultValues();
   _AString GetResultValue(int res);
   const _AString & GetObject();
   const _AString & GetMethod();
@@ -223,6 +223,7 @@ class _pyGen: public _pyObject
 public:
   _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+         std::set< TCollection_AsciiString >&      theRemovedObjIDs,
          SALOMEDS::Study_ptr&                      theStudy,
          const bool                                theToKeepAllCommands);
   Handle(_pyCommand) AddCommand( const _AString& theCommand );
@@ -236,8 +237,8 @@ public:
   _pyID GenerateNewID( const _pyID& theID );
   void AddObject( Handle(_pyObject)& theObj );
   void SetProxyObject( const _pyID& theID, Handle(_pyObject)& theObj );
-  Handle(_pyObject) FindObject( const _pyID& theObjID ) const;
-  Handle(_pySubMesh) FindSubMesh( const _pyID& theSubMeshID );
+  Handle(_pyObject)     FindObject( const _pyID& theObjID ) const;
+  Handle(_pySubMesh)    FindSubMesh( const _pyID& theSubMeshID );
   Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
   Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
                                   const Handle(_pyHypothesis)& theHypothesis);
@@ -249,6 +250,7 @@ public:
 
   bool IsGeomObject(const _pyID& theObjID) const;
   bool IsNotPublished(const _pyID& theObjID) const;
+  void ObjectCreationRemoved(const _pyID& theObjID);
   bool IsToKeepAllCommands() const { return myToKeepAllCommands; }
   void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh )
   { myFile2ExportedMesh[ file ] = mesh; }
@@ -268,21 +270,22 @@ private:
                             const bool theIsAfter );
   
 private:
-  std::map< _pyID, Handle(_pyMesh) >       myMeshes;
-  std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
-  std::map< _pyID, Handle(_pyObject) >     myObjects;
-  std::list< Handle(_pyHypothesis) >       myHypos;
-  std::list< Handle(_pyCommand) >          myCommands;
-  int                                      myNbCommands;
+  std::map< _pyID, Handle(_pyMesh) >        myMeshes;
+  std::map< _pyID, Handle(_pyMeshEditor) >  myMeshEditors;
+  std::map< _pyID, Handle(_pyObject) >      myObjects;
+  std::list< Handle(_pyHypothesis) >        myHypos;
+  std::list< Handle(_pyCommand) >           myCommands;
+  int                                       myNbCommands;
   Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
   Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
-  Handle(_pyCommand)                       myLastCommand;
-  int                                      myNbFilters;
-  bool                                     myToKeepAllCommands;
-  SALOMEDS::Study_var                      myStudy;
-  int                                      myGeomIDNb, myGeomIDIndex;
-  std::map< _AString, ExportedMeshData >   myFile2ExportedMesh;
-  Handle( _pyHypothesisReader )            myHypReader;
+  std::set< TCollection_AsciiString >&      myRemovedObjIDs;
+  Handle(_pyCommand)                        myLastCommand;
+  int                                       myNbFilters;
+  bool                                      myToKeepAllCommands;
+  SALOMEDS::Study_var                       myStudy;
+  int                                       myGeomIDNb, myGeomIDIndex;
+  std::map< _AString, ExportedMeshData >    myFile2ExportedMesh;
+  Handle( _pyHypothesisReader )             myHypReader;
 
   DEFINE_STANDARD_RTTI (_pyGen)
 };
index 0a80143866f5a24e2326a4502f39eda50e880b50..cebc6e37ef3c1d7e3b96172c15c7d4fc226334f8 100644 (file)
@@ -915,9 +915,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   // Some objects are wrapped with python classes and
   // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
   Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
+  std::set< TCollection_AsciiString >      aRemovedObjIDs;
   if ( !getenv("NO_2smeshpy_conversion"))
     aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
-                                             theObjectNames, theStudy, isHistoricalDump );
+                                             theObjectNames, aRemovedObjIDs,
+                                             theStudy, isHistoricalDump );
 
   // Replace characters used instead of quote marks to quote notebook variables
   {
@@ -1017,6 +1019,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
   }
   for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
+    if ( aRemovedObjIDs.count( seqRemoved.Value(ir) )) continue;
     anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
     anUpdatedScript += seqRemoved.Value(ir);
     // for object wrapped by class of smesh.py
@@ -1037,13 +1040,14 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   for (Standard_Integer i = 1; i <= aLen; i += 2)
   {
     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
-    aName = geom->GetDumpName( anEntry.ToCString() );
+    aName   = geom->GetDumpName( anEntry.ToCString() );
     if (aName.IsEmpty() && // Not a GEOM object
         theNames.IsBound(anEntry) &&
+        !aRemovedObjIDs.count(anEntry) && // a command creating anEntry was erased
         !mapEntries.IsBound(anEntry) && // Not yet processed
         !mapRemoved.IsBound(anEntry)) // Was not removed
     {
-      aName = theObjectNames.Find(anEntry);
+      aName    = theObjectNames.Find(anEntry);
       aGUIName = theNames.Find(anEntry);
       mapEntries.Bind(anEntry, aName);
       anUpdatedScript += helper + "\n\t" + aSMESHGen + ".SetName(" + aName;
index 852f7bc91ccc61bc6809d75ea74f4fe0396469c9..0646d94d1551f673031d2b716a21912fb25fa94e 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <sstream>
 #include <vector>
+#include <set>
 
 class SMESH_Gen_i;
 class SMESH_MeshEditor_i;
@@ -51,8 +52,10 @@ public:
   /*!
    * \brief Convert a python script using commands of smesh.py
    * \param theScript - Input script
-   * \param theEntry2AccessorMethod - The returning method names to access to
+   * \param theEntry2AccessorMethod - returns method names to access to
    *        objects wrapped with python class
+   * \param theObjectNames - names of objects
+   * \param theRemovedObjIDs - entries of objects whose created commands were removed
    * \param theHistoricalDump - true means to keep all commands, false means
    *        to exclude commands relating to objects removed from study
    * \retval TCollection_AsciiString - Convertion result
@@ -61,6 +64,7 @@ public:
   ConvertScript(const TCollection_AsciiString&            theScript,
                 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+                std::set< TCollection_AsciiString >&      theRemovedObjIDs,
                 SALOMEDS::Study_ptr&                      theStudy,
                 const bool                                theHistoricalDump);