From 009d0c03b448873137f8f67dfdebbd0803ddcee0 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Thu, 24 Dec 2015 14:38:50 +0100 Subject: [PATCH] Document/PropertyExpressionEngine: Added onDocumentRestored function, to update internals of PropertyExpressionEngine after loading a document from disk. --- src/App/Document.cpp | 2 ++ src/App/PropertyExpressionEngine.cpp | 22 ++++++++++++++-------- src/App/PropertyExpressionEngine.h | 9 ++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 08f5937bd..db987e505 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1274,6 +1274,7 @@ Document::importObjects(Base::XMLReader& reader) // reset all touched for (std::vector::iterator it= objs.begin();it!=objs.end();++it) { (*it)->onDocumentRestored(); + (*it)->ExpressionEngine.onDocumentRestored(); (*it)->purgeTouched(); } return objs; @@ -1488,6 +1489,7 @@ void Document::restore (void) for (std::map::iterator It= d->objectMap.begin();It!=d->objectMap.end();++It) { It->second->connectRelabelSignals(); It->second->onDocumentRestored(); + It->second->ExpressionEngine.onDocumentRestored(); It->second->purgeTouched(); } diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 141be9508..6359dfdd7 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -130,6 +130,7 @@ TYPESYSTEM_SOURCE(App::PropertyExpressionEngine , App::Property); PropertyExpressionEngine::PropertyExpressionEngine() : Property() + , AtomicPropertyChangeInterface() , running(false) , validator(0) { @@ -172,7 +173,7 @@ void PropertyExpressionEngine::Paste(const Property &from) { const PropertyExpressionEngine * fromee = static_cast(&from); - aboutToSetValue(); + AtomicPropertyChange signaller(*this); expressions.clear(); for (ExpressionMap::const_iterator it = fromee->expressions.begin(); it != fromee->expressions.end(); ++it) { @@ -181,8 +182,6 @@ void PropertyExpressionEngine::Paste(const Property &from) } validator = fromee->validator; - - hasSetValue(); } void PropertyExpressionEngine::Save(Base::Writer &writer) const @@ -206,6 +205,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader) int count = reader.getAttributeAsFloat("count"); + restoredExpressions.clear(); for (int i = 0; i < count; ++i) { DocumentObject * docObj = freecad_dynamic_cast(getContainer()); @@ -214,7 +214,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader) boost::shared_ptr expression(ExpressionParser::parse(docObj, reader.getAttribute("expression"))); const char * comment = reader.hasAttribute("comment") ? reader.getAttribute("comment") : 0; - setValue(path, expression, comment); + restoredExpressions[path] = ExpressionInfo(expression, comment); } reader.readEndElement("ExpressionEngine"); @@ -363,6 +363,14 @@ void PropertyExpressionEngine::slotObjectDeleted(const DocumentObject &obj) } } +void PropertyExpressionEngine::onDocumentRestored() +{ + AtomicPropertyChange signaller(*this); + + for (ExpressionMap::iterator it = restoredExpressions.begin(); it != restoredExpressions.end(); ++it) + setValue(it->first, it->second.expression, it->second.comment.size() > 0 ? it->second.comment.c_str() : 0); +} + /** * @brief Get expression for \a path. * @param path ObjectIndentifier to query for. @@ -408,16 +416,14 @@ void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::sh if (error.size() > 0) throw Base::Exception(error.c_str()); - aboutToSetValue(); + AtomicPropertyChange signaller(*this); expressions[usePath] = ExpressionInfo(expr, comment); expressionChanged(usePath); - hasSetValue(); } else { - aboutToSetValue(); + AtomicPropertyChange signaller(*this); expressions.erase(usePath); expressionChanged(usePath); - hasSetValue(); } } diff --git a/src/App/PropertyExpressionEngine.h b/src/App/PropertyExpressionEngine.h index a2d948abd..ee9dbe740 100644 --- a/src/App/PropertyExpressionEngine.h +++ b/src/App/PropertyExpressionEngine.h @@ -44,7 +44,8 @@ class DocumentObjectExecReturn; class ObjectIdentifier; class Expression; -class AppExport PropertyExpressionEngine : public App::Property + +class AppExport PropertyExpressionEngine : public App::Property, private App::AtomicPropertyChangeInterface { TYPESYSTEM_HEADER(); public: @@ -124,6 +125,8 @@ public: ///signal called when a expression was changed boost::signal expressionChanged; + void onDocumentRestored(); + /* Python interface */ PyObject *getPyObject(void); void setPyObject(PyObject *); @@ -149,6 +152,10 @@ private: ValidatorFunc validator; /**< Valdiator functor */ + ExpressionMap restoredExpressions; /**< Expressions are read from file to this map first before they are validated and inserted into the actual map */ + + friend class AtomicPropertyChange; + }; }