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)
18 int aNewTag = mySize->Get() + 1;
19 TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
21 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
22 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
24 aNewAttr->setObject(owner());
26 mySubs.push_back(aNewAttr);
28 aNewAttr->setValue(theContext, theSubShape);
29 owner()->data()->sendAttributeUpdated(this);
32 int Model_AttributeSelectionList::size()
37 boost::shared_ptr<ModelAPI_AttributeSelection>
38 Model_AttributeSelectionList::value(const int theIndex)
40 return mySubs[theIndex];
43 void Model_AttributeSelectionList::clear()
45 if (!mySubs.empty()) {
47 TDF_ChildIterator aSubIter(mySize->Label());
48 for(; aSubIter.More(); aSubIter.Next()) {
49 aSubIter.Value().ForgetAllAttributes(Standard_True);
51 owner()->data()->sendAttributeUpdated(this);
55 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
57 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
58 if (!myIsInitialized) {
59 mySize = TDataStd_Integer::Set(theLabel, 0);
60 } else { // recollect mySubs
61 int aNum = mySize->Get();
62 TDF_ChildIterator aSubIter(theLabel);
63 for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
64 TDF_Label aChildLab = aSubIter.Value();
65 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
66 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
68 aNewAttr->setObject(owner());
69 mySubs.push_back(aNewAttr);
74 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
76 ModelAPI_AttributeSelectionList::setObject(theObject);
77 std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
78 for(; aSubIter != mySubs.end(); aSubIter++) {
79 (*aSubIter)->setObject(theObject);