Salome HOME
Task #2924 implementation : Ability to remove a result
[modules/shaper.git] / src / Model / Model_Data.cpp
index 697bfedd91724a9702dfeb8fe834f6aab255101e..35137cce8ee6a06b3bca1444e21832fcdee6afaf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <Model_Data.h>
@@ -39,6 +38,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultPart.h>
@@ -96,22 +96,13 @@ void Model_Data::setLabel(TDF_Label theLab)
     myFlags->SetValue(kFlagInHistory, Standard_True); // is in history by default is true
     myFlags->SetValue(kFlagDisplayed, Standard_True); // is displayed by default is true
     myFlags->SetValue(kFlagDeleted, Standard_False); // is deleted by default is false
-  } else if (myFlags->Length() != 3) { // for old formats support
-    Standard_Boolean aFlag0 = myFlags->Upper() >= 0 ? myFlags->Value(0) : Standard_True;
-    Standard_Boolean aFlag1 = myFlags->Upper() >= 1 ? myFlags->Value(1) : Standard_True;
-    Standard_Boolean aFlag2 = myFlags->Upper() >= 2 ? myFlags->Value(2) : Standard_True;
-    Handle(TColStd_HArray1OfByte) aNewArray = new TColStd_HArray1OfByte(0, 2);
-    myFlags->SetInternalArray(aNewArray);
-    myFlags->SetValue(0, aFlag0);
-    myFlags->SetValue(1, aFlag1);
-    myFlags->SetValue(2, aFlag2);
   }
 }
 
 std::string Model_Data::name()
 {
   Handle(TDataStd_Name) aName;
-  if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
+  if (shapeLab().FindAttribute(TDataStd_Name::GetID(), aName)) {
 #ifdef DEBUG_NAMES
     myObject->myName = TCollection_AsciiString(aName->Get()).ToCString();
 #endif
@@ -125,8 +116,8 @@ void Model_Data::setName(const std::string& theName)
   bool isModified = false;
   std::string anOldName = name();
   Handle(TDataStd_Name) aName;
-  if (!myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
-    TDataStd_Name::Set(myLab, theName.c_str());
+  if (!shapeLab().FindAttribute(TDataStd_Name::GetID(), aName)) {
+    TDataStd_Name::Set(shapeLab(), theName.c_str());
     isModified = true;
   } else {
     isModified = !aName->Get().IsEqual(theName.c_str());
@@ -138,12 +129,12 @@ void Model_Data::setName(const std::string& theName)
       bool isUserDefined = true;
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
       if (aResult) {
-        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult).first;
+        std::string aDefaultName = ModelAPI_Tools::getDefaultName(aResult, false).first;
         isUserDefined = aDefaultName != theName;
       }
       if (isUserDefined) {
         // name is user-defined, thus special attribute is set
-        TDataStd_UAttribute::Set(myLab, kUSER_DEFINED_NAME);
+        TDataStd_UAttribute::Set(shapeLab(), kUSER_DEFINED_NAME);
       }
     }
   }
@@ -151,7 +142,7 @@ void Model_Data::setName(const std::string& theName)
     ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
   if (isModified && myObject && myObject->document()) {
     std::dynamic_pointer_cast<Model_Document>(myObject->document())->
-      changeNamingName(anOldName, theName, myLab);
+      changeNamingName(anOldName, theName, shapeLab());
   }
 #ifdef DEBUG_NAMES
   myObject->myName = theName;
@@ -160,7 +151,7 @@ void Model_Data::setName(const std::string& theName)
 
 bool Model_Data::hasUserDefinedName() const
 {
-  return myLab.IsAttribute(kUSER_DEFINED_NAME);
+  return shapeLab().IsAttribute(kUSER_DEFINED_NAME);
 }
 
 AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
@@ -345,8 +336,8 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
         myWasChangedButBlocked.push_back(theAttr);
     }
   } else {
-    // trim: need to redisplay
-    if (myObject) {
+    // trim: need to redisplay or set color in the python script
+    if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color")) {
       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
       ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
     }
@@ -417,7 +408,7 @@ enum StatesIndexes {
   STATE_INDEX_TRANSACTION = 2, // transaction ID
 };
 
-/// Returns the label array, initialises it by default values if not exists
+/// Returns the label array, initializes it by default values if not exists
 static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
 {
   Handle(TDataStd_IntegerArray) aStateArray;
@@ -481,15 +472,6 @@ int Model_Data::featureId() const
   return myLab.Father().Tag(); // tag of the feature label
 }
 
-void Model_Data::eraseBackReferences()
-{
-  myRefsToMe.clear();
-  std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
-  if (aRes) {
-    aRes->setIsConcealed(false);
-  }
-}
-
 void Model_Data::removeBackReference(ObjectPtr theObject, std::string theAttrID)
 {
   AttributePtr anAttribute = theObject->data()->attribute(theAttrID);
@@ -503,7 +485,7 @@ void Model_Data::removeBackReference(AttributePtr theAttr)
 
   myRefsToMe.erase(theAttr);
 
-  // remove concealment immideately: on deselection it must be posible to reselect in GUI the same
+  // remove concealment immediately: on deselection it must be possible to reselect in GUI the same
   FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttr->owner());
   if (aFeatureOwner.get() &&
     ModelAPI_Session::get()->validators()->isConcealed(aFeatureOwner->getKind(), theAttr->id())) {
@@ -523,7 +505,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
     // be displayed and previewed; also for avoiding of quick show/hide on history
     // moving deep down
     if (aRes && !theFeature->isDisabled()) {
-      aRes->setIsConcealed(true);
+      aRes->setIsConcealed(true, theFeature->getKind() == "RemoveResults");
     }
   }
 }
@@ -545,10 +527,16 @@ void Model_Data::updateConcealmentFlag()
       if (aFeature.get() && !aFeature->isDisabled() && aFeature->isStable()) {
         if (ModelAPI_Session::get()->validators()->isConcealed(
               aFeature->getKind(), (*aRefsIter)->id())) {
-          std::shared_ptr<ModelAPI_Result> aRes = std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+          std::shared_ptr<ModelAPI_Result> aRes =
+            std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
           if (aRes.get()) {
-            aRes->setIsConcealed(true); // set concealed
-            return;
+            if (aRes->groupName() != ModelAPI_ResultConstruction::group()) {
+              aRes->setIsConcealed(true); // set concealed
+              return;
+            } else if (aFeature->getKind() == "RemoveResults") {
+              aRes->setIsConcealed(true, true);
+              return;
+            }
           }
         }
       }
@@ -740,7 +728,7 @@ void Model_Data::copyTo(std::shared_ptr<ModelAPI_Data> theTarget)
   // reinitialize Model_Attributes by TDF_Attributes set
   std::shared_ptr<Model_Data> aTData = std::dynamic_pointer_cast<Model_Data>(theTarget);
   aTData->myAttrs.clear();
-  theTarget->owner()->initAttributes(); // reinit feature attributes
+  theTarget->owner()->initAttributes(); // reinitialize feature attributes
 }
 
 bool Model_Data::isInHistory()