]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_IBooleanOperations.cxx
Salome HOME
Backward compatibility OCCT < 6.8.0
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IBooleanOperations.cxx
index bae1dd0c6da1b260ed32db464ec7a57dcdb1263a..eddc96add4747623e0d02a7441ab0839742e10d9 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include <Standard_Stream.hxx>
 
 #include <GEOMImpl_IBooleanOperations.hxx>
@@ -34,6 +35,8 @@
 #include <GEOMImpl_PartitionDriver.hxx>
 #include <GEOMImpl_IPartition.hxx>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <TDF_Tool.hxx>
 
 #include "utilities.h"
@@ -68,9 +71,11 @@ GEOMImpl_IBooleanOperations::~GEOMImpl_IBooleanOperations()
  *  MakeBoolean
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object) theShape1,
-                                                              Handle(GEOM_Object) theShape2,
-                                                              Standard_Integer    theOp)
+Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean
+                                  (Handle(GEOM_Object)    theShape1,
+                                   Handle(GEOM_Object)    theShape2,
+                                   const Standard_Integer theOp,
+                                   const Standard_Boolean IsCheckSelfInte)
 {
   SetErrorCode(KO);
 
@@ -105,12 +110,11 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object
 
   aCI.SetShape1(aRef1);
   aCI.SetShape2(aRef2);
+  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
 
   //Compute the Boolean value
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Boolean driver failed");
       return NULL;
@@ -130,7 +134,276 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object
   else if (theOp == 3) pd << " = geompy.MakeFuse(";
   else if (theOp == 4) pd << " = geompy.MakeSection(";
   else {}
-  pd << theShape1 << ", " << theShape2 << ")";
+  pd << theShape1 << ", " << theShape2;
+
+  if (IsCheckSelfInte) {
+    pd << ", True";
+  }
+
+  pd << ")";
+
+  SetErrorCode(OK);
+  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(GetDocID(), 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) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    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
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeFuseList
+                  (const Handle(TColStd_HSequenceOfTransient)& theShapes,
+                   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);
+
+  //Add a new Boolean function
+  Handle(GEOM_Function) aFunction =
+    aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_FUSE_LIST);
+
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL;
+
+  GEOMImpl_IBoolean aCI (aFunction);
+
+  TCollection_AsciiString aDescription;
+  Handle(TColStd_HSequenceOfTransient) aShapesSeq =
+    getShapeFunctions(theShapes, aDescription);
+
+  if (aShapesSeq.IsNull()) return NULL;
+
+  aCI.SetShapes(aShapesSeq);
+  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) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump pd (aFunction);
+
+  pd << aBool << " = geompy.MakeFuseList([" << aDescription.ToCString() << "], "
+     << IsCheckSelfInte << ", " << IsRmExtraEdges << ")";
+
+  SetErrorCode(OK);
+  return aBool;
+}
+
+//=============================================================================
+/*!
+ *  MakeCommonList
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCommonList
+                  (const Handle(TColStd_HSequenceOfTransient)& theShapes,
+                   const Standard_Boolean IsCheckSelfInte)
+{
+  SetErrorCode(KO);
+
+  if (theShapes.IsNull()) return NULL;
+
+  //Add a new Boolean object
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+
+  //Add a new Boolean function
+  Handle(GEOM_Function) aFunction =
+    aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_COMMON_LIST);
+
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL;
+
+  GEOMImpl_IBoolean aCI (aFunction);
+
+  TCollection_AsciiString aDescription;
+  Handle(TColStd_HSequenceOfTransient) aShapesSeq =
+    getShapeFunctions(theShapes, aDescription);
+
+  if (aShapesSeq.IsNull()) return NULL;
+
+  aCI.SetShapes(aShapesSeq);
+  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
+
+  //Compute the Boolean value
+  try {
+    OCC_CATCH_SIGNALS;
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Boolean driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump pd (aFunction);
+
+  pd << aBool <<
+    " = geompy.MakeCommonList([" << aDescription.ToCString() << "]";
+
+  if (IsCheckSelfInte) {
+    pd << ", True";
+  }
+
+  pd << ")";
+
+  SetErrorCode(OK);
+  return aBool;
+}
+
+//=============================================================================
+/*!
+ *  MakeCutList
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeCutList
+                  (Handle(GEOM_Object) theMainShape,
+                   const Handle(TColStd_HSequenceOfTransient)& theShapes,
+                   const Standard_Boolean IsCheckSelfInte)
+{
+  SetErrorCode(KO);
+
+  if (theShapes.IsNull()) return NULL;
+
+  //Add a new Boolean object
+  Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
+
+  //Add a new Boolean function
+  Handle(GEOM_Function) aFunction =
+    aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_CUT_LIST);
+
+  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) aMainRef = theMainShape->GetLastFunction();
+
+  if (aMainRef.IsNull()) return NULL;
+
+  TCollection_AsciiString aDescription;
+  Handle(TColStd_HSequenceOfTransient) aShapesSeq =
+    getShapeFunctions(theShapes, aDescription);
+
+  if (aShapesSeq.IsNull()) return NULL;
+
+  aCI.SetShape1(aMainRef);
+  aCI.SetShapes(aShapesSeq);
+  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
+
+  //Compute the Boolean value
+  try {
+    OCC_CATCH_SIGNALS;
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Boolean driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump pd (aFunction);
+
+  pd << aBool << " = geompy.MakeCutList("
+    << theMainShape << ", [" << aDescription.ToCString() << "]";
+
+  if (IsCheckSelfInte) {
+    pd << ", True";
+  }
+
+  pd << ")";
 
   SetErrorCode(OK);
   return aBool;
@@ -149,8 +422,9 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
                               const Standard_Integer                      theLimit,
                               const Standard_Boolean                      theRemoveWebs,
                               const Handle(TColStd_HArray1OfInteger)&     theMaterials,
-                             const Standard_Integer theKeepNonlimitShapes,
-                              const Standard_Boolean thePerformSelfIntersections)
+                              const Standard_Integer theKeepNonlimitShapes,
+                              const Standard_Boolean thePerformSelfIntersections,
+                              const Standard_Boolean IsCheckSelfInte)
 {
   SetErrorCode(KO);
 
@@ -170,90 +444,53 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
 
   GEOMImpl_IPartition aCI (aFunction);
 
-  Handle(TColStd_HSequenceOfTransient) aShapesSeq  = new TColStd_HSequenceOfTransient;
-  Handle(TColStd_HSequenceOfTransient) aToolsSeq   = new TColStd_HSequenceOfTransient;
-  Handle(TColStd_HSequenceOfTransient) aKeepInsSeq = new TColStd_HSequenceOfTransient;
-  Handle(TColStd_HSequenceOfTransient) aRemInsSeq  = new TColStd_HSequenceOfTransient;
-
-  Standard_Integer ind, aLen;
-  TCollection_AsciiString anEntry;
+  Handle(TColStd_HSequenceOfTransient) aShapesSeq;
+  Handle(TColStd_HSequenceOfTransient) aToolsSeq;
+  Handle(TColStd_HSequenceOfTransient) aKeepInsSeq;
+  Handle(TColStd_HSequenceOfTransient) aRemInsSeq;
   TCollection_AsciiString aShapesDescr, aToolsDescr, aKeepInsDescr, aRemoveInsDescr;
 
   // Shapes
-  aLen = theShapes->Length();
-  for (ind = 1; ind <= aLen; ind++) {
-    Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theShapes->Value(ind));
-    Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
-    if (aRefSh.IsNull()) {
-      SetErrorCode("NULL shape for Partition");
-      return NULL;
-    }
-    aShapesSeq->Append(aRefSh);
+  aShapesSeq = getShapeFunctions(theShapes, aShapesDescr);
 
-    // For Python command
-    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-    if (ind > 1) aShapesDescr += ", ";
-    aShapesDescr += anEntry;
+  if (aShapesSeq.IsNull()) {
+    SetErrorCode("NULL shape for Partition");
+    return NULL;
   }
-  aCI.SetShapes(aShapesSeq);
 
   // Tools
-  aLen = theTools->Length();
-  for (ind = 1; ind <= aLen; ind++) {
-    Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theTools->Value(ind));
-    Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
-    if (aRefSh.IsNull()) {
-      SetErrorCode("NULL tool shape for Partition");
-      return NULL;
-    }
-    aToolsSeq->Append(aRefSh);
+  aToolsSeq = getShapeFunctions(theTools, aToolsDescr);
 
-    // For Python command
-    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-    if (ind > 1) aToolsDescr += ", ";
-    aToolsDescr += anEntry;
+  if (aToolsSeq.IsNull()) {
+    SetErrorCode("NULL tool shape for Partition");
+    return NULL;
   }
-  aCI.SetTools(aToolsSeq);
 
   // Keep Inside
-  aLen = theKeepIns->Length();
-  for (ind = 1; ind <= aLen; ind++) {
-    Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theKeepIns->Value(ind));
-    Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
-    if (aRefSh.IsNull()) {
-      SetErrorCode("NULL <keep inside> shape for Partition");
-      return NULL;
-    }
-    aKeepInsSeq->Append(aRefSh);
+  aKeepInsSeq = getShapeFunctions(theKeepIns, aKeepInsDescr);
 
-    // For Python command
-    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-    if (ind > 1) aKeepInsDescr += ", ";
-    aKeepInsDescr += anEntry;
+  if (aKeepInsSeq.IsNull()) {
+    SetErrorCode("NULL <keep inside> shape for Partition");
+    return NULL;
   }
-  aCI.SetKeepIns(aKeepInsSeq);
 
   // Remove Inside
-  aLen = theRemoveIns->Length();
-  for (ind = 1; ind <= aLen; ind++) {
-    Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theRemoveIns->Value(ind));
-    Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
-    if (aRefSh.IsNull()) {
-      SetErrorCode("NULL <remove inside> shape for Partition");
-      return NULL;
-    }
-    aRemInsSeq->Append(aRefSh);
+  aRemInsSeq  = getShapeFunctions(theRemoveIns, aRemoveInsDescr);
 
-    // For Python command
-    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-    if (ind > 1) aRemoveInsDescr += ", ";
-    aRemoveInsDescr += anEntry;
+  if (aRemInsSeq.IsNull()) {
+    SetErrorCode("NULL <remove inside> shape for Partition");
+    return NULL;
   }
+
+  aCI.SetShapes(aShapesSeq);
+  aCI.SetTools(aToolsSeq);
+  aCI.SetKeepIns(aKeepInsSeq);
   aCI.SetRemoveIns(aRemInsSeq);
 
   // Limit
   aCI.SetLimit(theLimit);
   aCI.SetKeepNonlimitShapes(theKeepNonlimitShapes);
+  aCI.SetCheckSelfIntersection(IsCheckSelfInte);
 
   // Materials
   if (theRemoveWebs) {
@@ -269,9 +506,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
 
   //Compute the Partition
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Partition driver failed");
       return NULL;
@@ -305,7 +540,13 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
       pd << ", " << theMaterials->Value(i);
     }
   }
-  pd << "], " << theKeepNonlimitShapes <<")";
+  pd << "], " << theKeepNonlimitShapes;
+
+  if (IsCheckSelfInte && !thePerformSelfIntersections) {
+    pd << ", True";
+  }
+
+  pd << ")";
 
   SetErrorCode(OK);
   return aPartition;
@@ -346,9 +587,7 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition
 
   //Compute the Partition value
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Partition driver failed");
       return NULL;
@@ -361,9 +600,53 @@ Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition
   }
 
   //Make a Python command
-  GEOM::TPythonDump(aFunction) << aPart << " = geompy.MakeHalfPartition("
-                               << theShape << ", " << thePlane << ")";
+  GEOM::TPythonDump pd (aFunction);
+  pd << aPart << " = geompy.MakeHalfPartition("
+     << theShape << ", " << thePlane << ")";
 
   SetErrorCode(OK);
   return aPart;
 }
+
+//=============================================================================
+/*!
+ *  getShapeFunctions
+ */
+//=============================================================================
+Handle(TColStd_HSequenceOfTransient)
+  GEOMImpl_IBooleanOperations::getShapeFunctions
+                  (const Handle(TColStd_HSequenceOfTransient)& theObjects,
+                         TCollection_AsciiString &theDescription)
+{
+  Handle(TColStd_HSequenceOfTransient) aResult =
+    new TColStd_HSequenceOfTransient;
+  Standard_Integer aNbObjects = theObjects->Length();
+  Standard_Integer i;
+  TCollection_AsciiString anEntry;
+  Handle(GEOM_Object) anObj;
+  Handle(GEOM_Function) aRefObj;
+
+  // Shapes
+  for (i = 1; i <= aNbObjects; i++) {
+    anObj = Handle(GEOM_Object)::DownCast(theObjects->Value(i));
+    aRefObj = anObj->GetLastFunction();
+
+    if (aRefObj.IsNull()) {
+      aResult.Nullify();
+      break;
+    }
+
+    aResult->Append(aRefObj);
+
+    // For Python command
+    TDF_Tool::Entry(anObj->GetEntry(), anEntry);
+
+    if (i > 1) {
+      theDescription += ", ";
+    }
+
+    theDescription += anEntry;
+  }
+
+  return aResult;
+}