Sketcher: SketchGeometryExtension refactor InternalGeometry string conversion

=============================================================================

Minor refactoring to centralise string to enum conversion in a single place
This commit is contained in:
Abdullah Tahiri
2020-11-14 06:54:01 +01:00
committed by abdullahtahiriyo
parent 72fa70add8
commit 91ac9d2951
4 changed files with 28 additions and 22 deletions

View File

@@ -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.");