+ simplify porting of Part module to Python3

This commit is contained in:
wmayer 2016-01-20 22:05:53 +01:00
parent 08dda60d00
commit b10f838687
3 changed files with 1477 additions and 1564 deletions

View File

@ -91,19 +91,20 @@
#include "PartFeaturePy.h" #include "PartFeaturePy.h"
#include "PropertyGeometryList.h" #include "PropertyGeometryList.h"
extern struct PyMethodDef Part_methods[]; namespace Part {
extern PyObject* initModule();
}
using namespace Part; using namespace Part;
PyObject* Part::PartExceptionOCCError; PyObject* Part::PartExceptionOCCError;
PyObject* Part::PartExceptionOCCDomainError; PyObject* Part::PartExceptionOCCDomainError;
PyObject* Part::PartExceptionOCCRangeError; PyObject* Part::PartExceptionOCCRangeError;
PyObject* Part::PartExceptionOCCConstructionError; PyObject* Part::PartExceptionOCCConstructionError;
PyObject* Part::PartExceptionOCCDimensionError; PyObject* Part::PartExceptionOCCDimensionError;
PyDoc_STRVAR(module_part_doc,
"This is a module working with shapes.");
extern "C" { PyMODINIT_FUNC initPart()
void PartExport initPart()
{ {
std::stringstream str; std::stringstream str;
str << OCC_VERSION_MAJOR << "." << OCC_VERSION_MINOR << "." << OCC_VERSION_MAINTENANCE; str << OCC_VERSION_MAJOR << "." << OCC_VERSION_MINOR << "." << OCC_VERSION_MAINTENANCE;
@ -122,7 +123,7 @@ void PartExport initPart()
OSD::SetSignal(Standard_False); OSD::SetSignal(Standard_False);
#endif #endif
PyObject* partModule = Py_InitModule3("Part", Part_methods, module_part_doc); /* mod name, table ptr */ PyObject* partModule = Part::initModule();
Base::Console().Log("Loading Part module... done\n"); Base::Console().Log("Loading Part module... done\n");
PyObject* OCCError = 0; PyObject* OCCError = 0;
if (PyObject_IsSubclass(Base::BaseExceptionFreeCADError, if (PyObject_IsSubclass(Base::BaseExceptionFreeCADError,
@ -381,5 +382,3 @@ void PartExport initPart()
Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product", Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product",
Interface_Static::CVal("write.step.product.name")).c_str()); Interface_Static::CVal("write.step.product.name")).c_str());
} }
} // extern "C"

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,9 @@
# include <Inventor/system/inttypes.h> # include <Inventor/system/inttypes.h>
#endif #endif
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Interpreter.h> #include <Base/Interpreter.h>
@ -77,13 +80,28 @@ void loadPartResource()
Gui::Translator::instance()->refresh(); Gui::Translator::instance()->refresh();
} }
/* registration table */ namespace PartGui {
static struct PyMethodDef PartGui_methods[] = { class Module : public Py::ExtensionModule<Module>
{NULL, NULL} /* end of table marker */ {
public:
Module() : Py::ExtensionModule<Module>("PartGui")
{
initialize("This module is the PartGui module."); // register with Python
}
virtual ~Module() {}
private:
}; };
extern "C" { PyObject* initModule()
void PartGuiExport initPartGui() {
return (new Module)->module().ptr();
}
} // namespace PartGui
PyMODINIT_FUNC initPartGui()
{ {
if (!Gui::Application::Instance) { if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
@ -99,7 +117,7 @@ void PartGuiExport initPartGui()
return; return;
} }
(void) Py_InitModule("PartGui", PartGui_methods); /* mod name, table ptr */ (void)PartGui::initModule();
Base::Console().Log("Loading GUI of Part module... done\n"); Base::Console().Log("Loading GUI of Part module... done\n");
PartGui::SoBrepFaceSet ::initClass(); PartGui::SoBrepFaceSet ::initClass();
@ -176,4 +194,3 @@ void PartGuiExport initPartGui()
rclBmpFactory.addXPM("PartFeature",(const char**) PartFeature_xpm); rclBmpFactory.addXPM("PartFeature",(const char**) PartFeature_xpm);
rclBmpFactory.addXPM("PartFeatureImport",(const char**) PartFeatureImport_xpm); rclBmpFactory.addXPM("PartFeatureImport",(const char**) PartFeatureImport_xpm);
} }
} // extern "C"