Part: add TopoShape::getSub(Topo)Shapes()

This commit is contained in:
Zheng, Lei
2019-10-22 21:36:27 +08:00
committed by wwmayer
parent 2034323bf4
commit a0b14f2dcd
2 changed files with 31 additions and 0 deletions

View File

@@ -408,6 +408,35 @@ bool TopoShape::hasSubShape(const char *Type) const {
return idx.second>0 && idx.second<=(int)countSubShapes(idx.first);
}
template<class T>
static inline std::vector<T> _getSubShapes(const TopoDS_Shape &s, TopAbs_ShapeEnum type) {
std::vector<T> shapes;
if(s.IsNull())
return shapes;
if(type == TopAbs_SHAPE) {
for(TopoDS_Iterator it(s);it.More();it.Next())
shapes.emplace_back(it.Value());
return shapes;
}
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(s, type, anIndices);
int count = anIndices.Extent();
shapes.reserve(count);
for(int i=1;i<=count;++i)
shapes.emplace_back(anIndices.FindKey(i));
return shapes;
}
std::vector<TopoShape> TopoShape::getSubTopoShapes(TopAbs_ShapeEnum type) const {
return _getSubShapes<TopoShape>(_Shape,type);
}
std::vector<TopoDS_Shape> TopoShape::getSubShapes(TopAbs_ShapeEnum type) const {
return _getSubShapes<TopoDS_Shape>(_Shape,type);
}
static std::array<std::string,TopAbs_SHAPE> _ShapeNames;
static void initShapeNameMap() {

View File

@@ -153,6 +153,8 @@ public:
/// get the Topo"sub"Shape with the given name
TopoDS_Shape getSubShape(const char* Type, bool silent=false) const;
TopoDS_Shape getSubShape(TopAbs_ShapeEnum type, int idx, bool silent=false) const;
std::vector<TopoShape> getSubTopoShapes(TopAbs_ShapeEnum type=TopAbs_SHAPE) const;
std::vector<TopoDS_Shape> getSubShapes(TopAbs_ShapeEnum type=TopAbs_SHAPE) const;
unsigned long countSubShapes(const char* Type) const;
unsigned long countSubShapes(TopAbs_ShapeEnum type) const;
bool hasSubShape(const char *Type) const;