Skip to content

Commit

Permalink
Part: add TopoShape::getSub(Topo)Shapes()
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed Dec 30, 2019
1 parent 7dffaf4 commit 474d874
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Mod/Part/App/TopoShape.cpp
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Part/App/TopoShape.h
Expand Up @@ -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<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;
Expand Down

0 comments on commit 474d874

Please sign in to comment.