1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_MakeShape.cpp
4 // Created: 20 Oct 2014
5 // Author: Sergey ZARITCHNY
7 // Modified by Clarisse Genrault (CEA) : 17 Mar 2016
9 #include "GeomAlgoAPI_MakeShape.h"
11 #include <BOPAlgo_Builder.hxx>
12 #include <BRepBuilderAPI_MakeShape.hxx>
13 #include <BRepCheck_Analyzer.hxx>
14 #include <BRepGProp.hxx>
15 #include <GProp_GProps.hxx>
16 #include <Precision.hxx>
17 #include <TopExp_Explorer.hxx>
18 #include <TopTools_ListOfShape.hxx>
19 #include <TopTools_ListIteratorOfListOfShape.hxx>
20 #include <GeomAPI_ShapeExplorer.h>
22 //=================================================================================================
23 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
24 : myBuilderType(Unknown),
29 //=================================================================================================
30 bool GeomAlgoAPI_MakeShape::isDone() const
35 //=================================================================================================
36 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
41 //=================================================================================================
42 bool GeomAlgoAPI_MakeShape::isValid() const
44 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
45 return (aChecker.IsValid() == Standard_True);
48 //=================================================================================================
49 bool GeomAlgoAPI_MakeShape::hasVolume() const
51 bool hasVolume = false;
53 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
55 BRepGProp::VolumeProperties(aRShape, aGProp);
56 if(aGProp.Mass() > Precision::Confusion())
62 //=================================================================================================
63 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_MakeShape::mapOfSubShapes() const
68 //=================================================================================================
69 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
70 ListOfShape& theHistory)
72 TopTools_ListOfShape aList;
73 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
74 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
75 aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
76 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
77 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
78 aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
80 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
81 if(anIt.Value().IsNull()) {
84 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
85 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
86 theHistory.push_back(aShape);
90 //=================================================================================================
91 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
92 ListOfShape& theHistory)
94 TopTools_ListOfShape aList;
95 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
96 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
98 aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
99 } catch(Standard_NoSuchObject) {
101 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
102 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
103 aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
105 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
106 if(anIt.Value().IsNull()) {
109 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
110 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
111 theHistory.push_back(aShape);
115 //=================================================================================================
116 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
118 bool isDeleted = false;
119 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
120 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
121 isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
122 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
123 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
124 isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
130 //=================================================================================================
131 void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType)
133 myBuilderType = theBuilderType;
136 //=================================================================================================
137 void GeomAlgoAPI_MakeShape::setDone(const bool theFlag)
142 //=================================================================================================
143 void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theShape)
145 if(myShape.get() && myShape->isEqual(theShape)) {
151 // Filling data map to keep correct orientation of sub-shapes.
156 myMap.reset(new GeomAPI_DataMapOfShapeShape);
159 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
160 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_VERTEX); anExp.More(); anExp.Next()) {
161 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
162 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
163 myMap->bind(aCurrentShape, aCurrentShape);
165 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_EDGE); anExp.More(); anExp.Next()) {
166 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
167 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
168 myMap->bind(aCurrentShape, aCurrentShape);
170 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
171 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
172 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
173 myMap->bind(aCurrentShape, aCurrentShape);
182 //=================================================================================================
183 void GeomAlgoAPI_MakeShape::initialize() {
184 switch (myBuilderType) {
185 case OCCT_BRepBuilderAPI_MakeShape: {
186 myDone = implPtr<BRepBuilderAPI_MakeShape>()->IsDone() == Standard_True;
187 myShape.reset(new GeomAPI_Shape());
188 myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
191 case OCCT_BOPAlgo_Builder: {
193 myShape.reset(new GeomAPI_Shape());
194 myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
202 myMap.reset(new GeomAPI_DataMapOfShapeShape);
205 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
206 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
207 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
208 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
209 myMap->bind(aCurrentShape, aCurrentShape);
214 //=================================================================================================
215 void GeomAlgoAPI_MakeShape::prepareNamingFaces()
218 GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE);
219 for(GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
220 std::shared_ptr<GeomAPI_Shape> aFace = anExp.current();
221 myCreatedFaces["Face_" + std::to_string(index++)] = aFace;
226 //=================================================================================================
227 bool GeomAlgoAPI_MakeShape::checkValid(std::string theMessage){
229 // isValid() is called from this method
231 myError = theMessage + " :: resulting shape is not valid.";
235 // Check the number of volumes in myShape, make sure there's one and only one.
236 TopoDS_Shape aTopoDSShape = myShape->impl<TopoDS_Shape>();
238 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_SOLID); anExp.More(); anExp.Next()) {
242 if (aNbVolumes != 1) {
243 myError = theMessage +
244 " :: connexity error, the resulting shape is made of several separate solids.";