Salome HOME
Fix compilation on Linux
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index 1985400a453644d51c3836b917ee216dd87f687a..8a85cd6f49d438e2419fb271686611e9721d456d 100644 (file)
@@ -7,6 +7,7 @@
 #include "ModuleBase_ModelWidget.h"
 #include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_Tools.h"
+#include "ModuleBase_WidgetValidator.h"
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Attribute.h>
@@ -30,7 +31,9 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
     : QWidget(theParent),
       myIsEditing(false),
       myState(Stored),
-      myIsValueStateBlocked(false)
+      myIsValueStateBlocked(false),
+      myFlushUpdateBlocked(false),
+      myWidgetValidator(0)
 {
   myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
 
@@ -84,7 +87,7 @@ QString ModuleBase_ModelWidget::getValueStateError() const
   return anError;
 }
 
-QString ModuleBase_ModelWidget::getError() const
+QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
 {
   QString anError;
 
@@ -107,7 +110,7 @@ QString ModuleBase_ModelWidget::getError() const
   }
 
   anError = QString::fromStdString(anErrorMsg);
-  if (anError.isEmpty())
+  if (anError.isEmpty() && theValueStateChecked)
     anError = getValueStateError();
 
   return anError;
@@ -136,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()
@@ -168,6 +176,10 @@ void ModuleBase_ModelWidget::activate()
     if (anAttribute.get() != NULL && !anAttribute->isInitialized())
       initializeValueByActivate();
   }
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(true);
+
   activateCustom();
 }
 
@@ -177,6 +189,9 @@ void ModuleBase_ModelWidget::deactivate()
   if (myState == ModifiedInPP || myState == ModifiedInViewer)
     storeValue();
   myState = Stored;
+
+  if (myWidgetValidator)
+    myWidgetValidator->activateFilters(false);
 }
 
 void ModuleBase_ModelWidget::initializeValueByActivate()
@@ -276,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)
@@ -351,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);
-}