Attacher: Py: GUI resources interface

Routines to get UI strings for attacher: mode names, mode tooltips,
ref.type names
This commit is contained in:
DeepSOIC 2016-05-13 02:09:42 +03:00
parent 8b4f1210ed
commit 76c0a81fe3
3 changed files with 82 additions and 3 deletions

View File

@ -28,6 +28,7 @@
#include <Mod/Part/App/PropertyTopoShape.h>
#include "AttacherTexts.h"
#include "SoBrepFaceSet.h"
#include "SoBrepEdgeSet.h"
#include "SoBrepPointSet.h"
@ -117,9 +118,15 @@ PyMODINIT_FUNC initPartGui()
return;
}
(void)PartGui::initModule();
PyObject* partGuiModule = PartGui::initModule();
Base::Console().Log("Loading GUI of Part module... done\n");
PyObject* pAttachEngineTextsModule = Py_InitModule3("AttachEngineResources", AttacherGui::AttacherGuiPy::Methods,
"AttachEngine Gui resources");
Py_INCREF(pAttachEngineTextsModule);
PyModule_AddObject(partGuiModule, "AttachEngineResources", pAttachEngineTextsModule);
PartGui::SoBrepFaceSet ::initClass();
PartGui::SoBrepEdgeSet ::initClass();
PartGui::SoBrepPointSet ::initClass();

View File

@ -25,6 +25,8 @@
# include <QApplication>
#endif
#include "AttacherTexts.h"
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
using namespace Attacher;
@ -262,7 +264,7 @@ TextSet getUIStrings(Base::Type attacherType, eMapMode mmode)
}
}
assert(false && "No user-friendly string defined for this attachment mode.");
Base::Console().Warning("No user-friendly string defined for this attachment mode and attacher type: %s %s \n",AttachEngine::getModeName(mmode).c_str(), attacherType.getName());
return TwoStrings(QString::fromStdString(AttachEngine::getModeName(mmode)), QString());
}
@ -325,4 +327,64 @@ QStringList getRefListForMode(AttachEngine &attacher, eMapMode mmode)
return strlist;
}
// --------------------Py interface---------------------
PyObject* AttacherGuiPy::sGetModeStrings(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
{
int modeIndex = 0;
char* attacherType;
if (!PyArg_ParseTuple(args, "si", &attacherType, &modeIndex))
return NULL;
try {
Base::Type t = Base::Type::fromName(attacherType);
if (! t.isDerivedFrom(AttachEngine::getClassTypeId())){
std::stringstream ss;
ss << "Object of this type is not derived from AttachEngine: ";
ss << attacherType;
throw Py::TypeError(ss.str());
}
TextSet strs = getUIStrings(t,eMapMode(modeIndex));
Py::List result;
for(QString &s : strs){
QByteArray ba_utf8 = s.toUtf8();
result.append(Py::String(ba_utf8.data(), "utf-8"));
}
return Py::new_reference_to(result);
} catch (const Py::Exception&) {
return 0;
} catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return 0;
}
}
PyObject* AttacherGuiPy::sGetRefTypeUserFriendlyName(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
{
int refTypeIndex = 0;
if (!PyArg_ParseTuple(args, "i", &refTypeIndex))
return NULL;
try {
QByteArray ba_utf8 = getShapeTypeText(eRefType(refTypeIndex)).toUtf8();
return Py::new_reference_to(Py::String(ba_utf8.data(), "utf-8"));
} catch (const Py::Exception&) {
return 0;
} catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return 0;
}
}
PyMethodDef AttacherGuiPy::Methods[] = {
{"getModeStrings", (PyCFunction) AttacherGuiPy::sGetModeStrings, 1,
"getModeStrings(attacher_type, mode_index) - gets mode user-friendly name and brief description."},
{"getRefTypeUserFriendlyName", (PyCFunction) AttacherGuiPy::sGetRefTypeUserFriendlyName, 1,
"getRefTypeUserFriendlyName(type_index) - gets user-friendly name of AttachEngine's shape type."},
};
} //namespace AttacherGui

View File

@ -33,8 +33,10 @@
#include <vector>
#include <QString>
#include <QStringList>
#include <CXX/Objects.hxx>
#include <Mod/Part/App/Attacher.h>
namespace AttacherGui {
typedef std::vector<QString> TextSet;
@ -54,6 +56,14 @@ QString PartGuiExport getShapeTypeText(Attacher::eRefType type);
QStringList PartGuiExport getRefListForMode(Attacher::AttachEngine &attacher, Attacher::eMapMode mmode);
}
// Python interface
class PartGuiExport AttacherGuiPy{
public:
static PyMethodDef Methods[];
static PyObject* sGetModeStrings(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/);
static PyObject* sGetRefTypeUserFriendlyName(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/);
};
}
#endif