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());
32 REMOVE_BACK_REF(theObject);
34 else { // in case of empty object remove, the first empty object is removed from the list
35 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
38 const TDF_LabelList& aList = myRef->List();
39 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
40 ObjectPtr anObj = aDoc->object(aLIter.Value());
41 if (anObj.get() == NULL) {
42 myRef->Remove(aLIter.Value());
43 REMOVE_BACK_REF(theObject);
49 owner()->data()->sendAttributeUpdated(this);
52 int Model_AttributeRefList::size() const
54 return myRef->Extent();
57 bool Model_AttributeRefList::isInitialized()
59 if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
62 return ModelAPI_AttributeRefList::isInitialized();
65 list<ObjectPtr> Model_AttributeRefList::list()
67 std::list<ObjectPtr> aResult;
68 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
71 const TDF_LabelList& aList = myRef->List();
72 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
73 ObjectPtr anObj = aDoc->object(aLIter.Value());
74 aResult.push_back(anObj);
80 ObjectPtr Model_AttributeRefList::object(const int theIndex) const
82 std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
85 const TDF_LabelList& aList = myRef->List();
87 for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
88 if (anIndex == theIndex)
89 return aDoc->object(aLIter.Value());
95 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
97 myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
98 if (!myIsInitialized) {
99 myRef = TDataStd_ReferenceList::Set(theLabel);