Salome HOME
Replace boost::shared_ptr<ModelAPI_Feature> on FeaturePtr
[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_Events.h"
8 #include "Model_Data.h"
9 #include <ModelAPI_Feature.h>
10 #include <Events_Loop.h>
11 #include <TDF_ListIteratorOfLabelList.hxx>
12
13 using namespace std;
14
15 void Model_AttributeRefList::append(FeaturePtr theFeature)
16 {
17   boost::shared_ptr<Model_Data> aData = 
18     boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
19   myRef->Append(aData->label());
20
21   static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
22   Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
23   Events_Loop::loop()->send(aMsg);
24 }
25
26 void Model_AttributeRefList::remove(FeaturePtr theFeature)
27 {
28   boost::shared_ptr<Model_Data> aData = 
29     boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
30   myRef->Remove(aData->label());
31
32 }
33
34 int Model_AttributeRefList::size()
35 {
36   return myRef->Extent();
37 }
38
39 list<FeaturePtr > Model_AttributeRefList::list()
40 {
41   std::list< FeaturePtr > aResult;
42   boost::shared_ptr<Model_Document> aDoc = 
43     boost::dynamic_pointer_cast<Model_Document>(owner()->document());
44   if (aDoc) {
45     const TDF_LabelList& aList = myRef->List();
46     for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
47       aResult.push_back(aDoc->feature(aLIter.Value()));
48     }
49   }
50   return aResult;
51 }
52
53 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
54 {
55   // check the attribute could be already presented in this doc (after load document)
56   if (!theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef)) {
57     myRef = TDataStd_ReferenceList::Set(theLabel);
58   }
59 }