Salome HOME
Added the removeLast method into AttributeRefList
authormpv <mpv@opencascade.com>
Thu, 20 Aug 2015 06:53:21 +0000 (09:53 +0300)
committermpv <mpv@opencascade.com>
Thu, 20 Aug 2015 06:53:21 +0000 (09:53 +0300)
src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeRefList.h
src/ModelAPI/ModelAPI_AttributeRefList.h

index 443d089bbad60593fe789e789519613a1adb44cd..01e288ab9204a435353b046fec5ccc3e5c2705da 100644 (file)
@@ -159,6 +159,20 @@ void Model_AttributeRefList::substitute(const ObjectPtr& theCurrent, const Objec
   }
 }
 
+void Model_AttributeRefList::removeLast()
+{
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+      owner()->document());
+  if (aDoc && !myRef->IsEmpty()) {
+    ObjectPtr anObj = aDoc->objects()->object(myRef->Last());
+    if (anObj.get()) {
+      myRef->Remove(myRef->Last());
+      REMOVE_BACK_REF(anObj);
+      owner()->data()->sendAttributeUpdated(this);
+    }
+  }
+}
+
 Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
index c7d909b6b8bd0fb1e3e58f72a12458e17d4eaceb..52de359b1ea41042959c5f7b0da4546c87fee383 100644 (file)
@@ -50,6 +50,9 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList
   /// Substitutes the feature by another one. Does nothing if such object is not found.
   MODEL_EXPORT virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew);
 
+  /// Removes the last element in the list.
+  MODEL_EXPORT virtual void removeLast();
+
   /// Returns true if attribute was  initialized by some value
   MODEL_EXPORT virtual bool isInitialized();
  protected:
index 91c2741cf8f50cb0f170a306ed0cffdf3e1aebb6..2a282108fb911197c2f837557fa4e62cd827865b 100644 (file)
@@ -55,6 +55,9 @@ class ModelAPI_AttributeRefList : public ModelAPI_Attribute
   /// Substitutes the feature by another one. Does nothing if such object is not found.
   virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew) = 0;
 
+  /// Removes the last element in the list.
+  virtual void removeLast() = 0;
+
   MODELAPI_EXPORT virtual ~ModelAPI_AttributeRefList();
  protected:
   /// Objects are created for features automatically