From 66fb1c77777fdc30fdeee4dd9448f79cbedde250 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 25 Aug 2023 14:06:16 +0200 Subject: [PATCH] Part: refactor ViewProviderPartExt::getDetail --- src/Mod/Part/App/TopoShape.cpp | 16 +++++++++++ src/Mod/Part/App/TopoShape.h | 3 ++ src/Mod/Part/Gui/ViewProviderExt.cpp | 41 ++++++++++++---------------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 09de01f302..ba14734787 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include # include @@ -292,6 +293,21 @@ TopoShape::TopoShape(const TopoShape& shape) Tag = shape.Tag; } +std::pair TopoShape::getElementTypeAndIndex(const char* Name) +{ + int index = 0; + std::string element; + boost::regex ex("^(Face|Edge|Vertex)([1-9][0-9]*)$"); + boost::cmatch what; + + if (boost::regex_match(Name, what, ex)) { + element = what[1].str(); + index = std::atoi(what[2].str().c_str()); + } + + return std::make_pair(element, index); +} + std::vector TopoShape::getElementTypes() const { static const std::vector temp = {"Face","Edge","Vertex"}; diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index faaaa97555..aa36ac3d95 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -154,6 +154,9 @@ public: /** @name Subelement management */ //@{ + /// Unlike \ref getTypeAndIndex() this function only handles the supported + /// element types. + static std::pair getElementTypeAndIndex(const char* Name); /** Sub type list * List of different subelement types * it is NOT a list of the subelements itself diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 99adaa6019..04be9a3022 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -67,7 +67,6 @@ # include # include -# include # include #endif @@ -509,31 +508,27 @@ std::string ViewProviderPartExt::getElement(const SoDetail* detail) const SoDetail* ViewProviderPartExt::getDetail(const char* subelement) const { - std::string element; - int index; - SoDetail* detail = nullptr; - boost::regex ex("^(Face|Edge|Vertex)([1-9][0-9]*)$"); - boost::cmatch what; + auto type = Part::TopoShape::getElementTypeAndIndex(subelement); + std::string element = type.first; + int index = type.second; - if (boost::regex_match(subelement, what, ex)) { - element = what[1].str(); - index = std::atoi(what[2].str().c_str()); - - if (element == "Face") { - detail = new SoFaceDetail(); - static_cast(detail)->setPartIndex(index - 1); - } - else if (element == "Edge") { - detail = new SoLineDetail(); - static_cast(detail)->setLineIndex(index - 1); - } - else if (element == "Vertex") { - detail = new SoPointDetail(); - static_cast(detail)->setCoordinateIndex(index + nodeset->startIndex.getValue() - 1); - } + if (element == "Face") { + SoFaceDetail* detail = new SoFaceDetail(); + detail->setPartIndex(index - 1); + return detail; + } + else if (element == "Edge") { + SoLineDetail* detail = new SoLineDetail(); + detail->setLineIndex(index - 1); + return detail; + } + else if (element == "Vertex") { + SoPointDetail* detail = new SoPointDetail(); + static_cast(detail)->setCoordinateIndex(index + nodeset->startIndex.getValue() - 1); + return detail; } - return detail; + return nullptr; } std::vector ViewProviderPartExt::getModelPoints(const SoPickedPoint* pp) const