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 <BRepAlgoAPI_BooleanOperation.hxx>
12 #include <BRepAlgoAPI_Common.hxx>
13 #include <BRepAlgoAPI_Cut.hxx>
14 #include <BRepAlgoAPI_Fuse.hxx>
15 #include <TopTools_ListOfShape.hxx>
17 //=================================================================================================
18 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects,
19 const ListOfShape& theTools,
20 const OperationType theOperationType)
22 build(theObjects, theTools, theOperationType);
26 //=================================================================================================
27 void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
28 const ListOfShape& theTools,
29 const OperationType theOperationType)
31 if(theObjects.empty() || theTools.empty()) {
36 TopTools_ListOfShape anObjects;
37 for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
39 anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
43 TopTools_ListOfShape aTools;
44 for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
46 aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
49 // Creating boolean operation.
50 BRepAlgoAPI_BooleanOperation* anOperation;
51 switch (theOperationType) {
53 anOperation = new BRepAlgoAPI_Cut();
57 anOperation = new BRepAlgoAPI_Fuse();
61 anOperation = new BRepAlgoAPI_Common();
68 this->setImpl(anOperation);
69 this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
70 anOperation->SetArguments(anObjects);
71 anOperation->SetTools(aTools);
73 // Building and getting result.
75 if(anOperation->IsDone() != Standard_True) {
78 TopoDS_Shape aResult = anOperation->Shape();
80 if(aResult.ShapeType() == TopAbs_COMPOUND) {
81 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
84 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
85 aShape->setImpl(new TopoDS_Shape(aResult));
86 this->setShape(aShape);