Salome HOME
Fix solvespace version number in environment.
[modules/shaper.git] / src / Model / Model_AttributeRefList.cpp
index ee9b20d749bdc785f6c7919eff937de7aa9310e0..a1e0aeb666779046950ce637308c46a517661ec3 100644 (file)
@@ -100,6 +100,9 @@ list<ObjectPtr> Model_AttributeRefList::list()
 
 bool Model_AttributeRefList::isInList(const ObjectPtr& theObj)
 {
+  if(!theObj.get()) {
+    return false;
+  }
   std::list<ObjectPtr> aResult;
   std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
       owner()->document());
@@ -209,6 +212,32 @@ void Model_AttributeRefList::removeLast()
   }
 }
 
+void Model_AttributeRefList::remove(const std::set<int>& theIndices)
+{
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+      owner()->document());
+  if (aDoc && !myRef->IsEmpty()) {
+    // collet labels that will be removed
+    TDF_LabelList aLabelsToRemove;
+    TDF_ListIteratorOfLabelList aLabIter(myRef->List());
+    for(int aCurrent = 0; aLabIter.More(); aLabIter.Next(), aCurrent++) {
+      if (theIndices.find(aCurrent) != theIndices.end())
+        aLabelsToRemove.Append(aLabIter.Value());
+    }
+    // remove labels
+    for(aLabIter.Initialize(aLabelsToRemove); aLabIter.More(); aLabIter.Next()) {
+      ObjectPtr anObj = aDoc->objects()->object(aLabIter.Value());
+      if (anObj.get()) {
+        myRef->Remove(aLabIter.Value());
+        REMOVE_BACK_REF(anObj);
+      }
+    }
+    if (!aLabelsToRemove.IsEmpty()) {
+      owner()->data()->sendAttributeUpdated(this);
+    }
+  }
+}
+
 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;