From 58e53c1b22d689aa57d79e8ef1700a5eed866d95 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 23 Dec 2023 11:38:38 -0600 Subject: [PATCH] Part/Toponaming: Add original cache methods --- src/Mod/Part/App/TopoShape.h | 9 ++-- src/Mod/Part/App/TopoShapeExpansion.cpp | 67 +++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 8ddc6aa014..469f7ffb95 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -444,10 +444,11 @@ public: * @param tol: tolerance to check coincident vertices * @param atol: tolerance to check for same angles */ - std::vector searchSubShape(const TopoShape &subshape, - std::vector *names=nullptr, - bool checkGeometry=true, - double tol=1e-7, double atol=1e-12) const; + // TODO: Implement this method and its tests later in Toponaming Phase 3. + //std::vector searchSubShape(const TopoShape &subshape, + // std::vector *names=nullptr, + // bool checkGeometry=true, + // double tol=1e-7, double atol=1e-12) const; //@} friend class TopoShapeCache; diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index f935f4bd87..2eaea9c368 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -22,6 +22,7 @@ * * ***************************************************************************/ +#include #include "PreCompiled.h" #include "TopoShape.h" @@ -130,4 +131,70 @@ TopoDS_Shape TopoShape::located(const TopoDS_Shape& tds, const gp_Trsf& transfer return moved(sCopy, transfer); } + +int TopoShape::findShape(const TopoDS_Shape& subshape) const +{ + initCache(); + return _cache->findShape(_Shape, subshape); +} + +static const std::string _SubShape("SubShape"); + +TopoDS_Shape TopoShape::findShape(const char* name) const +{ + if (!name) { + return TopoDS_Shape(); + } + + Data::MappedElement res = getElementName(name); + if (!res.index) { + return TopoDS_Shape(); + } + + auto idx = shapeTypeAndIndex(name); + if (!idx.second) { + return TopoDS_Shape(); + } + initCache(); + return _cache->findShape(_Shape, idx.first, idx.second); +} + +TopoDS_Shape TopoShape::findShape(TopAbs_ShapeEnum type, int idx) const +{ + initCache(); + return _cache->findShape(_Shape, type, idx); +} + +int TopoShape::findAncestor(const TopoDS_Shape& subshape, TopAbs_ShapeEnum type) const +{ + initCache(); + return _cache->findShape(_Shape, _cache->findAncestor(_Shape, subshape, type)); +} + +TopoDS_Shape TopoShape::findAncestorShape(const TopoDS_Shape& subshape, TopAbs_ShapeEnum type) const +{ + initCache(); + return _cache->findAncestor(_Shape, subshape, type); +} + +std::vector TopoShape::findAncestors(const TopoDS_Shape& subshape, TopAbs_ShapeEnum type) const +{ + const auto& shapes = findAncestorsShapes(subshape, type); + std::vector ret; + ret.reserve(shapes.size()); + for (const auto& shape : shapes) { + ret.push_back(findShape(shape)); + } + return ret; +} + +std::vector TopoShape::findAncestorsShapes(const TopoDS_Shape& subshape, + TopAbs_ShapeEnum type) const +{ + initCache(); + std::vector shapes; + _cache->findAncestor(_Shape, subshape, type, &shapes); + return shapes; +} + } // namespace Part