[chronojump] Implemented eccentric overload on encoder CairoBars plot



commit 58708610b8af6de89f2013955760c692badce9aa
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Apr 4 12:14:45 2022 +0200

    Implemented eccentric overload on encoder CairoBars plot

 src/gui/cairo/bars.cs    | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gui/cairo/encoder.cs |  1 -
 src/gui/eventExecute.cs  | 41 +++++++++++++++++++++++++-------
 3 files changed, 95 insertions(+), 9 deletions(-)
---
diff --git a/src/gui/cairo/bars.cs b/src/gui/cairo/bars.cs
index eedfb6dbf..d60e3b11c 100644
--- a/src/gui/cairo/bars.cs
+++ b/src/gui/cairo/bars.cs
@@ -72,6 +72,8 @@ public abstract class CairoBars : CairoGeneric
        protected Cairo.Color gray153; //light
        protected Cairo.Color white;
        protected Cairo.Color red;
+       protected Cairo.Color green;
+       protected Cairo.Color greenDark;
        protected Cairo.Color blue;
        //protected Cairo.Color blueChronojump;
        //protected Cairo.Color bluePlots;
@@ -79,6 +81,8 @@ public abstract class CairoBars : CairoGeneric
 
        protected RepetitionMouseLimits mouseLimits;
        protected List<double> lineData_l; //related to secondary variable (by default range)
+       protected List<CairoBarsArrow> eccOverload_l;
+       protected bool eccOverloadWriteValue;
        protected List<int> saved_l;
 
        // ---- values can be passed from outside via accessors ---->
@@ -336,6 +340,8 @@ public abstract class CairoBars : CairoGeneric
                gray153 = colorFromRGB(153,153,153);
                white = colorFromRGB(255,255,255);
                red = colorFromRGB(200,0,0);
+               green = colorFromRGB(0,200,0);
+               greenDark = colorFromRGB(0,140,0);
                blue = colorFromRGB(178, 223, 238); //lightblue
                //blueChronojump = colorFromRGB(14, 30, 70);
                //bluePlots = colorFromRGB(0, 0, 200);
@@ -348,6 +354,8 @@ public abstract class CairoBars : CairoGeneric
 
                mouseLimits = new RepetitionMouseLimits();
                lineData_l = new List<double>();
+               eccOverload_l = new List<CairoBarsArrow>();
+               eccOverloadWriteValue = false;
                saved_l = new List<int>();
        }
 
@@ -571,6 +579,43 @@ public abstract class CairoBars : CairoGeneric
                                calculatePaintY(cairoBarsArrow.y1));
        }
 
+       //same as above but as a list
+       protected virtual void plotEccOverload ()
+       {
+               //caution
+               if(eccOverload_l == null || barsXCenter_l == null)
+                       return;
+
+               g.SetSourceColor (greenDark);
+               double yValues = UtilAll.DivideSafe(calculatePaintY(maxY), 2);
+               foreach(CairoBarsArrow cba in eccOverload_l)
+               {
+                       LogB.Information("eccOverload: " + cba.ToString());
+
+                       if(cba.x0pos >= barsXCenter_l.Count ||
+                                       cba.x1pos >= barsXCenter_l.Count)
+                               continue;
+
+                       plotArrowFree (g, greenDark, 3, 14,
+                                       cba.GetX0Graph (barsXCenter_l),
+                                       calculatePaintY(cba.y0),
+                                       cba.GetX1Graph (barsXCenter_l),
+                                       calculatePaintY(cba.y1));
+
+                       if(eccOverloadWriteValue)
+                               printText((cba.GetX0Graph (barsXCenter_l) + cba.GetX1Graph(barsXCenter_l))/2,
+                                               //same height aprox than values (non clear if overload has 3 
digits)
+                                               //calculatePaintY(cba.y1) -1.5*resultFontHeight + 
resultFontHeight/2,
+                                               //up the bar values, ok, but maybe better all on same Y
+                                               //calculatePaintY(cba.y1) -2*resultFontHeight,
+                                               yValues,
+                                               0, resultFontHeight,
+                                               Util.TrimDecimals(100.0 * UtilAll.DivideSafe(cba.y1 - cba.y0, 
cba.y0), 0) + "%",
+                                               g, alignTypes.CENTER);
+               }
+               g.SetSourceColor (black);
+       }
+
        protected void plotAlternativeLine (List<double> lineData_l)
        {
                //be safe
@@ -972,6 +1017,13 @@ public abstract class CairoBars : CairoGeneric
                set { lineData_l = value; }
        }
 
+       public List<CairoBarsArrow> EccOverload_l {
+               set { eccOverload_l = value; }
+       }
+       public bool EccOverloadWriteValue {
+               set { eccOverloadWriteValue = value; }
+       }
+
        public List<int> Saved_l {
                set { saved_l = value; }
        }
@@ -1601,6 +1653,9 @@ public class CairoBarsNHSeries : CairoBars
                if(lineData_l.Count > 0)
                        plotAlternativeLine(lineData_l);
 
+               if(eccOverload_l.Count > 0)
+                       plotEccOverload();
+
                plotResultsOnBar();
 
                writeTitleAtTop ();
@@ -1774,6 +1829,7 @@ public class CairoBarsGuideManage
 
 // ----
 //note x0pos, x1pos are the pos (meaning the bar)
