From 207ced8de4e84e1fc5b3d0e0ee098caefe2134a7 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 24 Oct 2014 11:04:50 +0400 Subject: [PATCH] Correct selection attributes dependencies checkings --- src/Model/Model_AttributeSelectionList.cpp | 12 ++++---- src/Model/Model_Update.cpp | 34 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index 5aca20aee..31a2e6473 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -42,12 +42,14 @@ boost::shared_ptr void Model_AttributeSelectionList::clear() { - mySubs.clear(); - TDF_ChildIterator aSubIter(mySize->Label()); - for(; aSubIter.More(); aSubIter.Next()) { - aSubIter.Value().ForgetAllAttributes(Standard_True); + if (!mySubs.empty()) { + mySubs.clear(); + TDF_ChildIterator aSubIter(mySize->Label()); + for(; aSubIter.More(); aSubIter.Next()) { + aSubIter.Value().ForgetAllAttributes(Standard_True); + } + owner()->data()->sendAttributeUpdated(this); } - owner()->data()->sendAttributeUpdated(this); } Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 6d50871d7..5ef4a8f09 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -187,10 +188,20 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) boost::dynamic_pointer_cast(*aRefsIter); if (updateObject(aSel->context())) { aMustbeUpdated = true; - aSel->update(); + // aSel->update(); // this must be done on execution since it may be long operation + } + } + // lists of selection attributes: must be called "update" methods if needed + aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type()); + for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) { + boost::shared_ptr aSel = + boost::dynamic_pointer_cast(*aRefsIter); + for(int a = aSel->size() - 1; a >= 0; a--) { + if (updateObject(aSel->value(a)->context())) { + aMustbeUpdated = true; + } } } - // execute feature if it must be updated if (aMustbeUpdated) { @@ -200,7 +211,24 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); if (aFactory->validate(theFeature)) { if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) || - !theFeature->isPersistentResult() /* execute quick, not persistent results */) { + !theFeature->isPersistentResult() /* execute quick, not persistent results */) + { + // before execution update the selection attributes if any + aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); + for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) { + boost::shared_ptr aSel = + boost::dynamic_pointer_cast(*aRefsIter); + aSel->update(); // this must be done on execution since it may be long operation + } + aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type()); + for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) { + boost::shared_ptr aSel = + boost::dynamic_pointer_cast(*aRefsIter); + for(int a = aSel->size() - 1; a >= 0; a--) { + aSel->value(a)->update(); + } + } + // execute in try-catch to avoid internal problems of the feature try { theFeature->execute(); } catch(...) { -- 2.39.2