[chronojump] Encoder capture realtime pointsplot



commit 4fc01ba478528b3eac0f156d2ebea4514b28dcf6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Feb 20 19:33:03 2013 +0100

    Encoder capture realtime pointsplot

 glade/chronojump.glade  |   71 ++++++++++++++++++++++++--
 src/gui/chronojump.cs   |   12 ++++-
 src/gui/encoder.cs      |  126 +++++++++++++++++++++++++++++++++++++++++++++--
 src/gui/eventExecute.cs |   36 ++++----------
 src/utilGtk.cs          |   21 ++++++++
 5 files changed, 228 insertions(+), 38 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 61b6154..74a5f00 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -12707,7 +12707,7 @@ on current Chronojump version.</property>
                                                             <widget class="GtkHBox" id="hbox87">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
-                                                            <property name="spacing">8</property>
+                                                            <property name="spacing">4</property>
                                                             <child>
                                                             <widget class="GtkButton" 
id="button_encoder_load_signal">
                                                             <property name="visible">True</property>
@@ -12865,16 +12865,75 @@ on current Chronojump version.</property>
                                                 <property name="spacing">4</property>
                                                 <property name="homogeneous">True</property>
                                                 <child>
-                                                  <widget class="GtkViewport" 
id="viewport_image_encoder_capture">
+                                                  <widget class="GtkNotebook" id="notebook3">
                                                     <property name="visible">True</property>
-                                                    <property name="can_focus">False</property>
-                                                    <property name="resize_mode">queue</property>
+                                                    <property name="can_focus">True</property>
+                                                    <child>
+                                                      <widget class="GtkFrame" id="frame7">
+                                                        <property name="visible">True</property>
+                                                        <property name="sensitive">False</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label_xalign">0</property>
+                                                        <property name="shadow_type">out</property>
+                                                        <child>
+                                                          <widget class="GtkDrawingArea" 
id="encoder_capture_drawingarea">
+                                                            <property name="visible">True</property>
+                                                            <property name="sensitive">False</property>
+                                                            <property name="can_focus">False</property>
+                                                            <signal name="configure_event" 
handler="on_encoder_capture_drawingarea_configure_event" swapped="no"/>
+                                                            <signal name="expose_event" 
handler="on_encoder_capture_drawingarea_expose_event" swapped="no"/>
+                                                          </widget>
+                                                        </child>
+                                                        <child>
+                                                          <widget class="GtkLabel" 
id="label_encoder_capture_title">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="type">label_item</property>
+                                                          </packing>
+                                                        </child>
+                                                      </widget>
+                                                    </child>
                                                     <child>
-                                                      <widget class="GtkImage" id="image_encoder_capture">
+                                                      <widget class="GtkLabel" id="label114">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
-                                                        <property name="stock">gtk-missing-image</property>
+                                                        <property name="label" translatable="yes">page 
1</property>
                                                       </widget>
+                                                      <packing>
+                                                        <property name="tab_fill">False</property>
+                                                        <property name="type">tab</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkViewport" 
id="viewport_image_encoder_capture">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="resize_mode">queue</property>
+                                                        <child>
+                                                          <widget class="GtkImage" 
id="image_encoder_capture">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                          </widget>
+                                                        </child>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label115">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label" translatable="yes">page 
2</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="position">1</property>
+                                                        <property name="tab_fill">False</property>
+                                                        <property name="type">tab</property>
+                                                      </packing>
                                                     </child>
                                                   </widget>
                                                   <packing>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 18ac624..1c33794 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4622,7 +4622,7 @@ Console.WriteLine("X");
 
        private void deleted_last_test_update_widgets() {
                vbox_this_test_buttons.Sensitive = false;
-               event_execute_clearDrawingArea();
+               UtilGtk.ClearDrawingArea(event_execute_drawingarea, event_execute_pixmap);
                notebook_results_data.CurrentPage = 7; //shows "deleted test"
        }
        
