Salome HOME
0022318: [CEA] Problems with study dump in SMESH
authoreap <eap@opencascade.com>
Thu, 12 Sep 2013 11:11:30 +0000 (11:11 +0000)
committereap <eap@opencascade.com>
Thu, 12 Sep 2013 11:11:30 +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 de6a57be91f9c3d51e57d922e4f024baa02c5dfb..b4315cf233ddb158461493c5514463f64a839292 100644 (file)
@@ -447,14 +447,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,
@@ -462,33 +483,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();
@@ -510,7 +513,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" );
@@ -524,17 +527,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 b409ca96865eec7462335ae8de89f1620dd08d0b..7d26ddd73e05e956ad5b7b0e94516aeb5fc0966c 100644 (file)
@@ -234,12 +234,12 @@ namespace SMESH
   TPythonDump::
   operator<<(SALOMEDS::SObject_ptr aSObject)
   {
-    if ( !aSObject->_is_nil() ) {\r
-      CORBA::String_var entry = aSObject->GetID();\r
-      myStream << entry.in();\r
-    }\r
-    else {\r
-      myStream << theNotPublishedObjectName;\r
+    if ( !aSObject->_is_nil() ) {
+      CORBA::String_var entry = aSObject->GetID();
+      myStream << entry.in();
+    }
+    else {
+      myStream << theNotPublishedObjectName;
     }
     return *this;
   }
@@ -461,9 +461,9 @@ namespace SMESH
     DumpArray( theList, *this );
     return *this;
   }
-  const char* TPythonDump::NotPublishedObjectName()\r
-  {\r
-    return theNotPublishedObjectName;\r
+  const char* TPythonDump::NotPublishedObjectName()
+  {
+    return theNotPublishedObjectName;
   }
 
   TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
@@ -870,9 +870,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,\r
-                                             theObjectNames, aRemovedObjIDs,\r
-                                             theStudy, isHistoricalDump );
+    SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
+                                   theObjectNames, aRemovedObjIDs,
+                                   theStudy, isHistoricalDump );
 
   // Replace characters used instead of quote marks to quote notebook variables
   {
@@ -1005,10 +1005,10 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
       aSetNameScriptPart += helper + ", '" + aGUIName + "')";
     }
   }
-  if ( !aSetNameScriptPart.IsEmpty() )\r
-  {\r
-    anUpdatedScript += "\n\t## set object names";\r
-    anUpdatedScript += aSetNameScriptPart;\r
+  if ( !aSetNameScriptPart.IsEmpty() )
+  {
+    anUpdatedScript += "\n\t## set object names";
+    anUpdatedScript += aSetNameScriptPart;
   }
 
   // -----------------------------------------------------------------
index ac92008dff3f03d8621c7021f087b477a37a264e..b0447907130e49a777611ba96bb0eaa3fc1404fb 100644 (file)
@@ -46,22 +46,21 @@ class Resource_DataMapOfAsciiStringAsciiString;
  */
 // ===========================================================================================
 
-class SMESH_2smeshpy
+namespace SMESH_2smeshpy
 {
-public:
   /*!
-   * \brief Convert a python script using commands of smesh.py\r
-   * \param theScript - Input script\r
-   * \param theEntry2AccessorMethod - returns method names to access to\r
-   *        objects wrapped with python class\r
-   * \param theObjectNames - names of objects\r
-   * \param theRemovedObjIDs - entries of objects whose created commands were removed\r
-   * \param theHistoricalDump - true means to keep all commands, false means\r
-   *        to exclude commands relating to objects removed from study\r
+   * \brief Convert a python script using commands of smeshBuilder.py
+   * \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
+   * \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
    */
-  static TCollection_AsciiString
-  ConvertScript(const TCollection_AsciiString&            theScript,
+  void
+  ConvertScript(TCollection_AsciiString&                  theScript,
                 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
                 std::set< TCollection_AsciiString >&      theRemovedObjIDs,