Salome HOME
Merge V8_4_BR branch.
[modules/geom.git] / src / GEOM / GEOM_Engine.cxx
index ac1216f5a27922600c4eb93f3c2011d5867b53cb..dd4bc10126af391032cf63bed182c38951086002 100644 (file)
@@ -34,8 +34,6 @@
 #include "GEOM_SubShapeDriver.hxx"
 #include "Sketcher_Profile.hxx"
 
-#include <Basics_OCCTVersion.hxx>
-
 #include "utilities.h"
 
 #include <Basics_Utils.hxx>
 
 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
 
+#include <BinDrivers.hxx>
+#include <StdDrivers_DocumentRetrievalDriver.hxx>
+#include <PCDM_StorageDriver.hxx>
+
 #include <set>
 
 #include <Standard_Failure.hxx>
@@ -84,6 +86,14 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
+// VSR 29/08/2017: 0023327, 0023428: eliminate unnecessary lines in Python dump
+// Next macro, when defined, causes appearing of SubShapeAllIDs(), SubShapeAllSortedIDs(), GetSameIDs()
+// and other such commands in Python dump.
+// See also GEOMImpl_IShapesOperations.cxx.
+// ---------------------------------------
+// #define DUMP_SUBSHAPE_IDS
+// ---------------------------------------
+
 typedef std::map< TCollection_AsciiString, TCollection_AsciiString > TSting2StringMap;
 typedef std::map< TCollection_AsciiString, TObjectData >             TSting2ObjDataMap;
 typedef std::map< TCollection_AsciiString, TObjectData* >            TSting2ObjDataPtrMap;
@@ -159,6 +169,8 @@ static TCollection_AsciiString GetPublishCommands
                     const TIntToListIntMap                         &theMapRefs,
                           std::set< int >                          &thePublished);
 
+void Prettify(TCollection_AsciiString& theScript);
+
 //================================================================================
 /*!
  * \brief Fix up the name of python variable
@@ -225,6 +237,9 @@ GEOM_Engine::GEOM_Engine()
   TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver());
   
   _OCAFApp = new GEOM_Application();
+  _OCAFApp->DefineFormat("SALOME_GEOM", "GEOM Document Version 1.0", "sgd",
+                         new StdDrivers_DocumentRetrievalDriver, 0);
+  BinDrivers::DefineFormat(_OCAFApp);
   _UndoLimit = 0;
 }
 
@@ -264,11 +279,7 @@ Handle(TDocStd_Document) GEOM_Engine::GetDocument(int theDocID, bool force)
     aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
   }
   else if (force) {
-#if OCC_VERSION_MAJOR > 6
     _OCAFApp->NewDocument("BinOcaf", aDoc);
-#else
-    _OCAFApp->NewDocument("SALOME_GEOM", aDoc);
-#endif
     aDoc->SetUndoLimit(_UndoLimit);
     _mapIDDocument.Bind(theDocID, aDoc);
     TDataStd_Integer::Set(aDoc->Main(), theDocID);
@@ -429,9 +440,8 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object)              th
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    MESSAGE("GEOM_Engine::AddSubShape Error: " << aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    MESSAGE("GEOM_Engine::AddSubShape Error: " << aFail.GetMessageString());
     return NULL;
   }
 
@@ -508,7 +518,7 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject)
   if ( aFreeLabels.empty() || aFreeLabels.back() != aLabel )
     aFreeLabels.push_back(aLabel);
 
-  // we can't explicitely delete theObject. At least prevent its functioning
+  // we can't explicitly delete theObject. At least prevent its functioning
   // as an alive object when aLabel is reused for a new object
   theObject->_label = aLabel.Root();
   theObject->_ior.Clear();
@@ -567,12 +577,10 @@ bool GEOM_Engine::Load(int theDocID, const char* theFileName)
     return false;
   }
 
-#if OCC_VERSION_MAJOR > 6
   // Replace old document format by the new one.
   if (aDoc->StorageFormat().IsEqual("SALOME_GEOM")) {
     aDoc->ChangeStorageFormat("BinOcaf");
   }
-#endif
 
   aDoc->SetUndoLimit(_UndoLimit);
 
@@ -658,7 +666,7 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
   // a map containing copies of TObjectData from theObjectData
   TSting2ObjDataMap    aEntry2ObjData;
   // contains pointers to TObjectData of either aEntry2ObjData or theObjectData; the latter
-  // occures when several StudyEntries correspond to one Entry
+  // occurs when several StudyEntries correspond to one Entry
   TSting2ObjDataPtrMap aStEntry2ObjDataPtr;
 
   //Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry, theObjectNames;
@@ -858,6 +866,11 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
     aScript.Insert( posToInsertGlobalVars, globalVars );
   }
 
+  // VSR 29/08/2017: 0023327, 0023428: eliminate unnecessary lines in Python dump
+#ifndef DUMP_SUBSHAPE_IDS
+  Prettify(aScript);
+#endif
+
   return aScript;
 }
 
@@ -1842,7 +1855,7 @@ void PublishObject (TObjectData&                              theObjectData,
 
     // store aCreationCommand before publishing commands
     int tag = GetTag(theObjectData._entry);
-    theEntryToCmdMap.insert( std::make_pair( tag + 2*theEntry2ObjData.size(), aCreationCommand ));
+    theEntryToCmdMap.insert( std::make_pair( tag + -2*theEntry2ObjData.size(), aCreationCommand ));
   }
 
   // make a command
@@ -1907,6 +1920,43 @@ TCollection_AsciiString GetPublishCommands
   return aResult;
 }
 
+void Prettify(TCollection_AsciiString& theScript)
+{
+  TCollection_AsciiString output;
+  static std::list<TCollection_AsciiString> ToRemove;
+  if (ToRemove.empty()) {
+    ToRemove.push_back("geompy.SubShapeAllIDs");
+    ToRemove.push_back("geompy.SubShapeAllSortedCentresIDs");
+    ToRemove.push_back("geompy.SubShapeAllSortedIDs");
+    ToRemove.push_back("geompy.GetFreeFacesIDs");
+    ToRemove.push_back("geompy.GetShapesOnBoxIDs");
+    ToRemove.push_back("geompy.GetShapesOnShapeIDs");
+    ToRemove.push_back("geompy.GetShapesOnPlaneIDs");
+    ToRemove.push_back("geompy.GetShapesOnPlaneWithLocationIDs");
+    ToRemove.push_back("geompy.GetShapesOnCylinderIDs");
+    ToRemove.push_back("geompy.GetShapesOnCylinderWithLocationIDs");
+    ToRemove.push_back("geompy.GetShapesOnSphereIDs");
+    ToRemove.push_back("geompy.GetShapesOnQuadrangleIDs");
+    ToRemove.push_back("geompy.GetSameIDs");
+  }
+
+  int start = 1;
+  while (start <= theScript.Length()) {
+    int end = theScript.Location("\n", start, theScript.Length());
+    if (end == -1) end = theScript.Length();
+    TCollection_AsciiString line = theScript.SubString(start, end);
+    bool found = false;
+    for (std::list<TCollection_AsciiString>::const_iterator it = ToRemove.begin(); it != ToRemove.end() && !found; ++it)
+      found = line.Search( *it ) != -1;
+    if (!found)
+      output += line;
+    start = end + 1;
+  }
+  theScript = output;
+
+  //OK @@@@@@@@@@@@@@@@@@@@@@@@@@@
+}
+
 //================================================================================
 /*!
  * \brief Constructor