From 644f0470e456dbe2f085869d4b501b5f601b308d Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 7 Nov 2014 13:53:02 +0300 Subject: [PATCH] Groups transactions mechanism debug --- src/Model/Model_AttributeSelectionList.cpp | 42 ++++++++++++++++------ src/Model/Model_AttributeSelectionList.h | 3 +- src/Model/Model_ResultGroup.cpp | 2 +- src/ModelAPI/ModelAPI_Tools.cpp | 26 ++++++++------ src/XGUI/XGUI_Selection.cpp | 10 +++--- 5 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index e1cb750aa..443eed177 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -15,6 +15,8 @@ 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); @@ -47,12 +49,13 @@ void Model_AttributeSelectionList::setSelectionType(int theType) boost::shared_ptr Model_AttributeSelectionList::value(const int theIndex) { + updateSubs(); return mySubs[theIndex]; } void Model_AttributeSelectionList::clear() { - if (!mySubs.empty()) { + if (mySize->Get() != 0) { mySize->Set(0); mySubs.clear(); TDF_ChildIterator aSubIter(mySize->Label()); @@ -70,16 +73,8 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel) mySize = TDataStd_Integer::Set(theLabel, 0); mySelectionType = TDataStd_Real::Set(theLabel, 0); } else { // recollect mySubs - int aNum = mySize->Get(); - TDF_ChildIterator aSubIter(theLabel); - for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) { - 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); - } + theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType); + updateSubs(); } } @@ -91,3 +86,28 @@ void Model_AttributeSelectionList::setObject(const boost::shared_ptrsetObject(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; + 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 f10d6d97f..51001b6d0 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -47,7 +47,8 @@ public: protected: /// Objects are created for features automatically MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel); - /// Performs the selection for the body result (TNaming Selection) + /// Updates the mySubs if needed since it is not persistent value + void updateSubs(); friend class Model_Data; }; diff --git a/src/Model/Model_ResultGroup.cpp b/src/Model/Model_ResultGroup.cpp index 2fd1ead9d..3e467395d 100644 --- a/src/Model/Model_ResultGroup.cpp +++ b/src/Model/Model_ResultGroup.cpp @@ -19,7 +19,7 @@ boost::shared_ptr Model_ResultGroup::shape() const AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list"); if (aList) { std::list > aSubs; - for(int a = aList->size(); a >= 0; a--) { + for(int a = aList->size() - 1; a >= 0; a--) { boost::shared_ptr aSelection = aList->value(a)->value(); if (aSelection && !aSelection->isNull()) { aSubs.push_back(aSelection); diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 52b88b5b0..8656f2fd7 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -5,19 +5,25 @@ #include "ModelAPI_Tools.h" #include #include +#include namespace ModelAPI_Tools { -boost::shared_ptr shape(const ResultPtr& theResult) -{ - ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); - if (aBody) - return aBody->shape(); - ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast( + boost::shared_ptr shape(const ResultPtr& theResult) + { + + ResultBodyPtr aBody = boost::dynamic_pointer_cast(theResult); + if (aBody) + return aBody->shape(); + + ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast( theResult); - if (aConstruct) - return aConstruct->shape(); - return boost::shared_ptr(); -} + if (aConstruct) + return aConstruct->shape(); + ResultGroupPtr aGroup = boost::dynamic_pointer_cast(theResult); + if (aGroup) + return aGroup->shape(); + return boost::shared_ptr(); + } } diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 0dd985f97..265fb9029 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -125,10 +125,12 @@ void XGUI_Selection::selectedShapes(NCollection_List& theList, if (!aShape.IsNull()) { theList.Append(aShape); Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner(); - Handle(AIS_InteractiveObject) anObj = - Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable()); - ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj); - theOwners.push_back(anObject); + if (!aEO.IsNull()) { + Handle(AIS_InteractiveObject) anObj = + Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable()); + ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj); + theOwners.push_back(anObject); + } } } } -- 2.39.2