diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 90aa7316e472..b63c1a6a623d 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -408,6 +408,35 @@ bool TopoShape::hasSubShape(const char *Type) const { return idx.second>0 && idx.second<=(int)countSubShapes(idx.first); } +template +static inline std::vector _getSubShapes(const TopoDS_Shape &s, TopAbs_ShapeEnum type) { + std::vector 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::getSubTopoShapes(TopAbs_ShapeEnum type) const { + return _getSubShapes(_Shape,type); +} + +std::vector TopoShape::getSubShapes(TopAbs_ShapeEnum type) const { + return _getSubShapes(_Shape,type); +} + static std::array _ShapeNames; static void initShapeNameMap() { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 8d0c7dcd5250..0786f486e61f 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -153,6 +153,8 @@ class PartExport TopoShape : public Data::ComplexGeoData /// 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 getSubTopoShapes(TopAbs_ShapeEnum type=TopAbs_SHAPE) const; + std::vector 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;