1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Boolean.cpp
4 // Created: 02 Sept 2014
5 // Author: Vitaly Smetannikov
7 #include "GeomAlgoAPI_Boolean.h"
9 #include <GeomAlgoAPI_DFLoader.h>
11 #include <BOPAlgo_BOP.hxx>
12 #include <TopTools_ListOfShape.hxx>
14 //=================================================================================================
15 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects,
16 const ListOfShape& theTools,
17 const OperationType theOperationType)
19 build(theObjects, theTools, theOperationType);
23 //=================================================================================================
24 void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
25 const ListOfShape& theTools,
26 const OperationType theOperationType)
28 if(theObjects.empty() || theTools.empty()) {
33 TopTools_ListOfShape anObjects;
34 for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
36 anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
40 TopTools_ListOfShape aTools;
41 for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
43 aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
46 // Creating boolean operation.
47 BOPAlgo_BOP* aBuilder = new BOPAlgo_BOP();
48 switch (theOperationType) {
50 aBuilder->SetOperation(BOPAlgo_CUT);
54 aBuilder->SetOperation(BOPAlgo_FUSE);
58 aBuilder->SetOperation(BOPAlgo_COMMON);
65 this->setImpl(aBuilder);
66 this->setBuilderType(OCCT_BOPAlgo_Builder);
67 aBuilder->SetArguments(anObjects);
68 aBuilder->SetTools(aTools);
70 // Building and getting result.
72 if(aBuilder->ErrorStatus() != 0) {
75 TopoDS_Shape aResult = aBuilder->Shape();
77 if(aResult.ShapeType() == TopAbs_COMPOUND) {
78 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
81 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
82 aShape->setImpl(new TopoDS_Shape(aResult));
83 this->setShape(aShape);