From fa12b433dfd0aaa7401de68787010a68d155c039 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 25 Aug 2023 14:03:25 +0200 Subject: [PATCH] App: refactor ComplexGeoData::getSubElementByName --- src/App/ComplexGeoData.cpp | 12 +++++++++--- src/App/ComplexGeoData.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index 52c3c09199..50bb84d607 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -57,19 +57,25 @@ using namespace Data; ComplexGeoData::ComplexGeoData() = default; -Data::Segment* ComplexGeoData::getSubElementByName(const char* name) const +std::pair ComplexGeoData::getTypeAndIndex(const char* Name) { int index = 0; std::string element; boost::regex ex("^([^0-9]*)([0-9]*)$"); boost::cmatch what; - if (boost::regex_match(name, what, ex)) { + if (boost::regex_match(Name, what, ex)) { element = what[1].str(); index = std::atoi(what[2].str().c_str()); } - return getSubElement(element.c_str(), static_cast(index)); + return std::make_pair(element, index); +} + +Data::Segment* ComplexGeoData::getSubElementByName(const char* name) const +{ + auto type = getTypeAndIndex(name); + return getSubElement(type.first.c_str(),type.second); } void ComplexGeoData::applyTransform(const Base::Matrix4D& rclTrf) diff --git a/src/App/ComplexGeoData.h b/src/App/ComplexGeoData.h index 7f2bf79301..52cbb29580 100644 --- a/src/App/ComplexGeoData.h +++ b/src/App/ComplexGeoData.h @@ -95,6 +95,9 @@ public: */ virtual std::vector getElementTypes() const=0; virtual unsigned long countSubElements(const char* Type) const=0; + /// Returns a generic element type and index. The determined element type isn't + /// necessarily supported by this geometry. + static std::pair getTypeAndIndex(const char* Name); /// get the sub-element by type and number virtual Segment* getSubElement(const char* Type, unsigned long) const=0; /// get sub-element by combined name