[chronojump] RaceAnalyzer capture tab cairo graphs show grid lines according to segmentMeters (if fixed)



commit e347f0d84cb6f095af7e7da1bda38d209e5b57d6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Feb 4 16:47:59 2022 +0100

    RaceAnalyzer capture tab cairo graphs show grid lines according to segmentMeters (if fixed)

 src/gui/app1/runEncoder.cs    | 30 +++++++++++++++++++----
 src/gui/cairo/generic.cs      |  3 ++-
 src/gui/cairo/raceAnalyzer.cs | 57 ++++++++++++++++++++++++++++++++++++++++---
 src/gui/cairo/xy.cs           |  2 +-
 src/runEncoder.cs             | 24 ++++++++++++++++--
 src/utilMath.cs               |  9 +++++--
 6 files changed, 110 insertions(+), 15 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index daa30697a..f94aca41a 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -571,7 +571,7 @@ public partial class ChronoJumpWindow
                cairoGraphRaceAnalyzerPoints_at_l = new List<PointF>();
 
                //RunEncoderCaptureGetSpeedAndDisplacement reCGSD = new 
RunEncoderCaptureGetSpeedAndDisplacement();
-               reCGSD = new RunEncoderCaptureGetSpeedAndDisplacement();
+               reCGSD = new 
RunEncoderCaptureGetSpeedAndDisplacement(currentRunEncoderExercise.SegmentMeters);
                runEncoderShouldShowCaptureGraphsWithData = true;
 
                runEncoderCaptureThread = new Thread(new ThreadStart(runEncoderCaptureDo));
@@ -1039,7 +1039,7 @@ public partial class ChronoJumpWindow
                // ---- capture tab graphs start ---->
 
                int count = 0;
-               reCGSD = new RunEncoderCaptureGetSpeedAndDisplacement();
+               reCGSD = new 
RunEncoderCaptureGetSpeedAndDisplacement(currentRunEncoderExercise.SegmentMeters);
                runEncoderShouldShowCaptureGraphsWithData = true;
 
                cairoGraphRaceAnalyzer_dt = null;
@@ -2223,20 +2223,35 @@ public partial class ChronoJumpWindow
                if(radio_race_analyzer_capture_view_simple.Active)
                        return;
 
+               int verticalGridSeps = -1;
+               if(currentRunEncoderExercise != null && currentRunEncoderExercise.SegmentMeters > 0)
+                       verticalGridSeps = currentRunEncoderExercise.SegmentMeters;
+
+               TwoListsOfInts verticalLinesUs_2l = new TwoListsOfInts("dist","time");
+               if(currentRunEncoderExercise != null && currentRunEncoderExercise.SegmentMeters > 0 &&
+                               reCGSD.SegmentMetersTime_2l != null)
+                       verticalLinesUs_2l = reCGSD.SegmentMetersTime_2l;
+
+
                if(cairoGraphRaceAnalyzer_dt == null)
                        cairoGraphRaceAnalyzer_dt = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_position_time, "title",
-                                       Catalog.GetString("Distance"), "m", false);
+                                       Catalog.GetString("Distance"), "m", false, verticalGridSeps, 
verticalLinesUs_2l);
 
                cairoGraphRaceAnalyzer_dt.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_dt_l, forceRedraw, CairoXY.PlotTypes.LINES);
        }
        private void updateRaceAnalyzerCaptureSpeedTime(bool forceRedraw)
        {
+               TwoListsOfInts verticalLinesUs_2l = new TwoListsOfInts("dist","time");
+               if(currentRunEncoderExercise != null && currentRunEncoderExercise.SegmentMeters > 0 &&
+                               reCGSD.SegmentMetersTime_2l != null)
+                       verticalLinesUs_2l = reCGSD.SegmentMetersTime_2l;
+
                if(cairoGraphRaceAnalyzer_st == null)
                        cairoGraphRaceAnalyzer_st = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_speed_time, "title",
-                                       Catalog.GetString("Speed"), "m/s", true);
+                                       Catalog.GetString("Speed"), "m/s", true, -1, verticalLinesUs_2l);
 
                cairoGraphRaceAnalyzer_st.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_st_l, forceRedraw, CairoXY.PlotTypes.LINES);
@@ -2246,10 +2261,15 @@ public partial class ChronoJumpWindow
                if(radio_race_analyzer_capture_view_simple.Active)
                        return;
 
