Salome HOME
Fix mixed Python dump of a new and a closed study
[modules/smesh.git] / src / SMESH_I / SMESH_PythonDump.cxx
index cd2e6ba3aab658c0c610afd23c9ba6587b46c43f..7ffedf1d4eeed4e0b958bf6f8a7778027a3e1779 100644 (file)
@@ -678,33 +678,33 @@ namespace SMESH
     cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << endl;
 #endif
   }
-}
 
 //=======================================================================
 //function : RemoveTabulation
 //purpose  : 
 //=======================================================================
-void RemoveTabulation( TCollection_AsciiString& theScript )
-{
-  std::string aString( theScript.ToCString() );
-  std::string::size_type aPos = 0;
-  while( aPos < aString.length() )
+  void RemoveTabulation( TCollection_AsciiString& theScript )
   {
-    aPos = aString.find( "\n\t", aPos );
-    if( aPos == std::string::npos )
-      break;
-    aString.replace( aPos, 2, "\n" );
-    aPos++;
+    std::string aString( theScript.ToCString() );
+    std::string::size_type aPos = 0;
+    while( aPos < aString.length() )
+    {
+      aPos = aString.find( "\n\t", aPos );
+      if( aPos == std::string::npos )
+        break;
+      aString.replace( aPos, 2, "\n" );
+      aPos++;
+    }
+    theScript = aString.c_str();
   }
-  theScript = aString.c_str();
 }
 
 //=======================================================================
 //function : DumpPython
 //purpose  :
 //=======================================================================
-Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Boolean isPublished,
-                                           CORBA::Boolean isMultiFile,
+Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Boolean  isPublished,
+                                           CORBA::Boolean  isMultiFile,
                                            CORBA::Boolean& isValidScript)
 {
   SALOMEDS::Study_var aStudy = getStudyServant();
@@ -995,10 +995,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   std::list< TCollection_AsciiString > lines; // lines of a script
   std::list< TCollection_AsciiString >::iterator linesIt;
   
-  if ( isPublished )
-    lines.push_back(  aSMESHGen + " = smeshBuilder.New()" );
-   else
-    lines.push_back(  aSMESHGen + " = smeshBuilder.New(False)" );
+  lines.push_back(  aSMESHGen + " = smeshBuilder.New()" );
+  if ( !isPublished )
+    lines.push_back(  aSMESHGen + ".SetEnablePublish( False )" );
   lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
   lines.push_back( helper + "aMeasurements = "  + aSMESHGen + ".CreateMeasurements()" );
 
@@ -1176,26 +1175,28 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   }
   // import python files corresponding to plugins if they are used in anUpdatedScript
   {
-    TCollection_AsciiString importStr;
+    //TCollection_AsciiString importStr;
     std::vector<std::string> pluginNames = getPluginNames();
     for ( size_t i = 0; i < pluginNames.size(); ++i )
     {
       // Convert access to plugin members:
-      // e.g. StdMeshers.QUAD_REDUCED -> StdMeshersBuilder.QUAD_REDUCED
+      // e.g. StdMeshers.QUAD_REDUCED -> smeshBuilder.QUAD_REDUCED
       TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ;
       int iFrom = 1, iPos;
       while (( iPos = anUpdatedScript.Location( pluginAccess, iFrom, anUpdatedScript.Length() )))
       {
-        anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" );
-        iFrom = iPos + pluginNames[i].size() + 8;
+        //anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" );
+        anUpdatedScript.Remove( iPos, pluginNames[i].size() );
+        anUpdatedScript.Insert( iPos, "smeshBuilder" );
+        iFrom = iPos - pluginNames[i].size() + 12;
       }
       // if any plugin member is used, import the plugin
-      if ( iFrom > 1 )
-        importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() +
-                       " import " + pluginNames[i].c_str() +"Builder" );
+      // if ( iFrom > 1 )
+      //   importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() +
+      //                  " import " + pluginNames[i].c_str() +"Builder" );
     }
-    if ( !importStr.IsEmpty() )
-      initPart += importStr + "\n";
+    // if ( !importStr.IsEmpty() )
+    //   initPart += importStr + "\n";
   }
 
   if ( isMultiFile )