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 <BRepAlgoAPI_Cut.hxx>
10 #include <BRepAlgoAPI_Common.hxx>
11 #include <BRepAlgoAPI_Fuse.hxx>
12 #include <BRepCheck_Analyzer.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <GeomAlgoAPI_DFLoader.h>
16 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCut(
17 std::shared_ptr<GeomAPI_Shape> theShape,
18 std::shared_ptr<GeomAPI_Shape> theTool)
20 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
21 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
23 BRepAlgoAPI_Cut aCut(aShape, aTool);
25 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
26 aResult->setImpl(new TopoDS_Shape(aCut.Shape()));
29 return std::shared_ptr<GeomAPI_Shape>();
33 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeFuse(
34 std::shared_ptr<GeomAPI_Shape> theShape,
35 std::shared_ptr<GeomAPI_Shape> theTool)
37 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
38 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
40 BRepAlgoAPI_Fuse aFuse(aShape, aTool);
42 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
43 aResult->setImpl(new TopoDS_Shape(aFuse.Shape()));
46 return std::shared_ptr<GeomAPI_Shape>();
50 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Boolean::makeCommon(
51 std::shared_ptr<GeomAPI_Shape> theShape,
52 std::shared_ptr<GeomAPI_Shape> theTool)
54 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
55 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
57 BRepAlgoAPI_Common aCommon(aShape, aTool);
58 if (aCommon.IsDone()) {
59 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
60 aResult->setImpl(new TopoDS_Shape(aCommon.Shape()));
63 return std::shared_ptr<GeomAPI_Shape>();
66 //============================================================================
67 GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(std::shared_ptr<GeomAPI_Shape> theObject,
68 std::shared_ptr<GeomAPI_Shape> theTool,
70 : myOperation(theType), myDone(false), myShape(new GeomAPI_Shape())
72 build(theObject, theTool);
76 //============================================================================
77 void GeomAlgoAPI_Boolean::build(std::shared_ptr<GeomAPI_Shape> theObject,
78 std::shared_ptr<GeomAPI_Shape> theTool)
80 const TopoDS_Shape& anObject = theObject->impl<TopoDS_Shape>();
81 const TopoDS_Shape& aTool = theTool->impl<TopoDS_Shape>();
83 switch (myOperation) {
86 BRepAlgoAPI_Fuse* mkFuse = new BRepAlgoAPI_Fuse(anObject, aTool);
87 if (mkFuse && mkFuse->IsDone()) {
89 myDone = mkFuse->IsDone() == Standard_True;
90 myMkShape = new GeomAlgoAPI_MakeShape (mkFuse);
91 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();
108 BRepAlgoAPI_Common* mkCom = new BRepAlgoAPI_Common(anObject, aTool);
109 if (mkCom && mkCom->IsDone()) {
111 myDone = mkCom->IsDone() == Standard_True;
112 myMkShape = new GeomAlgoAPI_MakeShape (mkCom);
113 aResult = mkCom->Shape();
119 if(aResult.ShapeType() == TopAbs_COMPOUND)
120 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
121 myShape->setImpl(new TopoDS_Shape(aResult));
122 std::shared_ptr<GeomAPI_Shape> aGeomResult(new GeomAPI_Shape());
123 aGeomResult->setImpl(new TopoDS_Shape(aResult));
125 // fill data map to keep correct orientation of sub-shapes
126 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
127 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
128 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
129 myMap.bind(aCurrentShape, aCurrentShape);
135 //============================================================================
136 const bool GeomAlgoAPI_Boolean::isDone() const
139 //============================================================================
140 const bool GeomAlgoAPI_Boolean::isValid() const
142 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
143 return (aChecker.IsValid() == Standard_True);
146 //============================================================================
147 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Boolean::shape () const
152 //============================================================================
153 void GeomAlgoAPI_Boolean::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
158 //============================================================================
159 GeomAlgoAPI_MakeShape * GeomAlgoAPI_Boolean::makeShape() const
164 //============================================================================
165 GeomAlgoAPI_Boolean::~GeomAlgoAPI_Boolean()