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>
17 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCut(
18 boost::shared_ptr<GeomAPI_Shape> theShape,
19 boost::shared_ptr<GeomAPI_Shape> theTool)
21 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
22 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
24 BRepAlgoAPI_Cut aCut(aShape, aTool);
26 boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
27 aResult->setImpl(new TopoDS_Shape(aCut.Shape()));
30 return boost::shared_ptr<GeomAPI_Shape>();
34 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeFuse(
35 boost::shared_ptr<GeomAPI_Shape> theShape,
36 boost::shared_ptr<GeomAPI_Shape> theTool)
38 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
39 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
41 BRepAlgoAPI_Fuse aFuse(aShape, aTool);
43 boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
44 aResult->setImpl(new TopoDS_Shape(aFuse.Shape()));
47 return boost::shared_ptr<GeomAPI_Shape>();
51 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCommon(
52 boost::shared_ptr<GeomAPI_Shape> theShape,
53 boost::shared_ptr<GeomAPI_Shape> theTool)
55 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
56 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
58 BRepAlgoAPI_Common aCommon(aShape, aTool);
59 if (aCommon.IsDone()) {
60 boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
61 aResult->setImpl(new TopoDS_Shape(aCommon.Shape()));
64 return boost::shared_ptr<GeomAPI_Shape>();
67 //============================================================================
68 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(boost::shared_ptr<GeomAPI_Shape> theObject,
69 boost::shared_ptr<GeomAPI_Shape> theTool,
71 : myOperation(theType), myDone(false), myShape(new GeomAPI_Shape())
73 build(theObject, theTool);
77 //============================================================================
78 void GeomAlgoAPI_Boolean::build(boost::shared_ptr<GeomAPI_Shape> theObject,
79 boost::shared_ptr<GeomAPI_Shape> theTool)
81 const TopoDS_Shape& anObject = theObject->impl<TopoDS_Shape>();
82 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
84 switch (myOperation) {
87 BRepAlgoAPI_Fuse* mkFuse = new BRepAlgoAPI_Fuse(anObject, aTool);
88 if (mkFuse && mkFuse->IsDone()) {
90 myDone = mkFuse->IsDone() == Standard_True;
91 myMkShape = new GeomAlgoAPI_MakeShape (mkFuse);
92 aResult = mkFuse->Shape();//GeomAlgoAPI_DFLoader::refineResult(aFuse->Shape());
97 BRepAlgoAPI_Cut* mkCut = new BRepAlgoAPI_Cut(anObject, aTool);
98 if (mkCut && mkCut->IsDone()) {
100 myDone = mkCut->IsDone() == Standard_True;
101 myMkShape = new GeomAlgoAPI_MakeShape (mkCut);
102 aResult = mkCut->Shape();
107 BRepAlgoAPI_Common* mkCom = new BRepAlgoAPI_Common(anObject, aTool);
108 if (mkCom && mkCom->IsDone()) {
110 myDone = mkCom->IsDone() == Standard_True;
111 myMkShape = new GeomAlgoAPI_MakeShape (mkCom);
112 aResult = mkCom->Shape();
117 if(aResult.ShapeType() == TopAbs_COMPOUND)
118 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
119 myShape->setImpl(new TopoDS_Shape(aResult));
120 boost::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 boost::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 boost::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()