Salome HOME
Regression of XSMESH_TEST/SMESHCOMMON/SMESH_TEST/Grids/smesh/bugs12/M6
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
index cebc6e37ef3c1d7e3b96172c15c7d4fc226334f8..8736356acfe23c534f4d7da058e6dff63fe743fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -71,26 +71,31 @@ namespace SMESH
       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(!aStudy->_is_nil() && !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);
         if(MYDEBUG) MESSAGE(aString);
-        aSMESHGen->UpdateParameters(""); // prevent misuse of already treated variables
+        // prevent misuse of already treated variables
+        aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
       }
     }
   }
 
-  TPythonDump& //!< to store a variable value
+  TPythonDump& //!< store a variable value. Write either a value or '$varID$'
   TPythonDump::
   operator<<(const TVar& theVarValue)
   {
-    const std::vector< std::string >& varNames = SMESH_Gen_i::GetSMESHGen()->GetLastParameters();
+    const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
     if ( theVarValue.myVals.size() != 1 )
     {
       myStream << "[ ";
       for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
       {
-        if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() )
-          myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote();
+        if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
+          myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
         else
           myStream << theVarValue.myVals[i-1];
         if ( i < theVarValue.myVals.size() )
@@ -101,8 +106,8 @@ namespace SMESH
     }
     else
     {
-      if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() )
-        myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote();
+      if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
+        myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
       else
         myStream << theVarValue.myVals[0];
       ++myVarsCounter;
@@ -310,7 +315,7 @@ namespace SMESH
     if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
       myStream << "hyp_" << theArg->GetId();
     else
-      *this << CORBA::Object_ptr( theArg );
+      *this << aSObject;
     return *this;
   }
 
@@ -657,7 +662,6 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
   }
 
   // Get trace of restored study
-  //SALOMEDS::SObject_wrap aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
   SALOMEDS::GenericAttribute_wrap anAttr =
     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
@@ -865,9 +869,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   aScript += helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()\n\t";
   aScript += helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()\n\t";
   if ( isPublished )
-    aScript += aSMESHGen + ".SetCurrentStudy(theStudy)";
+    aScript += aSMESHGen + " = smeshBuilder.New(theStudy)";
   else
-    aScript += aSMESHGen + ".SetCurrentStudy(None)";
+    aScript += aSMESHGen + " = smeshBuilder.New(None)";
 
   // import python files corresponding to plugins
   set<string> moduleNameSet;
@@ -876,14 +880,14 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     string moduleName = hyp_creator->second->GetModuleName();
     bool newModule = moduleNameSet.insert( moduleName ).second;
     if ( newModule )
-      aScript += helper + "\n\t" + "import " + (char*) moduleName.c_str();
+      aScript += helper + "\n\t" + "from salome." + (char*) moduleName.c_str() + " import " + (char*) moduleName.c_str() +"Builder";
   }
 
   // Dump trace of restored study
   if (theSavedTrace.Length() > 0) {
-    // For the convertion of IDL API calls -> smesh.py API, "smesh" standing for SMESH_Gen
+    // For the convertion 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 smesh.py API
+    // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API
     bool isNewVersion =
       theSavedTrace.Location( anOldGen + ".", 1, theSavedTrace.Length() );
     if ( !isNewVersion ) {
@@ -911,7 +915,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     aScript += helper + "\n" + aNewLines;
   }
 
-  // Convert IDL API calls into smesh.py API.
+  // Convert IDL API calls into smeshBuilder.py API.
   // Some objects are wrapped with python classes and
   // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
   Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
@@ -999,7 +1003,8 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   TCollection_AsciiString initPart = "import ";
   if ( isMultiFile )
     initPart += helper + "salome, ";
-  initPart += aSmeshpy + ", SMESH, SALOMEDS\n";
+  initPart += " SMESH, SALOMEDS\n";
+  initPart += "from salome.smesh import smeshBuilder\n";
   if ( importGeom && isMultiFile )
   {
     initPart += ("\n## import GEOM dump file ## \n"
@@ -1022,7 +1027,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     if ( aRemovedObjIDs.count( seqRemoved.Value(ir) )) continue;
     anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
     anUpdatedScript += seqRemoved.Value(ir);
-    // for object wrapped by class of smesh.py
+    // for object wrapped by class of smeshBuilder.py
     anEntry = theObjectNames( seqRemoved.Value(ir) );
     if ( anEntry2AccessorMethod.IsBound( anEntry ) )
       anUpdatedScript += helper + "." + anEntry2AccessorMethod( anEntry );