Salome HOME
Merge multi-study removal branch.
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
index cc842f215462cc31dedfe6acfedeca3f84b65e55..92506466cdbd268668025cb1c8106b4745bb1861 100644 (file)
@@ -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(),"");
@@ -316,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;
@@ -336,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
@@ -352,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;
@@ -368,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
@@ -718,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);
 
@@ -761,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();
@@ -782,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);
 }
 
 //=============================================================================
@@ -795,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);
   }
 }
 
@@ -807,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");
 
@@ -835,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();
 }
 
 
@@ -979,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
@@ -993,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,
@@ -1003,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() );
@@ -1015,9 +1007,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   std::list< TCollection_AsciiString >::iterator linesIt;
   
   if ( isPublished )
-    lines.push_back(  aSMESHGen + " = smeshBuilder.New(theStudy)" );
+    lines.push_back(  aSMESHGen + " = smeshBuilder.New()" );
    else
-    lines.push_back(  aSMESHGen + " = smeshBuilder.New(None)" );
+    lines.push_back(  aSMESHGen + " = smeshBuilder.New(False)" );
   lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" );
   lines.push_back( helper + "aMeasurements = "  + aSMESHGen + ".CreateMeasurements()" );
 
@@ -1063,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 ));
@@ -1079,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();
@@ -1218,7 +1210,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   }
 
   if ( isMultiFile )
-    initPart += "def RebuildData(theStudy):";
+    initPart += "def RebuildData():";
   initPart += "\n";
 
   anUpdatedScript.Prepend( initPart );
@@ -1229,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 ) )
@@ -1272,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();
@@ -1289,9 +1281,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
       "\nif __name__ == '__main__':"
       "\n\tSMESH_RebuildData = RebuildData"
       "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')"
-      "\n\tGEOM_dump.RebuildData( salome.myStudy )"
+      "\n\tGEOM_dump.RebuildData()"
       "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')"
-      "\n\tSMESH_RebuildData( salome.myStudy )";
+      "\n\tSMESH_RebuildData()";
   }
   anUpdatedScript += "\n";
 
@@ -1368,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";
@@ -1391,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();
   }
 }