[chronojump] ForceSensor show error when stiffness does not match at loading set



commit 87902d14a212501ba61252c496ba913948c56f3d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Oct 25 12:44:07 2019 +0200

    ForceSensor show error when stiffness does not match at loading set

 src/forceSensor.cs     | 16 ++++++++++++++--
 src/gui/forceSensor.cs | 15 +++++++++++----
 2 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index ffe16ea2..aa242e0d 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -525,11 +525,18 @@ public class ForceSensorElasticBand
                return str;
        }
 
-       //stiffnessString is the string of a loaded set
-       public static void UpdateBandsStatusToSqlite (List<ForceSensorElasticBand> list_at_db, string 
stiffnessString)
+       /*
+        * stiffnessString is the string of a loaded set
+        * stiffnessToBeReached is the double of stiffness of a loaded set
+        * processing them have to match if there are no deletions of elastic bands or their values have been 
changed
+        *
+        * return if stiffnessString with current elastic bands on SQL can achieve deired stiffness
+        */
+       public static bool UpdateBandsStatusToSqlite (List<ForceSensorElasticBand> list_at_db, string 
stiffnessString, double stiffnessToBeReached)
        {
                List<ForceSensorElasticBand> list_to_db = new List<ForceSensorElasticBand>();
 
+               double stiffnessAcumulated = 0;
                foreach(ForceSensorElasticBand fseb in list_at_db)
                {
                        string [] strAll = stiffnessString.Split(new char[] {';'});
@@ -543,6 +550,8 @@ public class ForceSensorElasticBand
                                                Util.IsNumber(strBandWithMult[1], false) && 
Convert.ToInt32(strBandWithMult[0]) == fseb.UniqueID)
                                {
                                        fsebNew.active = Convert.ToInt32(strBandWithMult[1]);
+                                       stiffnessAcumulated += fsebNew.active * fsebNew.Stiffness;
+
                                        list_to_db.Add(fsebNew);
                                        found = true;
                                        break;
@@ -556,6 +565,9 @@ public class ForceSensorElasticBand
 
                }
                SqliteForceSensorElasticBand.UpdateList(false, list_to_db);
+
+               //LogB.Information(string.Format("stiffness match: {0}, {1}", stiffnessAcumulated, 
stiffnessToBeReached));
+               return Util.SimilarDouble(stiffnessAcumulated, stiffnessToBeReached);
        }
 
        public int UniqueID
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index df20fe0e..e5a6f04e 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -1539,15 +1539,22 @@ LogB.Information(" fs R ");
                {
                        setStiffnessButtonLabel(fs.Stiffness);
                        button_force_sensor_stiffness.Visible = true;
+
+                       // stiffness 2: update elastic bands table
+                       if(! ForceSensorElasticBand.UpdateBandsStatusToSqlite (
+                                               SqliteForceSensorElasticBand.SelectAll(false, false), 
fs.StiffnessString, fs.Stiffness) )
+                       {
+                               //TODO: improve this message and apply any needed change on 
ForceSensorElasticBandsWindow
+                               //when is definitive mark to be translated with Catalog
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               "Loaded set used elastic bands that does not exist on the 
database or have been changed." + "\n" +
+                                               "Stiffness calculation is ok but stiffness configuration 
window will not be able to match elastic bands and total stiffness.");
+                       }
                } else
                {
                        button_force_sensor_stiffness.Label = "0";
                        button_force_sensor_stiffness.Visible = false;
                }
-               // stiffness 2: update elastic bands table
-               ForceSensorElasticBand.UpdateBandsStatusToSqlite (
-                               SqliteForceSensorElasticBand.SelectAll(false, false), fs.StiffnessString);
-
 
                forceSensorCopyTempAndDoGraphs();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]