[chronojump] force sensor images can be saved



commit b8a1dbda5619359c9c5e05a17d38aa07689c8287
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Oct 20 11:38:10 2017 +0200

    force sensor images can be saved

 glade/app1.glade           |   91 +++++++++++++++++++++++++++++++++++++++++++-
 po/POTFILES.in             |    1 +
 src/constants.cs           |    6 ++-
 src/gui/chronojump.cs      |    2 +
 src/gui/chronojumpIcons.cs |    1 +
 src/gui/encoder.cs         |   71 +++++++++++++++++++++-------------
 src/gui/forceSensor.cs     |   34 ++++++++++++++++-
 src/util.cs                |   10 ++++-
 src/utilEncoder.cs         |    3 +
 9 files changed, 188 insertions(+), 31 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 16a5b7f..be3a7a5 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1387,6 +1387,15 @@
                                                             <placeholder/>
                                                             </child>
                                                             <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkLabel" 
id="label_start_selector_jumps">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -10839,7 +10848,7 @@ after time</property>
                                                             <widget class="GtkVBox" id="vbox79">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property name="border_width">10</property>
+                                                            <property name="border_width">8</property>
                                                             <property name="spacing">10</property>
                                                             <child>
                                                             <widget class="GtkHBox" id="hbox207">
@@ -11023,11 +11032,17 @@ after time</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkHBox" id="hbox182">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">6</property>
+                                                            <child>
                                                             <widget class="GtkScrolledWindow" 
id="scrolledwindow5">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="hscrollbar_policy">automatic</property>
                                                             <property 
name="vscrollbar_policy">automatic</property>
+                                                            <property name="shadow_type">in</property>
                                                             <child>
                                                             <widget class="GtkViewport" 
id="viewport_force_sensor_graph">
                                                             <property name="visible">True</property>
@@ -11046,6 +11061,71 @@ after time</property>
                                                             <packing>
                                                             <property name="expand">True</property>
                                                             <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox109">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_force_sensor_image_save">
+                                                            <property name="visible">True</property>
+                                                            <property name="sensitive">False</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <property name="tooltip" translatable="yes">Save 
image</property>
+                                                            <signal name="clicked" 
handler="on_button_force_sensor_image_save_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox108">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_forcesensor_analyze_image_save">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_forcesensor_analyze_image_save2">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-save</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">2</property>
                                                             </packing>
                                                             </child>
@@ -21509,6 +21589,15 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e307a6d..2ffc97a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -76,6 +76,7 @@ src/gui/evaluator.cs
 src/gui/event.cs
 src/gui/eventExecute.cs
 src/gui/executeAuto.cs
+src/gui/forceSensor.cs
 src/gui/genericWindow.cs
 src/gui/helpPorts.cs
 src/gui/jump.cs
diff --git a/src/constants.cs b/src/constants.cs
index ee9de8a..8da0b2f 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -789,7 +789,11 @@ public class Constants
        //public static string ConcentricEccentric = "Concentric-eccentric";
 
        public enum EncoderGI {ALL, GRAVITATORY, INERTIAL}
-       public enum EncoderCheckFileOp { CAPTURE_EXPORT_ALL, ANALYZE_SAVE_IMAGE, ANALYZE_SAVE_AB, 
ANALYZE_SAVE_TABLE}
+       public enum CheckFileOp {
+               ENCODER_CAPTURE_EXPORT_ALL, ENCODER_ANALYZE_SAVE_IMAGE,
+               ENCODER_ANALYZE_SAVE_AB, ENCODER_ANALYZE_SAVE_TABLE,
+               FORCESENSOR_SAVE_IMAGE
+       }
 
        public static double EncoderErrorCode = -1;
        
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 58cfc8e..d270668 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -361,6 +361,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_encoder_signal_delete;
        [Widget] Gtk.Image image_encoder_inertial_instructions;
 
+       //forcesensor
+       [Widget] Gtk.Image image_forcesensor_analyze_image_save;
 
        Random rand;
 
diff --git a/src/gui/chronojumpIcons.cs b/src/gui/chronojumpIcons.cs
index 99968eb..99abc30 100644
--- a/src/gui/chronojumpIcons.cs
+++ b/src/gui/chronojumpIcons.cs
@@ -419,6 +419,7 @@ public partial class ChronoJumpWindow
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "gpm-statistics.png");
                image_encoder_analyze_stats.Pixbuf = pixbuf;
                image_encoder_analyze_image_save.Pixbuf = pixbuf;
+               image_forcesensor_analyze_image_save.Pixbuf = pixbuf;
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "stock_delete.png");
                image_encoder_signal_delete.Pixbuf = pixbuf;
        
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index b4bbeea..db7f753 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1834,7 +1834,7 @@ public partial class ChronoJumpWindow
        
        void on_button_encoder_export_all_curves_clicked (object o, EventArgs args) 
        {
-               checkFile(Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL);
+               checkFile(Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL);
        }
 
        // encoder session overview
@@ -1907,26 +1907,38 @@ public partial class ChronoJumpWindow
        }
 
        string exportFileName;  
