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 <BRepCheck_Analyzer.hxx>
16 #include <TopExp_Explorer.hxx>
17 #include <TopTools_ListOfShape.hxx>
19 //=================================================================================================
20 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const ListOfShape& theObjects,
21 const ListOfShape& theTools,
22 const OperationType theOperationType)
25 build(theObjects, theTools, theOperationType);
29 //=================================================================================================
30 void GeomAlgoAPI_Boolean::build(const ListOfShape& theObjects,
31 const ListOfShape& theTools,
32 const OperationType theOperationType)
34 if(theObjects.empty() || theTools.empty()) {
39 TopTools_ListOfShape anObjects;
40 for(ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++)
42 anObjects.Append((*anObjectsIt)->impl<TopoDS_Shape>());
46 TopTools_ListOfShape aTools;
47 for(ListOfShape::const_iterator aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++)
49 aTools.Append((*aToolsIt)->impl<TopoDS_Shape>());
52 // Creating boolean operation.
53 BRepAlgoAPI_BooleanOperation* anOperation;
54 switch (theOperationType) {
56 anOperation = new BRepAlgoAPI_Cut();
60 anOperation = new BRepAlgoAPI_Fuse();
64 anOperation = new BRepAlgoAPI_Common();
71 myMkShape.reset(new GeomAlgoAPI_MakeShape(anOperation));
72 anOperation->SetArguments(anObjects);
73 anOperation->SetTools(aTools);
75 // Building and getting result.
77 myDone = anOperation->IsDone() == Standard_True;
81 TopoDS_Shape aResult = anOperation->Shape();
83 if(aResult.ShapeType() == TopAbs_COMPOUND) {
84 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
87 // fill data map to keep correct orientation of sub-shapes
88 myMap.reset(new GeomAPI_DataMapOfShapeShape());
89 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
90 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
91 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
92 myMap->bind(aCurrentShape, aCurrentShape);
94 myShape.reset(new GeomAPI_Shape());
95 myShape->setImpl(new TopoDS_Shape(aResult));
99 //=================================================================================================
100 const bool GeomAlgoAPI_Boolean::isDone() const
105 //=================================================================================================
106 const bool GeomAlgoAPI_Boolean::isValid() const
108 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
109 return (aChecker.IsValid() == Standard_True);
112 //=================================================================================================
113 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Boolean::shape() const
118 //=================================================================================================
119 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Boolean::mapOfShapes() const
124 //=================================================================================================
125 std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Boolean::makeShape() const