From: mpv Date: Mon, 8 Dec 2014 14:38:44 +0000 (+0300) Subject: Fix for issue #309: update all documents features in right order X-Git-Tag: V_0.6.0^2~2^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4b1c827abfbf7af9359088dce8f80692d4d33602;p=modules%2Fshaper.git Fix for issue #309: update all documents features in right order --- 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);