1 // File: Model_AttributeSelectionList.h
2 // Created: 22 Oct 2014
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeSelectionList.h"
6 #include "Model_AttributeSelection.h"
7 #include "Model_Application.h"
8 #include "Model_Events.h"
9 #include "Model_Data.h"
11 #include <TDF_ChildIterator.hxx>
15 void Model_AttributeSelectionList::append(
16 const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
20 int aNewTag = mySize->Get() + 1;
21 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
23 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
24 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
26 aNewAttr->setObject(owner());
28 mySubs.push_back(aNewAttr);
30 aNewAttr->setValue(theContext, theSubShape);
31 owner()->data()->sendAttributeUpdated(this);
34 int Model_AttributeSelectionList::size()
39 int Model_AttributeSelectionList::selectionType()
41 return (int) mySelectionType->Get();
44 void Model_AttributeSelectionList::setSelectionType(int theType)
46 mySelectionType->Set((double) theType);
49 boost::shared_ptr<ModelAPI_AttributeSelection>
50 Model_AttributeSelectionList::value(const int theIndex)
53 return mySubs[theIndex];
56 void Model_AttributeSelectionList::clear()
58 if (mySize->Get() != 0) {
61 TDF_ChildIterator aSubIter(mySize->Label());
62 for(; aSubIter.More(); aSubIter.Next()) {
63 aSubIter.Value().ForgetAllAttributes(Standard_True);
65 owner()->data()->sendAttributeUpdated(this);
69 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
71 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
72 if (!myIsInitialized) {
73 mySize = TDataStd_Integer::Set(theLabel, 0);
74 mySelectionType = TDataStd_Real::Set(theLabel, 0);
75 } else { // recollect mySubs
76 theLabel.FindAttribute(TDataStd_Real::GetID(), mySelectionType);
81 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
83 ModelAPI_AttributeSelectionList::setObject(theObject);
84 std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
85 for(; aSubIter != mySubs.end(); aSubIter++) {
86 (*aSubIter)->setObject(theObject);
90 void Model_AttributeSelectionList::updateSubs()
92 unsigned int aNum = mySize->Get();
93 if (aNum > mySubs.size()) { // add subs what are not yet created
94 TDF_ChildIterator aSubIter(mySize->Label());
95 for(int aExisting = mySubs.size(); aExisting > 0; aSubIter.Next()) aExisting--;
96 for(; aSubIter.More(); aSubIter.Next()) {
97 TDF_Label aChildLab = aSubIter.Value();
98 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
99 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
101 aNewAttr->setObject(owner());
102 mySubs.push_back(aNewAttr);
104 } else if (aNum < mySubs.size()) { // remove excess subs from the end
108 std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter;
109 for(int aExisting = aNum; aExisting != 0; aSubIter++) aExisting--;
110 mySubs.erase(aSubIter, mySubs.end());