[chronojump] forceSensor is stored on data folder and data can be opened



commit 00ca8668821e9353959983904d8e68d47aec0e5b
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 5 13:01:28 2017 +0200

    forceSensor is stored on data folder and data can be opened

 glade/app1.glade       |   18 ++++++++++++++++++
 src/chronojump.cs      |    2 ++
 src/gui/forceSensor.cs |   23 ++++++++++++++++++++---
 src/util.cs            |   39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 3 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index b6a9581..82c79a0 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -4340,6 +4340,21 @@ Carles</property>
                                                             <property name="position">2</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_force_sensor_data_folder">
+                                                            <property name="label" translatable="yes">Open 
data folder</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_force_sensor_data_folder_clicked" swapped="no"/>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="padding">20</property>
+                                                            <property name="position">3</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                           </widget>
@@ -19827,6 +19842,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 2e3d4e1..c899094 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -255,6 +255,8 @@ public class ChronoJump
                Util.CreateMultimediaDirsIfNeeded();
                //to store encoder data and graphs
                UtilEncoder.CreateEncoderDirIfNeeded();
+               //to store force sensor data and graphs
+               Util.CreateForceSensorDirIfNeeded();
 
 //TODO: when a session is deleted, encoder data has to be deleted, also multimedia videos, I suppose. Show 
message to user warning about it
 //TODO: encoder weight auto written depending on person loaded, and changes if it changes person or weight
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 32204cf..794f49f 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -111,9 +111,12 @@ public partial class ChronoJumpWindow
                }
                while(! str.StartsWith("StartedOk"));
 
-               str = "";
-               string fileName = "/tmp/force_" + currentPerson.Name + "_" + UtilDate.ToFile(DateTime.Now) + 
".txt"; //TODO: hardcoded
+               Util.CreateForceSensorSessionDirIfNeeded (currentSession.UniqueID);
+               string fileName = Util.GetForceSensorSessionDir(currentSession.UniqueID) + 
Path.DirectorySeparatorChar +
+                       currentPerson.Name + "_" + UtilDate.ToFile(DateTime.Now) + ".txt";
+
                TextWriter writer = File.CreateText(fileName);
+               str = "";
                while(! forceProcessFinish && ! forceProcessCancel)
                {
                        str = port.ReadLine();
@@ -158,6 +161,20 @@ public partial class ChronoJumpWindow
                LogB.Information(" ForceSensor:"+ forceThread.ThreadState.ToString());
                return true;
        }
-       
+
+       private void on_button_force_sensor_data_folder_clicked (object o, EventArgs args)
+       {
+               System.IO.DirectoryInfo folderSession =
+                       new System.IO.DirectoryInfo(Util.GetForceSensorSessionDir(currentSession.UniqueID));
+               System.IO.DirectoryInfo folderGeneric =
+                       new System.IO.DirectoryInfo(Util.GetForceSensorDir());
+
+               if(folderSession.Exists)
+                       
System.Diagnostics.Process.Start(Util.GetForceSensorSessionDir(currentSession.UniqueID));
+               else if(folderGeneric.Exists)
+                       System.Diagnostics.Process.Start(Util.GetForceSensorDir());
+               else
+                       new DialogMessage(Constants.MessageTypes.WARNING, Constants.DirectoryCannotOpen);
+       }
 }
 
diff --git a/src/util.cs b/src/util.cs
index f5abc8d..e2cf55c 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -874,6 +874,45 @@ public class Util
                }
        }
        
+       /*
+        * force sensor suff ------------------>
+        */
+
+       //to store force sensor data and graphs
+       public static string GetForceSensorDir()
+       {
+               return Path.Combine(
+                               Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+                               "Chronojump" + Path.DirectorySeparatorChar + "forceSensor");
+       }
+       public static void CreateForceSensorDirIfNeeded ()
+       {
+               string dir = GetForceSensorDir();
+               if( ! Directory.Exists(dir)) {
+                       Directory.CreateDirectory (dir);
+                       LogB.Information ("created dir:", dir);
+               }
+       }
+
+       //forceSensor organized by sessions.
+       public static string GetForceSensorSessionDir (int sessionID)
+       {
+               return GetForceSensorDir() + Path.DirectorySeparatorChar + sessionID.ToString();
+       }
+       public static void CreateForceSensorSessionDirIfNeeded (int sessionID)
+       {
+               string dir = GetForceSensorSessionDir(sessionID);
+               if( ! Directory.Exists(dir)) {
+                       Directory.CreateDirectory (dir);
+                       LogB.Information ("created dir:", dir);
+               }
+       }
+
+       /*
+        * <--------------- end of force sensor suff
+        */
+
+
        //videos ar organized by sessions. Photos no.   
        public static string GetVideoSessionDir (int sessionID) {
                return GetVideosDir() + Path.DirectorySeparatorChar + sessionID.ToString();


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