From 9edb6f58d5f11a40f39644549e8acc4112e84dde Mon Sep 17 00:00:00 2001 From: bgbsww <120601209+bgbsww@users.noreply.github.com> Date: Mon, 22 Jan 2024 08:39:47 -0500 Subject: [PATCH] ShapeMapper that works with OCCT7.8.0 --- src/Mod/Part/App/TopoShape.h | 57 ++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 8cc5d0621e..abcd8157e8 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -935,46 +935,73 @@ private: static TopoShape reverseEdge (const TopoShape& edge); }; + /// Shape hasher that ignore orientation -struct ShapeHasher { - inline size_t operator()(const TopoShape &s) const { +struct ShapeHasher +{ + inline size_t operator()(const TopoShape& s) const + { +#if OCC_VERSION_HEX >= 0x070800 + return std::hash {}(s.getShape()); +#else return s.getShape().HashCode(INT_MAX); +#endif } - inline size_t operator()(const TopoDS_Shape &s) const { + inline size_t operator()(const TopoDS_Shape& s) const + { +#if OCC_VERSION_HEX >= 0x070800 + return std::hash {}(s); +#else return s.HashCode(INT_MAX); +#endif } - inline bool operator()(const TopoShape &a, const TopoShape &b) const { + inline bool operator()(const TopoShape& a, const TopoShape& b) const + { return a.getShape().IsSame(b.getShape()); } - inline bool operator()(const TopoDS_Shape &a, const TopoDS_Shape &b) const { + inline bool operator()(const TopoDS_Shape& a, const TopoDS_Shape& b) const + { return a.IsSame(b); } - template + template static inline void hash_combine(std::size_t& seed, const T& v) { // copied from boost::hash_combine std::hash hasher; - seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); + seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - inline size_t operator()(const std::pair &s) const { + inline size_t operator()(const std::pair& s) const + { +#if OCC_VERSION_HEX >= 0x070800 + size_t res = std::hash {}(s.first.getShape()); + hash_combine(res, std::hash {}(s.second.getShape())); +#else size_t res = s.first.getShape().HashCode(INT_MAX); hash_combine(res, s.second.getShape().HashCode(INT_MAX)); +#endif return res; } - inline size_t operator()(const std::pair &s) const { + inline size_t operator()(const std::pair& s) const + { +#if OCC_VERSION_HEX >= 0x070800 + size_t res = std::hash {}(s.first); + hash_combine(res, std::hash {}(s.second)); +#else size_t res = s.first.HashCode(INT_MAX); hash_combine(res, s.second.HashCode(INT_MAX)); +#endif return res; } - inline bool operator()(const std::pair &a, - const std::pair &b) const { + inline bool operator()(const std::pair& a, + const std::pair& b) const + { return a.first.getShape().IsSame(b.first.getShape()) && a.second.getShape().IsSame(b.second.getShape()); } - inline bool operator()(const std::pair &a, - const std::pair &b) const { - return a.first.IsSame(b.first) - && a.second.IsSame(b.second); + inline bool operator()(const std::pair& a, + const std::pair& b) const + { + return a.first.IsSame(b.first) && a.second.IsSame(b.second); } };