+
+ // Getting objects.
+ TopTools_ListOfShape anObjects;
+ for(ListOfShape::const_iterator
+ anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
+ {
+ anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
+ }
+
+ // Getting tools.
+ TopTools_ListOfShape aTools;
+ for(ListOfShape::const_iterator
+ aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
+ {
+ aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
+ }
+
+ // Creating boolean operation.
+ BOPAlgo_BOP* aBuilder = new BOPAlgo_BOP();
+ switch (theOperationType) {
+ case BOOL_CUT: {
+ aBuilder->SetOperation(BOPAlgo_CUT);
+ break;
+ }
+ case BOOL_FUSE: {
+ aBuilder->SetOperation(BOPAlgo_FUSE);
+ break;
+ }
+ case BOOL_COMMON: {
+ aBuilder->SetOperation(BOPAlgo_COMMON);
+ break;
+ }
+ default: {
+ return;
+ }
+ }
+ this->setImpl(aBuilder);
+ this->setBuilderType(OCCT_BOPAlgo_Builder);
+ aBuilder->SetArguments(anObjects);
+ aBuilder->SetTools(aTools);
+
+ // Building and getting result.
+ aBuilder->Perform();
+ if (aBuilder->HasErrors())
+ return;
+ TopoDS_Shape aResult = aBuilder->Shape();
+
+ if(aResult.ShapeType() == TopAbs_COMPOUND) {
+ aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+ }
+ if(aResult.ShapeType() == TopAbs_COMPOUND) {
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape(aResult));
+ ListOfShape aCompSolids, aFreeSolids;
+ aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
+ GeomAPI_Shape::COMPSOLID,
+ aCompSolids,
+ aFreeSolids);
+ aResult = aGeomShape->impl<TopoDS_Shape>();
+ }
+
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aResult));
+ this->setShape(aShape);
+ this->setDone(true);