Salome HOME
0022318: [CEA] Problems with study dump in SMESH
authoreap <eap@opencascade.com>
Thu, 12 Sep 2013 11:11:52 +0000 (11:11 +0000)
committereap <eap@opencascade.com>
Thu, 12 Sep 2013 11:11:52 +0000 (11:11 +0000)
Memory needed for SMESH_2smeshpy::ConvertScript() reduced by 3 times

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

index 4d4dd0a639bc8efe2f2084157c34d61af51c3f3d..e00c43f4ad4c237299ce271056a76e162d4ac074 100644 (file)
@@ -455,14 +455,35 @@ namespace {
  */
 //================================================================================
 
-TCollection_AsciiString
-SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScript,
+void
+SMESH_2smeshpy::ConvertScript(TCollection_AsciiString&                  theScript,
                               Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                               Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
                               std::set< TCollection_AsciiString >&      theRemovedObjIDs,
                               SALOMEDS::Study_ptr&                      theStudy,
                               const bool                                theToKeepAllCommands)
 {
+  // process notebook variables
+  {
+    SMESH_NoteBook aNoteBook;
+
+    int from = 1, end = theScript.Length(), to;
+    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;
+    }
+    theScript.Clear();
+
+    aNoteBook.ReplaceVariables();
+
+    theScript = aNoteBook.GetResultScript();
+  }
+
+  // convert to smeshBuilder.py API
+
   theGen = new _pyGen( theEntry2AccessorMethod,
                        theObjectNames,
                        theRemovedObjIDs,
@@ -470,33 +491,15 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScrip
                        theToKeepAllCommands );
 
   // split theScript into separate commands
-
-  SMESH_NoteBook * aNoteBook = new SMESH_NoteBook();
-
   int from = 1, end = theScript.Length(), to;
   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;
-  }
-
-  aNoteBook->ReplaceVariables();
-
-  TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript();
-  delete aNoteBook;
-  aNoteBook = 0;
-
-  // split theScript into separate commands
-  from = 1, end = aNoteScript.Length();
-  while ( from < end && ( to = aNoteScript.Location( "\n", from, end )))
-  {
-    if ( to != from )
-      // cut out and store a command
-      theGen->AddCommand( aNoteScript.SubString( from, to - 1 ));
+      theGen->AddCommand( theScript.SubString( from, to - 1 ));
     from = to + 1;
   }
+  theScript.Clear();
 
   // finish conversion
   theGen->Flush();
@@ -518,7 +521,7 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScrip
   } while ( orderChanges );
 
   // concat commands back into a script
-  TCollection_AsciiString aScript, aPrevCmd;
+  TCollection_AsciiString aPrevCmd;
   set<_pyID> createdObjects;
   createdObjects.insert( "smeshBuilder" );
   createdObjects.insert( "smesh" );
@@ -532,17 +535,15 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString&            theScrip
       CheckObjectPresence( *cmd, createdObjects );
       if ( !(*cmd)->IsEmpty() ) {
         aPrevCmd = (*cmd)->GetString();
-        aScript += "\n";
-        aScript += aPrevCmd;
+        theScript += "\n";
+        theScript += aPrevCmd;
       }
     }
   }
-  aScript += "\n";
+  theScript += "\n";
 
   theGen->Free();
   theGen.Nullify();
-
-  return aScript;
 }
 
 //================================================================================
index 3a5af32a34f7fb84e8440e8ecc89c176e988e979..163565431379bf757a7abab5d8b56727e1d61359 100644 (file)
@@ -984,9 +984,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
   std::set< TCollection_AsciiString >      aRemovedObjIDs;
   if ( !getenv("NO_2smeshpy_conversion"))
-    aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
-                                             theObjectNames, aRemovedObjIDs,
-                                             theStudy, isHistoricalDump );
+    SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
+                                   theObjectNames, aRemovedObjIDs,
+                                   theStudy, isHistoricalDump );
 
   // Replace characters used instead of quote marks to quote notebook variables
   {
index 6f0c4e8bfe64986009e7ed73fbdd27cff1a729b7..8783d9f5e8e69f61fd3b04961e5c81d7a50cdd39 100644 (file)
@@ -46,12 +46,11 @@ class Resource_DataMapOfAsciiStringAsciiString;
  */
 // ===========================================================================================
 
-class SMESH_2smeshpy
+namespace SMESH_2smeshpy
 {
-public:
   /*!
    * \brief Convert a python script using commands of smeshBuilder.py
-   * \param theScript - Input script
+   * \param theScript - the Input script to convert
    * \param theEntry2AccessorMethod - returns method names to access to
    *        objects wrapped with python class
    * \param theObjectNames - names of objects
@@ -60,8 +59,8 @@ public:
    *        to exclude commands relating to objects removed from study
    * \retval TCollection_AsciiString - Convertion result
    */
-  static TCollection_AsciiString
-  ConvertScript(const TCollection_AsciiString&            theScript,
+  void
+  ConvertScript(TCollection_AsciiString&                  theScript,
                 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
                 std::set< TCollection_AsciiString >&      theRemovedObjIDs,