-       protected void checkFile (Constants.EncoderCheckFileOp checkFileOp)
+       protected void checkFile (Constants.CheckFileOp checkFileOp)
        {
                string exportString = ""; 
-               if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
+               if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL)
                        exportString = Catalog.GetString ("Export set in CSV format");
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE ||
+                       checkFileOp == Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE)
                        exportString = Catalog.GetString ("Save image");
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                        exportString = Catalog.GetString ("Export repetition in CSV format");
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
                        exportString = Catalog.GetString ("Save table");
                
                string nameString = currentPerson.Name + "_" + currentSession.DateShortAsSQL;
-               if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
+
+               //at force sensor we can graph a different person than selected person, so use graph-file 
loaded
+               if(checkFileOp == Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE)
+               {
+                       if(lastForceSensorFile == null || lastForceSensorFile == "")
+                               nameString = "unnamed";
+                       else
+                               nameString = lastForceSensorFile;
+               }
+
+               if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL)
                        nameString += "_encoder_set_export.csv";
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE ||
+                       checkFileOp == Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE)
                        nameString += ".png";
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                        nameString += "_encoder_repetition_export.csv";
-               else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
+               else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
                        nameString += "_encoder_curves_table.csv";
                
                Gtk.FileChooserDialog fc=
@@ -1942,11 +1954,11 @@ public partial class ChronoJumpWindow
                {
                        exportFileName = fc.Filename;
                        //add ".csv" if needed
-                       if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL ||
-                                       checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB ||
-                                       checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
+                       if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL ||
+                                       checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB ||
+                                       checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
                                exportFileName = Util.AddCsvIfNeeded(exportFileName);
-                       else
+                       else //ENCODER_ANALYZE_SAVE_IMAGE, FORCESENSOR_SAVE_IMAGE
                                exportFileName = Util.AddPngIfNeeded(exportFileName);
                        try {
                                if (File.Exists(exportFileName)) {
@@ -1960,33 +1972,38 @@ public partial class ChronoJumpWindow
                                                                "Are you sure you want to overwrite file: "), 
"", 
                                                        exportFileName);
 
-                                       if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
+                                       if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL)
                                                confirmWin.Button_accept.Clicked += 
                                                        new 
EventHandler(on_overwrite_file_export_all_curves_accepted);
-                                       else if(checkFileOp == 
Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
+                                       else if(checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE)
                                                confirmWin.Button_accept.Clicked += 
                                                        new 
EventHandler(on_overwrite_file_encoder_save_image_accepted);
-                                       else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
+                                       else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                                                confirmWin.Button_accept.Clicked += 
                                                        new 
EventHandler(on_overwrite_file_encoder_save_AB_accepted);
-                                       else if(checkFileOp == 
Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
+                                       else if(checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
                                                confirmWin.Button_accept.Clicked += 
                                                        new 
EventHandler(on_overwrite_file_encoder_save_table_accepted);
+                                       else if(checkFileOp == Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE)
+                                               confirmWin.Button_accept.Clicked +=
+                                                       new 
EventHandler(on_overwrite_file_forcesensor_save_image_accepted);
 
                                } else {
-                                       if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL)
+                                       if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL)
                                                on_button_encoder_export_all_curves_file_selected 
(exportFileName);
-                                       else if(checkFileOp == 
Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE)
+                                       else if(checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE)
                                                on_button_encoder_save_image_file_selected (exportFileName);
-                                       else if(checkFileOp == Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
+                                       else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                                                on_button_encoder_save_AB_file_selected (exportFileName);
-                                       else if(checkFileOp == 
Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE)
+                                       else if(checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
                                                on_button_encoder_save_table_file_selected (exportFileName);
+                                       else if(checkFileOp == Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE)
+                                               on_button_forcesensor_save_image_file_selected 
(exportFileName);
 
                                        string myString = string.Format(Catalog.GetString("Saved to {0}"), 
                                                        exportFileName);
-                                       if(checkFileOp == Constants.EncoderCheckFileOp.CAPTURE_EXPORT_ALL ||
-                                                       checkFileOp == 
Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB)
+                                       if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL ||
+                                                       checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                                                myString += 
Constants.GetSpreadsheetString(preferences.CSVExportDecimalSeparator);
                                        new DialogMessage(Constants.MessageTypes.INFO, myString);
                                }
@@ -3739,7 +3756,7 @@ public partial class ChronoJumpWindow
                 * or changing person, loading session, ...
                 */
 
-               checkFile(Constants.EncoderCheckFileOp.ANALYZE_SAVE_IMAGE);
+               checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE);
        }
        void on_button_encoder_save_image_file_selected (string destination)
        {
@@ -3762,7 +3779,7 @@ public partial class ChronoJumpWindow
                 * No problem. Is nice to play with seinsitiveness, but the reading will be from treeview and 
not from file
                 */
 
-               checkFile(Constants.EncoderCheckFileOp.ANALYZE_SAVE_TABLE);
+               checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE);
        }
 
        void on_button_encoder_save_table_file_selected (string destination)
