[chronojump] ForceSensor AI graph: click zooms repetition



commit ba39a7243364e9ac613adb512d2c94e0aa55c90c
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Feb 11 15:47:12 2020 +0100

    ForceSensor AI graph: click zooms repetition

 glade/app1.glade                   |  1 +
 src/forceSensor.cs                 |  2 +-
 src/gui/app1/forceSensorAnalyze.cs | 73 +++++++++++++++++++++++++++++++++++++-
 src/gui/usefulObjects.cs           |  9 +++++
 4 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 5d7966f6..ec84407d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -21911,6 +21911,7 @@ Concentric</property>
                                                             <widget class="GtkDrawingArea" 
id="force_sensor_ai_drawingarea">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
+                                                            <signal name="button_press_event" 
handler="on_force_sensor_ai_drawingarea_button_press_event" swapped="no"/>
                                                             <signal name="configure_event" 
handler="on_force_sensor_ai_drawingarea_configure_event" swapped="no"/>
                                                             <signal name="expose_event" 
handler="on_force_sensor_ai_drawingarea_expose_event" swapped="no"/>
                                                             </widget>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 02c98903..2a7c366e 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -1495,7 +1495,7 @@ public class ForceSensorAnalyzeInstant
 
        public int GetLength()
        {
-               LogB.Information("GetLength: " + fscAIPoints.GetLength());
+               //LogB.Information("GetLength: " + fscAIPoints.GetLength());
                return fscAIPoints.GetLength();
        }
 
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 82bf53d1..927caa05 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -131,6 +131,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_force_sensor_ai_variability_values;
        [Widget] Gtk.Label label_force_sensor_ai_feedback_values;
 
+       private RepetitionMouseLimits fsAIRepetitionMouseLimits;
+
        /*
         * analyze options -------------------------->
         */
@@ -839,6 +841,9 @@ public partial class ChronoJumpWindow
                if(force_sensor_ai_drawingarea == null)
                        return;
 
+               //needed to have mouse clicks button_press_event ()
+               force_sensor_ai_drawingarea.AddEvents((int) (Gdk.EventMask.ButtonPressMask | 
Gdk.EventMask.ButtonReleaseMask));
+
                /* in some mono installations, configure_event is not called, but expose_event yes.
                 * Do here the initialization
                 */
@@ -877,6 +882,57 @@ public partial class ChronoJumpWindow
                LogB.Information("EXPOSE END");
        }
 
+       private void on_force_sensor_ai_drawingarea_button_press_event (object o, ButtonPressEventArgs args)
+       {
+               //LogB.Information(string.Format("Mouse X: {0}; Mouse Y: {1}", args.Event.X, args.Event.Y));
+
+               //if zoomed: unzoom and return
+               if(forceSensorZoomApplied)
+               {
+                       button_force_sensor_ai_zoom.Click();
+                       return;
+               }
+
+               //if list exists, select the repetition
+               if(fsAIRepetitionMouseLimits != null)
+               {
+                       int repetition = fsAIFindBarInPixel(args.Event.X);
+                       LogB.Information("Repetition: " + repetition.ToString());
+                       if(repetition >= 0)
+                       {
+                               double start = fsAIRepetitionMouseLimits.GetStartOfARep(repetition);
+                               double end = fsAIRepetitionMouseLimits.GetEndOfARep(repetition);
+                               //LogB.Information(string.Format("start: {0}, end: {1}", start, end));
+
+                               //find the hscale value for this x
+                               //TODO: move this to forceSensor.cs
+                               bool startFound = false;
+                               bool endFound = false;
+                               for(int i = 0; i < fsAI.GetLength() -1; i++)
+                               {
+                                       int xposHere = fsAI.GetXFromSampleCount(i);
+
+                                       //with >= to solve problems of doubles
+                                       if(! startFound && xposHere >= start)
+                                       {
+                                               hscale_force_sensor_ai_a.Value = i;
+                                               //LogB.Information(string.Format("start2: {0}", i));
+                                               startFound = true;
+                                       }
+
+                                       if(! endFound && xposHere >= end)
+                                       {
+                                               hscale_force_sensor_ai_b.Value = i;
+                                               //LogB.Information(string.Format("end2: {0}", i));
+                                               endFound = true;
+                                       }
+                               }
+                               button_force_sensor_ai_zoom.Click();
+
+                               //TODO: need to paint the repetition value at top
+                       }
+               }
+       }
 
        private bool forceSensorZoomApplied;
        private void forceSensorZoomDefaultValues()
@@ -921,6 +977,7 @@ public partial class ChronoJumpWindow
                        return;
 
                LogB.Information("forceSensorAnalyzeManualGraphDo() START");
+               fsAIRepetitionMouseLimits = new RepetitionMouseLimits();
                bool debug = false;
 
                button_force_sensor_image_save_rfd_manual.Sensitive = true;
@@ -1011,7 +1068,7 @@ public partial class ChronoJumpWindow
                        force_sensor_ai_pixmap.DrawLine(pen_green_force_ai,
                                        xposRep, 0, xposRep, allocation.Height -20);
 
-                       // write repetition count
+                       // write repetition count and store MouseLimits
                        if(i > 0)
                        {
                                layout_force_ai_text.SetMarkup(i.ToString());
@@ -1020,6 +1077,12 @@ public partial class ChronoJumpWindow
                                force_sensor_ai_pixmap.DrawLayout (pen_green_force_ai,
                                                Convert.ToInt32((xposRepPrevious + xposRep)/2 - textWidth/2), 
0,
                                                layout_force_ai_text);
+
+                               //store the graph X
+                               fsAIRepetitionMouseLimits.Add(xposRepPrevious, xposRep);
+                               //store the sample count, because we want to move the progressbars there
+                               //fsAIRepetitionMouseLimits.Add(fsAI.ForceSensorRepetition_l[i-1].posX,
+                               //              fsAI.ForceSensorRepetition_l[i].posX);
                        }
 
                        xposRepPrevious = xposRep;
@@ -1081,6 +1144,14 @@ public partial class ChronoJumpWindow
                LogB.Information("forceSensorAnalyzeManualGraphDo() END");
        }
 
+       private int fsAIFindBarInPixel (double pixel)
+       {
+               if(fsAIRepetitionMouseLimits == null)
+                       return -1;
+
+               return fsAIRepetitionMouseLimits.FindBarInPixel(pixel);
+       }
+
        private void plotRFDLineDebugConstruction(int countRFDMax)
        {
                /*
diff --git a/src/gui/usefulObjects.cs b/src/gui/usefulObjects.cs
index fa37e6e2..76b1ec2e 100644
--- a/src/gui/usefulObjects.cs
+++ b/src/gui/usefulObjects.cs
@@ -459,4 +459,13 @@ public class RepetitionMouseLimits
 
                return -1;
        }
+
+       public double GetStartOfARep(int rep)
+       {
+               return ((PointStartEnd) list[rep]).Start;
+       }
+       public double GetEndOfARep(int rep)
+       {
+               return ((PointStartEnd) list[rep]).End;
+       }
 }


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