Salome HOME
Make data located on the same level for features and results
[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(ObjectPtr theObject)
14 {
15   boost::shared_ptr<Model_Data> aData = 
16     boost::dynamic_pointer_cast<Model_Data>(theObject->data());
17   myRef->Append(aData->label().Father()); // store label of the object
18
19   owner()->data()->sendAttributeUpdated(this);
20 }
21
22 void Model_AttributeRefList::remove(ObjectPtr theObject)
23 {
24   boost::shared_ptr<Model_Data> aData = 
25     boost::dynamic_pointer_cast<Model_Data>(theObject->data());
26   myRef->Remove(aData->label().Father());
27
28   owner()->data()->sendAttributeUpdated(this);
29 }
30
31 int Model_AttributeRefList::size()
32 {
33   return myRef->Extent();
34 }
35
36 list<ObjectPtr> Model_AttributeRefList::list()
37 {
38   std::list< ObjectPtr > 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       ObjectPtr anObj = aDoc->object(aLIter.Value());
45       aResult.push_back(anObj);
46     }
47   }
48   return aResult;
49 }
50
51 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
52 {
53   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
54   if (!myIsInitialized) {
55     myRef = TDataStd_ReferenceList::Set(theLabel);
56   }
57 }