Skip to content

Commit

Permalink
Attacher: preparations for Py interface of shape type system
Browse files Browse the repository at this point in the history
+ add getModeByName to AttachEngine
  • Loading branch information
DeepSOIC committed May 13, 2016
1 parent 53bd9b6 commit 1623782
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
83 changes: 83 additions & 0 deletions src/Mod/Part/App/Attacher.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/Mod/Part/App/Attacher.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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<const TopoDS_Shape*> &shapes);


public: //enums
static const char* eMapModeStrings[];
static const char* eRefTypeStrings[];


public: //members
Expand Down

0 comments on commit 1623782

Please sign in to comment.