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()
46 TDF_ChildIterator aSubIter(mySize->Label());
47 for(; aSubIter.More(); aSubIter.Next()) {
48 aSubIter.Value().ForgetAllAttributes(Standard_True);
50 owner()->data()->sendAttributeUpdated(this);
53 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
55 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
56 if (!myIsInitialized) {
57 mySize = TDataStd_Integer::Set(theLabel, 0);
58 } else { // recollect mySubs
59 int aNum = mySize->Get();
60 TDF_ChildIterator aSubIter(theLabel);
61 for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
62 TDF_Label aChildLab = aSubIter.Value();
63 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
64 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
66 aNewAttr->setObject(owner());
67 mySubs.push_back(aNewAttr);
72 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
74 ModelAPI_AttributeSelectionList::setObject(theObject);
75 std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
76 for(; aSubIter != mySubs.end(); aSubIter++) {
77 (*aSubIter)->setObject(theObject);