Salome HOME
Merge 'master' branch into 'V9_dev' branch.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IBooleanOperations.cxx
index 8b2b2a1e9814e0ea1a6cbb9cad7e0f815cea70a5..3cd0f6b40e899e38f996bbdc97f6ad6140d7f330 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -35,8 +35,6 @@
 #include <GEOMImpl_PartitionDriver.hxx>
 #include <GEOMImpl_IPartition.hxx>
 
-#include <Basics_OCCTVersion.hxx>
-
 #include <TDF_Tool.hxx>
 
 #include "utilities.h"
@@ -49,8 +47,8 @@
  *   constructor:
  */
 //=============================================================================
-GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations (GEOM_Engine* theEngine, int theDocID)
-: GEOM_IOperations(theEngine, theDocID)
+GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations (GEOM_Engine* theEngine)
+: GEOM_IOperations(theEngine)
 {
   MESSAGE("GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations");
 }
@@ -82,7 +80,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean
   if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
 
   //Add a new Boolean object
-  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GEOM_BOOLEAN);
 
   //Add a new Boolean function
   Handle(GEOM_Function) aFunction;
@@ -114,17 +112,14 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean
 
   //Compute the Boolean value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Boolean driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
@@ -148,6 +143,69 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean
   return aBool;
 }
 
+//=============================================================================
+/*!
+ *  MakeFuse
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeFuse
+                                  (Handle(GEOM_Object)    theShape1,
+                                   Handle(GEOM_Object)    theShape2,
+                                   const bool             IsCheckSelfInte,
+                                   const bool             IsRmExtraEdges)
+{
+  SetErrorCode(KO);
+
+  if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
+
+  //Add a new Boolean object
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GEOM_BOOLEAN);
+
+  //Add a new Boolean function
+  Handle(GEOM_Function) aFunction =
+    aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_FUSE);
+
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL;
+
+  GEOMImpl_IBoolean aCI (aFunction);
+
+  Handle(GEOM_Function) aRef1 = theShape1->GetLastFunction();
+  Handle(GEOM_Function) aRef2 = theShape2->GetLastFunction();
+
+  if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
+
+  aCI.SetShape1(aRef1);
+  aCI.SetShape2(aRef2);
+  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
+  aCI.SetRmExtraEdges(IsRmExtraEdges);
+
+  //Compute the Boolean value
+  try {
+    OCC_CATCH_SIGNALS;
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Boolean driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump pd (aFunction);
+
+  pd << aBool << " = geompy.MakeFuse(";
+  pd << theShape1 << ", " << theShape2 << ", "
+     << IsCheckSelfInte << ", " << IsRmExtraEdges << ")";
+
+  SetErrorCode(OK);
+  return aBool;
+}
+
 //=============================================================================
 /*!
  *  MakeFuseList
@@ -155,14 +213,15 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeFuseList
                   (const Handle(TColStd_HSequenceOfTransient)& theShapes,
-                   const Standard_Boolean IsCheckSelfInte)
+                   const bool                                  IsCheckSelfInte,
+                   const bool                                  IsRmExtraEdges)
 {
   SetErrorCode(KO);
 
   if (theShapes.IsNull()) return NULL;
 
   //Add a new Boolean object
-  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GEOM_BOOLEAN);
 
   //Add a new Boolean function
   Handle(GEOM_Function) aFunction =
@@ -183,34 +242,26 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeFuseList
 
   aCI.SetShapes(aShapesSeq);
   aCI.SetCheckSelfIntersection(IsCheckSelfInte);
+  aCI.SetRmExtraEdges(IsRmExtraEdges);
 
   //Compute the Boolean value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Boolean driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
   //Make a Python command
   GEOM::TPythonDump pd (aFunction);
 
-  pd << aBool <<
-    " = geompy.MakeFuseList([" << aDescription.ToCString() << "]";
-
-  if (IsCheckSelfInte) {
-    pd << ", True";
-  }
-
-  pd << ")";
+  pd << aBool << " = geompy.MakeFuseList([" << aDescription.ToCString() << "], "
+     << IsCheckSelfInte << ", " << IsRmExtraEdges << ")";
 
   SetErrorCode(OK);
   return aBool;
@@ -230,7 +281,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCommonList
   if (theShapes.IsNull()) return NULL;
 
   //Add a new Boolean object
-  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GEOM_BOOLEAN);
 
   //Add a new Boolean function
   Handle(GEOM_Function) aFunction =
@@ -254,17 +305,14 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCommonList
 
   //Compute the Boolean value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Boolean driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
@@ -299,7 +347,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCutList
   if (theShapes.IsNull()) return NULL;
 
   //Add a new Boolean object
-  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GEOM_BOOLEAN);
 
   //Add a new Boolean function
   Handle(GEOM_Function) aFunction =
@@ -327,17 +375,14 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCutList
 
   //Compute the Boolean value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Boolean driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
@@ -377,7 +422,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
   SetErrorCode(KO);
 
   //Add a new Partition object
-  Handle(GEOM_Object) aPartition = GetEngine()->AddObject(GetDocID(), GEOM_PARTITION);
+  Handle(GEOM_Object) aPartition = GetEngine()->AddObject(GEOM_PARTITION);
 
   //Add a new Partition function
   Handle(GEOM_Function) aFunction;
@@ -454,17 +499,14 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
 
   //Compute the Partition
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Partition driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
@@ -492,7 +534,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
   }
   pd << "], " << theKeepNonlimitShapes;
 
-  if (IsCheckSelfInte) {
+  if (IsCheckSelfInte && !thePerformSelfIntersections) {
     pd << ", True";
   }
 
@@ -508,15 +550,14 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition
-       (Handle(GEOM_Object) theShape, Handle(GEOM_Object) thePlane,
-        const Standard_Boolean IsCheckSelfInte)
+       (Handle(GEOM_Object) theShape, Handle(GEOM_Object) thePlane)
 {
   SetErrorCode(KO);
 
   if (theShape.IsNull() || thePlane.IsNull()) return NULL;
 
   //Add a new Boolean object
-  Handle(GEOM_Object) aPart = GetEngine()->AddObject(GetDocID(), GEOM_PARTITION);
+  Handle(GEOM_Object) aPart = GetEngine()->AddObject(GEOM_PARTITION);
 
   //Add a new Partition function
   Handle(GEOM_Function) aFunction =
@@ -535,34 +576,24 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition
 
   aCI.SetShape(aRef1);
   aCI.SetPlane(aRef2);
-  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
 
   //Compute the Partition value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Partition driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
   //Make a Python command
   GEOM::TPythonDump pd (aFunction);
   pd << aPart << " = geompy.MakeHalfPartition("
-     << theShape << ", " << thePlane;
-
-  if (IsCheckSelfInte) {
-    pd << ", True";
-  }
-
-  pd << ")";
+     << theShape << ", " << thePlane << ")";
 
   SetErrorCode(OK);
   return aPart;