@@ -5993,7 +6010,7 @@ public partial class ChronoJumpWindow
        
        void on_button_encoder_analyze_AB_save_clicked (object o, EventArgs args) 
        {
-               checkFile(Constants.EncoderCheckFileOp.ANALYZE_SAVE_AB);
+               checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB);
        }
 
        public void on_drawingarea_encoder_analyze_instant_expose_event(object o, ExposeEventArgs args)
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 362c486..0badf35 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -26,6 +26,7 @@ using Gtk;
 using Glade;
 using System.Text; //StringBuilder
 using System.Collections.Generic; //List<T>
+using Mono.Unix;
 
 public partial class ChronoJumpWindow 
 {
@@ -39,6 +40,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Viewport viewport_force_sensor_graph;
        [Widget] Gtk.Image image_force_sensor_graph;
        [Widget] Gtk.SpinButton spin_force_sensor_calibration_kg_value;
+       [Widget] Gtk.Button button_force_sensor_image_save;
        
        Thread forceCaptureThread;
        static bool forceProcessFinish;
@@ -48,6 +50,7 @@ public partial class ChronoJumpWindow
        static string forceSensorOtherMessage = "";
        static bool forceSensorOtherMessageShowSeconds;
        static DateTime forceSensorTimeStart;
+       static string lastForceSensorFile = "";
 
        /*
         * forceStatus:
@@ -421,7 +424,10 @@ public partial class ChronoJumpWindow
                                        forceSensorDoGraph();
                                }
                        } else if(forceProcessCancel)
+                       {
                                event_execute_label_message.Text = "Cancelled.";
+                               button_force_sensor_image_save.Sensitive = false;
+                       }
                        else
                                event_execute_label_message.Text = "";
 
@@ -487,8 +493,10 @@ public partial class ChronoJumpWindow
                FileFilter file_filter = new FileFilter();
                file_filter.AddPattern ("*.csv");
 
+               lastForceSensorFile = "";
                if (filechooser.Run () == (int)ResponseType.Accept)
                {
+                       lastForceSensorFile = 
Util.RemoveExtension(Util.GetLastPartOfPath(filechooser.Filename));
                        File.Copy(filechooser.Filename,
                                        Path.GetTempPath() + Path.DirectorySeparatorChar + "cj_mif_Data.csv",
                                        true); //can be overwritten
@@ -500,7 +508,7 @@ public partial class ChronoJumpWindow
 
        void forceSensorDoGraph()
        {
-               string imagePath = Path.GetTempPath() + Path.DirectorySeparatorChar + "cj_mif_Graph.png";
+               string imagePath = UtilEncoder.GetmifTempFileName();
                Util.FileDelete(imagePath);
                image_force_sensor_graph.Sensitive = false;
 
@@ -521,8 +529,32 @@ public partial class ChronoJumpWindow
                                imagePath,
                                image_force_sensor_graph);
                image_force_sensor_graph.Sensitive = true;
+               button_force_sensor_image_save.Sensitive = true;
        }
 
+       private void on_button_force_sensor_image_save_clicked (object o, EventArgs args)
+       {
+               checkFile(Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE);
+       }
+       void on_button_forcesensor_save_image_file_selected (string destination)
+       {
+               try {
+                       File.Copy(UtilEncoder.GetmifTempFileName(), destination, true);
+               } catch {
+                       string myString = string.Format(
+                                       Catalog.GetString("Cannot save file {0} "), destination);
+                       new DialogMessage(Constants.MessageTypes.WARNING, myString);
+               }
+       }
+       private void on_overwrite_file_forcesensor_save_image_accepted(object o, EventArgs args)
+       {
+               on_button_forcesensor_save_image_file_selected (exportFileName);
+
+               string myString = string.Format(Catalog.GetString("Saved to {0}"), exportFileName);
+               new DialogMessage(Constants.MessageTypes.INFO, myString);
+       }
+
+
        private void on_button_force_sensor_data_folder_clicked (object o, EventArgs args)
        {
                string dataDir = ForceSensorGraph.GetDataDir(currentSession.UniqueID);
diff --git a/src/util.cs b/src/util.cs
index 31980b3..4bac7c8 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1679,7 +1679,15 @@ public class Util
                
                return myFile;
        }
-       
+
+       public static string RemoveExtension(string myFile)
+       {
+               int posOfDot = myFile.LastIndexOf('.');
+               if (posOfDot > 0)
+                       myFile = myFile.Substring(0, posOfDot);
+
+               return myFile;
+       }
 
        public static bool IntToBool (int myInt) {
                if(myInt == 1)
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index c08c92a..6f568e8 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -253,6 +253,9 @@ public class UtilEncoder
        public static string GetmifScript() {
                return System.IO.Path.Combine(GetSprintPath(), "maximumIsometricForce.R");
        }
+       public static string GetmifTempFileName() {
+               return Path.Combine(Path.GetTempPath(), "cj_mif_Graph.png");
+       }
 
        /********** end of r-scripts paths ************/
 


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