Salome HOME
Abort Sketch by click on the button in the tool bar. Abort nested opened operations.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index 4053a2a4b6c8d33f25b9c116462d7d9d3ca93555..9e222e9869d3d007ef441173dc7b041830977705 100644 (file)
@@ -5,10 +5,11 @@
 // Author:      Vitaly Smetannikov
 
 #include <ModuleBase_WidgetDoubleValue.h>
-#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 
 #include <Config_Keywords.h>
@@ -46,7 +47,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   if (!aLabelIcon.isEmpty())
     myLabel->setPixmap(QPixmap(aLabelIcon));
 
-  mySpinBox = new ModuleBase_DoubleSpinBox(this);
+  mySpinBox = new ModuleBase_ParamSpinBox(this);
   QString anObjName = QString::fromStdString(attributeID());
   mySpinBox->setObjectName(anObjName);
 
@@ -95,16 +96,19 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 
 void ModuleBase_WidgetDoubleValue::reset()
 {
-  if (isComputedDefault()) {
+  if (isComputedDefault() || mySpinBox->hasVariable()) {
     return;
     //if (myFeature->compute(myAttributeID))
     //  restoreValue();
-  }
-  else {
+  } else {
     bool isOk;
     double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
-    ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
-    storeValueCustom();
+    // reset the value just if there is a default value definition in the XML definition
+    // if the double value can not be found by the default value, do nothing
+    if (isOk) {
+      ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
+      storeValueCustom();
+    }
   }
 }
 
@@ -113,6 +117,13 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
   aReal->setValue(mySpinBox->value());
+  std::string aTextRepr = aReal->text();
+  if (mySpinBox->hasVariable()) {
+    aTextRepr = mySpinBox->text().toStdString();
+  } else {
+    aTextRepr = "";
+  }
+  aReal->setText(aTextRepr);
   updateObject(myFeature);
   return true;
 }
@@ -121,9 +132,14 @@ bool ModuleBase_WidgetDoubleValue::restoreValue()
 {
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
-
-  ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
-
+  std::string aTextRepr = aRef->text();
+  if (!aTextRepr.empty()) {
+    bool isBlocked = mySpinBox->blockSignals(true);
+    mySpinBox->setText(QString::fromStdString(aTextRepr));
+    mySpinBox->blockSignals(isBlocked);
+  } else {
+    ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
+  }
   return true;
 }