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;
26 if (theObject.get() != NULL) {
27 aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
28 myRef->Remove(aData->label().Father());
30 else { // in case of empty object remove, the first empty object is removed from the list
31 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
34 const TDF_LabelList& aList = myRef->List();
35 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
36 ObjectPtr anObj = aDoc->object(aLIter.Value());
37 if (anObj.get() == NULL) {
38 myRef->Remove(aLIter.Value());
44 owner()->data()->sendAttributeUpdated(this);
47 int Model_AttributeRefList::size() const
49 return myRef->Extent();
52 list<ObjectPtr> Model_AttributeRefList::list()
54 std::list<ObjectPtr> aResult;
55 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
58 const TDF_LabelList& aList = myRef->List();
59 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
60 ObjectPtr anObj = aDoc->object(aLIter.Value());
61 aResult.push_back(anObj);
67 ObjectPtr Model_AttributeRefList::object(const int theIndex) const
69 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
72 const TDF_LabelList& aList = myRef->List();
74 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
75 if (anIndex == theIndex)
76 return aDoc->object(aLIter.Value());
82 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
84 myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
85 if (!myIsInitialized) {
86 myRef = TDataStd_ReferenceList::Set(theLabel);