]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeSelectionList.cpp
Salome HOME
The list of selection attributes is added
[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   mySubs.push_back(boost::shared_ptr<Model_AttributeSelection>(
21     new Model_AttributeSelection(aNewLab)));
22   mySize->Set(aNewTag);
23 }
24
25 int Model_AttributeSelectionList::size()
26 {
27   return mySize->Get();
28 }
29
30 boost::shared_ptr<ModelAPI_AttributeSelection> 
31   Model_AttributeSelectionList::value(const int theIndex)
32 {
33   return mySubs[theIndex];
34 }
35
36 void Model_AttributeSelectionList::clear()
37 {
38   mySubs.clear();
39   TDF_ChildIterator aSubIter(mySize->Label());
40   for(; aSubIter.More(); aSubIter.Next()) {
41     aSubIter.Value().ForgetAllAttributes(Standard_True);
42   }
43 }
44
45 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
46 {
47   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
48   if (!myIsInitialized) {
49     mySize = TDataStd_Integer::Set(theLabel, 0);
50   } else { // recollect mySubs
51     int aNum = mySize->Get();
52     TDF_ChildIterator aSubIter(theLabel);
53     for(; aSubIter.More(), aNum != 0; aSubIter.Next(), aNum--) {
54       TDF_Label aChildLab = aSubIter.Value();
55       boost::shared_ptr<Model_AttributeSelection> aNewAttr = 
56         boost::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aChildLab));
57       if (owner())
58         aNewAttr->setObject(owner());
59       mySubs.push_back(aNewAttr);
60     }
61   }
62 }
63
64 void Model_AttributeSelectionList::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
65 {
66   ModelAPI_AttributeSelectionList::setObject(theObject);
67   std::vector<boost::shared_ptr<Model_AttributeSelection> >::iterator aSubIter = mySubs.begin();
68   for(; aSubIter != mySubs.end(); aSubIter++) {
69     (*aSubIter)->setObject(theObject);
70   }
71 }