Salome HOME
Improvement #996: topological reference syntax
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.cpp
index f547a797fdcdbbc80bc10a844ed082a652a68d15..f762ebaf39699e006fc32d8f45ceab799528bdf0 100644 (file)
@@ -21,7 +21,8 @@
 using namespace std;
 
 void Model_AttributeSelectionList::append(
-    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
+    const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+    const bool theTemporarily)
 {
   // do not use the degenerated edge as a shape, a list is not incremented in this case
   if (theSubShape.get() && !theSubShape->isNull() && theSubShape->isEdge()) {
@@ -41,11 +42,16 @@ void Model_AttributeSelectionList::append(
   }
   aNewAttr->setID(id());
   mySize->Set(aNewTag);
-  aNewAttr->setValue(theContext, theSubShape);
+  aNewAttr->setValue(theContext, theSubShape, theTemporarily);
+  if (theTemporarily)
+    myTmpAttr = aNewAttr;
+  else 
+    myTmpAttr.reset();
   owner()->data()->sendAttributeUpdated(this);
 }
 
-void Model_AttributeSelectionList::append(std::string theNamingName)
+void Model_AttributeSelectionList::append(
+  const std::string theNamingName, const std::string& theType)
 {
   int aNewTag = mySize->Get() + 1;
   TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
@@ -55,11 +61,28 @@ void Model_AttributeSelectionList::append(std::string theNamingName)
   if (owner()) {
     aNewAttr->setObject(owner());
   }
+  aNewAttr->setID(id());
   mySize->Set(aNewTag);
-  aNewAttr->selectSubShape(selectionType(), theNamingName);
+  aNewAttr->selectSubShape(theType.empty() ? selectionType() : theType, theNamingName);
   owner()->data()->sendAttributeUpdated(this);
 }
 
+void Model_AttributeSelectionList::removeLast() 
+{
+  int anOldSize = mySize->Get();
+  if (anOldSize != 0) {
+    mySize->Set(anOldSize - 1);
+    TDF_Label aLab = mySize->Label().FindChild(anOldSize);
+    std::shared_ptr<Model_AttributeSelection> aOldAttr = 
+      std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLab));
+    aOldAttr->setObject(owner());
+    REMOVE_BACK_REF(aOldAttr->context());
+    aLab.ForgetAllAttributes(Standard_True);
+    myTmpAttr.reset();
+    owner()->data()->sendAttributeUpdated(this);
+  }
+}
+
 int Model_AttributeSelectionList::size()
 {
   return mySize->Get();
@@ -78,6 +101,9 @@ void Model_AttributeSelectionList::setSelectionType(const std::string& theType)
 std::shared_ptr<ModelAPI_AttributeSelection> 
   Model_AttributeSelectionList::value(const int theIndex)
 {
+  if (myTmpAttr.get() && theIndex == size() - 1) {
+    return myTmpAttr;
+  }
   TDF_Label aLabel = mySize->Label().FindChild(theIndex + 1);
   // create a new attribute each time, by demand
   // supporting of old attributes is too slow (synch each time) and buggy on redo
@@ -94,6 +120,7 @@ void Model_AttributeSelectionList::clear()
 {
   if (mySize->Get() != 0) {
     mySize->Set(0);
+    myTmpAttr.reset();
     TDF_ChildIterator aSubIter(mySize->Label());
     for(; aSubIter.More(); aSubIter.Next()) {
       TDF_Label aLab = aSubIter.Value();