[chronojump] Implemented force sensor edit/delete exercises



commit 6ad731e853be6636a29e0196846f1d90a3d859e1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Dec 10 21:41:50 2018 +0100

    Implemented force sensor edit/delete exercises

 glade/app1.glade           |  26 +++++++++-
 src/forceSensor.cs         |  23 +++++++-
 src/gui/chronojumpIcons.cs |   2 +
 src/gui/encoder.cs         |   6 +--
 src/gui/forceSensor.cs     | 127 +++++++++++++++++++++++++++++++++++++++------
 src/gui/genericWindow.cs   |   5 +-
 src/sqlite/forceSensor.cs  |  28 +++++++++-
 7 files changed, 191 insertions(+), 26 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 4b503f13..eb46a28e 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -5307,6 +5307,29 @@ EncoderInertialCapture</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">8</property>
                                                             <child>
+                                                            <widget class="GtkButton" 
id="button_force_sensor_exercise_edit">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <property name="has_tooltip">True</property>
+                                                            <property name="tooltip" translatable="yes">Edit 
exercise type</property>
+                                                            <signal name="clicked" 
handler="on_button_force_sensor_exercise_edit_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_force_sensor_exercise_edit">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-new</property>
+                                                            <property name="icon-size">2</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkButton" 
id="button_force_sensor_exercise_add">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
@@ -5326,7 +5349,7 @@ EncoderInertialCapture</property>
                                                             <packing>
                                                             <property name="expand">False</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">0</property>
+                                                            <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
@@ -21881,7 +21904,6 @@ Concentric</property>
                                                             <widget class="GtkHBox" 
id="hbox_combo_encoder_exercise_capture">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property name="tooltip" 
translatable="yes">Exercise</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index cf900820..befeb343 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -51,15 +51,36 @@ public class ForceSensorExercise
                this.description = description;
        }
 
+       public override string ToString()
+       {
+               return uniqueID.ToString() + ":" + name + ":" + percentBodyWeight.ToString() + ":" +
+                       resistance + ":" + angleDefault.ToString() + ":" + description;
+       }
+
        public int UniqueID
        {
                get { return uniqueID; }
        }
-
        public string Name
        {
                get { return name; }
        }
