From 38e02e6f36521af7fc0085329da8788af324f059 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 8 Feb 2023 15:02:11 +0100 Subject: [PATCH] App: support of method unsetupObject in Python feature classes --- src/App/FeaturePython.cpp | 22 ++++++++++++++++++++++ src/App/FeaturePython.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/src/App/FeaturePython.cpp b/src/App/FeaturePython.cpp index 646e1a599e..25c34f1111 100644 --- a/src/App/FeaturePython.cpp +++ b/src/App/FeaturePython.cpp @@ -232,6 +232,28 @@ void FeaturePythonImp::onDocumentRestored() } } +void FeaturePythonImp::unsetupObject() +{ + _FC_PY_CALL_CHECK(unsetupObject, return); + + // Run the execute method of the proxy object. + Base::PyGILStateLocker lock; + try { + if (has__object__) { + Base::pyCall(py_unsetupObject.ptr()); + } + else { + Py::Tuple args(1); + args.setItem(0, Py::Object(object->getPyObject(), true)); + Base::pyCall(py_unsetupObject.ptr(), args.ptr()); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + bool FeaturePythonImp::getSubObject(DocumentObject *&ret, const char *subname, PyObject **pyObj, Base::Matrix4D *_mat, bool transform, int depth) const { diff --git a/src/App/FeaturePython.h b/src/App/FeaturePython.h index 44734e6868..cb3dbf152c 100644 --- a/src/App/FeaturePython.h +++ b/src/App/FeaturePython.h @@ -53,6 +53,7 @@ public: bool onBeforeChangeLabel(std::string &newLabel); void onChanged(const Property* prop); void onDocumentRestored(); + void unsetupObject(); std::string getViewProviderName(); PyObject *getPyObject(); @@ -94,6 +95,7 @@ private: FC_PY_ELEMENT(onBeforeChangeLabel)\ FC_PY_ELEMENT(onChanged)\ FC_PY_ELEMENT(onDocumentRestored)\ + FC_PY_ELEMENT(unsetupObject)\ FC_PY_ELEMENT(getViewProviderName)\ FC_PY_ELEMENT(getSubObject)\ FC_PY_ELEMENT(getSubObjects)\ @@ -341,6 +343,10 @@ protected: imp->onDocumentRestored(); FeatureT::onDocumentRestored(); } + void unsetupObject() override { + imp->unsetupObject(); + FeatureT::unsetupObject(); + } public: FeaturePythonT(const FeaturePythonT&) = delete;