Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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());
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());
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       if (!anObj) { // try to use father (for feature)
46         anObj = aDoc->object(aLIter.Value().Father());
47       }
48       aResult.push_back(anObj);
49     }
50   }
51   return aResult;
52 }
53
54 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
55 {
56   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
57   if (!myIsInitialized) {
58     myRef = TDataStd_ReferenceList::Set(theLabel);
59   }
60 }