Salome HOME
Dump Python: respect dump names of GEOM to avoid same names of different objects.
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
index db8721515fd49fe618ca988cc572dac5a0629079..26eb938c1ed7ae0fbe12421b6cb4b7a5cffaaf3d 100644 (file)
 #include <TColStd_HSequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
 namespace SMESH
 {
 
@@ -31,10 +37,53 @@ namespace SMESH
        std::string aString = myStream.str();
        TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
        aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
+       if(MYDEBUG) MESSAGE(aString);
       }
     }
   }
 
+  TPythonDump& 
+  TPythonDump::
+  operator<<(long int theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
+  TPythonDump& 
+  TPythonDump::
+  operator<<(int theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
+  TPythonDump& 
+  TPythonDump::
+  operator<<(double theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
+  TPythonDump& 
+  TPythonDump::
+  operator<<(float theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
+  TPythonDump& 
+  TPythonDump::
+  operator<<(const void* theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
+  TPythonDump& 
+  TPythonDump::
+  operator<<(const char* theArg){
+    myStream<<theArg;
+    return *this;
+  }
+
   TPythonDump& 
   TPythonDump::
   operator<<(const SMESH::ElementType& theArg)
@@ -106,7 +155,7 @@ namespace SMESH
   TPythonDump::
   operator<<(SMESH::FilterManager_i* theArg)
   {
-    myStream<<"aFilterManager"<<theArg;
+    myStream<<"aFilterManager";
     return *this;
   }
 
@@ -439,13 +488,12 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   
   aScript += "def RebuildData(theStudy):";
   aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")";
+  aScript += "\n\taFilterManager = smesh.CreateFilterManager()";
   if ( isPublished )
     aScript += "\n\tsmesh.SetCurrentStudy(theStudy)";
   else
     aScript += "\n\tsmesh.SetCurrentStudy(None)";
 
-  TCollection_AsciiString globalVars;
-
   // Dump trace of restored study
   if (theSavedTrace.Length() > 0) {
     aScript += "\n";
@@ -470,42 +518,50 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   GEOM::GEOM_Gen_ptr geom = GetGeomEngine();
   TColStd_SequenceOfAsciiString seqRemoved;
   Resource_DataMapOfAsciiStringAsciiString mapRemoved;
-  Resource_DataMapOfAsciiStringAsciiString aNames;
   Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length();
   TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("smeshObj_");
 
+  // Collect names of GEOM objects to exclude same names for SMESH objects
+  GEOM::string_array_var aGeomNames = geom->GetAllDumpNames();
+  int ign = 0, nbgn = aGeomNames->length();
+  for (; ign < nbgn; ign++) {
+    aName = aGeomNames[ign];
+    theObjectNames.Bind(aName, "1");
+  }
+
   for (Standard_Integer i = 1; i <= aLen; i += 2) {
     anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
-    if (theObjectNames.IsBound(anEntry)) {
-      aName = theObjectNames.Find(anEntry);
-      if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
-        // diff objects have same name - make a new name
-        TCollection_AsciiString aName2;
-        Standard_Integer i = 0;
-        do {
-          aName2 = aName + "_" + ++i;
-        } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
-        aName = aName2;
-        theObjectNames(anEntry) = aName;
-      }
-    } else {
-      // is a GEOM object?
-      aName = geom->GetDumpName( anEntry.ToCString() );
-      if ( aName.IsEmpty() ) {
-      // ? Removed Object ?
+    // is a GEOM object?
+    aName = geom->GetDumpName( anEntry.ToCString() );
+    if (aName.IsEmpty()) {
+      // is a SMESH object
+      if (theObjectNames.IsBound(anEntry)) {
+        // The Object is in Study
+        aName = theObjectNames.Find(anEntry);
+        if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
+          // diff objects have same name - make a new name
+          TCollection_AsciiString aName2;
+          Standard_Integer i = 0;
+          do {
+            aName2 = aName + "_" + ++i;
+          } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
+          aName = aName2;
+          theObjectNames(anEntry) = aName;
+        }
+      } else {
+        // Removed Object
         do {
           aName = aBaseName + TCollection_AsciiString(++objectCounter);
         } while (theObjectNames.IsBound(aName));
         seqRemoved.Append(aName);
         mapRemoved.Bind(anEntry, "1");
+        theObjectNames.Bind(anEntry, aName);
       }
-      theObjectNames.Bind(anEntry, aName);
+      theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
     }
-    theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
 
     anUpdatedScript += aName;
-    aNames.Bind(aName, "1");
     aStart = aSeq->Value(i + 1) + 1;
   }