Salome HOME
Update copyrights
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Intersection.cpp
index 8cf31feba39aece75bf243ac508ddc31aa852b28..ea80a97b4f50de6f4d3aa8dabbba2238a14ab305 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "GeomAlgoAPI_Intersection.h"
 
 #include <GeomAlgoAPI_DFLoader.h>
-#include <GeomAlgoAPI_ShapeTools.h>
 
-#include <BRepAlgoAPI_Section.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Builder.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_Section.hxx>
 
-//=================================================================================================
-GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
-                                                   const ListOfShape& theTools)
+//==================================================================================================
+GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects)
+  : myFiller(0)
 {
-  build(theObjects, theTools);
+  build(theObjects);
 }
 
-//=================================================================================================
-void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
-                                     const ListOfShape& theTools)
+GeomAlgoAPI_Intersection::~GeomAlgoAPI_Intersection() {
+  if (myFiller)
+    delete (BOPAlgo_PaveFiller*)myFiller;
+}
+//==================================================================================================
+void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects)
 {
-  if (theObjects.empty() || theTools.empty()) {
+  if (theObjects.empty()) {
     return;
   }
 
   // Creating partition operation.
-  BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
+  BOPAlgo_Section* anOperation = new BOPAlgo_Section;
   this->setImpl(anOperation);
-  this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
-  TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
+  this->setBuilderType(OCCT_BOPAlgo_Builder);
 
   // Getting objects.
   TopTools_ListOfShape anObjects;
@@ -58,25 +56,32 @@ void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
       anObjects.Append(aShape);
     }
   }
-  anOperation->SetArguments(anObjects);
 
-  // Getting tools.
-  TopTools_ListOfShape aTools;
-  for (ListOfShape::const_iterator
-    aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
-    const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
-    if(!aShape.IsNull()) {
-      aTools.Append(aShape);
-    }
-  }
-  anOperation->SetTools(aTools);
+  BOPAlgo_PaveFiller* aDSFiller = new BOPAlgo_PaveFiller;
+  myFiller = aDSFiller;
+  aDSFiller->SetArguments(anObjects);
+
+  aDSFiller->SetRunParallel(false);
+  aDSFiller->SetNonDestructive(false);
+  aDSFiller->SetGlue(BOPAlgo_GlueOff);
+
   // optimization for the issue #2399
-  anOperation->Approximation(Standard_True);
-  anOperation->ComputePCurveOn1(Standard_True);
-  anOperation->ComputePCurveOn2(Standard_True);
-  // Building and getting result.
-  anOperation->Build();
-  if(!anOperation->IsDone()) {
+  BOPAlgo_SectionAttribute theSecAttr(Standard_True,
+                                      Standard_True,
+                                      Standard_True);
+  aDSFiller->SetSectionAttribute(theSecAttr);
+
+  aDSFiller->Perform();
+  if (aDSFiller->HasErrors()) {
+    return;
+  }
+
+  anOperation->SetArguments(anObjects);
+  anOperation->SetRunParallel(false);
+  anOperation->SetCheckInverted(true);
+
+  anOperation->PerformWithFiller(*aDSFiller); // it references a filler fields, so keep the filler
+  if(anOperation->HasErrors()) {
     return;
   }
   TopoDS_Shape aResult = anOperation->Shape();