Salome HOME
Fix mixed Python dump of a new and a closed study
[modules/smesh.git] / src / SMESH_I / SMESH_PythonDump.cxx
index 0204a498a17234c4d6373470aa5e4cf3016ff869..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();
@@ -884,25 +884,25 @@ namespace {
     bool isValidName = true;
     int nbUnderscore = 0;
     int p;
-//    // replace not allowed chars by underscore
-//    const char* name = aName.ToCString();
-//    for ( p = 0; name[p]; ++p ) {
-//      if ( !isalnum( name[p] ) && name[p] != '_' )
-//      {
-//        if ( p == 0 || p+1 == aName.Length() || name[p-1] == '_')
-//        {
-//          aName.Remove( p+1, 1 ); // remove __ and _ from the start and the end
-//          --p;
-//          name = aName.ToCString();
-//        }
-//        else
-//        {
-//          aName.SetValue( p+1, '_');
-//          nbUnderscore++;
-//        }
-//        isValidName = false;
-//      }
-//    }
+    // replace not allowed chars by underscore
+    const char* name = aName.ToCString();
+    for ( p = 0; name[p]; ++p ) {
+      if ( !isalnum( name[p] ) && name[p] != '_' )
+      {
+        if ( p == 0 || p+1 == aName.Length() || name[p-1] == '_')
+        {
+          aName.Remove( p+1, 1 ); // remove __ and _ from the start and the end
+          --p;
+          name = aName.ToCString();
+        }
+        else
+        {
+          aName.SetValue( p+1, '_');
+          nbUnderscore++;
+        }
+        isValidName = false;
+      }
+    }
     // aName must not start with a digit
     if ( aName.IsIntegerValue() ) {
       aName.Insert( 1, 'a' );
@@ -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()" );