]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOM/GEOM_Engine.cxx
Salome HOME
0021672: [CEA 565] Dump Study from script
[modules/geom.git] / src / GEOM / GEOM_Engine.cxx
index 523637151cd93f93124e4ead492ad8450679a9d8..cc284959899b3c6d8c5b285dbfd65abf269ba376 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  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
@@ -33,6 +33,8 @@
 #include "GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient.hxx"
 #include "GEOM_PythonDump.hxx"
 
+#include <Basics_OCCTVersion.hxx>
+
 #include "utilities.h"
 
 #include <Basics_Utils.hxx>
@@ -45,7 +47,6 @@
 #include <TDataStd_ChildNodeIterator.hxx>
 #include <TFunction_Driver.hxx>
 #include <TFunction_DriverTable.hxx>
-#include <TDataStd_HArray1OfByte.hxx>
 #include <TDataStd_ByteArray.hxx>
 #include <TDataStd_UAttribute.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TColStd_MapOfTransient.hxx>
 #include <TColStd_HSequenceOfInteger.hxx>
 
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+#include <TColStd_HArray1OfByte.hxx>
+#include <TColStd_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
+#else
+#include <TDataStd_HArray1OfByte.hxx>
 #include <Interface_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
+#endif
+
 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
 
 #include <set>
@@ -211,7 +219,7 @@ void GEOM_Engine::SetEngine(GEOM_Engine* theEngine) { TheEngine = theEngine; }
 GEOM_Engine::GEOM_Engine()
 {
   TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver());
-
+  
   _OCAFApp = new GEOM_Application();
   _UndoLimit = 10;
 }
@@ -230,7 +238,12 @@ GEOM_Engine::~GEOM_Engine()
     RemoveObject(*objit);
 
   //Close all documents not closed
-  for(Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr(_mapIDDocument); anItr.More(); anItr.Next())
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  TColStd_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
+#else
+  Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
+#endif
+  for (; anItr.More(); anItr.Next())
     Close(anItr.Key());
 
   _mapIDDocument.Clear();
@@ -264,12 +277,16 @@ Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID, bool force)
 //=============================================================================
 int GEOM_Engine::GetDocID(Handle(TDocStd_Document) theDocument)
 {
-  if(theDocument.IsNull()) return -1;
-  for(Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr(_mapIDDocument); anItr.More(); anItr.Next())
-    if(anItr.Value() == theDocument) return anItr.Key();
+  if (theDocument.IsNull()) return -1;
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  TColStd_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
+#else
+  Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
+#endif
+  for (; anItr.More(); anItr.Next())
+    if (anItr.Value() == theDocument) return anItr.Key();
 
   return -1;
-
 }
 
 //=============================================================================
@@ -377,7 +394,7 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape,
   aSSI.SetIndices(theIndices);
 
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     GEOM_Solver aSolver (GEOM_Engine::GetEngine());
@@ -397,7 +414,7 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape,
   if (_objects.IsBound(anID)) _objects.UnBind(anID);
   _objects.Bind(anID, anObject);
 
-  // Put this subshape in the list of subshapes of theMainShape
+  // Put this sub-shape in the list of sub-shapes of theMainShape
   aMainShape->AddSubShapeReference(aFunction);
 
   GEOM::TPythonDump pd (aFunction);
@@ -433,7 +450,7 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject)
   TCollection_AsciiString anID = BuildIDFromObject(theObject);
   if (_objects.IsBound(anID)) _objects.UnBind(anID);
 
