Salome HOME
Added the initialization of attributes flag and "attributes": method that returns...
[modules/shaper.git] / src / Model / Model_AttributeRefList.cpp
1 // File:        ModelAPI_AttributeRefList.cxx
2 // Created:     8 May 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "Model_AttributeRefList.h"
6 #include "Model_Application.h"
7 #include "Model_Data.h"
8 #include <ModelAPI_Feature.h>
9 #include <TDF_ListIteratorOfLabelList.hxx>
10
11 using namespace std;
12
13 void Model_AttributeRefList::append(FeaturePtr theFeature)
14 {
15   boost::shared_ptr<Model_Data> aData = 
16     boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
17   myRef->Append(aData->label());
18
19   owner()->data()->sendAttributeUpdated(this);
20 }
21
22 void Model_AttributeRefList::remove(FeaturePtr theFeature)
23 {
24   boost::shared_ptr<Model_Data> aData = 
25     boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
26   myRef->Remove(aData->label());
27
28   owner()->data()->sendAttributeUpdated(this);
29 }
30
31 int Model_AttributeRefList::size()
32 {
33   return myRef->Extent();
34 }
35
36 list<FeaturePtr > Model_AttributeRefList::list()
37 {
38   std::list< FeaturePtr > aResult;
39   boost::shared_ptr<Model_Document> aDoc = 
40     boost::dynamic_pointer_cast<Model_Document>(owner()->document());
41   if (aDoc) {
42     const TDF_LabelList& aList = myRef->List();
43     for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
44       aResult.push_back(aDoc->feature(aLIter.Value()));
45     }
46   }
47   return aResult;
48 }
49
50 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
51 {
52   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
53   if (!myIsInitialized) {
54     myRef = TDataStd_ReferenceList::Set(theLabel);
55   }
56 }