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>
10 #include <GeomAlgoAPI_ShapeTools.h>
12 #include <BOPAlgo_BOP.hxx>
13 #include <TopTools_ListOfShape.hxx>
15 //=================================================================================================
16 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects,
17 const ListOfShape& theTools,
18 const OperationType theOperationType)
20 build(theObjects, theTools, theOperationType);
24 //=================================================================================================
25 void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
26 const ListOfShape& theTools,
27 const OperationType theOperationType)
29 if(theObjects.empty() || theTools.empty()) {
34 TopTools_ListOfShape anObjects;
35 for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
37 anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
41 TopTools_ListOfShape aTools;
42 for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
44 aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
47 // Creating boolean operation.
48 BOPAlgo_BOP* aBuilder = new BOPAlgo_BOP();
49 switch (theOperationType) {
51 aBuilder->SetOperation(BOPAlgo_CUT);
55 aBuilder->SetOperation(BOPAlgo_FUSE);
59 aBuilder->SetOperation(BOPAlgo_COMMON);
66 this->setImpl(aBuilder);
67 this->setBuilderType(OCCT_BOPAlgo_Builder);
68 aBuilder->SetArguments(anObjects);
69 aBuilder->SetTools(aTools);
71 // Building and getting result.
73 if(aBuilder->ErrorStatus() != 0) {
76 TopoDS_Shape aResult = aBuilder->Shape();
78 if(aResult.ShapeType() == TopAbs_COMPOUND) {
79 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
81 if(aResult.ShapeType() == TopAbs_COMPOUND) {
82 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
83 aGeomShape->setImpl(new TopoDS_Shape(aResult));
84 ListOfShape aCompSolids, aFreeSolids;
85 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
86 GeomAPI_Shape::COMPSOLID,
89 aResult = aGeomShape->impl<TopoDS_Shape>();
92 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
93 aShape->setImpl(new TopoDS_Shape(aResult));
94 this->setShape(aShape);