+       public int PercentBodyWeight
+       {
+               get { return percentBodyWeight; }
+       }
+       public string Resistance
+       {
+               get { return resistance; }
+       }
+       public int AngleDefault
+       {
+               get { return angleDefault; }
+       }
+       public string Description
+       {
+               get { return description; }
+       }
 }
 
 /*
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index 310f734b..9810e983 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -140,6 +140,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_force_sensor_analyze_options;
        [Widget] Gtk.Image image_force_sensor_analyze_options_close;
        [Widget] Gtk.Image image_force_sensor_analyze_recalculate;
+       [Widget] Gtk.Image image_force_sensor_exercise_edit;
 
        //video play icons
        [Widget] Gtk.Image image_video_play_this_test;
@@ -322,6 +323,7 @@ public partial class ChronoJumpWindow
                image_encoder_exercise_add.Pixbuf = pixbuf;
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_edit.png");
                image_encoder_exercise_edit.Pixbuf = pixbuf;
+               image_force_sensor_exercise_edit.Pixbuf = pixbuf;
                image_edit_current_person.Pixbuf = pixbuf;
                image_edit_current_person_h.Pixbuf = pixbuf;
                image_session_edit.Pixbuf = pixbuf;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 33906244..73feddfb 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -4549,7 +4549,7 @@ public partial class ChronoJumpWindow
        
        void on_button_encoder_exercise_edit_accepted (object o, EventArgs args)
        {
-               if(encoder_exercise_edit(false))
+               if(encoder_exercise_do_add_or_edit(false))
                {
                        genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_edit_accepted);
                        genericWin.HideAndNull();
@@ -4557,14 +4557,14 @@ public partial class ChronoJumpWindow
        }
        void on_button_encoder_exercise_add_accepted (object o, EventArgs args)
        {
-               if(encoder_exercise_edit(true))
+               if(encoder_exercise_do_add_or_edit(true))
                {
                        genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_encoder_exercise_add_accepted);
                        genericWin.HideAndNull();
                }
        }
                        
-       bool encoder_exercise_edit (bool adding)
+       bool encoder_exercise_do_add_or_edit (bool adding)
        {
                string name = Util.RemoveTildeAndColonAndDot(genericWin.EntrySelected);
                name = Util.RemoveChar(name, '"');
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 0599f6db..99eeeed4 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -1492,17 +1492,16 @@ LogB.Information(" re R ");
                //force_sensor_exercise
 
                combo_force_sensor_exercise = ComboBox.NewText ();
-               fillForceSensorExerciseCombo();
+               fillForceSensorExerciseCombo("");
 
 //             combo_force_sensor_exercise.Changed += new EventHandler 
(on_combo_force_sensor_exercise_changed);
                hbox_combo_force_sensor_exercise.PackStart(combo_force_sensor_exercise, true, true, 0);
                hbox_combo_force_sensor_exercise.ShowAll();
        }
 
-       //TODO: implement this with id:name like exerciseNameTranslated but without translation
-       private void fillForceSensorExerciseCombo()
+       private void fillForceSensorExerciseCombo(string name)
        {
-               ArrayList forceSensorExercises = SqliteForceSensorExercise.Select (false, -1, true);
+               ArrayList forceSensorExercises = SqliteForceSensorExercise.Select (false, -1, false);
                if(forceSensorExercises.Count == 0)
                {
                        forceSensorComboExercisesString = new String [0];
@@ -1520,7 +1519,10 @@ LogB.Information(" re R ");
                }
 
                UtilGtk.ComboUpdate(combo_force_sensor_exercise, exerciseNamesToCombo, "");
-               combo_force_sensor_exercise.Active = 0;
+               if(name == "")
+                       combo_force_sensor_exercise.Active = 0;
+               else
+                       combo_force_sensor_exercise.Active = 
UtilGtk.ComboMakeActive(combo_force_sensor_exercise, name);
        }
 
        //info is now info and edit (all values can be changed), and detete (there's delete button)
@@ -1532,7 +1534,57 @@ LogB.Information(" re R ");
                        return;
                }
 
-               //TODO
+               ForceSensorExercise ex = (ForceSensorExercise) SqliteForceSensorExercise.Select (
+                                false, getExerciseIDFromAnyCombo(combo_force_sensor_exercise, 
forceSensorComboExercisesString, false), false)[0];
+
+               LogB.Information("selected exercise: " + ex.ToString());
+
+               ArrayList bigArray = new ArrayList();
+
+               ArrayList a1 = new ArrayList();
+               ArrayList a2 = new ArrayList();
+               ArrayList a3 = new ArrayList();
+               ArrayList a4 = new ArrayList();
+               //ArrayList a5 = new ArrayList();
+
+               //0 is the widgget to show; 1 is the editable; 2 id default value
+               a1.Add(Constants.GenericWindowShow.ENTRY); a1.Add(true); a1.Add(ex.Name); //name can be 
changed (opposite to encoder), because we use always the uniqueID
+               bigArray.Add(a1);
+
+               a2.Add(Constants.GenericWindowShow.SPININT); a2.Add(true); a2.Add("");
+               bigArray.Add(a2);
+
+               a3.Add(Constants.GenericWindowShow.ENTRY2); a3.Add(true); a3.Add(ex.Resistance);
+               bigArray.Add(a3);
+
+               a4.Add(Constants.GenericWindowShow.ENTRY3); a4.Add(true); a4.Add(ex.Description);
+               bigArray.Add(a4);
+
+               //a5.Add(Constants.GenericWindowShow.SPININT2); a5.Add(true); a5.Add(ex.AngleDefault);
+               //bigArray.Add(a5);
+
+
+               genericWin = GenericWindow.Show(Catalog.GetString("Exercise"), false,   //don't show now
+                               Catalog.GetString("Force sensor exercise:"), bigArray);
+               genericWin.LabelSpinInt = Catalog.GetString("Involved body weight") + " (%)";
+               genericWin.SetSpinRange(0, 100);
+               genericWin.SetSpinValue(ex.PercentBodyWeight);
+
+               genericWin.LabelEntry2 = Catalog.GetString("Resistance");
+               genericWin.LabelEntry3 = Catalog.GetString("Description");
+               //genericWin.LabelSpinInt2 = Catalog.GetString("Default angle");
+               //genericWin.SetSpin2Range(0,180);
+
+               genericWin.ShowButtonCancel(false);
+
+               genericWin.ShowButtonDelete(true);
+               genericWin.Button_delete.Clicked += new EventHandler(on_button_force_sensor_exercise_delete);
+
+               genericWin.nameUntranslated = ex.Name;
+               genericWin.uniqueID = ex.UniqueID;
+
+               genericWin.Button_accept.Clicked += new 
EventHandler(on_button_force_sensor_exercise_edit_accepted);
+               genericWin.ShowNow();
        }
 
        private void on_button_force_sensor_exercise_add_clicked (object o, EventArgs args)
@@ -1579,35 +1631,58 @@ LogB.Information(" re R ");
                genericWin.ShowNow();
        }
 
+       void on_button_force_sensor_exercise_edit_accepted (object o, EventArgs args)
+       {
+               if(force_sensor_exercise_do_add_or_edit(false))
+               {
+                       genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_force_sensor_exercise_edit_accepted);
+                       genericWin.HideAndNull();
+               }
+       }
        void on_button_force_sensor_exercise_add_accepted (object o, EventArgs args)
        {
-               if(force_sensor_exercise_add())
+               if(force_sensor_exercise_do_add_or_edit(true))
                {
                        genericWin.Button_accept.Clicked -= new 
EventHandler(on_button_force_sensor_exercise_add_accepted);
                        genericWin.HideAndNull();
                }
        }
 
-       bool force_sensor_exercise_add ()
+       bool force_sensor_exercise_do_add_or_edit (bool adding)
        {
                string name = Util.RemoveTildeAndColonAndDot(genericWin.EntrySelected);
                name = Util.RemoveChar(name, '"');
 
-               LogB.Information("force_sensor_exercise_add - Trying to insert: " + name);
+               if(adding)
+                       LogB.Information("force_sensor_exercise_do - Trying to insert: " + name);
+               else
+                       LogB.Information("force_sensor_exercise_do - Trying to edit: " + name);
 
                if(name == "")
                        genericWin.SetLabelError(Catalog.GetString("Error: Missing name of exercise."));
-               else if (Sqlite.Exists(false, Constants.ForceSensorExerciseTable, name))
+               else if (adding && Sqlite.Exists(false, Constants.ForceSensorExerciseTable, name))
                        genericWin.SetLabelError(string.Format(Catalog.GetString(
                                                        "Error: An exercise named '{0}' already exists."), 
name));
                else {
-                       SqliteForceSensorExercise.Insert(false, -1, name, genericWin.SpinIntSelected,
-                                       genericWin.Entry2Selected,
-                                       genericWin.SpinInt2Selected,
-                                       genericWin.Entry3Selected
-                                       );
+                       if(adding)
+                               SqliteForceSensorExercise.Insert(false, -1, name, genericWin.SpinIntSelected,
+                                               genericWin.Entry2Selected,
+                                               genericWin.SpinInt2Selected,
+                                               genericWin.Entry3Selected
+                                               );
+                       else {
+                               ForceSensorExercise ex = new ForceSensorExercise(
+                                               genericWin.uniqueID,
+                                               name,
+                                               genericWin.SpinIntSelected,
+                                               genericWin.Entry2Selected,
+                                               genericWin.SpinInt2Selected,
+                                               genericWin.Entry3Selected
+                                               );
+                               SqliteForceSensorExercise.Update(false, ex);
+                       }
 
-                       fillForceSensorExerciseCombo();
+                       fillForceSensorExerciseCombo(name);
 
                        LogB.Information("done");
                        return true;
@@ -1616,6 +1691,26 @@ LogB.Information(" re R ");
                return false;
        }
 
+       void on_button_force_sensor_exercise_delete (object o, EventArgs args)
+       {
+               ForceSensorExercise ex = (ForceSensorExercise) SqliteForceSensorExercise.Select(
+                               false, genericWin.uniqueID, false)[0];
+
+               //TODO: when forceSensor records get in database, ensure to delete them if exercise is deleted
+               //see: on_button_encoder_exercise_delete
+
+               //delete exercise
+               Sqlite.Delete(false, Constants.ForceSensorExerciseTable, genericWin.uniqueID);
+
+               genericWin.HideAndNull();
+
+               fillForceSensorExerciseCombo("");
+               combo_force_sensor_exercise.Active = 0;
+
+               new DialogMessage(Constants.MessageTypes.INFO, Catalog.GetString("Exercise deleted."));
+       }
+
+
        // -------------------------------- end of exercise stuff --------------------
 
        // ------------------------------------------------ slides stuff for presentations
diff --git a/src/gui/genericWindow.cs b/src/gui/genericWindow.cs
index 5fce578f..96bb39f6 100644
--- a/src/gui/genericWindow.cs
+++ b/src/gui/genericWindow.cs
@@ -109,9 +109,8 @@ public class GenericWindow
        public int TreeviewSelectedUniqueID;
        private int commentColumn;
 
-       //used on encoder edit exercise
-       public int uniqueID;
-       public string nameUntranslated;
+       public int uniqueID;                    //used on encoder & forceSensor edit exercise
+       public string nameUntranslated;         //used on encoder edit exercise
 
        public enum Types { UNDEFINED, ENCODER_SESSION_LOAD, 
                ENCODER_SEL_REPS_IND_CURRENT_SESS, ENCODER_SEL_REPS_IND_ALL_SESS, 
ENCODER_SEL_REPS_GROUP_CURRENT_SESS };
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 17403ebe..50e17666 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -73,6 +73,32 @@ class SqliteForceSensorExercise : Sqlite
                        Sqlite.Close();
        }
 
+       public static void Update (bool dbconOpened, ForceSensorExercise ex)
+       {
+               if(! dbconOpened)
+                       Sqlite.Open();
+
+               /*
+                  string uniqueIDStr = "NULL";
+                  if(ex.UniqueID != -1)
+                          uniqueIDStr = ex.UniqueID.ToString();
+                  */
+
+               dbcmd.CommandText = "UPDATE " + table + " SET " +
+                       " name = \"" + ex.Name +
+                       "\", percentBodyWeight = " + ex.PercentBodyWeight +
+                       ", resistance = \"" + ex.Resistance +
+                       "\", angleDefault = " + ex.AngleDefault +
+                       ", description = \"" + ex.Description +
+                       "\" WHERE uniqueID = " + ex.UniqueID;
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               if(! dbconOpened)
+                       Sqlite.Close();
+       }
+
        public static ArrayList Select (bool dbconOpened, int uniqueID, bool onlyNames)
        {
                if(! dbconOpened)
@@ -111,7 +137,7 @@ class SqliteForceSensorExercise : Sqlite
                                                Convert.ToInt32(reader[2].ToString()),  //percentBodyWeight
                                                reader[3].ToString(),                   //resistance
                                                angleDefault,
-                                               reader[4].ToString()                    //description
+                                               reader[5].ToString()                    //description
                                                );
                                array.Add(ex);
                        }


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