+               TwoListsOfInts verticalLinesUs_2l = new TwoListsOfInts("dist","time");
+               if(currentRunEncoderExercise != null && currentRunEncoderExercise.SegmentMeters > 0 &&
+                               reCGSD.SegmentMetersTime_2l != null)
+                       verticalLinesUs_2l = reCGSD.SegmentMetersTime_2l;
+
                if(cairoGraphRaceAnalyzer_at == null)
                        cairoGraphRaceAnalyzer_at = new CairoGraphRaceAnalyzer(
                                        drawingarea_race_analyzer_capture_accel_time, "title",
-                                       Catalog.GetString("Accel"), "m/s^2", false);
+                                       Catalog.GetString("Accel"), "m/s^2", false, -1, verticalLinesUs_2l);
 
                cairoGraphRaceAnalyzer_at.DoSendingList (preferences.fontType.ToString(),
                                cairoGraphRaceAnalyzerPoints_at_l, forceRedraw, CairoXY.PlotTypes.LINES);
diff --git a/src/gui/cairo/generic.cs b/src/gui/cairo/generic.cs
index ed64d5223..0c9e6ab4d 100644
--- a/src/gui/cairo/generic.cs
+++ b/src/gui/cairo/generic.cs
@@ -164,8 +164,9 @@ public abstract class CairoGeneric
        {
                g.MoveTo(xtemp, topMargin);
                g.LineTo(xtemp, graphHeight - bottomMargin);
+
                printText(xtemp, graphHeight -(bottomMargin/2), 0, fontH, text, g, alignTypes.CENTER);
-               LogB.Information("pvgl fontH: " + fontH.ToString());
+               //LogB.Information("pvgl fontH: " + fontH.ToString());
        }
 
        //horiz or vertical to manage spacement of arrow points and tip draw
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 212ac23a1..18e3c5142 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- *  Copyright (C) 2021   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2022   Xavier de Blas <xaviblas gmail com>
  */
 
 using System;
@@ -29,6 +29,8 @@ public class CairoGraphRaceAnalyzer : CairoXY
 {
        int points_list_painted;
        private bool plotHorizArrowFromMaxY;
+       private int verticalGridSep;
+       private TwoListsOfInts verticalLinesUs_2l;
 
        /*
        //constructor when there are no points
@@ -52,7 +54,9 @@ public class CairoGraphRaceAnalyzer : CairoXY
        public CairoGraphRaceAnalyzer (
                        DrawingArea area, string title,
                        string yVariable, string yUnits,
-                       bool plotHorizArrowFromMaxY)
+                       bool plotHorizArrowFromMaxY,
+                       int verticalGridSep, //-1 if auto
+                       TwoListsOfInts verticalLinesUs_2l)
        {
                this.area = area;
                this.title = title;
@@ -63,6 +67,8 @@ public class CairoGraphRaceAnalyzer : CairoXY
                xUnits = "s";
                this.yUnits = yUnits;
                this.plotHorizArrowFromMaxY = plotHorizArrowFromMaxY;
+               this.verticalGridSep = verticalGridSep;
+               this.verticalLinesUs_2l = verticalLinesUs_2l;
                
 //             doing = false;
                points_list_painted = 0;
@@ -98,7 +104,37 @@ public class CairoGraphRaceAnalyzer : CairoXY
 
                if(maxValuesChanged || forceRedraw)
                {
-                       paintGrid(gridTypes.BOTH, true);
+                       if(verticalGridSep < 0 && verticalLinesUs_2l.Count() == 0)
+                               paintGrid(gridTypes.BOTH, true);
+                       else {
+                               //horizontal
+                               if(verticalGridSep <= 0)
+                                       paintGrid(gridTypes.HORIZONTALLINES, true);
+                               else
+                                       paintGridInt (g, minX, absoluteMaxX, minY, absoluteMaxY, 
verticalGridSep, gridTypes.HORIZONTALLINES, textHeight);
+
+                               //vertical
+                               if(verticalLinesUs_2l.Count() == 0)
+                                       paintGridNiceAutoValues (g, minX, absoluteMaxX, minY, absoluteMaxY, 
5, gridTypes.VERTICALLINES, textHeight);
+                               else {
+                                       for(int i = 0 ; i < verticalLinesUs_2l.Count() ; i ++)
+                                       {
+                                               string xTextTop = 
verticalLinesUs_2l.GetFromFirst(i).ToString() + " m";
+                                               string xTextBottom = 
Convert.ToInt32(verticalLinesUs_2l.GetFromSecond(i)/1000000.0).ToString();
+                                               double xGraph = 
calculatePaintX(verticalLinesUs_2l.GetFromSecond(i)/1000000.0);
+
+                                               g.Save();
+                                               g.SetDash(new double[]{1, 2}, 0);
+                                               if(verticalGridSep > 0)
+                                                       paintVerticalGridLine(g, Convert.ToInt32(xGraph), 
xTextBottom, textHeight);
+                                               else
+                                                       paintVerticalGridLineTopBottom (g, 
Convert.ToInt32(xGraph), xTextTop, xTextBottom, textHeight);
+                                               g.Stroke ();
+                                               g.Restore();
+                                       }
+                               }
+                       }
+
                        paintAxis();
                }
 
@@ -127,15 +163,28 @@ public class CairoGraphRaceAnalyzer : CairoXY
 
        protected override void printXAxisText()
        {
-               printText(graphWidth - outerMargin, graphHeight -Convert.ToInt32(.25 * outerMargin), 0, 
textHeight, getXAxisLabel(), g, alignTypes.CENTER);
+               printText(graphWidth - outerMargin, graphHeight -Convert.ToInt32(.25 * outerMargin),
+                               0, textHeight, getXAxisLabel(), g, alignTypes.CENTER);
        }
+
+       /*
        protected override void paintVerticalGridLine(Cairo.Context g, int xtemp, string text, int fontH)
        {
                g.MoveTo(xtemp, graphHeight - outerMargin);
                g.LineTo(xtemp, outerMargin);
                printText(xtemp, graphHeight -Convert.ToInt32(.75 * outerMargin), 0, fontH, text, g, 
alignTypes.CENTER); //TODO: this only for raceAnalyzer
        }
+       */
+
+       private void paintVerticalGridLineTopBottom (Cairo.Context g, int xtemp, string textTop, string 
textBottom, int fontH)
+       {
+               g.MoveTo(xtemp, topMargin);
+               g.LineTo(xtemp, graphHeight - bottomMargin);
 
+               printText(xtemp, Convert.ToInt32(.8*topMargin), 0, fontH, textTop, g, alignTypes.CENTER);
+               printText(xtemp, graphHeight-(bottomMargin/2), 0, fontH, textBottom, g, alignTypes.CENTER);
+               //LogB.Information("pvgl fontH: " + fontH.ToString());
+       }
        protected override void writeTitle()
        {
        }
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 9361c7839..e5f78288d 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -319,7 +319,7 @@ public abstract class CairoXY : CairoGeneric
        {
                return getAxisLabel(yVariable, yUnits);
        }
-       private string getAxisLabel(string variable, string units)
+       protected string getAxisLabel(string variable, string units)
        {
                if(units == "")
                        return variable;
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 0e74471af..94c3dc624 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -269,6 +269,11 @@ public class RunEncoder
 //get speed, total distance, ...
 public class RunEncoderCaptureGetSpeedAndDisplacement
 {
+       //to calcule the vertical lines on pos/time, speed/time, accel/time
+       //it is calculated once and used on all
+       private int segmentMeters;
+       private TwoListsOfInts segmentMetersTime_2l;
+
        private int encoderDisplacement;
        private int time;
        private int force;
@@ -280,8 +285,11 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        private double runEncoderCaptureSpeedMax;
        private double runEncoderCaptureDistance;
 
-       public RunEncoderCaptureGetSpeedAndDisplacement()
+       public RunEncoderCaptureGetSpeedAndDisplacement(int segmentMeters)
        {
+               this.segmentMeters = segmentMeters;
+
+               segmentMetersTime_2l = new TwoListsOfInts("dist","time");
                timePre = 0;
        }
 
@@ -320,17 +328,26 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
                                        runEncoderCaptureSpeedMax = runEncoderCaptureSpeed;
 
                                runEncoderCaptureDistance += runEncoderCaptureDistanceAtThisSample;
+
+                               if(segmentMeters > 0)
+                                       updateSegmentMetersTime ();
+
                                hasCalculed = true;
                        }
                        timePre = time;
                }
                return hasCalculed;
        }
