[chronojump] RaceAnalyzer capture graphs (dist/speed)/time (while and at end) capture



commit 4a3938f62ba391e33a54468f61bbbfea0791b114
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 1 21:14:32 2021 +0200

    RaceAnalyzer capture graphs (dist/speed)/time (while and at end) capture

 src/gui/app1/runEncoder.cs    | 21 ++++++-----------
 src/gui/cairo/raceAnalyzer.cs | 31 ++++++++++++++++++-------
 src/gui/cairo/xy.cs           | 54 ++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 78 insertions(+), 28 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index ac00b0c9..784af920 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -432,6 +432,9 @@ public partial class ChronoJumpWindow
                event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
                event_execute_ButtonCancel.Clicked += new EventHandler(on_cancel_clicked);
 
+               cairoGraphRaceAnalyzerPoints_dt_l = new List<PointF>();
+               cairoGraphRaceAnalyzerPoints_st_l = new List<PointF>();
+
                runEncoderCaptureThread = new Thread(new ThreadStart(runEncoderCaptureDo));
                GLib.Idle.Add (new GLib.IdleHandler (pulseGTKRunEncoderCapture));
 
@@ -534,8 +537,6 @@ public partial class ChronoJumpWindow
                Stopwatch sw = new Stopwatch();
 
                int rowsCount = 0;
