From 061c67cbf82f5b72ca1dce3da186d4f87774eadc Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 5 Jan 2016 19:05:48 +0100 Subject: [PATCH] + expose onDocumentRestored to Python feature classes --- src/App/FeatureCustom.h | 6 ++++++ src/App/FeaturePython.cpp | 29 +++++++++++++++++++++++++++++ src/App/FeaturePython.h | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/src/App/FeatureCustom.h b/src/App/FeatureCustom.h index 5e7adab48..7d19a374b 100644 --- a/src/App/FeatureCustom.h +++ b/src/App/FeatureCustom.h @@ -161,6 +161,12 @@ protected: virtual void onChanged(const Property* prop) { FeatureT::onChanged(prop); } + virtual void onDocumentRestored() { + FeatureT::onDocumentRestored(); + } + virtual void onSettingDocument() { + FeatureT::onSettingDocument(); + } private: DynamicProperty* props; diff --git a/src/App/FeaturePython.cpp b/src/App/FeaturePython.cpp index 582b760f0..bcd06b459 100644 --- a/src/App/FeaturePython.cpp +++ b/src/App/FeaturePython.cpp @@ -154,6 +154,35 @@ void FeaturePythonImp::onChanged(const Property* prop) } } +void FeaturePythonImp::onDocumentRestored() +{ + // Run the execute method of the proxy object. + Base::PyGILStateLocker lock; + try { + Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == PropertyPythonObject::getClassTypeId()) { + Py::Object feature = static_cast(proxy)->getValue(); + if (feature.hasAttr(std::string("onDocumentRestored"))) { + if (feature.hasAttr("__object__")) { + Py::Callable method(feature.getAttr(std::string("onDocumentRestored"))); + Py::Tuple args; + method.apply(args); + } + else { + Py::Callable method(feature.getAttr(std::string("onDocumentRestored"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(object->getPyObject(), true)); + method.apply(args); + } + } + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + PyObject *FeaturePythonImp::getPyObject(void) { // ref counter is set to 1 diff --git a/src/App/FeaturePython.h b/src/App/FeaturePython.h index 1c706848c..113a5befe 100644 --- a/src/App/FeaturePython.h +++ b/src/App/FeaturePython.h @@ -47,6 +47,7 @@ public: bool execute(); void onBeforeChange(const Property* prop); void onChanged(const Property* prop); + void onDocumentRestored(); PyObject *getPyObject(void); private: @@ -200,6 +201,10 @@ protected: imp->onChanged(prop); FeatureT::onChanged(prop); } + virtual void onDocumentRestored() { + imp->onDocumentRestored(); + FeatureT::onDocumentRestored(); + } private: FeaturePythonImp* imp;