@@ -5360,29 +5360,38 @@ Console.WriteLine("X");
        }
    
        private void sensitiveGuiEventDone () {
+Log.WriteLine("1");
                session_menuitem.Sensitive = true;
                help_menuitem.Sensitive = true;
+Log.WriteLine("2");
                viewport_mode_small.Sensitive = true;
                frame_persons.Sensitive = true;
+Log.WriteLine("3");
 
                button_execute_test.Sensitive = true;
+Log.WriteLine("4");
                
                encoderButtonsSensitive(encoderSensEnum.DONENOSIGNAL);
 
+Log.WriteLine("5");
                //hbox
                hbox_jumps.Sensitive = true;
                hbox_jumps_rj.Sensitive = true;
                table_runs.Sensitive = true;
+Log.WriteLine("6");
                hbox_runs_interval.Sensitive = true;
                hbox_pulses.Sensitive = true;
                //hbox_multi_chronopic_buttons.Sensitive = true;
                vbox_this_test_buttons.Sensitive = true;
+Log.WriteLine("7");
                
                button_upload_session.Sensitive = true;
                button_activate_chronopics.Sensitive = true;
+Log.WriteLine("8");
                notebook_options.Sensitive = true;
                event_execute_button_update.Sensitive = true;
 
+Log.WriteLine("9");
                //allow repeat last jump or run (check also if it wasn't cancelled)
                if(! currentEventExecute.Cancel) {
                        switch (currentEventType.Type) {
@@ -5400,6 +5409,7 @@ Console.WriteLine("X");
                                        break;
                        }
                }
+Log.WriteLine("10");
        }
 
        private void showHideActionEventButtons(bool show, string type) {
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 0de3f6d..16364a8 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -59,6 +59,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Button button_encoder_update_signal;
        [Widget] Gtk.Button button_encoder_delete_signal;
        
+       [Widget] Gtk.DrawingArea encoder_capture_drawingarea;
+       
        [Widget] Gtk.Box hbox_combo_encoder_exercise;
        [Widget] Gtk.ComboBox combo_encoder_exercise;
        [Widget] Gtk.Box hbox_combo_encoder_eccon;
@@ -100,6 +102,8 @@ public partial class ChronoJumpWindow
         Gtk.ListStore encoderListStore;
 
        Thread encoderThread;
+       
+       Gdk.Pixmap encoder_capture_pixmap = null;
 
        int image_encoder_width;
        int image_encoder_height;
@@ -110,6 +114,7 @@ public partial class ChronoJumpWindow
        private string encoderSignalUniqueID;
 
        private static int encoderCaptureCountdown;
+       private static Gdk.Point [] encoderCapturePoints;               //stored to be realtime displayed
        private static bool encoderProcessCancel;
        private static bool encoderProcessFinish;
 
@@ -883,6 +888,10 @@ public partial class ChronoJumpWindow
        //private bool runEncoderCaptureCsharp(string title, EncoderStruct es, string port) 
        private bool runEncoderCaptureCsharp(string title, int time, string outputData1, string port) 
        {
+               int width=encoder_capture_drawingarea.Allocation.Width;
+               int height=encoder_capture_drawingarea.Allocation.Height;
+               int yrange = height;
+               
                Log.WriteLine("00a");
                SerialPort sp = new SerialPort(port);
                Log.WriteLine("00b");
@@ -890,7 +899,7 @@ public partial class ChronoJumpWindow
                Log.WriteLine("00c");
                sp.Open();
                Log.WriteLine("00d");
-               
+                       
                encoderCaptureCountdown = time;
                //int recordingTime = es.Ep.Time * 1000;
                int recordingTime = time * 1000;
@@ -902,15 +911,34 @@ public partial class ChronoJumpWindow
                
                int i =-20; //delete first records because there's encoder bug
                int msCount = 0;
+               int maxy = 1;
+               int miny = 1;
+               encoderCapturePoints = new Gdk.Point[recordingTime];
                do {
                        b = sp.ReadByte();
                        if(b > 128)
                                b = b-256;
                        i=i+1;
                        if(i >= 0) {
-                               Log.Write(sep + b.ToString());
+                               //Log.Write(sep + b.ToString());
+
+                               sum += b;
+
+                               /*
+                               if(sum > maxy)
+                                       maxy = sum;
+                               if(sum < miny)
+                                       miny = sum;
+                               yrange = maxy + System.Math.Abs(miny);
+                               encoderCapturePointsRange = yrange;
+                               */
+
+                               encoderCapturePoints[i] = new Gdk.Point(
+                                               Convert.ToInt32(width*i/recordingTime),
+                                               Convert.ToInt32( (height/2) - ( sum * height / 2000) ) //2m 
detection
+                                               );
+
                                dataString += sep + b.ToString();
-                               //sum += b;
                                sep = ", ";
                        
                                msCount ++;
@@ -919,7 +947,7 @@ public partial class ChronoJumpWindow
                                        msCount = 1;
                                }
                        }
-               } while (i < recordingTime && ! encoderProcessCancel && ! encoderProcessFinish);
+               } while (i < (recordingTime -1) && ! encoderProcessCancel && ! encoderProcessFinish);
                //Log.WriteLine(sum.ToString());
 
                Log.WriteLine("00e");
@@ -1977,7 +2005,94 @@ public partial class ChronoJumpWindow
        }
 
        /* end of sensitivity stuff */  
