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()), myMap(new GeomAPI_DataMapOfShapeShape())
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()) {
88 myDone = mkFuse->IsDone() == Standard_True;
89 myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape (mkFuse));
90 aResult = mkFuse->Shape();//GeomAlgoAPI_DFLoader::refineResult(aFuse->Shape());
96 BRepAlgoAPI_Cut* mkCut = new BRepAlgoAPI_Cut(anObject, aTool);
97 if (mkCut && mkCut->IsDone()) {
98 myDone = mkCut->IsDone() == Standard_True;
99 myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape (mkCut));
100 aResult = mkCut->Shape();
106 BRepAlgoAPI_Common* mkCom = new BRepAlgoAPI_Common(anObject, aTool);
107 if (mkCom && mkCom->IsDone()) {
108 myDone = mkCom->IsDone() == Standard_True;
109 myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape (mkCom));
110 aResult = mkCom->Shape();
116 if(aResult.ShapeType() == TopAbs_COMPOUND)
117 aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
118 myShape->setImpl(new TopoDS_Shape(aResult));
119 std::shared_ptr<GeomAPI_Shape> aGeomResult(new GeomAPI_Shape());
120 aGeomResult->setImpl(new TopoDS_Shape(aResult));
122 // fill data map to keep correct orientation of sub-shapes
123 for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
124 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
125 aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
126 myMap->bind(aCurrentShape, aCurrentShape);
132 //============================================================================
133 const bool GeomAlgoAPI_Boolean::isDone() const
136 //============================================================================
137 const bool GeomAlgoAPI_Boolean::isValid() const
139 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
140 return (aChecker.IsValid() == Standard_True);
143 //============================================================================
144 const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Boolean::shape () const
149 //============================================================================
150 void GeomAlgoAPI_Boolean::mapOfShapes(std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theMap) const
155 //============================================================================
156 const std::shared_ptr<GeomAlgoAPI_MakeShape>& GeomAlgoAPI_Boolean::makeShape() const
161 //============================================================================
162 GeomAlgoAPI_Boolean::~GeomAlgoAPI_Boolean()