From 60ef98a8fea2cd665899f0787da029fc89df37ad Mon Sep 17 00:00:00 2001 From: Shai Seger Date: Thu, 19 Oct 2017 18:21:01 +0300 Subject: [PATCH] add python object resistration --- .../PathSimulator/App/AppPathSimulator.cpp | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Mod/Path/PathSimulator/App/AppPathSimulator.cpp b/src/Mod/Path/PathSimulator/App/AppPathSimulator.cpp index c8c95c9ac8..c6d90d1603 100644 --- a/src/Mod/Path/PathSimulator/App/AppPathSimulator.cpp +++ b/src/Mod/Path/PathSimulator/App/AppPathSimulator.cpp @@ -28,10 +28,14 @@ #include #include +#include #include #include +#include "PathSim.h" +#include "PathSimPy.h" + namespace PathSimulator { class Module : public Py::ExtensionModule @@ -59,10 +63,27 @@ PyObject* initModule() /* Python entry */ PyMOD_INIT_FUNC(PathSimulator) { - // ADD YOUR CODE HERE - // - // + // load dependent module + try { + Base::Interpreter().runString("import Part"); + Base::Interpreter().runString("import Path"); + } + catch (const Base::Exception& e) { + PyErr_SetString(PyExc_ImportError, e.what()); + PyMOD_Return(NULL); + } + + // PyObject* mod = PathSimulator::initModule(); - Base::Console().Log("Loading PathSimulator module... done\n"); + Base::Console().Log("Loading PathSimulator module.... done\n"); PyMOD_Return(mod); + + // Add Types to module + Base::Interpreter().addType(&PathSimulator::PathSimPy::Type, mod, "PathSim"); + + // NOTE: To finish the initialization of our own type objects we must + // call PyType_Ready, otherwise we run into a segmentation fault, later on. + // This function is responsible for adding inherited slots from a type's base class. + PathSimulator::PathSim::init(); + }