From dd6638b1ab3cbb18eb1198ff0155392336fe2158 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 22 Nov 2024 15:39:07 +0100 Subject: [PATCH] Mesh::GetRegionName(element_or_elindex) --- libsrc/general/mystring.cpp | 10 ++++++++++ libsrc/general/mystring.hpp | 1 + libsrc/meshing/meshclass.cpp | 15 +++++++++++++++ libsrc/meshing/meshclass.hpp | 8 ++++++++ 4 files changed, 34 insertions(+) diff --git a/libsrc/general/mystring.cpp b/libsrc/general/mystring.cpp index cd2ed300..c88cfab3 100644 --- a/libsrc/general/mystring.cpp +++ b/libsrc/general/mystring.cpp @@ -223,6 +223,16 @@ MyStr::MyStr(const string & st) strcpy (str, st.c_str()); } +MyStr::MyStr(string_view sv) +{ + length = unsigned(sv.length()); + if (length > SHORTLEN) + str = new char[length + 1]; + else + str = shortstr; + strcpy (str, sv.data()); +} + MyStr::MyStr(const filesystem::path & path) : MyStr(path.string()) { } diff --git a/libsrc/general/mystring.hpp b/libsrc/general/mystring.hpp index ee364d77..4f2167ec 100644 --- a/libsrc/general/mystring.hpp +++ b/libsrc/general/mystring.hpp @@ -60,6 +60,7 @@ public: MyStr(const Point3d& p); MyStr(const Vec3d& p); MyStr(const string & st); + MyStr(string_view sv); MyStr(const filesystem::path & st); ~MyStr(); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 00958203..7fa8bfb1 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -7528,6 +7528,21 @@ namespace netgen } } + + std::string_view Mesh :: GetRegionName (const Segment & el) const + { + return *const_cast(*this).GetRegionNamesCD(GetDimension()-1)[el.edgenr-1]; + } + + std::string_view Mesh :: GetRegionName (const Element2d & el) const + { + return *const_cast(*this).GetRegionNamesCD(GetDimension()-2)[GetFaceDescriptor(el).BCProperty()-1]; + } + + std::string_view Mesh :: GetRegionName (const Element & el) const + { + return *const_cast(*this).GetRegionNamesCD(GetDimension()-3)[el.GetIndex()-1]; + } void Mesh :: SetUserData(const char * id, NgArray & data) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 5d7c7e7a..4be51c87 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -749,6 +749,14 @@ namespace netgen DLL_HEADER NgArray & GetRegionNamesCD (int codim); + + DLL_HEADER std::string_view GetRegionName(const Segment & el) const; + DLL_HEADER std::string_view GetRegionName(const Element2d & el) const; + DLL_HEADER std::string_view GetRegionName(const Element & el) const; + + std::string_view GetRegionName(SegmentIndex ei) const { return GetRegionName((*this)[ei]); } + std::string_view GetRegionName(SurfaceElementIndex ei) const { return GetRegionName((*this)[ei]); } + std::string_view GetRegionName(ElementIndex ei) const { return GetRegionName((*this)[ei]); } /// void ClearFaceDescriptors()