From 52e35523c96109a6d39d96509e631ac67af47d78 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 1 Feb 2013 22:08:01 +0000
Subject: [PATCH] better ReadOnlyRange + AutoCheck should be a number

---
 Common/DefaultOptions.h |  8 ++++----
 Common/GmshMessage.cpp  | 31 ++++++++++++++++++++++---------
 Fltk/inputRange.h       |  4 +++-
 Fltk/onelabGroup.cpp    |  3 ++-
 demos/indheat.geo       |  4 ++--
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index e21d39d1e4..3417beddf0 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -404,9 +404,9 @@ StringXNumber GeneralOptions_Number[] = {
     "Horizontal position (in pixels) of the upper left corner of the field window" },
   { F|S, "FieldPositionY" , opt_general_field_position1 , 550. ,
     "Vertical position (in pixels) of the upper left corner of the field window" },
-  { F|S, "FieldHeight" , opt_general_field_size1 , 300. ,
+  { F|S, "FieldHeight" , opt_general_field_size1 , 320. ,
     "Height (in pixels) of the field window" },
-  { F|S, "FieldWidth" , opt_general_field_size0 , 300. ,
+  { F|S, "FieldWidth" , opt_general_field_size0 , 420. ,
     "Width (in pixels) of the field window" },
   { F|S, "FileChooserPositionX" , opt_general_file_chooser_position0 , 200. ,
     "Horizontal position (in pixels) of the upper left corner of the file chooser "
@@ -558,9 +558,9 @@ StringXNumber GeneralOptions_Number[] = {
     "window" },
   { F|S, "PluginPositionY" , opt_general_plugin_position1 , 550. ,
     "Vertical position (in pixels) of the upper left corner of the plugin window" },
-  { F|S, "PluginHeight" , opt_general_plugin_size1 , 300. ,
+  { F|S, "PluginHeight" , opt_general_plugin_size1 , 320. ,
     "Height (in pixels) of the plugin window" },
-  { F|S, "PluginWidth" , opt_general_plugin_size0 , 300. ,
+  { F|S, "PluginWidth" , opt_general_plugin_size0 , 420. ,
     "Width (in pixels) of the plugin window" },
   { F|O, "PointSize" , opt_general_point_size , 3. ,
     "Display size of points (in pixels)" },
diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 01afdf7a5e..d61d3bb9e0 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -789,15 +789,24 @@ static void _setStandardOptions(onelab::parameter *p,
                                 std::map<std::string, std::vector<double> > &fopt,
                                 std::map<std::string, std::vector<std::string> > &copt)
 {
+  // strings
   if(copt.count("Label")) p->setLabel(copt["Label"][0]);
-  if(copt.count("ShortHelp")) p->setLabel(copt["ShortHelp"][0]);
+  if(copt.count("ShortHelp")) // for backward compatibility
+    p->setLabel(copt["ShortHelp"][0]);
   if(copt.count("Help")) p->setHelp(copt["Help"][0]);
-  if(fopt.count("Visible")) p->setVisible(fopt["Visible"][0] ? true : false);
-  if(fopt.count("ReadOnly")) p->setReadOnly(fopt["ReadOnly"][0] ? true : false);
   if(copt.count("Highlight")) p->setAttribute("Highlight", copt["Highlight"][0]);
-  if(copt.count("AutoCheck")) p->setAttribute("AutoCheck", copt["AutoCheck"][0]);
   if(copt.count("Macro")) p->setAttribute("Macro", copt["Macro"][0]);
   if(copt.count("GmshOption")) p->setAttribute("GmshOption", copt["GmshOption"][0]);
+  if(copt.count("AutoCheck")) // for backward compatibility
+    p->setAttribute("AutoCheck", copt["AutoCheck"][0]);
+
+  // numbers
+  if(fopt.count("Visible")) p->setVisible(fopt["Visible"][0] ? true : false);
+  if(fopt.count("ReadOnly")) p->setReadOnly(fopt["ReadOnly"][0] ? true : false);
+  if(fopt.count("ReadOnlyRange"))
+    p->setAttribute("ReadOnlyRange", fopt["ReadOnlyRange"][0] ? "1" : "0");
+  if(fopt.count("AutoCheck"))
+    p->setAttribute("AutoCheck", fopt["AutoCheck"][0] ? "1" : "0");
 }
 
 static std::string _getParameterName(const std::string &key,
@@ -837,11 +846,15 @@ void Msg::ExchangeOnelabParameter(const std::string &key,
       ps[0].setValue(val[0]); // use local value
     else
       val[0] = ps[0].getValue(); // use value from server
-    // keep track of these attributes, which can be changed server-side
-    if(ps[0].getMin() != -onelab::parameter::maxNumber() ||
-       ps[0].getMax() != onelab::parameter::maxNumber() ||
-       ps[0].getStep() != 0.) noRange = false;
-    if(ps[0].getChoices().size()) noChoices = false;
+    // keep track of these attributes, which can be changed server-side (unless,
+    // for the range/choices, when explicitely setting these attributes as
+    // ReadOnly)
+    if(!(fopt.count("ReadOnlyRange") && fopt["ReadOnlyRange"][0])){
+      if(ps[0].getMin() != -onelab::parameter::maxNumber() ||
+         ps[0].getMax() != onelab::parameter::maxNumber() ||
+         ps[0].getStep() != 0.) noRange = false;
+      if(ps[0].getChoices().size()) noChoices = false;
+    }
     if(ps[0].getAttribute("Loop").size()) noLoop = false;
     if(ps[0].getAttribute("Graph").size()) noGraph = false;
     if(ps[0].getAttribute("Closed").size()) noClosed = false;
diff --git a/Fltk/inputRange.h b/Fltk/inputRange.h
index d391749d14..76049bdb89 100644
--- a/Fltk/inputRange.h
+++ b/Fltk/inputRange.h
@@ -255,7 +255,8 @@ class inputRange : public Fl_Group {
     b->do_callback();
   }
  public:
-  inputRange(int x, int y, int w, int h, double max_number, const char *l=0)
+  inputRange(int x, int y, int w, int h, double max_number, bool readOnlyRange=false,
+             const char *l=0)
     : Fl_Group(x,y,w,h,l), _min(-max_number), _max(max_number), _step(1.),
       _max_number(max_number), _do_callback_on_values(true)
   {
@@ -273,6 +274,7 @@ class inputRange : public Fl_Group {
     _range->callback(_range_cb, this);
     _range->when(FL_WHEN_ENTER_KEY|FL_WHEN_RELEASE);
     _range->hide();
+    if(readOnlyRange) _range->deactivate();
 
     _range_butt = new Fl_Toggle_Button(x + input_w, y, dot_w, h, ":");
     _range_butt->callback(_range_butt_cb, this);
diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index 2ac556ddfe..1b372b04b3 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -1084,7 +1084,8 @@ Fl_Widget *onelabGroup::_addParameterWidget(onelab::number &p, Fl_Tree_Item *n,
   }
 
   // general number input
-  inputRange *but = new inputRange(1, 1, ww, 1, onelab::parameter::maxNumber());
+  inputRange *but = new inputRange(1, 1, ww, 1, onelab::parameter::maxNumber(),
+                                   p.getAttribute("ReadOnlyRange") == "1");
   but->value(p.getValue());
   but->minimum(p.getMin());
   but->maximum(p.getMax());
diff --git a/demos/indheat.geo b/demos/indheat.geo
index 93a95179af..7ed7752d72 100644
--- a/demos/indheat.geo
+++ b/demos/indheat.geo
@@ -13,9 +13,9 @@ DefineConstant
  lb = {1, Label "Infinite box width", Path "Parameters"},
  left = {1, Choices{0,1}, Label "Terminals on the left?", Path "Parameters"}
  macro = {"title.script", Label "Add title", Path "Macros",
-          Macro "Gmsh", AutoCheck "0" /*, Highlight "Turquoise"*/ },
+          Macro "Gmsh", AutoCheck 0 /*, Highlight "Turquoise"*/ },
  showLines = {Geometry.Lines, Choices {0,1}, Label "Show lines?", Path "Options",
-              GmshOption "Geometry.Lines", AutoCheck "0"}
+              GmshOption "Geometry.Lines", AutoCheck 0}
 ];
 
 // inductor
-- 
GitLab