+ 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 "PropertyGeometryList.h"
extern struct PyMethodDef Part_methods[];
namespace Part {
extern PyObject* initModule();
}
using namespace Part;
PyObject* Part::PartExceptionOCCError;
PyObject* Part::PartExceptionOCCDomainError;
PyObject* Part::PartExceptionOCCRangeError;
PyObject* Part::PartExceptionOCCConstructionError;
PyObject* Part::PartExceptionOCCDimensionError;
PyDoc_STRVAR(module_part_doc,
"This is a module working with shapes.");
extern "C" {
void PartExport initPart()
PyMODINIT_FUNC initPart()
{
std::stringstream str;
str << OCC_VERSION_MAJOR << "." << OCC_VERSION_MINOR << "." << OCC_VERSION_MAINTENANCE;
@ -122,7 +123,7 @@ void PartExport initPart()
OSD::SetSignal(Standard_False);
#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");
PyObject* OCCError = 0;
if (PyObject_IsSubclass(Base::BaseExceptionFreeCADError,
@ -381,5 +382,3 @@ void PartExport initPart()
Interface_Static::SetCVal("write.step.product.name", hStepGrp->GetASCII("Product",
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>
#endif
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include <Base/Console.h>
#include <Base/Interpreter.h>
@ -77,13 +80,28 @@ void loadPartResource()
Gui::Translator::instance()->refresh();
}
/* registration table */
static struct PyMethodDef PartGui_methods[] = {
{NULL, NULL} /* end of table marker */
namespace PartGui {
class Module : public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("PartGui")
{
initialize("This module is the PartGui module."); // register with Python
}
virtual ~Module() {}
private:
};
extern "C" {
void PartGuiExport initPartGui()
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace PartGui
PyMODINIT_FUNC initPartGui()
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
@ -99,7 +117,7 @@ void PartGuiExport initPartGui()
return;
}
(void) Py_InitModule("PartGui", PartGui_methods); /* mod name, table ptr */
(void)PartGui::initModule();
Base::Console().Log("Loading GUI of Part module... done\n");
PartGui::SoBrepFaceSet ::initClass();
@ -176,4 +194,3 @@ void PartGuiExport initPartGui()
rclBmpFactory.addXPM("PartFeature",(const char**) PartFeature_xpm);
rclBmpFactory.addXPM("PartFeatureImport",(const char**) PartFeatureImport_xpm);
}
} // extern "C"