[chronojump] Force sensor implemented load window



commit c3f7317b309be2599b9997839d26fff2cd67dc53
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Sep 6 16:32:27 2019 +0200

    Force sensor implemented load window

 src/forceSensor.cs        | 22 ++++++++++++++++-
 src/gui/forceSensor.cs    | 63 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/sqlite/forceSensor.cs | 61 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 143 insertions(+), 3 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 029f73d1..ae745a2f 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -40,9 +40,11 @@ public class ForceSensor
        private string comments;
        private string videoURL;
 
+       private string exerciseName;
+
        //constructor
        public ForceSensor(int uniqueID, int personID, int sessionID, int exerciseID, int angle,
-                       string laterality, string filename, string url, string dateTime, string comments, 
string videoURL)
+                       string laterality, string filename, string url, string dateTime, string comments, 
string videoURL, string exerciseName)
        {
                this.uniqueID = uniqueID;
                this.personID = personID;
@@ -55,6 +57,8 @@ public class ForceSensor
                this.dateTime = dateTime;
                this.comments = comments;
                this.videoURL = videoURL;
+
+               this.exerciseName = exerciseName;
        }
 
        public void InsertSQL(bool dbconOpened)
@@ -74,6 +78,22 @@ public class ForceSensor
                        comments + "\", \"" + videoURL + "\")";
        }
 
+       public string [] ToStringArray (int count)
+       {
+               int all = 7;
+               string [] str = new String [all];
+               int i=0;
+               str[i++] = uniqueID.ToString();
+               str[i++] = count.ToString();
+               str[i++] = exerciseName;
+               str[i++] = Catalog.GetString(laterality);
+               str[i++] = dateTime;
+               str[i++] = videoURL;
+               str[i++] = comments;
+
+               return str;
+       }
+
        //static methods
        public static double ForceWithCaptureOptionsAndBW (double force, CaptureOptions fsco, int 
percentBodyWeight, double personWeight)
        {
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index b0427266..c894f4c3 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -898,7 +898,8 @@ public partial class ChronoJumpWindow
                                currentForceSensorExercise.UniqueID, ForceSensor.AngleUndefined, 
getLaterality(false),
                                Util.GetLastPartOfPath(fileName), //filename
                                Util.MakeURLrelative(Util.GetForceSensorSessionDir(currentSession.UniqueID)), 
//url
-                               UtilDate.ToFile(forceSensorTimeStartCapture), captureComment, ""); 
//dateTime, comment, videoURL
+                               UtilDate.ToFile(forceSensorTimeStartCapture), captureComment, "", //dateTime, 
comment, videoURL
+                               currentForceSensorExercise.Name);
                forceSensor.InsertSQL(false);
 
                if(forceProcessCancel || forceProcessError)
@@ -1223,6 +1224,65 @@ LogB.Information(" re R ");
                force_capture_allocationXOld = allocation.Width;
        }
 
+       //this is called when user clicks on load signal
+       private void on_button_force_sensor_load_clicked (object o, EventArgs args)
+       {
+               ArrayList data = SqliteForceSensor.Select(false, -1, currentPerson.UniqueID, 
currentSession.UniqueID);
+
+               ArrayList dataPrint = new ArrayList();
+               int count = 1;
+               foreach(ForceSensor fs in data)
+                       dataPrint.Add(fs.ToStringArray(count++));
+
+               string [] columnsString = {
+                       Catalog.GetString("ID"),
+                       Catalog.GetString("Set"),
+                       Catalog.GetString("Exercise"),
+                       Catalog.GetString("Laterality"),
+                       Catalog.GetString("Date"),
+                       Catalog.GetString("Video"),
+                       Catalog.GetString("Comment")
+               };
+
+               ArrayList bigArray = new ArrayList();
+               ArrayList a1 = new ArrayList();
+               ArrayList a2 = new ArrayList();
+               //0 is the widgget to show; 1 is the editable; 2 id default value
+               a1.Add(Constants.GenericWindowShow.TREEVIEW); a1.Add(true); a1.Add("");
+               bigArray.Add(a1);
+
+               a2.Add(Constants.GenericWindowShow.COMBO); a2.Add(true); a2.Add("");
+               bigArray.Add(a2);
+
+               genericWin = GenericWindow.Show(Catalog.GetString("Load"), false,       //don't show now
+                               string.Format(Catalog.GetString("Select set of athlete {0} on this session."),
+                                       currentPerson.Name)
+                               //      + "\n" +
+                               //Catalog.GetString("If you want to edit or delete a row, right click on it.")
+                               , bigArray);
+
+               genericWin.SetTreeview(columnsString, false, dataPrint, new ArrayList(), 
Constants.ContextMenu.NONE, true);
+
+               //select row corresponding to current signal
+               //genericWin.SelectRowWithID(0, myEncoderSignalUniqueID); //colNum, id
+
+               genericWin.ShowButtonCancel(true);
+               genericWin.SetButtonAcceptLabel(Catalog.GetString("Load"));
+               genericWin.SetButtonCancelLabel(Catalog.GetString("Close"));
+               genericWin.SetButtonAcceptSensitive(false);
+               genericWin.Button_accept.Clicked += new EventHandler(on_force_sensor_load_signal_accepted);
+
+               genericWin.ShowNow();
+       }
+
+       private void on_force_sensor_load_signal_accepted (object o, EventArgs args)
+       {
+               new DialogMessage(Constants.MessageTypes.INFO, "TODO");
+       }
+
+       /*
+        * OLD: load file
+        * now using above methods that load from SQL
        private void on_button_force_sensor_load_clicked (object o, EventArgs args)
        {
                if (currentSession == null)
@@ -1286,6 +1346,7 @@ LogB.Information(" re R ");
                }
                filechooser.Destroy ();
        }
+       */
 
        private void on_button_force_sensor_capture_recalculate_clicked (object o, EventArgs args)
        {
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index b34d3baf..680c66ae 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -74,6 +74,63 @@ class SqliteForceSensor : Sqlite
                        Sqlite.Close();
        }
 
