diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonFeature.cpp index 05fadc1c6..b6fbe0ec7 100644 --- a/src/Gui/ViewProviderPythonFeature.cpp +++ b/src/Gui/ViewProviderPythonFeature.cpp @@ -670,6 +670,46 @@ void ViewProviderPythonFeatureImp::finishRestoring() } } +bool ViewProviderPythonFeatureImp::onDelete(const std::vector & sub) +{ + Base::PyGILStateLocker lock; + try { + App::Property* proxy = object->getPropertyByName("Proxy"); + if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { + Py::Object vp = static_cast(proxy)->getValue(); + if (vp.hasAttr(std::string("onDelete"))) { + Py::Tuple seq(sub.size()); + int index=0; + for (std::vector::const_iterator it = sub.begin(); it != sub.end(); ++it) { + seq.setItem(index++, Py::String(*it)); + } + + if (vp.hasAttr("__object__")) { + Py::Callable method(vp.getAttr(std::string("onDelete"))); + Py::Tuple args(1); + args.setItem(0, seq); + Py::Boolean ok(method.apply(args)); + return (bool)ok; + } + else { + Py::Callable method(vp.getAttr(std::string("onDelete"))); + Py::Tuple args(2); + args.setItem(0, Py::Object(object->getPyObject(), true)); + args.setItem(1, seq); + Py::Boolean ok(method.apply(args)); + return (bool)ok; + } + } + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } + + return true; +} + const char* ViewProviderPythonFeatureImp::getDefaultDisplayMode() const { // Run the getDefaultDisplayMode method of the proxy object. diff --git a/src/Gui/ViewProviderPythonFeature.h b/src/Gui/ViewProviderPythonFeature.h index a845f2f46..193942838 100644 --- a/src/Gui/ViewProviderPythonFeature.h +++ b/src/Gui/ViewProviderPythonFeature.h @@ -62,6 +62,7 @@ public: void onChanged(const App::Property* prop); void startRestoring(); void finishRestoring(); + bool onDelete(const std::vector & sub); //@} /** @name Display methods */ @@ -156,6 +157,11 @@ public: virtual void getTaskViewContent(std::vector& c) const { ViewProviderT::getTaskViewContent(c); } + virtual bool onDelete(const std::vector & sub) { + bool ok = imp->onDelete(sub); + if (!ok) return ok; + return ViewProviderT::onDelete(sub); + } //@} /** @name Restoring view provider from document load */