+       private void updateSegmentMetersTime () //TODO: implement also for variable segmentMeters
+       {
+               if(runEncoderCaptureDistance >= segmentMeters * (segmentMetersTime_2l.Count() +1))
+                       segmentMetersTime_2l.Add(segmentMeters * (segmentMetersTime_2l.Count() +1), time);
+       }
 
        public int EncoderDisplacement {
                get { return encoderDisplacement; }
        }
-       public int Time {
+       public int Time { //microseconds
                get { return time; }
        }
        public int Force {
@@ -350,6 +367,9 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        public double RunEncoderCaptureDistance {
                get { return runEncoderCaptureDistance; }
        }
+       public TwoListsOfInts SegmentMetersTime_2l {
+               get { return segmentMetersTime_2l; }
+       }
 }
 
 public class RunEncoderExercise
diff --git a/src/utilMath.cs b/src/utilMath.cs
index ed6bd5a6c..fcac27708 100644
--- a/src/utilMath.cs
+++ b/src/utilMath.cs
@@ -113,7 +113,6 @@ public class KeyDouble
        }
 }
 
-/*
 public class TwoListsOfInts
 {
        private string firstIntName; //just to be able to debug
@@ -160,8 +159,14 @@ public class TwoListsOfInts
        {
                return second_l[pos];
        }
+
+       public override string ToString()
+       {
+               return (string.Format("firstIntName: {0}, secondIntName: {1}",
+                                       firstIntName, secondIntName)); // just to debug, add the values
+       }
+
 }
-*/
 
 //like Point but for having an xStart and xEnd
 public class PointStartEnd


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