+       //SELECT forceSensor.*, forceSensorExercise.Name FROM forceSensor, forceSensorExercise WHERE 
forceSensor.exerciseID = forceSensorExercise.UniqueID ORDER BY forceSensor.uniqueID;
+       public static ArrayList Select (bool dbconOpened, int uniqueID, int personID, int sessionID)
+       {
+               if(! dbconOpened)
+                       Sqlite.Open();
+
+               string selectStr = "SELECT " + table + ".*, " + Constants.ForceSensorExerciseTable + ".Name 
FROM " + table + ", " + Constants.ForceSensorExerciseTable;
+               string whereStr = " WHERE " + table + ".exerciseID = " + Constants.ForceSensorExerciseTable + 
".UniqueID ";
+
+               string uniqueIDStr = "";
+               if(uniqueID != -1)
+                       uniqueIDStr = " AND " + table + ".uniqueID = " + uniqueID;
+
+               string personIDStr = "";
+               if(personID != -1)
+                       personIDStr = " AND " + table + ".personID = " + personID;
+
+               string sessionIDStr = "";
+               if(sessionID != -1)
+                       sessionIDStr = " AND " + table + ".sessionID = " + sessionID;
+
+               dbcmd.CommandText = selectStr + whereStr + uniqueIDStr + personIDStr + sessionIDStr + " Order 
BY " + table + ".uniqueID";
+
+               LogB.SQL(dbcmd.CommandText.ToString());
+               dbcmd.ExecuteNonQuery();
+
+               SqliteDataReader reader;
+               reader = dbcmd.ExecuteReader();
+
+               ArrayList array = new ArrayList(1);
+               ForceSensor fs;
+
+               while(reader.Read()) {
+                       fs = new ForceSensor (
+                                       Convert.ToInt32(reader[0].ToString()),  //uniqueID
+                                       Convert.ToInt32(reader[1].ToString()),  //personID
+                                       Convert.ToInt32(reader[2].ToString()),  //sessionID
+                                       Convert.ToInt32(reader[3].ToString()),  //exerciseID
+                                       Convert.ToInt32(reader[4].ToString()),  //angle
+                                       reader[5].ToString(),                   //laterality
+                                       reader[6].ToString(),                   //filename
+                                       reader[7].ToString(),                   //url
+                                       reader[8].ToString(),                   //datetime
+                                       reader[9].ToString(),                   //comments
+                                       reader[10].ToString(),                  //videoURL
+                                       reader[11].ToString()                   //exerciseName
+                                       );
+                       array.Add(fs);
+               }
+
+               reader.Close();
+               if(! dbconOpened)
+                       Sqlite.Close();
+
+               return array;
+       }
+
        protected internal static void import_from_1_68_to_1_69() //database is opened
        {
                LogB.PrintAllThreads = true; //TODO: remove this
@@ -105,6 +162,7 @@ class SqliteForceSensor : Sqlite
                                //"person name_2017-11-11_19-35-55.csv"
                                //if cannot found exercise, assign to Unknown
                                int exerciseID = -1;
+                               string exerciseName = fslt.Exercise;
                                if(fslt.Exercise != "")
                                        exerciseID = ExistsAndGetUniqueID(true, 
Constants.ForceSensorExerciseTable, fslt.Exercise);
 
@@ -114,6 +172,7 @@ class SqliteForceSensor : Sqlite
                                                unknownExerciseID = SqliteForceSensorExercise.Insert (true, 
-1, Catalog.GetString("Unknown"), 0, "", 0, "", false);
 
                                        exerciseID = unknownExerciseID;
+                                       exerciseName = Catalog.GetString("Unknown");
                                }
 
                                //laterality (in English)
@@ -134,7 +193,7 @@ class SqliteForceSensor : Sqlite
                                                //file.Name,
                                                p.UniqueID + "_" + p.Name + "_" + parsedDate, //filename
                                                
Util.MakeURLrelative(Util.GetForceSensorSessionDir(Convert.ToInt32(session.Name))), //laterality, filename, 
url
-                                               parsedDate, fslt.Comment, "");
+                                               parsedDate, fslt.Comment, "", exerciseName);
                                forceSensor.InsertSQL(true);
                        }
                }


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