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>();
94 aList = aMakeShape->Modified(theShape->impl<TopoDS_Shape>());
95 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
96 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
97 aList = aBOPBuilder->Modified(theShape->impl<TopoDS_Shape>());
99 for(TopTools_ListIteratorOfListOfShape anIt(aList); anIt.More(); anIt.Next()) {
100 if(anIt.Value().IsNull()) {
103 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
104 aShape->setImpl(new TopoDS_Shape(anIt.Value()));
105 theHistory.push_back(aShape);
109 //=================================================================================================
110 bool GeomAlgoAPI_MakeShape::isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape)
112 bool isDeleted = false;
113 if(myBuilderType == OCCT_BRepBuilderAPI_MakeShape) {
114 BRepBuilderAPI_MakeShape* aMakeShape = implPtr<BRepBuilderAPI_MakeShape>();
115 isDeleted = aMakeShape->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
116 } else if(myBuilderType == OCCT_BOPAlgo_Builder) {
117 BOPAlgo_Builder* aBOPBuilder = implPtr<BOPAlgo_Builder>();
118 isDeleted = aBOPBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
124 //=================================================================================================
125 void GeomAlgoAPI_MakeShape::setBuilderType(const BuilderType theBuilderType)
127 myBuilderType = theBuilderType;
130 //=================================================================================================
131 void GeomAlgoAPI_MakeShape::setDone(const bool theFlag)
136 //=================================================================================================
137 void GeomAlgoAPI_MakeShape::setShape(const std::shared_ptr<GeomAPI_Shape> theShape)
139 if(myShape.get() && myShape->isEqual(theShape)) {
145 // Filling data map to keep correct orientation of sub-shapes.
150 myMap.reset(new GeomAPI_DataMapOfShapeShape);
153 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
154 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
155 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
156 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
157 myMap->bind(aCurrentShape, aCurrentShape);
166 //=================================================================================================
167 void GeomAlgoAPI_MakeShape::initialize() {
168 switch (myBuilderType) {
169 case OCCT_BRepBuilderAPI_MakeShape: {
170 myDone = implPtr<BRepBuilderAPI_MakeShape>()->IsDone() == Standard_True;
171 myShape.reset(new GeomAPI_Shape());
172 myShape->setImpl(new TopoDS_Shape(implPtr<BRepBuilderAPI_MakeShape>()->Shape()));
175 case OCCT_BOPAlgo_Builder: {
177 myShape.reset(new GeomAPI_Shape());
178 myShape->setImpl(new TopoDS_Shape(implPtr<BOPAlgo_Builder>()->Shape()));
186 myMap.reset(new GeomAPI_DataMapOfShapeShape);
189 const TopoDS_Shape& aTopoDSShape = myShape->impl<TopoDS_Shape>();
190 for(TopExp_Explorer anExp(aTopoDSShape,TopAbs_FACE); anExp.More(); anExp.Next()) {
191 std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
192 aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
193 myMap->bind(aCurrentShape, aCurrentShape);