From 4b1c827abfbf7af9359088dce8f80692d4d33602 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 8 Dec 2014 17:38:44 +0300 Subject: [PATCH] Fix for issue #309: update all documents features in right order --- src/Model/Model_Document.h | 1 + src/Model/Model_Update.cpp | 51 +++++++++++++++++++------------------- src/Model/Model_Update.h | 4 ++- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index c753ebff0..0b7a618c6 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -181,6 +181,7 @@ class Model_Document : public ModelAPI_Document friend class Model_Application; friend class Model_Session; + friend class Model_Update; friend class Model_AttributeReference; friend class DFBrowser; diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index ca900b86b..31c8b7565 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -115,37 +115,15 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag //Events_LongOp::start(this); isExecuted = true; - std::list > aDocs; std::shared_ptr aMsg = std::dynamic_pointer_cast(theMessage); if (aMsg) myInitial = aMsg->objects(); else { myInitial.clear(); - // on change flag all documents must be updated - if (isAutomatic) { - aDocs = ModelAPI_Session::get()->allOpenedDocuments(); - } - } - // collect all documents involved into the update process - set >::iterator aFIter = myInitial.begin(); - for (; aFIter != myInitial.end(); aFIter++) { - aDocs.push_back((*aFIter)->document()); - } - // iterate all features of features-documents to update them (including hidden) - std::set > alreadyUsed; - list >::iterator aDIter = aDocs.begin(); - for (; aDIter != aDocs.end(); aDIter++) { - if (alreadyUsed.find(*aDIter) != alreadyUsed.end()) - continue; - alreadyUsed.insert(*aDIter); - int aNbFeatures = (*aDIter)->size(ModelAPI_Feature::group(), true); - for (int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) { - FeaturePtr aFeature = std::dynamic_pointer_cast( - (*aDIter)->object(ModelAPI_Feature::group(), aFIndex, true)); - if (aFeature) - updateFeature(aFeature); - } } + // iterate all documents: features in Root first, then - subs + updateInDoc(ModelAPI_Session::get()->moduleDocument()); + myUpdated.clear(); // flush to update display static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); @@ -160,6 +138,29 @@ void Model_Update::processEvent(const std::shared_ptr& theMessag isExecuted = false; } +void Model_Update::updateInDoc(std::shared_ptr theDoc) +{ + // all features one by one + int aNbFeatures = theDoc->size(ModelAPI_Feature::group(), true); + for (int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) { + FeaturePtr aFeature = std::dynamic_pointer_cast( + theDoc->object(ModelAPI_Feature::group(), aFIndex, true)); + if (aFeature) + updateFeature(aFeature); + } + // all sub-documents one by one + std::shared_ptr aDoc = std::dynamic_pointer_cast(theDoc); + if (aDoc) { + const std::set& aSubs = aDoc->subDocuments(); + for(std::set::iterator aSub = aSubs.begin(); aSub != aSubs.end(); aSub++) { + DocumentPtr aSubDoc = theDoc->subDocument(*aSub); + if (aSubDoc) { + updateInDoc(aSubDoc); + } + } + } +} + void Model_Update::redisplayWithResults(FeaturePtr theFeature, const ModelAPI_ExecState theState) { // maske updated and redisplay all results diff --git a/src/Model/Model_Update.h b/src/Model/Model_Update.h index bc4c2be68..dd687177a 100644 --- a/src/Model/Model_Update.h +++ b/src/Model/Model_Update.h @@ -40,7 +40,9 @@ class Model_Update : public Events_Listener /// Processes the feature argument update: executes the results MODEL_EXPORT virtual void processEvent(const std::shared_ptr& theMessage); - protected: +protected: + /// updates all features in the document and then - in sub-documents + void updateInDoc(std::shared_ptr theDoc); /// Recoursively checks and updates the feature if needed (calls the execute method) /// Returns true if feature was updated. bool updateFeature(std::shared_ptr theFeature); -- 2.39.2