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
36 anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
38 anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
42 TopTools_ListOfShape aTools;
43 for(ListOfShape::const_iterator
44 aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
46 aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
49 // Creating boolean operation.
50 BOPAlgo_BOP* aBuilder = new BOPAlgo_BOP();
51 switch (theOperationType) {
53 aBuilder->SetOperation(BOPAlgo_CUT);
57 aBuilder->SetOperation(BOPAlgo_FUSE);
61 aBuilder->SetOperation(BOPAlgo_COMMON);
68 this->setImpl(aBuilder);
69 this->setBuilderType(OCCT_BOPAlgo_Builder);
70 aBuilder->SetArguments(anObjects);
71 aBuilder->SetTools(aTools);
73 // Building and getting result.
75 if(aBuilder->ErrorStatus() != 0) {
78 TopoDS_Shape aResult = aBuilder->Shape();
80 if(aResult.ShapeType() == TopAbs_COMPOUND) {
81 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
83 if(aResult.ShapeType() == TopAbs_COMPOUND) {
84 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
85 aGeomShape->setImpl(new TopoDS_Shape(aResult));
86 ListOfShape aCompSolids, aFreeSolids;
87 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
88 GeomAPI_Shape::COMPSOLID,
91 aResult = aGeomShape->impl<TopoDS_Shape>();
94 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
95 aShape->setImpl(new TopoDS_Shape(aResult));
96 this->setShape(aShape);