Salome HOME
Copyrights update 2013
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
index b609c57501ef9d686398557ee7507a9d9dfeb5dc..0e3ae652fd399f3c0767bf945130a3f03224f7f8 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
@@ -43,15 +43,11 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
-static TCollection_AsciiString NotPublishedObjectName()
-{
-  return "__NOT__Published__Object__";
-}
-
 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); }
@@ -75,26 +71,28 @@ 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())
+      {
         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() )
@@ -105,8 +103,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;
@@ -196,6 +194,40 @@ namespace SMESH
     }
     return *this;
   }
+  TPythonDump&
+  TPythonDump::
+  operator<<(const SMESH::EntityType& theArg)
+  {
+    myStream<<"SMESH.";
+    switch(theArg){
+    case Entity_0D:                myStream<<"Entity_0D";                break;
+    case Entity_Edge:              myStream<<"Entity_Edge";              break;
+    case Entity_Quad_Edge:         myStream<<"Entity_Quad_Edge";         break;
+    case Entity_Triangle:          myStream<<"Entity_Triangle";          break;
+    case Entity_Quad_Triangle:     myStream<<"Entity_Quad_Triangle";     break;
+    case Entity_Quadrangle:        myStream<<"Entity_Quadrangle";        break;
+    case Entity_Quad_Quadrangle:   myStream<<"Entity_Quad_Quadrangle";   break;
+    case Entity_BiQuad_Quadrangle: myStream<<"Entity_BiQuad_Quadrangle"; break;
+    case Entity_Polygon:           myStream<<"Entity_Polygon";           break;
+    case Entity_Quad_Polygon:      myStream<<"Entity_Quad_Polygon";      break;
+    case Entity_Tetra:             myStream<<"Entity_Tetra";             break;
+    case Entity_Quad_Tetra:        myStream<<"Entity_Quad_Tetra";        break;
+    case Entity_Pyramid:           myStream<<"Entity_Pyramid";           break;
+    case Entity_Quad_Pyramid:      myStream<<"Entity_Quad_Pyramid";      break;
+    case Entity_Hexa:              myStream<<"Entity_Hexa";              break;
+    case Entity_Quad_Hexa:         myStream<<"Entity_Quad_Hexa";         break;
+    case Entity_TriQuad_Hexa:      myStream<<"Entity_TriQuad_Hexa";      break;
+    case Entity_Penta:             myStream<<"Entity_Penta";             break;
+    case Entity_Quad_Penta:        myStream<<"Entity_Quad_Penta";        break;
+    case Entity_Hexagonal_Prism:   myStream<<"Entity_Hexagonal_Prism";   break;
+    case Entity_Polyhedra:         myStream<<"Entity_Polyhedra";         break;
+    case Entity_Quad_Polyhedra:    myStream<<"Entity_Quad_Polyhedra";    break;
+    case Entity_Ball:              myStream<<"Entity_Ball";              break;
+    case Entity_Last:              myStream<<"Entity_Last";              break;
+    default:    myStream<<"__UNKNOWN__EntityType: " << theArg;
+    }
+    return *this;
+  }
 
   template<class TArray>
   void DumpArray(const TArray& theArray, TPythonDump & theStream)
@@ -245,7 +277,7 @@ namespace SMESH
       myStream << entry.in();
     }
     else {
-      myStream << NotPublishedObjectName();
+      myStream << theNotPublishedObjectName;
     }
     return *this;
   }
@@ -264,7 +296,7 @@ namespace SMESH
       if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
         myStream << "smeshObj_" << size_t(theArg);
       else
-        myStream << NotPublishedObjectName();
+        myStream << theNotPublishedObjectName;
     }
     else
       myStream << "None";
@@ -309,7 +341,7 @@ namespace SMESH
       SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
       return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
     }
-    return *this;
+    return *this << theNotPublishedObjectName;
   }
 
   TPythonDump&
@@ -471,6 +503,10 @@ namespace SMESH
     DumpArray( theList, *this );
     return *this;
   }
+  const char* TPythonDump::NotPublishedObjectName()
+  {
+    return theNotPublishedObjectName;
+  }
 
   TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
   TCollection_AsciiString myLongStringEnd  ( "TPythonDump::LongStringEnd" );
@@ -623,7 +659,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");
@@ -645,7 +680,7 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
 
-  bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen);
+  bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen);
   isValidScript = isValidScript && !hasNotPublishedObjects;
 
   return aStreamFile._retn();
@@ -881,9 +916,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   // Some objects are wrapped with python classes and
   // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
   Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
+  std::set< TCollection_AsciiString >      aRemovedObjIDs;
   if ( !getenv("NO_2smeshpy_conversion"))
     aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
-                                             theObjectNames, theStudy, isHistoricalDump );
+                                             theObjectNames, aRemovedObjIDs,
+                                             theStudy, isHistoricalDump );
 
   // Replace characters used instead of quote marks to quote notebook variables
   {
@@ -983,6 +1020,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
     anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
   }
   for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
+    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
@@ -1003,13 +1041,14 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
   for (Standard_Integer i = 1; i <= aLen; i += 2)
   {
     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
-    aName = geom->GetDumpName( anEntry.ToCString() );
+    aName   = geom->GetDumpName( anEntry.ToCString() );
     if (aName.IsEmpty() && // Not a GEOM object
         theNames.IsBound(anEntry) &&
+        !aRemovedObjIDs.count(anEntry) && // a command creating anEntry was erased
         !mapEntries.IsBound(anEntry) && // Not yet processed
         !mapRemoved.IsBound(anEntry)) // Was not removed
     {
-      aName = theObjectNames.Find(anEntry);
+      aName    = theObjectNames.Find(anEntry);
       aGUIName = theNames.Find(anEntry);
       mapEntries.Bind(anEntry, aName);
       anUpdatedScript += helper + "\n\t" + aSMESHGen + ".SetName(" + aName;