[chronojump] ForceSensorExport with thread



commit 84c522a200f11c40c76c65af764d3ef93112ae29
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Feb 4 17:13:21 2021 +0100

    ForceSensorExport with thread

 glade/app1.glade                   | 95 ++++++++++++++++++++++++++++++--------
 src/forceSensor.cs                 | 43 ++++++++++++++++-
 src/gui/app1/forceSensorAnalyze.cs |  5 ++
 3 files changed, 124 insertions(+), 19 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 5501b401..aea44098 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -21762,6 +21762,17 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkNotebook" 
id="notebook_force_sensor_export">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="show_tabs">False</property>
+                                                            <property name="show_border">False</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox455">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
                                                             <widget class="GtkButton" 
id="button_force_sensor_export_currentperson_in_session">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
@@ -21776,9 +21787,9 @@ Concentric</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">1</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
                                                             </packing>
                                                             </child>
                                                             <child>
@@ -21796,9 +21807,51 @@ Concentric</property>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">True</property>
-                                                            <property name="fill">True</property>
-                                                            <property name="position">2</property>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label584">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">buttons</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkProgressBar" 
id="progressbar_force_sensor_export">
+                                                            <property name="width_request">50</property>
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label586">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">progressbar</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">1</property>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
@@ -23678,6 +23731,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -28524,6 +28580,18 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </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>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -28560,18 +28628,6 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </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>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -36854,6 +36910,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 7e64b8b1..ba1d978e 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -22,6 +22,7 @@ using System;
 using System.IO;               //for detect OS //TextWriter
 using System.Collections; //ArrayList
 using System.Collections.Generic; //List<T>
+using System.Threading;
 using Mono.Unix;
 
 public class ForceSensor
@@ -2126,6 +2127,8 @@ public class ForceSensorAnalyzeInstant
 public class ForceSensorExport
 {
        //passed variables
+       private Gtk.Notebook notebook;
+       private Gtk.ProgressBar progressbar;
        private bool isWindows;
        private int personID; // -1: all
        private int sessionID;
@@ -2140,6 +2143,9 @@ public class ForceSensorExport
        public bool forceSensorStartEndOptimized;
        public string CSVExportDecimalSeparator;
 
+       private static Thread thread;
+       private static double pulseFraction;
+
        List<ForceSensor> fs_l;
        ArrayList personSession_l;
        ArrayList fsEx_l;
@@ -2149,6 +2155,8 @@ public class ForceSensorExport
 
        //constructor
        public ForceSensorExport (
+                       Gtk.Notebook notebook,
+                       Gtk.ProgressBar progressbar,
                        bool isWindows, int personID, int sessionID,
                        List<ForceSensorRFD> rfdList, ForceSensorImpulse impulse,
                        int duration, int durationPercent,
@@ -2160,6 +2168,8 @@ public class ForceSensorExport
                        string CSVExportDecimalSeparator)
 
        {
+               this.notebook = notebook;
+               this.progressbar = progressbar;
                this.isWindows = isWindows;
                this.personID = personID;
                this.sessionID = sessionID;
@@ -2177,6 +2187,35 @@ public class ForceSensorExport
 
        ///public method
        public void Start()
+       {
+               pulseFraction= 0;
+               progressbar.Fraction = 0;
+               notebook.CurrentPage = 1;
+
+               thread = new Thread (new ThreadStart (forceSensorExportDo));
+               GLib.Idle.Add (new GLib.IdleHandler (pulseForceSensorExportGTK));
+               thread.Start();
+       }
+
+       private bool pulseForceSensorExportGTK ()
+       {
+               if(! thread.IsAlive)// || cancel)
+               {
+                       LogB.Information("pulseForceSensorExportGTK ending here");
+                       LogB.ThreadEnded();
+
+                       progressbar.Fraction = 1;
+                       notebook.CurrentPage = 0;
+                       return false;
+               }
+
+               progressbar.Fraction = pulseFraction;
+               Thread.Sleep (100);
+               //Log.Write(" (pulseForceSensorExportGTK:" + thread.ThreadState.ToString() + ") ");
+               return true;
+       }
+
+       private void forceSensorExportDo()
        {
                getData();
                processForceSensorSets();
@@ -2196,6 +2235,7 @@ public class ForceSensorExport
                Person p = new Person();
                PersonSession ps = new PersonSession();
 
+               int count = 0;
                foreach(ForceSensor fs in fs_l)
                {
                        // 1) checks
@@ -2274,7 +2314,6 @@ public class ForceSensorExport
                        //delete result file
                        Util.FileDelete(UtilEncoder.GetmifExportFileName());
 
-                       //TODO: només les concèntriques
                        foreach(ForceSensorRepetition rep in fsAI.ForceSensorRepetition_l)
                        {
                                ForceSensorGraph fsg = new ForceSensorGraph(fs.CaptureOption, rfdList, 
impulse,
@@ -2314,7 +2353,9 @@ public class ForceSensorExport
                                                        row);
                                }
                        }
+                       pulseFraction = UtilAll.DivideSafeFraction (count ++, fs_l.Count);
                }
+               pulseFraction = 1;
        }
 
        private bool writeFile()
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 1108a3af..748639eb 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -141,6 +141,9 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_force_sensor_ai_variability_cvrmssd;
        [Widget] Gtk.Label label_force_sensor_ai_variability_units;
 
+       [Widget] Gtk.Notebook notebook_force_sensor_export;
+       [Widget] Gtk.ProgressBar progressbar_force_sensor_export;
+
        private RepetitionMouseLimits fsAIRepetitionMouseLimits;
 
        private enum notebook_force_sensor_analyze_pages { AUTOMATIC, MANUAL, AUTOMATICOPTIONS }
@@ -702,6 +705,8 @@ public partial class ChronoJumpWindow
                        duration = Convert.ToInt32(spin_force_duration_seconds.Value);
 
                ForceSensorExport fse = new ForceSensorExport (
+                               notebook_force_sensor_export,
+                               progressbar_force_sensor_export,
                                UtilAll.IsWindows(), personID, currentSession.UniqueID,
                                rfdList, impulse,//getImpulseValue(),
                                duration, Convert.ToInt32(spin_force_rfd_duration_percent.Value),


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