Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / Model / Model_AttributeRefList.cpp
index af4cbd3ea6246983a910f4bc3f177540ebe8d1e5..9287cf0415079707b7ecfb17c91b01c51742deb4 100644 (file)
@@ -1,59 +1,72 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModelAPI_AttributeRefList.cxx
 // Created:     8 May 2014
 // Author:      Mikhail PONIKAROV
 
 #include "Model_AttributeRefList.h"
 #include "Model_Application.h"
-#include "Model_Events.h"
 #include "Model_Data.h"
 #include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
 #include <TDF_ListIteratorOfLabelList.hxx>
 
 using namespace std;
 
-void Model_AttributeRefList::append(FeaturePtr theFeature)
+void Model_AttributeRefList::append(ObjectPtr theObject)
 {
-  boost::shared_ptr<Model_Data> aData = 
-    boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
-  myRef->Append(aData->label());
+  std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
+  myRef->Append(aData->label().Father());  // store label of the object
 
-  static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
-  Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
-  Events_Loop::loop()->send(aMsg);
+  owner()->data()->sendAttributeUpdated(this);
 }
 
-void Model_AttributeRefList::remove(FeaturePtr theFeature)
+void Model_AttributeRefList::remove(ObjectPtr theObject)
 {
-  boost::shared_ptr<Model_Data> aData = 
-    boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
-  myRef->Remove(aData->label());
+  std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
+  myRef->Remove(aData->label().Father());
 
+  owner()->data()->sendAttributeUpdated(this);
 }
 
-int Model_AttributeRefList::size()
+int Model_AttributeRefList::size() const
 {
   return myRef->Extent();
 }
 
-list<FeaturePtr > Model_AttributeRefList::list()
+list<ObjectPtr> Model_AttributeRefList::list()
 {
-  std::list< FeaturePtr > aResult;
-  boost::shared_ptr<Model_Document> aDoc = 
-    boost::dynamic_pointer_cast<Model_Document>(owner()->document());
+  std::list<ObjectPtr> aResult;
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+      owner()->document());
   if (aDoc) {
     const TDF_LabelList& aList = myRef->List();
-    for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
-      aResult.push_back(aDoc->feature(aLIter.Value()));
+    for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
+      ObjectPtr anObj = aDoc->object(aLIter.Value());
+      aResult.push_back(anObj);
     }
   }
   return aResult;
 }
 
+ObjectPtr Model_AttributeRefList::object(const int theIndex) const
+{
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+      owner()->document());
+  if (aDoc) {
+    const TDF_LabelList& aList = myRef->List();
+    int anIndex = 0;
+    for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
+      if (anIndex == theIndex)
+        return aDoc->object(aLIter.Value());
+    }
+  }
+  return ObjectPtr();
+}
+
 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
 {
-  // check the attribute could be already presented in this doc (after load document)
-  if (!theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef)) {
+  myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
+  if (!myIsInitialized) {
     myRef = TDataStd_ReferenceList::Set(theLabel);
   }
 }