Salome HOME
Merge multi-study removal branch.
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
index 3cb64eedf920e84b3eae8e68ee6e28068130e036..92506466cdbd268668025cb1c8106b4745bb1861 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -53,10 +53,10 @@ namespace SMESH
   size_t TPythonDump::myCounter = 0;
   const char theNotPublishedObjectName[] = "__NOT__Published__Object__";
 
-  TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); }
-  TVar::TVar(CORBA::Long   value):myVals(1) { myVals[0] = SMESH_Comment(value); }
-  TVar::TVar(CORBA::Short  value):myVals(1) { myVals[0] = SMESH_Comment(value); }
-  TVar::TVar(const SMESH::double_array& value):myVals(value.length())
+  TVar::TVar(CORBA::Double value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
+  TVar::TVar(CORBA::Long   value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
+  TVar::TVar(CORBA::Short  value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); }
+  TVar::TVar(const SMESH::double_array& value):myVals(value.length()), myIsList(true)
   {
     for ( size_t i = 0; i < value.length(); i++)
       myVals[i] = SMESH_Comment(value[i]);
@@ -74,13 +74,12 @@ namespace SMESH
       SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
       std::string aString = myStream.str();
       TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
-      SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-      if(!aStudy->_is_nil() && !aCollection.IsEmpty())
+      if(!aCollection.IsEmpty())
       {
         const std::string & objEntry = SMESH_Gen_i::GetSMESHGen()->GetLastObjEntry();
         if ( !objEntry.empty() )
           aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
-        aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
+        aSMESHGen->AddToPythonScript(aCollection);
         if(MYDEBUG) MESSAGE(aString);
         // prevent misuse of already treated variables
         aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
@@ -93,12 +92,12 @@ namespace SMESH
   operator<<(const TVar& theVarValue)
   {
     const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
-    if ( theVarValue.myVals.size() != 1 )
+    if ( theVarValue.myIsList )
     {
       myStream << "[ ";
       for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
       {
-        if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
+        if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
           myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
         else
           myStream << theVarValue.myVals[i-1];
@@ -110,7 +109,7 @@ namespace SMESH
     }
     else
     {
-      if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
+      if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
         myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
       else
         myStream << theVarValue.myVals[0];
@@ -162,6 +161,13 @@ namespace SMESH
     return *this;
   }
 
+  TPythonDump&
+  TPythonDump::
+  operator<<(const std::string& theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
   TPythonDump&
   TPythonDump::
   operator<<(const SMESH::ElementType& theArg)
@@ -240,13 +246,20 @@ namespace SMESH
   template<class TArray>
   void DumpArray(const TArray& theArray, TPythonDump & theStream)
   {
-    theStream << "[ ";
-    for (int i = 1; i <= theArray.length(); i++) {
-      theStream << theArray[i-1];
-      if ( i < theArray.length() )
-        theStream << ", ";
+    if ( theArray.length() == 0 )
+    {
+      theStream << "[]";
+    }
+    else
+    {
+      theStream << "[ ";
+      for (CORBA::ULong i = 1; i <= theArray.length(); i++) {
+        theStream << theArray[i-1];
+        if ( i < theArray.length() )
+          theStream << ", ";
+      }
+      theStream << " ]";
     }
-    theStream << " ]";
   }
 
   TPythonDump&
@@ -263,11 +276,18 @@ namespace SMESH
     return *this;
   }
 
+  TPythonDump&
+  TPythonDump::operator<<(const SMESH::nodes_array& theArg)
+  {
+    DumpArray( theArg, *this );
+    return *this;
+  }
+
   TPythonDump&
   TPythonDump::operator<<(const SMESH::string_array& theArray)
   {
     myStream << "[ ";
-    for (int i = 1; i <= theArray.length(); i++) {
+    for ( CORBA::ULong i = 1; i <= theArray.length(); i++ ) {
       myStream << "'" << theArray[i-1] << "'";
       if ( i < theArray.length() )
         myStream << ", ";
@@ -295,8 +315,7 @@ namespace SMESH
   operator<<(CORBA::Object_ptr theArg)
   {
     SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
-    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
     if(!aSObject->_is_nil()) {
       CORBA::String_var id = aSObject->GetID();
       myStream << id;
@@ -315,8 +334,7 @@ namespace SMESH
   TPythonDump::
   operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
   {
-    SALOMEDS::Study_var     aStudy = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
-    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
     if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
       myStream << "hyp_" << theArg->GetId();
     else
@@ -331,8 +349,7 @@ namespace SMESH
     if ( CORBA::is_nil( theArg ) )
       return *this << "None";
     SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
-    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
+    SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg);
     if(!aSObject->_is_nil())
     {
       return *this << aSObject;
@@ -347,7 +364,7 @@ namespace SMESH
       SMESH::long_array_var    anElementsId = theArg->GetIDs();
       SMESH::array_of_ElementType_var types = theArg->GetTypes();
       SMESH::ElementType               type = types->length() ? types[0] : SMESH::ALL;
-      SALOMEDS::SObject_wrap         meshSO = SMESH_Gen_i::ObjectToSObject(aStudy,mesh);
+      SALOMEDS::SObject_wrap         meshSO = SMESH_Gen_i::ObjectToSObject(mesh);
       if ( meshSO->_is_nil() ) // don't waste memory for dumping not published objects
         return *this << mesh << ".GetIDSource([], " << type << ")";
       else
@@ -409,6 +426,8 @@ namespace SMESH
       case FT_MultiConnection2D:     myStream<< "aMultiConnection2D";     break;
       case FT_Length:                myStream<< "aLength";                break;
       case FT_Length2D:              myStream<< "aLength2D";              break;
+      case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break;
+      case FT_BelongToMeshGroup:     myStream<< "aBelongToMeshGroup";     break;
       case FT_BelongToGeom:          myStream<< "aBelongToGeom";          break;
       case FT_BelongToPlane:         myStream<< "aBelongToPlane";         break;
       case FT_BelongToCylinder:      myStream<< "aBelongToCylinder";      break;
@@ -433,8 +452,8 @@ namespace SMESH
       case FT_LogicalNOT:            myStream<< "aLogicalNOT";            break;
       case FT_LogicalAND:            myStream<< "aLogicalAND";            break;
       case FT_LogicalOR:             myStream<< "aLogicalOR";             break;
-      case FT_Undefined:
-      default:                       myStream<< "anUndefined";            break;
+      case FT_Undefined:             myStream<< "anUndefined";            break;
+        //default: -- commented to have a compilation warning
       }
       myStream<<theArg;
     }
@@ -517,11 +536,54 @@ namespace SMESH
     DumpArray( *theList, *this );
     return *this;
   }
+  TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGO& theList)
+  {
+    DumpArray( theList, *this );
+    return *this;
+  }
+  TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGBO& theList)
+  {
+    DumpArray( theList, *this );
+    return *this;
+  }
   TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList)
   {
     DumpArray( theList, *this );
     return *this;
   }
+  TPythonDump& TPythonDump::operator<<(const SMESH::CoincidentFreeBorders& theCFB)
+  {
+    // dump CoincidentFreeBorders as a list of lists, each enclosed list
+    // contains node IDs of a group of coincident free borders where
+    // each consequent triple of IDs describe a free border: (n1, n2, nLast)
+    // For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes
+    // two groups of coincident free borders, each group including two borders
+
+    myStream << "[";
+    for ( CORBA::ULong i = 0; i < theCFB.coincidentGroups.length(); ++i )
+    {
+      const SMESH::FreeBordersGroup& aGRP = theCFB.coincidentGroups[ i ];
+      if ( i ) myStream << ",";
+      myStream << "[";
+      for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP )
+      {
+        const SMESH::FreeBorderPart& aPART = aGRP[ iP ];
+        if ( 0 <= aPART.border && aPART.border < (CORBA::Long)theCFB.borders.length() )
+        {
+          if ( iP ) myStream << ", ";
+          const SMESH::FreeBorder& aBRD = theCFB.borders[ aPART.border ];
+          myStream << aBRD.nodeIDs[ aPART.node1    ] << ",";
+          myStream << aBRD.nodeIDs[ aPART.node2    ] << ",";
+          myStream << aBRD.nodeIDs[ aPART.nodeLast ];
+        }
+      }
+      myStream << "]";
+    }
+    myStream << "]";
+
+    return *this;
+  }
+
   const char* TPythonDump::NotPublishedObjectName()
   {
     return theNotPublishedObjectName;
@@ -652,12 +714,11 @@ void RemoveTabulation( TCollection_AsciiString& theScript )
 //function : DumpPython
 //purpose  :
 //=======================================================================
-Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
-                                           CORBA::Boolean isPublished,
+Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Boolean isPublished,
                                            CORBA::Boolean isMultiFile,
                                            CORBA::Boolean& isValidScript)
 {
-  SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
+  SALOMEDS::Study_var aStudy = getStudyServant();
   if (CORBA::is_nil(aStudy))
     return new Engines::TMPFile(0);
 
@@ -695,7 +756,7 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
 
   // Add trace of API methods calls and replace study entries by names
   TCollection_AsciiString aScript;
-  aScript += DumpPython_impl(aStudy, aMap, aMapNames, isPublished, isMultiFile,
+  aScript += DumpPython_impl(aMap, aMapNames, isPublished, isMultiFile,
                              myIsHistoricalPythonDump, isValidScript, aSavedTrace);
 
   int aLen = aScript.Length();
@@ -716,12 +777,12 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
  *  AddToPythonScript
  */
 //=============================================================================
-void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString)
+void SMESH_Gen_i::AddToPythonScript (const TCollection_AsciiString& theString)
 {
-  if (myPythonScripts.find(theStudyID) == myPythonScripts.end()) {
-    myPythonScripts[theStudyID] = new TColStd_HSequenceOfAsciiString;
+  if (myPythonScript.IsNull()) {
+    myPythonScript = new TColStd_HSequenceOfAsciiString;
   }
-  myPythonScripts[theStudyID]->Append(theString);
+  myPythonScript->Append(theString);
 }
 
 //=============================================================================
@@ -729,11 +790,11 @@ void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiStri
  *  RemoveLastFromPythonScript
  */
 //=============================================================================
-void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID)
+void SMESH_Gen_i::RemoveLastFromPythonScript()
 {
-  if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
-    int aLen = myPythonScripts[theStudyID]->Length();
-    myPythonScripts[theStudyID]->Remove(aLen);
+  if (!myPythonScript.IsNull()) {
+    int aLen = myPythonScript->Length();
+    myPythonScript->Remove(aLen);
   }
 }
 
@@ -741,15 +802,15 @@ void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID)
 //function : SavePython
 //purpose  :
 //=======================================================================
-void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
+void SMESH_Gen_i::SavePython()
 {
   // Dump trace of API methods calls
-  TCollection_AsciiString aScript = GetNewPythonLines(theStudy->StudyId());
+  TCollection_AsciiString aScript = GetNewPythonLines();
 
   // Check contents of PythonObject attribute
   CORBA::String_var compDataType = ComponentDataType();
-  SALOMEDS::SObject_wrap aSO = theStudy->FindComponent( compDataType.in() );
-  SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
+  SALOMEDS::SObject_wrap aSO = getStudyServant()->FindComponent( compDataType.in() );
+  SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder();
   SALOMEDS::GenericAttribute_wrap anAttr =
     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
 
@@ -769,7 +830,7 @@ void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
   pyAttr->SetObject(oldScript.ToCString(), 1);
 
   // Clean trace of API methods calls
-  CleanPythonTrace(theStudy->StudyId());
+  CleanPythonTrace();
 }
 
 
@@ -913,7 +974,6 @@ namespace {
 //================================================================================
 /*!
  * \brief Createa a Dump Python script
- *  \param [in] theStudy - the study to dump
  *  \param [in,out] theObjectNames - map of an entry to a study and python name
  *  \param [in] theNames -  - map of an entry to a study name
  *  \param [in] isPublished - \c true if dump of object publication in study is needed
@@ -927,8 +987,7 @@ namespace {
 //================================================================================
 
 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
-                        (SALOMEDS::Study_ptr                       theStudy,
-                         Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+                        (Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
                          Resource_DataMapOfAsciiStringAsciiString& theNames,
                          bool                                      isPublished,
                          bool                                      isMultiFile,
@@ -937,7 +996,6 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
                          TCollection_AsciiString&                  theSavedTrace)
 {
   SMESH_TRY;
-  const int aStudyID = theStudy->StudyId();
 
   const TCollection_AsciiString aSmeshpy ( SMESH_2smeshpy::SmeshpyName() );
   const TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() );
@@ -949,11 +1007,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   std::list< TCollection_AsciiString >::iterator linesIt;
   
   if ( isPublished )
-    lines.push_back(  tab + aSMESHGen + " = smeshBuilder.New(theStudy)" );
+    lines.push_back(  aSMESHGen + " = smeshBuilder.New()" );
    else
-    lines.push_back(  tab + aSMESHGen + " = smeshBuilder.New(None)" );
-  lines.push_back(  tab + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
-  lines.push_back(  tab + "aMeasurements = "  + aSMESHGen + ".CreateMeasurements()" );
+    lines.push_back(  aSMESHGen + " = smeshBuilder.New(False)" );
+  lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
+  lines.push_back( helper + "aMeasurements = "  + aSMESHGen + ".CreateMeasurements()" );
 
   // Treat dump trace of restored study
   if (theSavedTrace.Length() > 0)
@@ -969,7 +1027,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
         lines.push_back( theSavedTrace.SubString( from, to - 1 ));
       from = to + 1;
     }
-    // For the convertion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
+    // For the conversion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
     // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()).
     // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API
     bool isNewVersion =
@@ -997,9 +1055,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   }
 
   // Add new dump trace of API methods calls to script lines
-  if (myPythonScripts.find( aStudyID ) != myPythonScripts.end())
+  if (!myPythonScript.IsNull())
   {
-    Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[ aStudyID ];
+    Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
     Standard_Integer istr, aLen = aPythonScript->Length();
     for (istr = 1; istr <= aLen; istr++)
       lines.push_back( aPythonScript->Value( istr ));
@@ -1013,7 +1071,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   if ( !getenv("NO_2smeshpy_conversion"))
     SMESH_2smeshpy::ConvertScript( lines, anEntry2AccessorMethod,
                                    theObjectNames, aRemovedObjIDs,
-                                   theStudy, isHistoricalDump );
+                                   isHistoricalDump );
 
   bool importGeom = false;
   GEOM::GEOM_Gen_ptr geom = GetGeomEngine();
@@ -1121,9 +1179,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   if ( importGeom && isMultiFile )
   {
     initPart += ("\n## import GEOM dump file ## \n"
-                 "import string, os, sys, re\n"
-                 "sys.path.insert( 0, os.path.dirname(__file__) )\n"
-                 "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n");
+                 "import string, os, sys, re, inspect\n"
+                 "thisFile   = inspect.getfile( inspect.currentframe() )\n"
+                 "thisModule = os.path.splitext( os.path.basename( thisFile ))[0]\n"
+                 "sys.path.insert( 0, os.path.dirname( thisFile ))\n"
+                 "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",thisModule)+\" import *\")\n\n");
   }
   // import python files corresponding to plugins if they are used in anUpdatedScript
   {
@@ -1149,8 +1209,8 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
       initPart += importStr + "\n";
   }
 
-  if( isMultiFile )
-    initPart += "def RebuildData(theStudy):";
+  if ( isMultiFile )
+    initPart += "def RebuildData():";
   initPart += "\n";
 
   anUpdatedScript.Prepend( initPart );
@@ -1161,12 +1221,12 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   TCollection_AsciiString removeObjPart;
   if ( !mapRemoved.IsEmpty() ) {
     removeObjPart += nt + "## some objects were removed";
-    removeObjPart += nt + "aStudyBuilder = theStudy.NewBuilder()";
+    removeObjPart += nt + "aStudyBuilder = salome.myStudy.NewBuilder()";
     Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapRemovedIt;
     for ( mapRemovedIt.Initialize( mapRemoved ); mapRemovedIt.More(); mapRemovedIt.Next() ) {
       aName   = mapRemovedIt.Value(); // python name
       anEntry = mapRemovedIt.Key();
-      removeObjPart += nt + "SO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
+      removeObjPart += nt + "SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(";
       removeObjPart += aName;
       // for object wrapped by class of smeshBuilder.py
       if ( anEntry2AccessorMethod.IsBound( anEntry ) )
@@ -1185,6 +1245,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     if ( theNames.IsBound( anEntry ))
     {
       aGUIName = theNames.Find(anEntry);
+      aGUIName.RemoveAll('\''); // remove a quote from a name (issue 22360)
       setNamePart += nt + aSMESHGen + ".SetName(" + aName;
       if ( anEntry2AccessorMethod.IsBound( anEntry ) )
         setNamePart += helper + "." + anEntry2AccessorMethod( anEntry );
@@ -1203,7 +1264,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   {
     //Output the script that sets up the visual parameters.
     CORBA::String_var compDataType = ComponentDataType();
-    CORBA::String_var script = theStudy->GetDefaultScript( compDataType.in(), tab.ToCString() );
+    CORBA::String_var script = getStudyServant()->GetDefaultScript( compDataType.in(), tab.ToCString() );
     if ( script.in() && script.in()[0] ) {
       visualPropertiesPart += nt + "### Store presentation parameters of displayed objects\n";
       visualPropertiesPart += script.in();
@@ -1212,8 +1273,18 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
 
   anUpdatedScript += removeObjPart + '\n' + setNamePart + '\n' + visualPropertiesPart;
 
-  if( isMultiFile )
-    anUpdatedScript += "\n\tpass";
+  if ( isMultiFile )
+  {
+    anUpdatedScript +=
+      "\n\tpass"
+      "\n"
+      "\nif __name__ == '__main__':"
+      "\n\tSMESH_RebuildData = RebuildData"
+      "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')"
+      "\n\tGEOM_dump.RebuildData()"
+      "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')"
+      "\n\tSMESH_RebuildData()";
+  }
   anUpdatedScript += "\n";
 
   // no need now as we use 'tab' and 'nt' variables depending on isMultiFile
@@ -1226,7 +1297,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
 
   TCollection_AsciiString aLongString, aFunctionType;
   int where = 1;
-  set< string > functionNameSet;
+  std::set< std::string > functionNameSet;
   while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType ))
   {
     // make a python string literal
@@ -1289,13 +1360,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
  *  GetNewPythonLines
  */
 //=============================================================================
-TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID)
+TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines()
 {
   TCollection_AsciiString aScript;
 
   // Dump trace of API methods calls
-  if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
-    Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[theStudyID];
+  if (!myPythonScript.IsNull()) {
+    Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript;
     Standard_Integer istr, aLen = aPythonScript->Length();
     for (istr = 1; istr <= aLen; istr++) {
       aScript += "\n";
@@ -1312,12 +1383,12 @@ TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID)
  *  CleanPythonTrace
  */
 //=============================================================================
-void SMESH_Gen_i::CleanPythonTrace (int theStudyID)
+void SMESH_Gen_i::CleanPythonTrace()
 {
   TCollection_AsciiString aScript;
 
   // Clean trace of API methods calls
-  if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
-    myPythonScripts[theStudyID]->Clear();
+  if (!myPythonScript.IsNull()) {
+    myPythonScript->Clear();
   }
 }