diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index 1fd9642ea2c8..d0a83b0d8cb8 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -120,6 +120,38 @@ const char* AttachEngine::eMapModeStrings[]= { NULL}; +//this list must be in sync with eRefType enum. +//These strings are used only by Py interface of Attacher. Strings for use in Gui are in Mod/Part/Gui/AttacherTexts.cpp +const char* AttachEngine::eRefTypeStrings[]= { + "Any", + "Vertex", + "Edge", + "Face", + + "Line", + "Curve", + "Circle", + "Conic", + "Ellipse", + "Parabola", + "Hyperbola", + + "Plane", + "Sphere", + "Revolve", + "Cylinder", + "Torus", + "Cone", + + "Object", + "Solid", + "Wire", + NULL +}; + + + + TYPESYSTEM_SOURCE_ABSTRACT(Attacher::AttachEngine, Base::BaseClass); @@ -578,6 +610,57 @@ std::string AttachEngine::getModeName(eMapMode mmode) return std::string(AttachEngine::eMapModeStrings[mmode]); } +eMapMode AttachEngine::getModeByName(const std::string &modeName) +{ + for (int mmode = 0 ; mmode < mmDummy_NumberOfModes ; mmode++){ + if (strcmp(eMapModeStrings[mmode],modeName.c_str())==0) { + return eMapMode(mmode); + } + } + std::stringstream errMsg; + errMsg << "AttachEngine::getModeByName: mode with this name doesn't exist: " << modeName; + throw Base::Exception(errMsg.str()); +} + +std::string AttachEngine::getRefTypeName(eRefType shapeType) +{ + eRefType flagless = eRefType(shapeType & 0xFF); + if(flagless < 0 || flagless >= rtDummy_numberOfShapeTypes) + throw Base::Exception("eRefType value is out of range"); + std::string result = std::string(eRefTypeStrings[flagless]); + if (shapeType & rtFlagHasPlacement){ + result.append("|Placement"); + } + return result; +} + +eRefType AttachEngine::getRefTypeByName(const std::string& typeName) +{ + std::string flagless; + std::string flags; + size_t seppos = typeName.find('|'); + flagless = typeName.substr(0, seppos); + if(seppos != std::string::npos ){ + flags = typeName.substr(seppos+1); + } + for(int irt = 0 ; irt < rtDummy_numberOfShapeTypes ; irt++){ + if(strcmp(flagless.c_str(),eRefTypeStrings[irt]) == 0){ + if(strcmp("Placement",flags.c_str()) == 0){ + return eRefType(irt | rtFlagHasPlacement); + } else if (flags.length() == 0){ + return eRefType(irt); + } else { + std::stringstream errmsg; + errmsg << "RefType flag not recognized: " << flags; + throw Base::Exception(errmsg.str()); + } + } + } + std::stringstream errmsg; + errmsg << "RefType not recognized: " << typeName; + throw Base::Exception(errmsg.str()); +} + GProp_GProps AttachEngine::getInertialPropsOfShape(const std::vector &shapes) { //explode compounds diff --git a/src/Mod/Part/App/Attacher.h b/src/Mod/Part/App/Attacher.h index d2eb8b22c568..c0e88040115a 100644 --- a/src/Mod/Part/App/Attacher.h +++ b/src/Mod/Part/App/Attacher.h @@ -105,7 +105,8 @@ enum eMapMode { /** * @brief The eRefType enum lists the types of references. If adding one, see - * also AttachEngine::getShapeType(), AttachEngine::downgradeType(), AttacherTexts.cpp/getShTypeText() + * also AttachEngine::eRefTypeStrings, AttachEngine::getShapeType(), + * AttachEngine::downgradeType(), AttacherTexts.cpp/getShTypeText() */ enum eRefType { //topo //ranks: (number of times the type is downgradable) @@ -333,11 +334,18 @@ class PartExport AttachEngine : public Base::BaseClass */ static std::string getModeName(eMapMode mmode); + static eMapMode getModeByName(const std::string &modeName); + + static std::string getRefTypeName(eRefType shapeType); + + static eRefType getRefTypeByName(const std::string &typeName); + static GProp_GProps getInertialPropsOfShape(const std::vector &shapes); public: //enums static const char* eMapModeStrings[]; + static const char* eRefTypeStrings[]; public: //members