-               cairoGraphRaceAnalyzerPoints_dt_l = new List<PointF>();
-               cairoGraphRaceAnalyzerPoints_st_l = new List<PointF>();
                while(! runEncoderProcessFinish && ! runEncoderProcessCancel && ! runEncoderProcessError)
                {
                        /*
@@ -1433,8 +1434,8 @@ public partial class ChronoJumpWindow
                                cairoRadial.GraphSpeedAndDistance(runEncoderCaptureSpeed, 
runEncoderCaptureDistance);
 
                        //TODO: activate again when there's a real time update (not repaint all) method
-                       //updateRaceAnalyzerCapturePositionTime();
-                       //updateRaceAnalyzerCaptureSpeedTime();
+                       updateRaceAnalyzerCapturePositionTime();
+                       updateRaceAnalyzerCaptureSpeedTime();
 
                        if(runEncoderPulseMessage == capturingMessage)
                                event_execute_button_finish.Sensitive = true;
@@ -1831,11 +1832,7 @@ public partial class ChronoJumpWindow
                                        drawingarea_race_analyzer_capture_position_time, "title",
                                        Catalog.GetString("Distance"), "m");
 
-               if(cairoGraphRaceAnalyzerPoints_dt_l != null)
-               {
-                       if(cairoGraphRaceAnalyzer_dt.PassData(cairoGraphRaceAnalyzerPoints_dt_l))
-                               cairoGraphRaceAnalyzer_dt.Do(preferences.fontType.ToString());
-               }
+               cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(), 
cairoGraphRaceAnalyzerPoints_dt_l);
        }
        private void updateRaceAnalyzerCaptureSpeedTime()
        {
@@ -1844,10 +1841,6 @@ public partial class ChronoJumpWindow
                                        drawingarea_race_analyzer_capture_speed_time, "title",
                                        Catalog.GetString("Speed"), "m");
 
-               if(cairoGraphRaceAnalyzerPoints_st_l != null)
-               {
-                       if(cairoGraphRaceAnalyzer_st.PassData(cairoGraphRaceAnalyzerPoints_st_l))
-                               cairoGraphRaceAnalyzer_st.Do(preferences.fontType.ToString());
-               }
+               cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(), 
cairoGraphRaceAnalyzerPoints_st_l);
        }
 }
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index b3b78748..075553ce 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -27,6 +27,8 @@ using Cairo;
 
 public class CairoGraphRaceAnalyzer : CairoXY
 {
+       //static int lastPointPainted;
+
        /*
        //constructor when there are no points
        public CairoGraphRaceAnalyzer (DrawingArea area, string jumpType, string font)//, string title, 
string jumpType, string date)
@@ -44,7 +46,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
        */
 
        //to avoid to have new data on PassData while the for is working on plotRealPoints
-       static bool doing;
+//     static bool doing;
        //regular constructor
        public CairoGraphRaceAnalyzer (
 //                     List<PointF> point_l,
@@ -61,40 +63,53 @@ public class CairoGraphRaceAnalyzer : CairoXY
                xUnits = "s";
                this.yUnits = yUnits;
                
-               doing = false;
+//             doing = false;
+//             lastPointPainted = -1;
        }
 
+       /*
        public override bool PassData (List<PointF> point_l)
        {
+       */
+               /*
                if(doing)
                        return false;
                else
                        doing = true;
+                       */
+/*
+               foreach(PointF p in points_list)
 
                this.point_l = point_l;
                return true;
        }
+       */
 
-       public override void Do (string font)
+       public override void DoSendingList (string font, List<PointF> points_list)
        {
                LogB.Information("at RaceAnalyzerGraph.Do");
                initGraph(font, .9);
 
+//maybe do a copy of points_list or only consider last of them (using lastPointPainted)
+
                //because point_l is updated while foreach in findPointMaximums() and plotRealPoints()
                //TODO: on realtime do something better in order to just pass the new points and redo the 
graph just if margins changed
                //this new method will not have problems of changing the point_l list while iterating it
-               try {
-                       findPointMaximums(false);
+//             try {
+//
+                       if(points_list != null)
+                               findPointMaximums(false, points_list);
                        //TODO: have a way to pass the x min max if we want to have two graphs with same x
                        paintGrid(gridTypes.BOTH, true);
                        paintAxis();
 
                        pointsRadius = 1;
-                       plotRealPoints(false);
-               } catch {}
+                       if(points_list != null)
+                               plotRealPoints(false, points_list);
+//             } catch {}
 
                endGraphDisposing(g);
-               doing = false;
+//             doing = false;
        }
 
        protected override void writeTitle()
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 6de8b0e0..cc6fc764 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -102,13 +102,19 @@ public abstract class CairoXY : CairoGeneric
        protected string countStr = Catalog.GetString("Num");
        protected string jumpTypeStr = Catalog.GetString("Jump type:");
        protected string font;
+       //protected static int lastPointPainted;
 
        public virtual bool PassData (List<PointF> point_l)
        {
                return false;
        }
 
-       public abstract void Do(string font);
+       public virtual void Do(string font)
+       {
+       }
+       public virtual void DoSendingList(string font, List<PointF> points_list)
+       {
+       }
 
        protected void initGraph(string font, double widthPercent1)
        {
@@ -146,10 +152,27 @@ public abstract class CairoXY : CairoGeneric
 
        //showFullGraph means that has to plot both axis at 0 and maximums have to be f0,v0
        //used by default on jumpsWeightFVProfile
+       //called from almost all methods
        protected void findPointMaximums(bool showFullGraph)
        {
-               foreach(PointF p in point_l)
+               findPointMaximums(showFullGraph, point_l);
+       }
+
+       //called from raceAnalyzer (sending it own list of points)
+       protected void findPointMaximums(bool showFullGraph, List<PointF> points_list)
+       {
+               //foreach(PointF p in points_list)
+               /*
+               int start = lastPointPainted;
+               if(lastPointPainted < 0)
+                       start = 0;
+
+               //for(int i = start; i < points_list.Count; i ++)
+               */
+               for(int i = 0; i < points_list.Count; i ++)
                {
+                       PointF p = points_list[i];
+
                        if(p.X < minX)
                                minX = p.X;
                        if(p.X > maxX)
@@ -397,12 +420,19 @@ public abstract class CairoXY : CairoGeneric
                g.Stroke ();
        }
 
-       protected void plotRealPoints(bool joinByLine)
+       //called from almost all methods
+       protected void plotRealPoints (bool joinByLine)
+       {
+               plotRealPoints (joinByLine, point_l);
+       }
+
+       //called from raceAnalyzer (sending it own list of points)
+       protected void plotRealPoints (bool joinByLine, List<PointF> points_list)
        {
                if(joinByLine) //draw line first to not overlap the points
                {
                        bool firstDone = false;
-                       foreach(PointF p in point_l)
+                       foreach(PointF p in points_list)
                        {
                                double xgraph = calculatePaintX(p.X);
                                double ygraph = calculatePaintY(p.Y);
@@ -420,9 +450,19 @@ public abstract class CairoXY : CairoGeneric
 //             lock (point_l) {
 //             List<PointF> point_l_copy = point_l>;
 //             foreach(PointF p in point_l_copy)
-               foreach(PointF p in point_l)
+               //foreach(PointF p in points_list)
+               /*
+               int start = lastPointPainted;
+               if(lastPointPainted < 0)
+                       start = 0;
+
+               //for(int i = start; i < points_list.Count; i ++)
+               */
+               for(int i = 0; i < points_list.Count; i ++)
                {
-                       LogB.Information("point: " + p.ToString());
+                       PointF p = points_list[i];
+
+                       //LogB.Information("point: " + p.ToString());
                        double xgraph = calculatePaintX(p.X);
                        double ygraph = calculatePaintY(p.Y);
                        g.Arc(xgraph, ygraph, pointsRadius, 0.0, 2.0 * Math.PI); //full circle
@@ -431,6 +471,8 @@ public abstract class CairoXY : CairoGeneric
                        g.SetSourceRGB(0, 0, 0);
                        g.Stroke ();    //can this be done at the end?
 
+                       //lastPointPainted ++;
+
                        /*
                        //print X, Y of each point
                        printText(xgraph, graphHeight - Convert.ToInt32(bottomMargin/2), 0, textHeight, 
Util.TrimDecimals(p.X, 2), g, true);


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