+       
+       /* update capture graph */      
+       
+       private void updateEncoderCaptureGraph() {
+               if(encoderCapturePoints != null) {
+Log.WriteLine("RRR");  
+                       UtilGtk.ErasePaint(encoder_capture_drawingarea, encoder_capture_pixmap);
+Log.WriteLine("RRR2"); 
+               
+                       pen_azul = new Gdk.GC(encoder_capture_drawingarea.GdkWindow);
+                       pen_azul.Foreground = UtilGtk.BLUE_PLOTS;
+                                       
+Log.WriteLine("RRR3"); 
+
+/*
+                       int height=encoder_capture_drawingarea.Allocation.Height;
+                       for(int i=0; i < encoderCapturePoints.Length ; i ++)
+                               encoderCapturePoints[i].Y = Convert.ToInt32(
+                                               encoderCapturePoints[i].Y * height / 
encoderCapturePointsRange);
+*/
+
+
+                       //also can be optimized to do not erase window every time and only add points since 
last time
+                       encoder_capture_pixmap.DrawPoints(pen_azul, encoderCapturePoints);
+
+                       /*
+                       Gdk.Point [] myPoints = new Gdk.Point[3];
+                       myPoints[0] = new Gdk.Point(20,20);
+                       myPoints[1] = new Gdk.Point(40,20);
+                       myPoints[2] = new Gdk.Point(100,20);
+                       encoder_capture_pixmap.DrawPoints(pen_azul, myPoints);
+                       */
+Log.WriteLine("RRR4"); 
+               }
+       }
+       
+       int encoder_capture_allocationXOld;
+       bool encoder_capture_sizeChanged;
+       public void on_encoder_capture_drawingarea_configure_event(object o, ConfigureEventArgs args)
+       {
+               Gdk.EventConfigure ev = args.Event;
+               Gdk.Window window = ev.Window;
+
+               Gdk.Rectangle allocation = encoder_capture_drawingarea.Allocation;
+               
+               if(encoder_capture_pixmap == null || encoder_capture_sizeChanged || 
+                               allocation.Width != encoder_capture_allocationXOld) {
+                       encoder_capture_pixmap = new Gdk.Pixmap (window, allocation.Width, allocation.Height, 
-1);
+               
+                       UtilGtk.ErasePaint(encoder_capture_drawingarea, encoder_capture_pixmap);
                        
+                       encoder_capture_sizeChanged = false;
+               }
+
+               encoder_capture_allocationXOld = allocation.Width;
+       }
+       
+       public void on_encoder_capture_drawingarea_expose_event(object o, ExposeEventArgs args)
+       {
+               /* in some mono installations, configure_event is not called, but expose_event yes. 
+                * Do here the initialization
+                */
+               
+               Gdk.Rectangle allocation = encoder_capture_drawingarea.Allocation;
+               if(encoder_capture_pixmap == null || encoder_capture_sizeChanged || 
+                               allocation.Width != encoder_capture_allocationXOld) {
+                       encoder_capture_pixmap = new Gdk.Pixmap (encoder_capture_drawingarea.GdkWindow, 
allocation.Width, allocation.Height, -1);
+                       UtilGtk.ErasePaint(encoder_capture_drawingarea, encoder_capture_pixmap);
+
+                       encoder_capture_sizeChanged = false;
+               }
+
+               Gdk.Rectangle area = args.Event.Area;
+
+               //sometimes this is called when pait is finished
+               //don't let this erase win
+               if(encoder_capture_pixmap != null) {
+                       args.Event.Window.DrawDrawable(encoder_capture_drawingarea.Style.WhiteGC, 
encoder_capture_pixmap,
+                               area.X, area.Y,
+                               area.X, area.Y,
+                               area.Width, area.Height);
+               }
+               
+               encoder_capture_allocationXOld = allocation.Width;
+       }
+
+
+       /* end of update capture graph */       
        
        /* thread stuff */
 
@@ -2028,6 +2143,8 @@ public partial class ChronoJumpWindow
                        return false;
                }
                updatePulsebar(encoderModes.CAPTURE); //activity on pulsebar
+               updateEncoderCaptureGraph();
+
                Thread.Sleep (50);
                Log.Write(encoderThread.ThreadState.ToString());
                return true;
@@ -2181,4 +2298,3 @@ public partial class ChronoJumpWindow
        /* end of thread stuff */
        
 }      
-
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 58e2fff..5f21b24 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -248,7 +248,8 @@ public partial class ChronoJumpWindow
 
                event_execute_button_cancel.Sensitive = true;
 
-               event_execute_clearDrawingArea();
+               UtilGtk.ClearDrawingArea(event_execute_drawingarea, event_execute_pixmap);
+
                clearProgressBars();
 
        
@@ -461,15 +462,6 @@ public partial class ChronoJumpWindow
        }
        */
        
