From 7ac9a8c74710ef26b9481debf72c8df72c938d44 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 10 Nov 2014 15:34:03 +0300 Subject: [PATCH] Issue 192: fixed of possible crash on abort of modification of group --- src/Model/Model_AttributeSelectionList.cpp | 51 +++++----------------- src/Model/Model_AttributeSelectionList.h | 6 --- 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index e150fb56c..4a2012a33 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -15,8 +15,6 @@ using namespace std; void Model_AttributeSelectionList::append( const ResultPtr& theContext, const boost::shared_ptr& theSubShape) { - updateSubs(); - int aNewTag = mySize->Get() + 1; TDF_Label aNewLab = mySize->Label().FindChild(aNewTag); @@ -25,7 +23,6 @@ void Model_AttributeSelectionList::append( if (owner()) { aNewAttr->setObject(owner()); } - mySubs.push_back(aNewAttr); mySize->Set(aNewTag); aNewAttr->setValue(theContext, theSubShape); owner()->data()->sendAttributeUpdated(this); @@ -49,15 +46,22 @@ void Model_AttributeSelectionList::setSelectionType(int theType) boost::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { - updateSubs(); - return mySubs[theIndex]; + TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1); + // create a new attribute each time, by demand + // supporting of old attributes is too slow (synch each time) and buggy on redo + // (if attribute is deleted and created, the abort updates attriute and makes the Attr invalid) + boost::shared_ptr aNewAttr = + boost::shared_ptr(new Model_AttributeSelection(aLabel)); + if (owner()) { + aNewAttr->setObject(owner()); + } + return aNewAttr; } void Model_AttributeSelectionList::clear() { if (mySize->Get() != 0) { mySize->Set(0); - mySubs.clear(); TDF_ChildIterator aSubIter(mySize->Label()); for(; aSubIter.More(); aSubIter.Next()) { aSubIter.Value().ForgetAllAttributes(Standard_True); @@ -74,40 +78,5 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) mySelectionType = TDataStd_Real::Set(theLabel, 0); } else { // recollect mySubs theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); - updateSubs(); - } -} - -void Model_AttributeSelectionList::setObject(const boost::shared_ptr& theObject) -{ - ModelAPI_AttributeSelectionList::setObject(theObject); - std::vector >::iterator aSubIter = mySubs.begin(); - for(; aSubIter != mySubs.end(); aSubIter++) { - (*aSubIter)->setObject(theObject); - } -} - -void Model_AttributeSelectionList::updateSubs() -{ - unsigned int aNum = mySize->Get(); - if (aNum > mySubs.size()) { // add subs what are not yet created - TDF_ChildIterator aSubIter(mySize->Label()); - for(int aExisting = mySubs.size(); aExisting > 0; aSubIter.Next()) aExisting--; - for(; aSubIter.More(); aSubIter.Next()) { - TDF_Label aChildLab = aSubIter.Value(); - boost::shared_ptr aNewAttr = - boost::shared_ptr(new Model_AttributeSelection(aChildLab)); - if (owner()) - aNewAttr->setObject(owner()); - mySubs.push_back(aNewAttr); - } - } else if (aNum < mySubs.size()) { // remove excess subs from the end - if (aNum == 0) { - mySubs.clear(); - } else { - std::vector >::iterator aSubIter = mySubs.begin(); - for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--; - mySubs.erase(aSubIter, mySubs.end()); - } } } diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 51001b6d0..e52937e72 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -22,7 +22,6 @@ class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList { Handle(TDataStd_Integer) mySize; ///< Contains size of this list Handle(TDataStd_Real) mySelectionType; ///< Contains current index, TODO: make it integer, not real - std::vector > mySubs; /// the selection attributes public: /// Adds the new reference to the end of the list MODEL_EXPORT virtual void append( @@ -41,14 +40,9 @@ public: /// Returns all attributes MODEL_EXPORT virtual void clear(); - /// Sets the feature object - MODEL_EXPORT virtual void setObject(const boost::shared_ptr& theObject); - protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel); - /// Updates the mySubs if needed since it is not persistent value - void updateSubs(); friend class Model_Data; }; -- 2.39.2