-  // If subshape, remove it from the list of subshapes of its main shape
+  // If sub-shape, remove it from the list of sub-shapes of its main shape
   if (!theObject->IsMainShape()) {
     Handle(GEOM_Function) aFunction = theObject->GetFunction(1);
     GEOM_ISubShape aSSI (aFunction);
@@ -506,7 +523,11 @@ bool GEOM_Engine::Save(int theDocID, char* theFileName)
 bool GEOM_Engine::Load(int theDocID, char* theFileName)
 {
   Handle(TDocStd_Document) aDoc;
-  if(_OCAFApp->Open(theFileName, aDoc) != CDF_RS_OK) {
+#if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
+  if (_OCAFApp->Open(theFileName, aDoc) != PCDM_RS_OK) {
+#else
+  if (_OCAFApp->Open(theFileName, aDoc) != CDF_RS_OK) {
+#endif
     return false;
   }
 
@@ -650,7 +671,15 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
         continue;
       // add function description before dump
       if (!aCurScript.IsEmpty())
+      {
+        if ( aFunction->GetDriverGUID() == GEOM_Object::GetSubShapeID() )
+          // avoid repeated SubShape...() command at the end
+          if (aFuncScript.Location( aCurScript,
+                                    aFuncScript.Length() - aCurScript.Length(),
+                                    aFuncScript.Length()))
+              continue;
         aFuncScript += aCurScript;
+      }
       if (isDumpCollected ) {
         // Replace entries by the names
         ReplaceEntriesByNames( aFuncScript, aEntry2ObjData, isPublished,
@@ -806,7 +835,11 @@ Handle(TColStd_HSequenceOfAsciiString) GEOM_Engine::GetAllDumpNames() const
 #define TEXTURE_LABEL_DATA     5
 
 int GEOM_Engine::addTexture(int theDocID, int theWidth, int theHeight,
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+                            const Handle(TColStd_HArray1OfByte)& theTexture,
+#else
                             const Handle(TDataStd_HArray1OfByte)& theTexture,
+#endif
                             const TCollection_AsciiString& theFileName)
 {
   Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
@@ -851,11 +884,19 @@ int GEOM_Engine::addTexture(int theDocID, int theWidth, int theHeight,
   return aTextureID;
 }
 
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+Handle(TColStd_HArray1OfByte) GEOM_Engine::getTexture(int theDocID, int theTextureID,
+#else
 Handle(TDataStd_HArray1OfByte) GEOM_Engine::getTexture(int theDocID, int theTextureID,
-                                                       int& theWidth, int& theHeight,
-                                                       TCollection_AsciiString& theFileName)
+#endif
+                                                      int& theWidth, int& theHeight,
+                                                      TCollection_AsciiString& theFileName)
 {
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  Handle(TColStd_HArray1OfByte) anArray;
+#else
   Handle(TDataStd_HArray1OfByte) anArray;
+#endif
   theWidth = theHeight = 0;
 
   Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
@@ -1226,6 +1267,12 @@ void ReplaceVariables(TCollection_AsciiString& theCommand,
             else
               aEndParamPos = aSection.Length() + 1;
 
+            if(MYDEBUG)
+              cout<<"aParamIndex: "<<aParamIndex<<" aStartParamPos: " <<aStartParamPos<<" aEndParamPos: "<<aEndParamPos<<endl;
+
+           if ( aStartParamPos == aEndParamPos)
+             continue;
+
             aParameter = aSection.SubString(aStartParamPos, aEndParamPos-1);
             if(MYDEBUG)
               cout<<"aParameter: "<<aParameter<<endl;
@@ -1455,7 +1502,11 @@ void AddObjectColors (int                      theDocID,
   }
 }
 
-static TCollection_AsciiString pack_data(const Handle(TDataStd_HArray1OfByte)& aData )
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+static TCollection_AsciiString pack_data (const Handle(TColStd_HArray1OfByte)& aData)
+#else
+static TCollection_AsciiString pack_data (const Handle(TDataStd_HArray1OfByte)& aData)
+#endif
 {
   TCollection_AsciiString stream;
   if (!aData.IsNull()) {
@@ -1483,7 +1534,12 @@ void AddTextures (int theDocID, TCollection_AsciiString& theScript)
       if (*it <= 0) continue;
       Standard_Integer aWidth, aHeight;
       TCollection_AsciiString aFileName;
-      Handle(TDataStd_HArray1OfByte) aTexture = engine->getTexture(theDocID, *it, aWidth, aHeight, aFileName);
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+      Handle(TColStd_HArray1OfByte) aTexture =
+#else
+      Handle(TDataStd_HArray1OfByte) aTexture =
+#endif
+        engine->getTexture(theDocID, *it, aWidth, aHeight, aFileName);
       if (aWidth > 0 && aHeight > 0 && !aTexture.IsNull() && aTexture->Length() > 0 ) {
         TCollection_AsciiString aCommand = "\n\t";
         aCommand += "texture_map["; aCommand += *it; aCommand += "] = ";