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
19 // do it before the transaction finish to make just created/removed objects know dependencies
20 // and reference from composite feature is removed automatically
21 ADD_BACK_REF(theObject);
23 owner()->data()->sendAttributeUpdated(this);
26 void Model_AttributeRefList::remove(ObjectPtr theObject)
28 std::shared_ptr<Model_Data> aData;
29 if (theObject.get() != NULL) {
30 aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
31 myRef->Remove(aData->label().Father());
33 else { // in case of empty object remove, the first empty object is removed from the list
34 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
37 const TDF_LabelList& aList = myRef->List();
38 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
39 ObjectPtr anObj = aDoc->object(aLIter.Value());
40 if (anObj.get() == NULL) {
41 myRef->Remove(aLIter.Value());
42 REMOVE_BACK_REF(theObject);
48 owner()->data()->sendAttributeUpdated(this);
51 int Model_AttributeRefList::size() const
53 return myRef->Extent();
56 list<ObjectPtr> Model_AttributeRefList::list()
58 std::list<ObjectPtr> aResult;
59 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
62 const TDF_LabelList& aList = myRef->List();
63 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
64 ObjectPtr anObj = aDoc->object(aLIter.Value());
65 aResult.push_back(anObj);
71 ObjectPtr Model_AttributeRefList::object(const int theIndex) const
73 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
76 const TDF_LabelList& aList = myRef->List();
78 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
79 if (anIndex == theIndex)
80 return aDoc->object(aLIter.Value());
86 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
88 myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
89 if (!myIsInitialized) {
90 myRef = TDataStd_ReferenceList::Set(theLabel);