Salome HOME
0023505: Sigsegv with fuse on cylinder and cone
[modules/geom.git] / src / GEOM / GEOM_Engine.cxx
index f7ae8fc8e82a29a7217fa2d1dbebecc175e989ee..90faf13feca75632a95730280e45cb12ef2e8fb5 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>
 
-#if OCC_VERSION_LARGE > 0x07000000
 #include <BinDrivers.hxx>
 #include <StdDrivers_DocumentRetrievalDriver.hxx>
 #include <PCDM_StorageDriver.hxx>
-#endif
 
 #include <set>
 
@@ -90,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;
@@ -165,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
@@ -231,11 +237,9 @@ GEOM_Engine::GEOM_Engine()
   TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver());
   
   _OCAFApp = new GEOM_Application();
-#if OCC_VERSION_LARGE > 0x07000000
   _OCAFApp->DefineFormat("SALOME_GEOM", "GEOM Document Version 1.0", "sgd",
                          new StdDrivers_DocumentRetrievalDriver, 0);
   BinDrivers::DefineFormat(_OCAFApp);
-#endif
   _UndoLimit = 0;
 }
 
@@ -275,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);
@@ -440,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;
   }
 
@@ -578,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);
 
@@ -869,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;
 }
 
@@ -1918,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