+//used also for the eccentric overload
 public class CairoBarsArrow
 {
        public int x0pos;
@@ -1799,4 +1855,10 @@ public class CairoBarsArrow
        {
                return barsXCenter_l[x1pos];
        }
+
+       public override string ToString()
+       {
+               return string.Format("x0pos: {0}, y0: {1}, x1pos: {2}, y1: {3}",
+                               x0pos, y0, x1pos, y1);
+       }
 }
diff --git a/src/gui/cairo/encoder.cs b/src/gui/cairo/encoder.cs
index e5e027042..e9fa63b3c 100644
--- a/src/gui/cairo/encoder.cs
+++ b/src/gui/cairo/encoder.cs
@@ -188,4 +188,3 @@ public class CairoGraphEncoderSignal : CairoXY
        {
        }
 }
-
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 9336319d5..06f1b555c 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -3417,6 +3417,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
        private List<Cairo.Color> colorSecondary_l;
        private List<string> names_l;
        private List<int> saved_l; //saved repetitions
+       private List<CairoBarsArrow> eccOverload_l;
 
        private string titleStr;
        private string lossStr;
@@ -3697,6 +3698,10 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                TreeIter iter;
                bool iterOk = pegbe.encoderCaptureListStore.GetIterFirst(out iter);
 
+               //for eccentricOverload
+               eccOverload_l = new List<CairoBarsArrow>();
+               double concentricPreValue = -1;
+
                //discard repetitions according to pegbe.showNRepetitions
                //int countToDraw = pegbe.data9Variables.Count;
                //foreach(EncoderBarsData ebd in pegbe.data9Variables)
@@ -3708,7 +3713,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                {
                        double mainVariableValue = Convert.ToDouble(data[count]);
 
-                       //get phase (for color)
+                       // 1) get phase (for color)
                        Preferences.EncoderPhasesEnum phaseEnum = Preferences.EncoderPhasesEnum.BOTH; // 
(eccon == "c")
                        if (pegbe.eccon == "ec" || pegbe.eccon == "ecS") {
                                bool isEven = Util.IsEven(count +1); //TODO: check this (as for is reversed)
@@ -3718,7 +3723,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                                        phaseEnum = Preferences.EncoderPhasesEnum.ECC;
                        }
 
-                       //select pen color for bars and sounds
+                       // 2) manage colors for bars. select pen color for bars and sounds
                        string myColor = pegbe.feedback.AssignColorAutomatic(
                                        FeedbackEncoder.BestSetValueEnum.CAPTURE_MAIN_VARIABLE, 
mainVariableValue, phaseEnum);
 
@@ -3754,11 +3759,8 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                                 */
                                colorPhase = UtilGtk.GRAY;
                        }
-                       else {
-//                             colorPhase = UtilGtk.BLUE_PLOTS;
-//                             colorPhase = UtilGtk.BLUE_CHRONOJUMP;
+                       else
                                colorPhase = UtilGtk.BLUE_LIGHT;
-                       }
 
                        //know if ecc or con to paint with dark or light pen
                        if (pegbe.eccon == "ec" || pegbe.eccon == "ecS") {
@@ -3779,7 +3781,7 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                                        colorBar = CairoGeneric.colorFromGdk(colorPhase);
                        }
 
-
+                       // 3) add data in barA_l, barB_l, names_l and color lists
                        if(pegbe.eccon == "c")
                        {
                                barA_l.Add(new PointF(count +1, mainVariableValue));
@@ -3798,6 +3800,20 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                                }
                        }
 
+                       // 4) eccentric overload
+                       //draw green arrow eccentric overload on inertial only if ecc > con
+                       if (pegbe.hasInertia && preferences.encoderCaptureInertialEccOverloadMode !=
+                                       Preferences.encoderCaptureEccOverloadModes.NOT_SHOW &&
+                                       (pegbe.eccon == "ec" || pegbe.eccon == "ecS"))
+                       {
+                               bool isEven = Util.IsEven(count +1);
+                               if(isEven)
+                                       concentricPreValue = mainVariableValue;
+                               else if(concentricPreValue >= 0 && mainVariableValue > concentricPreValue)
+                                       eccOverload_l.Add (new CairoBarsArrow(count-1, concentricPreValue, 
count, mainVariableValue));
+                       }
+
+                       // 5) create saved list: saved_l and add to sumSaved and countSaved for title 
generation
                        if( iterOk && ((EncoderCurve) pegbe.encoderCaptureListStore.GetValue (iter, 
0)).Record )
                        {
                                if(pegbe.eccon == "c" ||
@@ -3814,7 +3830,8 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                                else if(phaseEnum == Preferences.EncoderPhasesEnum.CON)
                                        saved_l.Add(Convert.ToInt32(Math.Floor(UtilAll.DivideSafe(count, 
2))));
                        }
-                       //work and impulse
+
+                       // 6) work and impulse
                        if(dataWorkJ.Count > 0)
                        {
                                if(preferences.encoderWorkKcal)
@@ -3939,6 +3956,14 @@ public class CairoPaintBarplotPreEncoder : CairoPaintBarsPre
                if(lineData_l.Count > 0)
                        cb.LineData_l = lineData_l; //range
 
+               if(eccOverload_l.Count > 0)
+               {
+                       cb.EccOverload_l = eccOverload_l;
+                       if (preferences.encoderCaptureInertialEccOverloadMode ==
+                                       Preferences.encoderCaptureEccOverloadModes.SHOW_LINE_AND_PERCENT)
+                               cb.EccOverloadWriteValue = true;
+               }
+
                if(saved_l.Count > 0)
                        cb.Saved_l = saved_l;
 


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