Add signals for recomputed objects

This commit is contained in:
Stefan Tröger
2017-03-08 17:20:44 +01:00
committed by wmayer
parent 64e9c4ea5a
commit 2a15d8fc3a
8 changed files with 88 additions and 0 deletions

View File

@@ -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

View File

@@ -139,6 +139,10 @@ public:
boost::signal<void (const App::DocumentObject&)> signalRelabelObject;
/// signal on activated Object
boost::signal<void (const App::DocumentObject&)> signalActivatedObject;
/// signal on recomputed document
boost::signal<void (const App::Document&)> signalRecomputed;
/// signal on recomputed document object
boost::signal<void (const App::DocumentObject&)> 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:

View File

@@ -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();

View File

@@ -147,6 +147,7 @@ public:
boost::signal<void (const std::vector<App::DocumentObject*>&, Base::Reader&,
const std::map<std::string, std::string>&)> signalImportViewObjects;
boost::signal<void (const App::Document&)> signalRecomputed;
boost::signal<void (const App::DocumentObject&)> signalRecomputedObject;
//@}
/** @name File handling of the document */

View File

@@ -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()

View File

@@ -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;
};
/**

View File

@@ -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<App::DocumentObject&>(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<App::Document&>(doc).getPyObject(), true));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}

View File

@@ -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