Part: refactor ViewProviderPartExt::getDetail

This commit is contained in:
wmayer
2023-08-25 14:06:16 +02:00
committed by wwmayer
parent 56ccef84c2
commit 66fb1c7777
3 changed files with 37 additions and 23 deletions

View File

@@ -27,6 +27,7 @@
# include <cmath>
# include <cstdlib>
# include <sstream>
# include <boost/regex.hpp>
# include <APIHeaderSection_MakeHeader.hxx>
# include <BinTools.hxx>
@@ -292,6 +293,21 @@ TopoShape::TopoShape(const TopoShape& shape)
Tag = shape.Tag;
}
std::pair<std::string, unsigned long> 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<const char*> TopoShape::getElementTypes() const
{
static const std::vector<const char*> temp = {"Face","Edge","Vertex"};

View File

@@ -154,6 +154,9 @@ public:
/** @name Subelement management */
//@{
/// Unlike \ref getTypeAndIndex() this function only handles the supported
/// element types.
static std::pair<std::string, unsigned long> getElementTypeAndIndex(const char* Name);
/** Sub type list
* List of different subelement types
* it is NOT a list of the subelements itself

View File

@@ -67,7 +67,6 @@
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoShapeHints.h>
# include <boost/regex.hpp>
# include <boost/algorithm/string/predicate.hpp>
#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<SoFaceDetail*>(detail)->setPartIndex(index - 1);
}
else if (element == "Edge") {
detail = new SoLineDetail();
static_cast<SoLineDetail*>(detail)->setLineIndex(index - 1);
}
else if (element == "Vertex") {
detail = new SoPointDetail();
static_cast<SoPointDetail*>(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<SoPointDetail*>(detail)->setCoordinateIndex(index + nodeset->startIndex.getValue() - 1);
return detail;
}
return detail;
return nullptr;
}
std::vector<Base::Vector3d> ViewProviderPartExt::getModelPoints(const SoPickedPoint* pp) const