1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_AttributeRefList.cxx
5 // Author: Mikhail PONIKAROV
7 #include "Model_AttributeRefList.h"
8 #include "Model_Application.h"
9 #include "Model_Data.h"
10 #include <ModelAPI_Feature.h>
11 #include <TDF_ListIteratorOfLabelList.hxx>
15 void Model_AttributeRefList::append(ObjectPtr theObject)
17 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
18 myRef->Append(aData->label().Father()); // store label of the object
20 owner()->data()->sendAttributeUpdated(this);
23 void Model_AttributeRefList::remove(ObjectPtr theObject)
25 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
26 myRef->Remove(aData->label().Father());
28 owner()->data()->sendAttributeUpdated(this);
31 int Model_AttributeRefList::size() const
33 return myRef->Extent();
36 list<ObjectPtr> Model_AttributeRefList::list()
38 std::list<ObjectPtr> aResult;
39 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
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);
51 ObjectPtr Model_AttributeRefList::object(const int theIndex) const
53 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
56 const TDF_LabelList& aList = myRef->List();
58 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
59 if (anIndex == theIndex)
60 return aDoc->object(aLIter.Value());
66 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
68 myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
69 if (!myIsInitialized) {
70 myRef = TDataStd_ReferenceList::Set(theLabel);