]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeSelectionList.cpp
Salome HOME
5aca20aee34c8822d9ab946131976e70c7f13827
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.cpp
1 // File:        Model_AttributeSelectionList.h
2 // Created:     22 Oct 2014
3 // Author:      Mikhail PONIKAROV
4
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"
10
11 #include <TDF_ChildIterator.hxx>
12
13 using namespace std;
14
15 void Model_AttributeSelectionList::append(
16     const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
17 {
18   int aNewTag = mySize->Get() + 1;
19   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
20
21   boost::shared_ptr<Model_AttributeSelection> aNewAttr = 
22     boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
23   if (owner()) {
24     aNewAttr->setObject(owner());
25   }
26   mySubs.push_back(aNewAttr);
27   mySize->Set(aNewTag);
28   aNewAttr->setValue(theContext, theSubShape);
29   owner()->data()->sendAttributeUpdated(this);
30 }
31
32 int Model_AttributeSelectionList::size()
33 {
34   return mySize->Get();
35 }
36
37 boost::shared_ptr<ModelAPI_AttributeSelection> 
38   Model_AttributeSelectionList::value(const int theIndex)
39 {
40   return mySubs[theIndex];
41 }
42
43 void Model_AttributeSelectionList::clear()
44 {
45   mySubs.clear();
46   TDF_ChildIterator aSubIter(mySize->Label());
47   for(; aSubIter.More(); aSubIter.Next()) {
48     aSubIter.Value().ForgetAllAttributes(Standard_True);
49   }
50   owner()->data()->sendAttributeUpdated(this);
51 }
52
53 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
54 {
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));
65       if (owner())
66         aNewAttr->setObject(owner());
67       mySubs.push_back(aNewAttr);
68     }
69   }
70 }
71
72 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
73 {
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);
78   }
79 }