From 2a15d8fc3a3cdbe88579bb3a08ed4eb5210cbdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Wed, 8 Mar 2017 17:20:44 +0100 Subject: [PATCH] Add signals for recomputed objects --- src/App/Application.cpp | 11 ++++++++ src/App/Application.h | 6 +++++ src/App/Document.cpp | 2 ++ src/App/Document.h | 1 + src/App/DocumentObserver.cpp | 15 +++++++++++ src/App/DocumentObserver.h | 6 +++++ src/App/DocumentObserverPython.cpp | 41 ++++++++++++++++++++++++++++++ src/App/DocumentObserverPython.h | 6 +++++ 8 files changed, 88 insertions(+) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index aab699a2cf..6550031a83 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -423,6 +423,8 @@ Document* Application::newDocument(const char * Name, const char * UserName) _pActiveDoc->signalActivatedObject.connect(boost::bind(&App::Application::slotActivatedObject, this, _1)); _pActiveDoc->signalUndo.connect(boost::bind(&App::Application::slotUndoDocument, this, _1)); _pActiveDoc->signalRedo.connect(boost::bind(&App::Application::slotRedoDocument, this, _1)); + _pActiveDoc->signalRecomputedObject.connect(boost::bind(&App::Application::slotRecomputedObject, this, _1)); + _pActiveDoc->signalRecomputed.connect(boost::bind(&App::Application::slotRecomputed, this, _1)); // make sure that the active document is set in case no GUI is up { @@ -1006,6 +1008,15 @@ void Application::slotRedoDocument(const App::Document& d) { this->signalRedoDocument(d); } +void Application::slotRecomputedObject(const DocumentObject& obj) +{ + this->signalObjectRecomputed(obj); +} + +void Application::slotRecomputed(const Document& doc) +{ + this->signalRecomputed(doc); +} //************************************************************************** // Init, Destruct and singleton diff --git a/src/App/Application.h b/src/App/Application.h index 4996f03aa6..3a9252767c 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -139,6 +139,10 @@ public: boost::signal signalRelabelObject; /// signal on activated Object boost::signal signalActivatedObject; + /// signal on recomputed document + boost::signal signalRecomputed; + /// signal on recomputed document object + boost::signal signalObjectRecomputed; //@} /** @name Signals of property changes @@ -271,6 +275,8 @@ protected: void slotActivatedObject(const App::DocumentObject&); void slotUndoDocument(const App::Document&); void slotRedoDocument(const App::Document&); + void slotRecomputedObject(const App::DocumentObject&); + void slotRecomputed(const App::Document&); //@} private: diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 43262a1394..73c434b695 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2178,6 +2178,7 @@ int Document::recompute() d->vertexMap.clear(); return -1; } + signalRecomputedObject(*Cur); ++objectCount; } } @@ -2244,6 +2245,7 @@ int Document::recompute() if ((*objIt)->isTouched() || doRecompute) { (*objIt)->purgeTouched(); + signalObjectRecomputed(*(*objOt)); // force recompute of all dependent objects for (auto inObjIt : (*objIt)->getInList()) inObjIt->enforceRecompute(); diff --git a/src/App/Document.h b/src/App/Document.h index 46b70192c3..a41677391c 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -147,6 +147,7 @@ public: boost::signal&, Base::Reader&, const std::map&)> signalImportViewObjects; boost::signal signalRecomputed; + boost::signal signalRecomputedObject; //@} /** @name File handling of the document */ diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index 904292f0aa..6ee2604c07 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -228,6 +228,10 @@ void DocumentObserver::attachDocument(Document* doc) (&DocumentObserver::slotDeletedObject, this, _1)); this->connectDocumentChangedObject = _document->signalChangedObject.connect(boost::bind (&DocumentObserver::slotChangedObject, this, _1, _2)); + this->connectDocumentRecomputedObject = _document->signalRecomputedObject.connect(boost::bind + (&DocumentObserver::slotRecomputedObject, this, _1)); + this->connectDocumentRecomputed = _document->signalRecomputed.connect(boost::bind + (&DocumentObserver::slotRecomputedDocument, this, _1)); } } @@ -238,6 +242,8 @@ void DocumentObserver::detachDocument() this->connectDocumentCreatedObject.disconnect(); this->connectDocumentDeletedObject.disconnect(); this->connectDocumentChangedObject.disconnect(); + this->connectDocumentRecomputedObject.disconnect(); + this->connectDocumentRecomputed.disconnect(); } } @@ -261,6 +267,15 @@ void DocumentObserver::slotChangedObject(const App::DocumentObject& /*Obj*/, con { } +void DocumentObserver::slotRecomputedObject(const DocumentObject& /*Obj*/) +{ +} + +void DocumentObserver::slotRecomputedDocument(const Document& /*doc*/) +{ +} + + // ----------------------------------------------------------------------------- DocumentObjectObserver::DocumentObjectObserver() diff --git a/src/App/DocumentObserver.h b/src/App/DocumentObserver.h index de5e37828c..fe5f618380 100644 --- a/src/App/DocumentObserver.h +++ b/src/App/DocumentObserver.h @@ -151,6 +151,10 @@ private: virtual void slotDeletedObject(const App::DocumentObject& Obj); /** The property of an observed object has changed */ virtual void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop); + /** Called when a given object is recomputed */ + virtual void slotRecomputedObject(const App::DocumentObject& Obj); + /** Called when a observed document is recomputed */ + virtual void slotRecomputedDocument(const App::Document& Doc); protected: Document* getDocument() const; @@ -163,6 +167,8 @@ private: Connection connectDocumentCreatedObject; Connection connectDocumentDeletedObject; Connection connectDocumentChangedObject; + Connection connectDocumentRecomputedObject; + Connection connectDocumentRecomputed; }; /** diff --git a/src/App/DocumentObserverPython.cpp b/src/App/DocumentObserverPython.cpp index 417bab8992..9637a1c211 100644 --- a/src/App/DocumentObserverPython.cpp +++ b/src/App/DocumentObserverPython.cpp @@ -78,6 +78,11 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj (&DocumentObserverPython::slotDeletedObject, this, _1)); this->connectDocumentChangedObject = App::GetApplication().signalChangedObject.connect(boost::bind (&DocumentObserverPython::slotChangedObject, this, _1, _2)); + + this->connectDocumentObjectRecomputed = App::GetApplication().signalObjectRecomputed.connect(boost::bind + (&DocumentObserverPython::slotRecomputedObject, this, _1)); + this->connectDocumentRecomputed = App::GetApplication().signalRecomputed.connect(boost::bind + (&DocumentObserverPython::slotRecomputedDocument, this, _1)); } DocumentObserverPython::~DocumentObserverPython() @@ -92,6 +97,8 @@ DocumentObserverPython::~DocumentObserverPython() this->connectDocumentCreatedObject.disconnect(); this->connectDocumentDeletedObject.disconnect(); this->connectDocumentChangedObject.disconnect(); + this->connectDocumentObjectRecomputed.disconnect(); + this->connectDocumentRecomputed.disconnect(); } void DocumentObserverPython::slotCreatedDocument(const App::Document& Doc) @@ -253,3 +260,37 @@ void DocumentObserverPython::slotChangedObject(const App::DocumentObject& Obj, e.ReportException(); } } + +void DocumentObserverPython::slotRecomputedObject(const App::DocumentObject& Obj) +{ + Base::PyGILStateLocker lock; + try { + if (this->inst.hasAttr(std::string("slotRecomputedObject"))) { + Py::Callable method(this->inst.getAttr(std::string("slotRecomputedObject"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(const_cast(Obj).getPyObject(), true)); + method.apply(args); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + +void DocumentObserverPython::slotRecomputedDocument(const App::Document& doc) +{ + Base::PyGILStateLocker lock; + try { + if (this->inst.hasAttr(std::string("slotRecomputedDocument"))) { + Py::Callable method(this->inst.getAttr(std::string("slotRecomputedDocument"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(const_cast(doc).getPyObject(), true)); + method.apply(args); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} \ No newline at end of file diff --git a/src/App/DocumentObserverPython.h b/src/App/DocumentObserverPython.h index e83c220c21..91ddcfad7d 100644 --- a/src/App/DocumentObserverPython.h +++ b/src/App/DocumentObserverPython.h @@ -69,6 +69,10 @@ private: void slotUndoDocument(const App::Document& Doc); /** Redoes the last undone transaction of the document */ void slotRedoDocument(const App::Document& Doc); + /** Called when a given object is recomputed */ + void slotRecomputedObject(const App::DocumentObject& Obj); + /** Called when a observed document is recomputed */ + void slotRecomputedDocument(const App::Document& Doc); private: Py::Object inst; @@ -84,6 +88,8 @@ private: Connection connectDocumentCreatedObject; Connection connectDocumentDeletedObject; Connection connectDocumentChangedObject; + Connection connectDocumentObjectRecomputed; + Connection connectDocumentRecomputed; }; } //namespace App