diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 438b53b47f..8218b734cf 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -109,6 +109,8 @@ public: boost::signals2::signal signalNewObject; /// signal on deleted Object boost::signals2::signal signalDeletedObject; + /// signal on changed Object + boost::signals2::signal signalBeforeChangeObject; /// signal on changed object property boost::signals2::signal signalChangedObject; /// signal on renamed Object diff --git a/src/Gui/DocumentObserverPython.cpp b/src/Gui/DocumentObserverPython.cpp index 917c1ecd3b..ab59d9882e 100644 --- a/src/Gui/DocumentObserverPython.cpp +++ b/src/Gui/DocumentObserverPython.cpp @@ -83,6 +83,7 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj FC_PY_ELEMENT_ARG1(ActivateDocument, ActiveDocument) FC_PY_ELEMENT_ARG1(CreatedObject, NewObject) FC_PY_ELEMENT_ARG1(DeletedObject, DeletedObject) + FC_PY_ELEMENT_ARG2(BeforeChangeObject, BeforeChangeObject) FC_PY_ELEMENT_ARG2(ChangedObject, ChangedObject) FC_PY_ELEMENT_ARG1(InEdit, InEdit) FC_PY_ELEMENT_ARG1(ResetEdit, ResetEdit) @@ -190,6 +191,27 @@ void DocumentObserverPython::slotDeletedObject(const Gui::ViewProvider& Obj) } } +void DocumentObserverPython::slotBeforeChangeObject(const Gui::ViewProvider& Obj, + const App::Property& Prop) +{ + Base::PyGILStateLocker lock; + try { + Py::Tuple args(2); + args.setItem(0, Py::Object(const_cast(Obj).getPyObject(), true)); + // If a property is touched but not part of a document object then its name is null. + // In this case the slot function must not be called. + const char* prop_name = Obj.getPropertyName(&Prop); + if (prop_name) { + args.setItem(1, Py::String(prop_name)); + Base::pyCall(pyBeforeChangeObject.ptr(),args.ptr()); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + void DocumentObserverPython::slotChangedObject(const Gui::ViewProvider& Obj, const App::Property& Prop) { diff --git a/src/Gui/DocumentObserverPython.h b/src/Gui/DocumentObserverPython.h index c57591c38e..0f18696fc4 100644 --- a/src/Gui/DocumentObserverPython.h +++ b/src/Gui/DocumentObserverPython.h @@ -65,6 +65,8 @@ private: /** Checks if the given object is about to be removed. */ void slotDeletedObject(const Gui::ViewProvider& Obj); /** The property of an observed object has changed */ + void slotBeforeChangeObject(const Gui::ViewProvider& Obj, const App::Property& Prop); + /** The property of an observed object has changed */ void slotChangedObject(const Gui::ViewProvider& Obj, const App::Property& Prop); /** The object was set into edit mode */ void slotInEdit(const Gui::ViewProviderDocumentObject& Obj); @@ -90,6 +92,7 @@ private: Connection pyActivateDocument; Connection pyCreatedObject; Connection pyDeletedObject; + Connection pyBeforeChangeObject; Connection pyChangedObject; Connection pyInEdit; Connection pyResetEdit; diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index 6e3d8baadb..76a1927eda 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -514,6 +514,13 @@ int ViewProvider::getDefaultMode() const { return viewOverrideMode>=0?viewOverrideMode:_iActualMode; } +void ViewProvider::onBeforeChange(const App::Property* prop) +{ + Application::Instance->signalBeforeChangeObject(*this, *prop); + + App::TransactionalObject::onBeforeChange(prop); +} + void ViewProvider::onChanged(const App::Property* prop) { Application::Instance->signalChangedObject(*this, *prop); diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 849b05b73e..55abeb0161 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -522,6 +522,8 @@ protected: SoPickedPoint* getPointOnRay(const SbVec3f& pos, const SbVec3f& dir, const View3DInventorViewer* viewer) const; /// Reimplemented from subclass + void onBeforeChange(const App::Property* prop); + /// Reimplemented from subclass void onChanged(const App::Property* prop); diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index 8965c7ca57..0b993f2f7b 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -169,6 +169,8 @@ void ViewProviderDocumentObject::onBeforeChange(const App::Property* prop) onBeforeChangeProperty(doc, prop); } } + + ViewProvider::onBeforeChange(prop); } void ViewProviderDocumentObject::onChanged(const App::Property* prop)