1 // File: GeomAlgoAPI_Boolean.cpp
2 // Created: 02 Sept 2014
3 // Author: Vitaly Smetannikov
5 #include "GeomAlgoAPI_Boolean.h"
7 #include <BRepAlgoAPI_Cut.hxx>
8 #include <BRepAlgoAPI_Common.hxx>
9 #include <BRepAlgoAPI_Fuse.hxx>
10 #include <BRepCheck_Analyzer.hxx>
11 #include <TopExp_Explorer.hxx>
12 #include <GeomAlgoAPI_DFLoader.h>
14 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCut(
15 std::shared_ptr<GeomAPI_Shape> theShape,
16 std::shared_ptr<GeomAPI_Shape> theTool)
18 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
19 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
21 BRepAlgoAPI_Cut aCut(aShape, aTool);
23 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
24 aResult->setImpl(new TopoDS_Shape(aCut.Shape()));
27 return std::shared_ptr<GeomAPI_Shape>();
31 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeFuse(
32 std::shared_ptr<GeomAPI_Shape> theShape,
33 std::shared_ptr<GeomAPI_Shape> theTool)
35 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
36 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
38 BRepAlgoAPI_Fuse aFuse(aShape, aTool);
40 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
41 aResult->setImpl(new TopoDS_Shape(aFuse.Shape()));
44 return std::shared_ptr<GeomAPI_Shape>();
48 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCommon(
49 std::shared_ptr<GeomAPI_Shape> theShape,
50 std::shared_ptr<GeomAPI_Shape> theTool)
52 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
53 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
55 BRepAlgoAPI_Common aCommon(aShape, aTool);
56 if (aCommon.IsDone()) {
57 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
58 aResult->setImpl(new TopoDS_Shape(aCommon.Shape()));
61 return std::shared_ptr<GeomAPI_Shape>();
64 //============================================================================
65 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(std::shared_ptr<GeomAPI_Shape> theObject,
66 std::shared_ptr<GeomAPI_Shape> theTool,
68 : myOperation(theType), myDone(false), myShape(new GeomAPI_Shape())
70 build(theObject, theTool);
74 //============================================================================
75 void GeomAlgoAPI_Boolean::build(std::shared_ptr<GeomAPI_Shape> theObject,
76 std::shared_ptr<GeomAPI_Shape> theTool)
78 const TopoDS_Shape& anObject = theObject->impl<TopoDS_Shape>();
79 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
81 switch (myOperation) {
84 BRepAlgoAPI_Fuse* mkFuse = new BRepAlgoAPI_Fuse(anObject, aTool);
85 if (mkFuse && mkFuse->IsDone()) {
87 myDone = mkFuse->IsDone() == Standard_True;
88 myMkShape = new GeomAlgoAPI_MakeShape (mkFuse);
89 aResult = mkFuse->Shape();//GeomAlgoAPI_DFLoader::refineResult(aFuse->Shape());
95 BRepAlgoAPI_Cut* mkCut = new BRepAlgoAPI_Cut(anObject, aTool);
96 if (mkCut && mkCut->IsDone()) {
98 myDone = mkCut->IsDone() == Standard_True;
99 myMkShape = new GeomAlgoAPI_MakeShape (mkCut);
100 aResult = mkCut->Shape();
106 BRepAlgoAPI_Common* mkCom = new BRepAlgoAPI_Common(anObject, aTool);
107 if (mkCom && mkCom->IsDone()) {
109 myDone = mkCom->IsDone() == Standard_True;
110 myMkShape = new GeomAlgoAPI_MakeShape (mkCom);
111 aResult = mkCom->Shape();
117 if(aResult.ShapeType() == TopAbs_COMPOUND)
118 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
119 myShape->setImpl(new TopoDS_Shape(aResult));
120 std::shared_ptr<GeomAPI_Shape> aGeomResult(new GeomAPI_Shape());
121 aGeomResult->setImpl(new TopoDS_Shape(aResult));
123 // fill data map to keep correct orientation of sub-shapes
124 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
125 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
126 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
127 myMap.bind(aCurrentShape, aCurrentShape);
133 //============================================================================
134 const bool GeomAlgoAPI_Boolean::isDone() const
137 //============================================================================
138 const bool GeomAlgoAPI_Boolean::isValid() const
140 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
141 return (aChecker.IsValid() == Standard_True);
144 //============================================================================
145 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Boolean::shape () const
150 //============================================================================
151 void GeomAlgoAPI_Boolean::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
156 //============================================================================
157 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Boolean::makeShape() const
162 //============================================================================
163 GeomAlgoAPI_Boolean::~GeomAlgoAPI_Boolean()