From c18d771f43fecf5fc2479b05783feb4cbfa91487 Mon Sep 17 00:00:00 2001
From: Sergey Linev <S.Linev@gsi.de>
Date: Thu, 18 Apr 2019 10:46:14 +0200
Subject: [PATCH] v7 fitpanel: correctly handle fit function parameters

Convert them into string on client side and check afterwards if
parameter was changed when apply back to server
---
 gui/fitpanelv7/src/RFitPanel6.cxx             | 11 +++---
 .../controller/FitPanel.controller.js         | 39 ++++++++++++++++---
 2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/gui/fitpanelv7/src/RFitPanel6.cxx b/gui/fitpanelv7/src/RFitPanel6.cxx
index fbcb50f0965..aeb50ff066d 100644
--- a/gui/fitpanelv7/src/RFitPanel6.cxx
+++ b/gui/fitpanelv7/src/RFitPanel6.cxx
@@ -334,14 +334,13 @@ void ROOT::Experimental::RFitPanel6::ProcessData(unsigned connid, const std::str
             printf("Found func1 %s %p %d %d\n", info->name.c_str(), func, func->GetNpar(), (int) info->pars.size());
             // copy all parameters back to the function
             for (int n=0;n<func->GetNpar();++n) {
-              //func->SetParLimits(n, info->pars.min, info->pars.max);
-              // func->SetParameter(n, info->pars.value);
-              //func->SetParName(n, info->pars.name.c_str());
-              // func->SetParError(n, info->pars.error);
-
+               func->SetParameter(n, info->pars[n].value);
+               func->SetParError(n, info->pars[n].error);
+               func->SetParLimits(n, info->pars[n].min, info->pars[n].max);
+               if (info->pars[n].fixed)
+                  func->FixParameter(n, info->pars[n].value);
              }
           }
-
       }
    }
 }
diff --git a/ui5/fitpanel/controller/FitPanel.controller.js b/ui5/fitpanel/controller/FitPanel.controller.js
index a8f07206d20..a8b98e2eae0 100644
--- a/ui5/fitpanel/controller/FitPanel.controller.js
+++ b/ui5/fitpanel/controller/FitPanel.controller.js
@@ -173,6 +173,17 @@ sap.ui.define([
 
       closeParametersDialog: function(is_ok) {
          if (is_ok && this.parData) {
+            // first convert back to float values
+
+            for (var i=0;i<this.parData.pars.length;++i) {
+               var par = this.parData.pars[i];
+               // convert value into floats back
+               this.toFloat(par, "value");
+               this.toFloat(par, "error");
+               this.toFloat(par, "min");
+               this.toFloat(par, "max");
+            }
+
             var json = JSROOT.toJSON(this.parData);
             if (this.websocket)
                this.websocket.Send("SETPARS:" + json);
@@ -192,6 +203,20 @@ sap.ui.define([
             this.websocket.Send(msg);
       },
 
+      toString: function(par, field, digits) {
+         if (par[field] == Math.round(par[field])) digits = 0;
+         par[field+"Txt"] = par[field+"Txt0"] = par[field].toFixed(digits);
+      },
+
+      toFloat: function(par, field) {
+         if (par[field+"Txt"] !== par[field+"Txt0"]) {
+            var res = parseFloat(par[field+"Txt"]);
+            if (!isNaN(res)) par[field] = res;
+         }
+         delete par[field+"Txt"];
+         delete par[field+"Txt0"];
+      },
+
       showParametersDialog: function(data){
 
          var aData = { Data: data.pars };
@@ -201,7 +226,11 @@ sap.ui.define([
          // prepare text formatting
          for (var i=0;i<data.pars.length;++i) {
             var par = data.pars[i];
-            console.log(par.name, par.value, par.error, par.min, par.max);
+            // convert value into strings, requird by sap.m.Input
+            this.toString(par, "value", 3);
+            this.toString(par, "error", 3);
+            this.toString(par, "min", 3);
+            this.toString(par, "max", 3);
          }
 
          var oModel = new sap.ui.model.json.JSONModel(aData);
@@ -211,10 +240,10 @@ sap.ui.define([
               new mLabel({ text: "{name}" }),
               new mCheckBox({ selected: "{fixed}" }),
               new mCheckBox({ selected: "{Bound}" }),
-              new mInput({ value: "{value}", type: "Number", width: "50px" }),
-              new mInput({ value: "{min}", type: "Number", width: "50px" }),
-              new mInput({ value: "{max}", type: "Number", width: "50px" }),
-              new mInput({ value: "{error}" })
+              new mInput({ value: "{valueTxt}", type: "Number", width: "75px" }),
+              new mInput({ value: "{minTxt}", type: "Number", width: "75px" }),
+              new mInput({ value: "{maxTxt}", type: "Number", width: "75px" }),
+              new mInput({ value: "{errorTxt}", type: "Number", width: "75px" })
          ]});
 
          var oTable = new mTable({
-- 
GitLab