Salome HOME
Issue #1303 Re-ordering of Sketcher menus: Delete to be the last
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index a903538452c4c03ca7741b53368a53ee8aa4eb4a..cf67219928e96d3c8113dece3d4b4e8c584ddead 100644 (file)
@@ -5,7 +5,9 @@
 // Author:      Natalia ERMOLAEVA
 
 #include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_Tools.h"
+#include "ModuleBase_WidgetValidator.h"
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
 #include <QLabel>
 #include <QFocusEvent>
 
+//#define DEBUG_VALUE_STATE
+
 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
-                                               const Config_WidgetAPI* theData,
-                                               const std::string& theParentId)
+                                               const Config_WidgetAPI* theData)
     : QWidget(theParent),
-      myParentId(theParentId),
       myIsEditing(false),
       myState(Stored),
-      myIsValueStateBlocked(false)
+      myIsValueStateBlocked(false),
+      myFlushUpdateBlocked(false),
+      myWidgetValidator(0)
 {
   myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
 
@@ -135,11 +139,16 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
   }
 }
 
-void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue)
+void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue,
+                                        const bool isUpdateFlushed)
 {
+  /// it is possible to give this flag as parameter in storeValue/storeCustomValue
+  /// after debug, it may be corrected
+  myFlushUpdateBlocked = !isUpdateFlushed;
   myFeature = theFeature;
   if (theToStoreValue)
     storeValue();
+  myFlushUpdateBlocked = false;
 }
 
 bool ModuleBase_ModelWidget::focusTo()
@@ -167,6 +176,10 @@ void ModuleBase_ModelWidget::activate()
     if (anAttribute.get() != NULL && !anAttribute->isInitialized())
       initializeValueByActivate();
   }
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(true);
+
   activateCustom();
 }
 
@@ -176,6 +189,9 @@ void ModuleBase_ModelWidget::deactivate()
   if (myState == ModifiedInPP || myState == ModifiedInViewer)
     storeValue();
   myState = Stored;
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(false);
 }
 
 void ModuleBase_ModelWidget::initializeValueByActivate()
@@ -227,11 +243,32 @@ bool ModuleBase_ModelWidget::storeValue()
 
   return isDone;
 }
+#ifdef DEBUG_VALUE_STATE
+std::string getDebugInfo(const ModuleBase_ModelWidget::ValueState& theState)
+{
+  std::string anInfo;
+  switch (theState) {
+    case ModuleBase_ModelWidget::Stored:           anInfo = "Stored          "; break;
+    case ModuleBase_ModelWidget::ModifiedInPP:     anInfo = "ModifiedInPP    "; break;
+    case ModuleBase_ModelWidget::ModifiedInViewer: anInfo = "ModifiedInViewer"; break;
+    case ModuleBase_ModelWidget::Reset:            anInfo = "Reset           "; break;
+    default: break;
+  }
+  return anInfo;
+}
 
-ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState(const ModuleBase_ModelWidget::ValueState& theState)
+#endif
+ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState
+                                         (const ModuleBase_ModelWidget::ValueState& theState)
 {
   ValueState aState = myState;
+
   if (myState != theState && !myIsValueStateBlocked) {
+#ifdef DEBUG_VALUE_STATE
+    qDebug(QString("setValueState: previous state = %1,\t new state = %2")
+           .arg(getDebugInfo(myState).c_str())
+           .arg(getDebugInfo(theState).c_str()).toStdString().c_str());
+#endif
     myState = theState;
     emit valueStateChanged(aState);
   }
@@ -254,13 +291,12 @@ bool ModuleBase_ModelWidget::restoreValue()
   return isDone;
 }
 
-void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj)
+void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject)
 {
-  blockUpdateViewer(true);
-
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-
-  blockUpdateViewer(false);
+  if (!myFlushUpdateBlocked) {
+    ModuleBase_Tools::flushUpdated(theObject);
+    emit objectUpdated();
+  }
 }
 
 void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
@@ -329,23 +365,3 @@ void ModuleBase_ModelWidget::onWidgetValuesModified()
 {
   setValueState(ModifiedInPP);
 }
-
-//**************************************************************
-void ModuleBase_ModelWidget::blockUpdateViewer(const bool theValue)
-{
-  // the viewer update should be blocked in order to avoid the temporary feature content
-  // when the solver processes the feature, the redisplay message can be flushed
-  // what caused the display in the viewer preliminary states of object
-  // e.g. fillet feature, angle value change
-  std::shared_ptr<Events_Message> aMsg;
-  if (theValue) {
-    aMsg = std::shared_ptr<Events_Message>(
-        new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
-  }
-  else {
-    // the viewer update should be unblocked
-    aMsg = std::shared_ptr<Events_Message>(
-        new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
-  }
-  Events_Loop::loop()->send(aMsg);
-}