Salome HOME
Fix for the issue #1766 : treat face as equal with different orientation to find...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index 69cd60c463ba29b321ad6d99cf508fe7c15fb82a..fdfffa34389b7df51a34a367975047e4141ebec0 100644 (file)
@@ -20,6 +20,7 @@
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
 #include <Config_Translator.h>
+#include <Config_PropManager.h>
 
 #include <Events_Loop.h>
 
@@ -31,6 +32,7 @@
 //#define DEBUG_VALUE_STATE
 
 //#define DEBUG_WIDGET_INSTANCE
+//#define DEBUG_ENABLE_SKETCH_INPUT_FIELDS
 
 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
                                                const Config_WidgetAPI* theData)
@@ -53,6 +55,13 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   myAttributeID = theData ? theData->widgetId() : "";
   myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
 
+  myIsValueEnabled = On; // not defined or "true"
+  std::string anEnableValue = theData->getProperty(DOUBLE_WDG_ENABLE_VALUE);
+  if (anEnableValue == "false")
+    myIsValueEnabled = Off;
+  if (anEnableValue == DOUBLE_WDG_ENABLE_VALUE_BY_PREFERENCES)
+    myIsValueEnabled = DefinedInPreferences;
+
   connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
   connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified()));
 }
@@ -78,6 +87,24 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
   return theObject->data()->attribute(attributeID())->isInitialized();
 }
 
+bool ModuleBase_ModelWidget::isValueEnabled() const
+{
+  bool anEnabled = true;
+  if (myIsValueEnabled == DefinedInPreferences) {
+#ifdef DEBUG_ENABLE_SKETCH_INPUT_FIELDS
+    bool aCanDisable = false;
+#else
+    //Config_PropManager::boolean(SKETCH_TAB_NAME, "disable_input_fields", "true");
+    bool aCanDisable = true;
+#endif
+    if (aCanDisable)
+      anEnabled = false;
+  }
+  else if (myIsValueEnabled == Off)
+    anEnabled = false;
+  return anEnabled;
+}
+
 void ModuleBase_ModelWidget::processValueState()
 {
   if (myState == ModifiedInPP || myState == ModifiedInViewer)
@@ -188,8 +215,13 @@ void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool
   /// after debug, it may be corrected
   myFlushUpdateBlocked = !isUpdateFlushed;
   myFeature = theFeature;
-  if (theToStoreValue)
-    storeValue();
+  if (theToStoreValue) {
+    /// it is possible that the attribute is filled before the operation is started,
+    /// e.g. by reentrant operation case some attributes are filled by values of
+    /// feature of previous operation, we should not lost them here
+    if (!theFeature->data()->attribute(attributeID())->isInitialized())
+      storeValue();
+  }
   myFlushUpdateBlocked = false;
 }