-       //called for cleaning the graph of a event done before than the current
-       private void event_execute_clearDrawingArea() 
-       {
-               if(event_execute_pixmap == null) 
-                       event_execute_pixmap = new Gdk.Pixmap (event_execute_drawingarea.GdkWindow, 
event_execute_drawingarea.Allocation.Width, event_execute_drawingarea.Allocation.Height, -1);
-               
-               event_execute_erasePaint(event_execute_drawingarea);
-       }
-       
        //reactive, interval, pulse events, put flag needSensitiveButtonFinish to true when started
        //event.cs (Pulse.GTK) calls this method:
        //public void ButtonFinishMakeSensitive() {
@@ -506,7 +498,7 @@ public partial class ChronoJumpWindow
                if(event_execute_pixmap == null || sizeChanged || allocation.Width != allocationXOld) {
                        event_execute_pixmap = new Gdk.Pixmap (window, allocation.Width, allocation.Height, 
-1);
                
-                       event_execute_erasePaint(event_execute_drawingarea);
+                       UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                        
                        sizeChanged = false;
                }
@@ -523,7 +515,7 @@ public partial class ChronoJumpWindow
                Gdk.Rectangle allocation = event_execute_drawingarea.Allocation;
                if(event_execute_pixmap == null || sizeChanged || allocation.Width != allocationXOld) {
                        event_execute_pixmap = new Gdk.Pixmap (event_execute_drawingarea.GdkWindow, 
allocation.Width, allocation.Height, -1);
-                       event_execute_erasePaint(event_execute_drawingarea);
+                       UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
 
                        sizeChanged = false;
                }
@@ -543,14 +535,6 @@ public partial class ChronoJumpWindow
        }
 
 
-       private void event_execute_erasePaint(Gtk.DrawingArea drawingarea) {
-               event_execute_pixmap.DrawRectangle (drawingarea.Style.WhiteGC, true, 0, 0,
-                               drawingarea.Allocation.Width, drawingarea.Allocation.Height);
-               
-               // -- refresh
-               drawingarea.QueueDraw();
-       }
-
        CapturerBin capturer;
        //Gtk.Window capturerWindow;
        private void cameraRecordInitiate() 
@@ -1090,7 +1074,7 @@ Log.WriteLine("Preparing reactive A");
                int ancho=drawingarea.Allocation.Width;
                int alto=drawingarea.Allocation.Height;
                
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                writeMarginsText(maxValue, minValue, alto);
                
                //check now here that we will have not division by zero problems
@@ -1169,7 +1153,7 @@ Log.WriteLine("Preparing reactive A");
                int ancho=drawingarea.Allocation.Width;
                int alto=drawingarea.Allocation.Height;
                
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                writeMarginsText(maxValue, minValue, alto);
                
                //check now here that we will have not division by zero problems
@@ -1225,7 +1209,7 @@ Log.WriteLine("Preparing reactive A");
                int alto=drawingarea.Allocation.Height;
 
                
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                
                writeMarginsText(maxValue, minValue, alto);
                
@@ -1388,7 +1372,7 @@ Log.WriteLine("Preparing reactive A");
                int alto=drawingarea.Allocation.Height;
                
                
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                
                writeMarginsText(maxValue, minValue, alto);
                
@@ -1496,7 +1480,7 @@ Log.WriteLine("Preparing reactive A");
                int alto=drawingarea.Allocation.Height;
                
                
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
                
                writeMarginsText(maxValue, minValue, alto);
                
@@ -1599,7 +1583,7 @@ Log.WriteLine("Preparing reactive A");
 
                int ancho=drawingarea.Allocation.Width;
 
-               event_execute_erasePaint(drawingarea);
+               UtilGtk.ErasePaint(event_execute_drawingarea, event_execute_pixmap);
 
                //writeMarginsText(maxValue, minValue, alto);
                writeCpNames();
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index b122c6f..bd9d747 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -317,4 +317,25 @@ public class UtilGtk
                l.TooltipText = Util.RemoveMarkup(s);
        }
 
+       // -- drawingarea stuff
+       
+       public static void ErasePaint(Gtk.DrawingArea da, Gdk.Pixmap px) {
+               px.DrawRectangle (da.Style.WhiteGC, true, 0, 0, da.Allocation.Width, da.Allocation.Height);
+               da.QueueDraw(); // -- refresh
+       }
+       
+       //called for cleaning the graph of a event done before than the current
+       public static void ClearDrawingArea(Gtk.DrawingArea da, Gdk.Pixmap px) 
+       {
+               if(px == null) 
+                       px = new Gdk.Pixmap (da.GdkWindow, da.Allocation.Width, da.Allocation.Height, -1);
+               
+               UtilGtk.ErasePaint(da, px);
+       }
+       
+
+
+
+
+       // -- end of drawingarea stuff
 }


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