Salome HOME
Sources formated according to the codeing standards
[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 = boost::dynamic_pointer_cast<Model_Data>(theObject->data());
16   myRef->Append(aData->label().Father());  // store label of the object
17
18   owner()->data()->sendAttributeUpdated(this);
19 }
20
21 void Model_AttributeRefList::remove(ObjectPtr theObject)
22 {
23   boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theObject->data());
24   myRef->Remove(aData->label().Father());
25
26   owner()->data()->sendAttributeUpdated(this);
27 }
28
29 int Model_AttributeRefList::size()
30 {
31   return myRef->Extent();
32 }
33
34 list<ObjectPtr> Model_AttributeRefList::list()
35 {
36   std::list<ObjectPtr> aResult;
37   boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
38       owner()->document());
39   if (aDoc) {
40     const TDF_LabelList& aList = myRef->List();
41     for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
42       ObjectPtr anObj = aDoc->object(aLIter.Value());
43       aResult.push_back(anObj);
44     }
45   }
46   return aResult;
47 }
48
49 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
50 {
51   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
52   if (!myIsInitialized) {
53     myRef = TDataStd_ReferenceList::Set(theLabel);
54   }
55 }