Salome HOME
#1721 Selecting arcs in mirror constraint is too long and removes other edges
[modules/shaper.git] / src / ModelAPI / ModelAPI_Result.cpp
index c16732d99a9d9d0ad8ce117e7f5eede5ef277df0..187a1fc8271f608506ca716df73cf4d23a4f05ab 100644 (file)
@@ -8,16 +8,28 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeDouble.h>
+
 #include <Events_Loop.h>
 
 ModelAPI_Result::~ModelAPI_Result()
 {
 }
 
+void ModelAPI_Result::initAttributes()
+{
+  // append the color attribute. It is empty, the attribute will be filled by a request
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId());
+  aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId());
+}
+
 bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, const bool theFlag)
 {
   if (myIsDisabled != theFlag) {
     myIsDisabled = theFlag;
+    data()->setIsDeleted(theFlag); // store it in data model (t oget back on undo/redo, etc)
     // this must be before "updated" message send to have history updated for OB update
     document()->updateHistory(groupName()); // to update the history cash data in the document
     // generate related events
@@ -27,26 +39,43 @@ bool ModelAPI_Result::setDisabled(std::shared_ptr<ModelAPI_Result> theThis, cons
       aECreator->sendDeleted(document(), groupName());
     } else { // un-disabled equals to created
       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
-      aECreator->sendUpdated(theThis, anEvent, false); // do not group: creation must be immediate
+      aECreator->sendUpdated(theThis, anEvent /*, false*/); // flush is in setCurrentFeature
     }
     static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-    aECreator->sendUpdated(theThis, EVENT_DISP, false);
+    aECreator->sendUpdated(theThis, EVENT_DISP/*, false*/); // flush is in setCurrentFeature
     return true;
   }
   return false;
 }
 
-bool ModelAPI_Result::isDisabled() const
+bool ModelAPI_Result::isDisabled()
 {
+  if (myIsDisabled != data()->isDeleted())
+    setDisabled(std::dynamic_pointer_cast<ModelAPI_Result>(
+      data()->owner()), data()->isDeleted()); // restore from the data model the correct value
   return myIsDisabled;
 }
 
+bool ModelAPI_Result::isConcealed()
+{
+  return myIsConcealed;
+}
+
 void ModelAPI_Result::setIsConcealed(const bool theValue)
 {
   if (myIsConcealed != theValue) {
     myIsConcealed = theValue;
-    if (document().get()) // can be on creation of result
+    if (document().get()) // can be on creation of result
       document()->updateHistory(groupName()); // to update the history cash data in the document
+      if (myIsConcealed) {
+        ModelAPI_EventCreator::get()->sendDeleted(document(), groupName());
+        static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kDispEvent);
+      } else {
+        static Events_ID kEventCreated = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+        ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), kEventCreated);
+      }
+    }
   }
 }
 
@@ -63,3 +92,9 @@ void ModelAPI_Result::attributeChanged(const std::string& theID)
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
   aECreator->sendUpdated(data()->attribute(theID)->owner(), EVENT_DISP);
 }
+
+void ModelAPI_Result::init()
+{
+  myIsDisabled = true; // by default it is not initialized and false to be after created
+  myIsConcealed = false;
+}