Sketcher: SketchGeometryExtension refactor InternalGeometry string conversion
============================================================================= Minor refactoring to centralise string to enum conversion in a single place
This commit is contained in:
committed by
abdullahtahiriyo
parent
72fa70add8
commit
91ac9d2951
@@ -107,18 +107,11 @@ Py::String GeometryFacadePy::getInternalType(void) const
|
||||
void GeometryFacadePy::setInternalType(Py::String arg)
|
||||
{
|
||||
std::string argstr = arg;
|
||||
InternalType::InternalType type;
|
||||
|
||||
auto pos = std::find_if( SketchGeometryExtension::internaltype2str.begin(),
|
||||
SketchGeometryExtension::internaltype2str.end(),
|
||||
[argstr](const char * val) {
|
||||
return strcmp(val,argstr.c_str())==0;}
|
||||
);
|
||||
|
||||
if( pos != SketchGeometryExtension::internaltype2str.end()) {
|
||||
int index = std::distance( SketchGeometryExtension::internaltype2str.begin(), pos );
|
||||
|
||||
this->getGeometryFacadePtr()->setInternalType((InternalType::InternalType)index);
|
||||
return;
|
||||
if(SketchGeometryExtension::getInternalTypeFromName(argstr, type)) {
|
||||
this->getGeometryFacadePtr()->setInternalType(type);
|
||||
return;
|
||||
}
|
||||
|
||||
throw Py::ValueError("Argument is not a valid internal geometry type.");
|
||||
|
||||
@@ -98,3 +98,21 @@ PyObject * SketchGeometryExtension::getPyObject(void)
|
||||
return new SketchGeometryExtensionPy(new SketchGeometryExtension(*this));
|
||||
}
|
||||
|
||||
bool SketchGeometryExtension::getInternalTypeFromName(std::string str, InternalType::InternalType &type)
|
||||
{
|
||||
auto pos = std::find_if( SketchGeometryExtension::internaltype2str.begin(),
|
||||
SketchGeometryExtension::internaltype2str.end(),
|
||||
[str](const char * val) {
|
||||
return strcmp(val,str.c_str())==0;}
|
||||
);
|
||||
|
||||
if( pos != SketchGeometryExtension::internaltype2str.end()) {
|
||||
int index = std::distance( SketchGeometryExtension::internaltype2str.begin(), pos );
|
||||
|
||||
type = static_cast<InternalType::InternalType>(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ public:
|
||||
|
||||
constexpr static std::array<const char *,InternalType::NumInternalGeometryType> internaltype2str {{ "None", "EllipseMajorDiameter", "EllipseMinorDiameter","EllipseFocus1", "EllipseFocus2", "HyperbolaMajor", "HyperbolaMinor", "HyperbolaFocus", "ParabolaFocus", "BSplineControlPoint", "BSplineKnotPoint" }};
|
||||
|
||||
static bool getInternalTypeFromName(std::string str, InternalType::InternalType &type);
|
||||
|
||||
private:
|
||||
SketchGeometryExtension(const SketchGeometryExtension&) = default;
|
||||
|
||||
|
||||
@@ -104,18 +104,11 @@ Py::String SketchGeometryExtensionPy::getInternalType(void) const
|
||||
void SketchGeometryExtensionPy::setInternalType(Py::String arg)
|
||||
{
|
||||
std::string argstr = arg;
|
||||
InternalType::InternalType type;
|
||||
|
||||
auto pos = std::find_if(this->getSketchGeometryExtensionPtr()->internaltype2str.begin(),
|
||||
getSketchGeometryExtensionPtr()->internaltype2str.end(),
|
||||
[argstr](const char * val) {
|
||||
return strcmp(val,argstr.c_str())==0;}
|
||||
);
|
||||
|
||||
if( pos != getSketchGeometryExtensionPtr()->internaltype2str.end()) {
|
||||
int index = std::distance( getSketchGeometryExtensionPtr()->internaltype2str.begin(), pos );
|
||||
|
||||
this->getSketchGeometryExtensionPtr()->setInternalType((InternalType::InternalType)index);
|
||||
return;
|
||||
if(SketchGeometryExtension::getInternalTypeFromName(argstr, type)) {
|
||||
this->getSketchGeometryExtensionPtr()->setInternalType(type);
|
||||
return;
|
||||
}
|
||||
|
||||
throw Py::ValueError("Argument is not a valid internal geometry type.");
|
||||
|
||||
Reference in New Issue
Block a user