From aa32b9c6af126fb52ce5e4c30e0f869a6c6bdc4a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 10 Oct 2020 11:44:51 +0200 Subject: [PATCH] Part: [skip ci] harmonizing the way to add sub-modules to Part module --- src/Mod/Part/App/AppPart.cpp | 31 +++++-------------------------- src/Mod/Part/App/AppPartPy.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index d3a0fcfea9..1406ea900f 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -376,34 +376,13 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::GeometryBoolExtensionPy ::Type,partModule,"GeometryBoolExtension"); Base::Interpreter().addType(&Part::GeometryDoubleExtensionPy ::Type,partModule,"GeometryDoubleExtension"); -#if PY_MAJOR_VERSION >= 3 - static struct PyModuleDef BRepOffsetAPIDef = { - PyModuleDef_HEAD_INIT, - "BRepOffsetAPI", "BRepOffsetAPI", -1, 0, - NULL, NULL, NULL, NULL - }; - PyObject* brepModule = PyModule_Create(&BRepOffsetAPIDef); -#else - PyObject* brepModule = Py_InitModule3("BRepOffsetAPI", 0, "BrepOffsetAPI"); -#endif - Py_INCREF(brepModule); - PyModule_AddObject(partModule, "BRepOffsetAPI", brepModule); - Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepModule,"MakePipeShell"); - Base::Interpreter().addType(&Part::BRepOffsetAPI_MakeFillingPy::Type,brepModule,"MakeFilling"); + // BRepOffsetAPI package + PyObject* brepOffsetApiModule(module.getAttr("BRepOffsetAPI").ptr()); + Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepOffsetApiModule,"MakePipeShell"); + Base::Interpreter().addType(&Part::BRepOffsetAPI_MakeFillingPy::Type,brepOffsetApiModule,"MakeFilling"); // Geom2d package -#if PY_MAJOR_VERSION >= 3 - static struct PyModuleDef geom2dDef = { - PyModuleDef_HEAD_INIT, - "Geom2dD", "Geom2d", -1, 0, - NULL, NULL, NULL, NULL - }; - PyObject* geom2dModule = PyModule_Create(&geom2dDef); -#else - PyObject* geom2dModule = Py_InitModule3("Geom2d", 0, "Geom2d"); -#endif - Py_INCREF(geom2dModule); - PyModule_AddObject(partModule, "Geom2d", geom2dModule); + PyObject* geom2dModule(module.getAttr("Geom2d").ptr()); Base::Interpreter().addType(&Part::Geometry2dPy::Type,geom2dModule,"Geometry2d"); Base::Interpreter().addType(&Part::Curve2dPy::Type,geom2dModule,"Curve2d"); Base::Interpreter().addType(&Part::Conic2dPy::Type,geom2dModule,"Conic2d"); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 2c5fe46e22..4a94a21528 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -271,6 +271,28 @@ PartExport std::list sort_Edges(double tol3d, std::list +{ +public: + BRepOffsetAPIModule() : Py::ExtensionModule("BRepOffsetAPI") + { + initialize("This is a module working with the BRepOffsetAPI package."); // register with Python + } + + virtual ~BRepOffsetAPIModule() {} +}; + +class Geom2dModule : public Py::ExtensionModule +{ +public: + Geom2dModule() : Py::ExtensionModule("Geom2d") + { + initialize("This is a module working with 2d geometries."); // register with Python + } + + virtual ~Geom2dModule() {} +}; + class GeomPlateModule : public Py::ExtensionModule { public: @@ -295,6 +317,8 @@ public: class Module : public Py::ExtensionModule { + BRepOffsetAPIModule brepOffsetApi; + Geom2dModule geom2d; GeomPlateModule geomPlate; ShapeUpgradeModule shapeUpgrade; public: @@ -513,6 +537,8 @@ public: ); initialize("This is a module working with shapes."); // register with Python + PyModule_AddObject(m_module, "BRepOffsetAPI", brepOffsetApi.module().ptr()); + PyModule_AddObject(m_module, "Geom2d", geom2d.module().ptr()); PyModule_AddObject(m_module, "GeomPlate", geomPlate.module().ptr()); PyModule_AddObject(m_module, "ShapeUpgrade", shapeUpgrade.module().ptr()); }