Salome HOME
Make not-stable features lose the concealment ability
[modules/shaper.git] / src / Model / Model_Data.cpp
index aeb1489c47ac39f298439a7dc4090be4d5a174ed..64574892c2f6cc47dd140f191b25da6fd520ebd4 100644 (file)
@@ -25,6 +25,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Tools.h>
+#include <Model_Validator.h>
 
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
@@ -41,6 +42,7 @@
 #include <TDF_AttributeIterator.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_RelocationTable.hxx>
+#include <TColStd_HArray1OfByte.hxx>
 
 #include <string>
 
@@ -52,6 +54,8 @@
 static const int kFlagInHistory = 0;
 //                             1 - is displayed or not
 static const int kFlagDisplayed = 1;
+//                             2 - is deleted (for results) or not
+static const int kFlagDeleted = 2;
 
 // invalid data
 const static std::shared_ptr<ModelAPI_Data> kInvalid(new Model_Data());
@@ -66,9 +70,19 @@ void Model_Data::setLabel(TDF_Label theLab)
   // set or get the default flags
   if (!myLab.FindAttribute(TDataStd_BooleanArray::GetID(), myFlags)) {
     // set default values if not found
-    myFlags = TDataStd_BooleanArray::Set(myLab, 0, 1);
+    myFlags = TDataStd_BooleanArray::Set(myLab, 0, 2);
     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); 
   }
 }
 
@@ -288,7 +302,12 @@ static Handle(TDataStd_IntegerArray) stateArray(TDF_Label& theLab)
 void Model_Data::execState(const ModelAPI_ExecState theState)
 {
   if (theState != ModelAPI_StateNothing) {
-    stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
+    if (stateArray(myLab)->Value(STATE_INDEX_STATE) != (int)theState) {
+      stateArray(myLab)->SetValue(STATE_INDEX_STATE, (int)theState);
+    }
+    // send signal even if the new value corresponds to the one in data model: undo issue 980
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED);
+    ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
   }
 }
 
@@ -314,6 +333,13 @@ void Model_Data::setError(const std::string& theError, bool theSend)
     Events_Error::send(theError);
   }
   TDataStd_AsciiString::Set(myLab, theError.c_str());
+  static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED);
+  ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
+}
+
+void Model_Data::eraseErrorString()
+{
+  myLab.ForgetAttribute(TDataStd_AsciiString::GetID());
 }
 
 std::string Model_Data::error() const
@@ -362,7 +388,7 @@ void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID,
     return;
 
   myRefsToMe.insert(theFeature->data()->attribute(theAttrID));
-  if (theApplyConcealment && 
+  if (theApplyConcealment &&  theFeature->isStable() && 
       ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) {
     std::shared_ptr<ModelAPI_Result> aRes = 
       std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
@@ -392,7 +418,7 @@ void Model_Data::updateConcealmentFlag()
   // thus, no concealment references anymore => make not-concealed
   std::shared_ptr<ModelAPI_Result> aRes = 
     std::dynamic_pointer_cast<ModelAPI_Result>(myObject);
-  if (aRes.get()) {
+  if (aRes.get() && aRes->isConcealed()) {
     aRes->setIsConcealed(false);
     static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
     ModelAPI_EventCreator::get()->sendUpdated(aRes, anEvent);
@@ -400,8 +426,6 @@ void Model_Data::updateConcealmentFlag()
   }
 }
 
-#include <Model_Validator.h>
-
 std::set<std::string> set_union(const std::set<std::string>& theLeft, 
                                 const std::set<std::string>& theRight)
 {
@@ -548,6 +572,16 @@ void Model_Data::setIsInHistory(const bool theFlag)
   return myFlags->SetValue(kFlagInHistory, theFlag);
 }
 
+bool Model_Data::isDeleted()
+{
+  return myFlags->Value(kFlagDeleted) == Standard_True;
+}
+
+void Model_Data::setIsDeleted(const bool theFlag)
+{
+  return myFlags->SetValue(kFlagDeleted, theFlag);
+}
+
 bool Model_Data::isDisplayed()
 {
   if (!myObject.get() || !myObject->document().get() || // object is in valid