From b4c89adfecc74115c3b5e3a221083bb5b66758bf Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 3 Sep 2012 20:55:16 +0000
Subject: [PATCH] if no range/min/max/step is given, precompute one

---
 Common/GmshMessage.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index e31a3029e8..2cb2a7f750 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -717,6 +717,28 @@ void Msg::ExchangeOnelabParameter(const std::string &key,
     ps[0].setMax(fopt["Max"][0]); ps[0].setMin(-onelab::parameter::maxNumber());
   }
   if(noRange && fopt.count("Step")) ps[0].setStep(fopt["Step"][0]);
+  // if no range/min/max/step info is provided, try to compute a reasonnable
+  // range and step (this makes the gui much nicer to use)
+  if(noRange && !fopt.count("Range") && !fopt.count("Step") &&
+     !fopt.count("Min") && !fopt.count("Max")){
+    bool isInteger = (std::floor(val[0]) == val[0]);
+    double fact = isInteger ? 10. : 100.;
+    if(val[0] > 0){
+      ps[0].setMin(val[0] / fact);
+      ps[0].setMax(val[0] * fact);
+      ps[0].setStep((val[0] * fact - val[0] / fact) / 100.);
+    }
+    else if(val[0] < 0){
+      ps[0].setMin(val[0] * fact);
+      ps[0].setMax(val[0] / fact);
+      ps[0].setStep((val[0] / fact - val[0] * fact) / 100.);
+    }
+    if(std::floor(val[0]) == val[0]){ // integer
+      ps[0].setMin((int)ps[0].getMin());
+      ps[0].setMax((int)ps[0].getMax());
+      ps[0].setStep((int)ps[0].getStep());
+    }
+  }
   if(noChoices && fopt.count("Choices")){
     ps[0].setChoices(fopt["Choices"]);
     if(copt.count("Choices")) ps[0].setChoiceLabels(copt["Choices"]);
-- 
GitLab