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 #include "GeomAlgoAPI_MakeShape.h"
9 #include <BOPAlgo_Builder.hxx>
10 #include <BRepBuilderAPI_MakeShape.hxx>
11 #include <BRepCheck_Analyzer.hxx>
12 #include <BRepGProp.hxx>
13 #include <GProp_GProps.hxx>
14 #include <Precision.hxx>
15 #include <TopExp_Explorer.hxx>
16 #include <TopTools_ListOfShape.hxx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
19 //=================================================================================================
20 GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
21 : myBuilderType(Unknown),
26 //=================================================================================================
27 bool GeomAlgoAPI_MakeShape::isDone() const
32 //=================================================================================================
33 const std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
38 //=================================================================================================
39 bool GeomAlgoAPI_MakeShape::isValid() const
41 BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
42 return (aChecker.IsValid() == Standard_True);
45 //=================================================================================================
46 bool GeomAlgoAPI_MakeShape::hasVolume() const
48 bool hasVolume = false;
50 const TopoDS_Shape& aRShape = myShape->impl<TopoDS_Shape>();
52 BRepGProp::VolumeProperties(aRShape, aGProp);
53 if(aGProp.Mass() > Precision::Confusion())
59 //=================================================================================================
60 std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_MakeShape::mapOfSubShapes() const
65 //=================================================================================================
66 void GeomAlgoAPI_MakeShape::generated(const std::shared_ptr<GeomAPI_Shape> theShape,
67 ListOfShape& theHistory)
69 TopTools_ListOfShape aList;
70 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
71 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
72 aList = aMakeShape->Generated(theShape->impl<TopoDS_Shape>());
73 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
74 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
75 aList = aBOPBuilder->Generated(theShape->impl<TopoDS_Shape>());
77 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
78 if(anIt.Value().IsNull()) {
81 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
82 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
83 theHistory.push_back(aShape);
87 //=================================================================================================
88 void GeomAlgoAPI_MakeShape::modified(const std::shared_ptr<GeomAPI_Shape> theShape,
89 ListOfShape& theHistory)
91 TopTools_ListOfShape aList;
92 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
93 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
95 aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
96 } catch(Standard_NoSuchObject) {
98 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
99 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
100 aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
102 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
103 if(anIt.Value().IsNull()) {
106 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
107 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
108 theHistory.push_back(aShape);
112 //=================================================================================================
113 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
115 bool isDeleted = false;
116 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
117 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
118 isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
119 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
120 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
121 isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
127 //=================================================================================================
128 void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType)
130 myBuilderType = theBuilderType;
133 //=================================================================================================
134 void GeomAlgoAPI_MakeShape::setDone(const bool theFlag)
139 //=================================================================================================
140 void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theShape)
142 if(myShape.get() && myShape->isEqual(theShape)) {
148 // Filling data map to keep correct orientation of sub-shapes.
153 myMap.reset(new GeomAPI_DataMapOfShapeShape);
156 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
157 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_EDGE); anExp.More(); anExp.Next()) {
158 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
159 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
160 myMap->bind(aCurrentShape, aCurrentShape);
162 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
163 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
164 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
165 myMap->bind(aCurrentShape, aCurrentShape);
174 //=================================================================================================
175 void GeomAlgoAPI_MakeShape::initialize() {
176 switch (myBuilderType) {
177 case OCCT_BRepBuilderAPI_MakeShape: {
178 myDone = implPtr<BRepBuilderAPI_MakeShape>()->IsDone() == Standard_True;
179 myShape.reset(new GeomAPI_Shape());
180 myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
183 case OCCT_BOPAlgo_Builder: {
185 myShape.reset(new GeomAPI_Shape());
186 myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
194 myMap.reset(new GeomAPI_DataMapOfShapeShape);
197 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
198 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
199 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
200 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
201 myMap->bind(aCurrentShape, aCurrentShape);