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 int Model_AttributeSelectionList::selectionType()
39 return (int) mySelectionType->Get();
42 void Model_AttributeSelectionList::setSelectionType(int theType)
44 mySelectionType->Set((double) theType);
47 boost::shared_ptr<ModelAPI_AttributeSelection>
48 Model_AttributeSelectionList::value(const int theIndex)
50 return mySubs[theIndex];
53 void Model_AttributeSelectionList::clear()
55 if (!mySubs.empty()) {
58 TDF_ChildIterator aSubIter(mySize->Label());
59 for(; aSubIter.More(); aSubIter.Next()) {
60 aSubIter.Value().ForgetAllAttributes(Standard_True);
62 owner()->data()->sendAttributeUpdated(this);
66 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
68 myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
69 if (!myIsInitialized) {
70 mySize = TDataStd_Integer::Set(theLabel, 0);
71 mySelectionType = TDataStd_Real::Set(theLabel, 0);
72 } else { // recollect mySubs
73 int aNum = mySize->Get();
74 TDF_ChildIterator aSubIter(theLabel);
75 for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
76 TDF_Label aChildLab = aSubIter.Value();
77 boost::shared_ptr<Model_AttributeSelection> aNewAttr =
78 boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
80 aNewAttr->setObject(owner());
81 mySubs.push_back(aNewAttr);
86 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
88 ModelAPI_AttributeSelectionList::setObject(theObject);
89 std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
90 for(; aSubIter != mySubs.end(); aSubIter++) {
91 (*aSubIter)->setObject(theObject);