Attacher: preparations for Py interface of shape type system

+ add getModeByName to AttachEngine
This commit is contained in:
DeepSOIC 2016-05-08 13:43:10 +03:00
parent 53bd9b674b
commit 162378220d
2 changed files with 92 additions and 1 deletions

View File

@ -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<const TopoDS_Shape*> &shapes)
{
//explode compounds

View File

@ -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 @@ public://helper functions that may be useful outside of the class
*/
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<const TopoDS_Shape*> &shapes);
public: //enums
static const char* eMapModeStrings[];
static const char* eRefTypeStrings[];
public: //members