Salome HOME
Issue #355 Delete: elements of sketch and constraints:
[modules/shaper.git] / src / Model / Model_AttributeRefList.cpp
index 13233fb9c4e0128becbf03d324014051ceb4539e..b7719ca78f5011e5b4b32980831b452729c773f8 100644 (file)
@@ -7,6 +7,7 @@
 #include "Model_AttributeRefList.h"
 #include "Model_Application.h"
 #include "Model_Data.h"
+#include "Model_Objects.h"
 #include <ModelAPI_Feature.h>
 #include <TDF_ListIteratorOfLabelList.hxx>
 
@@ -37,7 +38,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
     if (aDoc) {
       const TDF_LabelList& aList = myRef->List();
       for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
-        ObjectPtr anObj = aDoc->object(aLIter.Value());
+        ObjectPtr anObj = aDoc->objects()->object(aLIter.Value());
         if (anObj.get() == NULL) {
           myRef->Remove(aLIter.Value());
           REMOVE_BACK_REF(theObject);
@@ -49,11 +50,29 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
   owner()->data()->sendAttributeUpdated(this);
 }
 
+void Model_AttributeRefList::clear()
+{
+  std::list<ObjectPtr> anOldList = list();
+  myRef->Clear();
+  std::list<ObjectPtr>::iterator anOldIter = anOldList.begin();
+  for(; anOldIter != anOldList.end(); anOldIter++) {
+    REMOVE_BACK_REF((*anOldIter));
+  }
+}
+
 int Model_AttributeRefList::size() const
 {
   return myRef->Extent();
 }
 
+bool Model_AttributeRefList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeRefList::isInitialized();
+}
+
 list<ObjectPtr> Model_AttributeRefList::list()
 {
   std::list<ObjectPtr> aResult;
@@ -62,7 +81,7 @@ list<ObjectPtr> Model_AttributeRefList::list()
   if (aDoc) {
     const TDF_LabelList& aList = myRef->List();
     for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
-      ObjectPtr anObj = aDoc->object(aLIter.Value());
+      ObjectPtr anObj = aDoc->objects()->object(aLIter.Value());
       aResult.push_back(anObj);
     }
   }
@@ -78,7 +97,7 @@ ObjectPtr Model_AttributeRefList::object(const int theIndex) const
     int anIndex = 0;
     for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next(), anIndex++) {
       if (anIndex == theIndex)
-        return aDoc->object(aLIter.Value());
+        return aDoc->objects()->object(aLIter.Value());
     }
   }
   return ObjectPtr();