[chronojump] Last commit with a bit better POO



commit 0f4ded2277292890d52b6824adebaff186eb0d4e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 7 18:09:53 2022 +0100

    Last commit with a bit better POO

 src/encoderRhythm.cs    | 129 +++++++++++++++++++++++++++++++-----------------
 src/gui/app1/encoder.cs |  23 ++++++---
 2 files changed, 99 insertions(+), 53 deletions(-)
---
diff --git a/src/encoderRhythm.cs b/src/encoderRhythm.cs
index d4f0d3ed9..f5ea26c38 100644
--- a/src/encoderRhythm.cs
+++ b/src/encoderRhythm.cs
@@ -122,30 +122,70 @@ public class EncoderRhythm
        }
 }
 
+//not good POO, sorry
+public abstract class EncoderRhythmExecute
+{
+       public bool FirstPhaseDone;
+       protected EncoderRhythm encoderRhythm;
+
+       protected double fraction;
+       protected string textRepetition;
+       protected string textRest;
+       //private double fractionRest;
+
+
+       public abstract void FirstPhaseDo(bool up);
+
+       // ---- just for EncoderRhythmExecuteHasRhythm --->
+       public virtual void CalculateFractionsAndText() {}
+
+       public double Fraction
+       {
+               get {
+                       if(fraction < 0)
+                               return 0;
+                       else if(fraction > 1)
+                               return 1;
+                       return fraction;
+               }
+       }
+
+       public string TextRepetition
+       {
+               get { return textRepetition; }
+       }
+
+       public string TextRest
+       {
+               get { return textRest; }
+       }
+       // <---- end of just for EncoderRhythmExecuteHasRhythm ----
+
+       // ---- just for EncoderRhythmExecuteJustClusters ---->
+
+       public virtual bool ClusterRestDoing () { return false; }
+       public virtual void ClusterRestStart () {}
+       public virtual void ClusterRestStop () {}
+       public virtual string ClusterRestSecondsStr () { return ""; }
+       // <---- end of just for EncoderRhythmExecuteJustClusters ----
+}
+
 /*
  * this is fixed rhythm starting when first repetition ends
  * easy to follow. not adaptative
  */
-public class EncoderRhythmExecute
+public class EncoderRhythmExecuteHasRhythm : EncoderRhythmExecute
 {
-       public bool FirstPhaseDone;
        private DateTime phaseStartDT;
-       private EncoderRhythm encoderRhythm;
        private int nreps;
 
-       private double fraction;
-       private string textRepetition;
-       private string textRest;
-
-       //private double fractionRest;
-
        //REPETITION is doing the repetition (no differentiate between ecc/con)
        //ECC is ECC phase using phases
        //CON is CON phase using phases
        //RESTRESP is rest between repetitions
        //RESTCLUSTER is rest between clusters
-       enum phases { REPETITION, ECC, CON, RESTREP, RESTCLUSTER }
-       phases currentPhase;
+       protected enum phases { REPETITION, ECC, CON, RESTREP, RESTCLUSTER }
+       protected phases currentPhase;
 
        private bool gravitatory = true;
        /*
@@ -153,10 +193,9 @@ public class EncoderRhythmExecute
         * on gravitatory rest can be after ecc or con (see RestAfterEcc)
         */
 
-
        // Constructor ---------------------
 
-       public EncoderRhythmExecute(EncoderRhythm encoderRhythm, bool gravitatory)
+       public EncoderRhythmExecuteHasRhythm (EncoderRhythm encoderRhythm, bool gravitatory)
        {
                this.encoderRhythm = encoderRhythm;
                //this.eccon_ec = eccon_ec;
@@ -172,7 +211,7 @@ public class EncoderRhythmExecute
 
        // Public methods ------------------
 
-       public void FirstPhaseDo(bool up)
+       public override void FirstPhaseDo(bool up)
        {
                if(FirstPhaseDone)
                        return;
@@ -188,8 +227,9 @@ public class EncoderRhythmExecute
                        currentPhase = getNextPhase(phases.ECC);
        }
 
+
        //useful for fraction of the repetition and the rest time
-       public void CalculateFractionsAndText()
+       public override void CalculateFractionsAndText()
        {
                //double fraction = 0;
                TimeSpan span = DateTime.Now - phaseStartDT;
@@ -354,15 +394,37 @@ public class EncoderRhythmExecute
                }
                LogB.Information("currentPhase = " + currentPhase.ToString());
        }
+}
 
-       // ----- all this is when we only care for clusters and not for rhythm of each rep or phase
+//this manages just the rest time between clusters
+public class EncoderRhythmExecuteJustClusters : EncoderRhythmExecute
+{
        private bool clusterRestSecondsDoing = false;
        private Stopwatch clusterRestSeconds;
-       public bool ClusterRestDoing ()
+
+       // Constructor ---------------------
+
+       public EncoderRhythmExecuteJustClusters (EncoderRhythm encoderRhythm, bool gravitatory)
+       {
+               this.encoderRhythm = encoderRhythm;
+       }
+
+       // Public methods ------------------
+
+       public override void FirstPhaseDo(bool up)
+       {
+               if(FirstPhaseDone)
+                       return;
+
+               FirstPhaseDone = true;
+       }
+
+       public override bool ClusterRestDoing ()
        {
                return clusterRestSecondsDoing;
        }
-       public void ClusterRestStart ()
+
+       public override void ClusterRestStart ()
        {
                if(clusterRestSeconds == null)
                        clusterRestSeconds = new Stopwatch();
@@ -370,12 +432,14 @@ public class EncoderRhythmExecute
 
                clusterRestSecondsDoing = true;
        }
-       public void ClusterRestStop ()
+
+       public override void ClusterRestStop ()
        {
                clusterRestSeconds.Reset(); //Stops time interval measurement and resets the elapsed time to 
zero.
                clusterRestSecondsDoing = false;
        }
-       public string ClusterRestSecondsStr ()
+
+       public override string ClusterRestSecondsStr ()
        {
                double restTime = encoderRhythm.RestClustersSeconds - clusterRestSeconds.Elapsed.TotalSeconds;
 
@@ -387,31 +451,6 @@ public class EncoderRhythmExecute
                //LogB.Information("clusterRestSeconds.Elapsed.TotalSeconds: " + 
clusterRestSeconds.Elapsed.TotalSeconds.ToString());
                return string.Format(Catalog.GetString("Resting {0} s"), Util.TrimDecimals(restTime, 1));
        }
-       // <------
-
-
-       // Accessors ------------------
-
-       public double Fraction
-       {
-               get {
-                       if(fraction < 0)
-                               return 0;
-                       else if(fraction > 1)
-                               return 1;
-                       return fraction;
-               }
-       }
-
-       public string TextRepetition
-       {
-               get { return textRepetition; }
-       }
-
-       public string TextRest
-       {
-               get { return textRest; }
-       }
 }
 
 /*
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index 4745ab968..575852dc7 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -6220,7 +6220,14 @@ public partial class ChronoJumpWindow
                                 * initialize DateTime for rhythm
                                 * also variable eccon_ec gravitatory mode is e -> c, inertial is c -> e
                                 */
-                               encoderRhythmExecute = new EncoderRhythmExecute(encoderRhythm, ! 
encoderConfigurationCurrent.has_inertia);
+                               if(encoderRhythm.ActiveRhythm) {
+                                       encoderRhythmExecute = new EncoderRhythmExecuteHasRhythm 
(encoderRhythm, ! encoderConfigurationCurrent.has_inertia);
+                                       encoder_pulsebar_rhythm_eccon.Visible = true;
+                               } else if(encoderRhythm.UseClusters()) {
+                                       encoderRhythmExecute = new EncoderRhythmExecuteJustClusters 
(encoderRhythm, ! encoderConfigurationCurrent.has_inertia);
+                                       encoder_pulsebar_rhythm_eccon.Visible = false;
+                               }
+
                                image_encoder_rhythm_alert.Visible = false;
 
                                //triggers only work on gravitatory, concentric
@@ -6731,7 +6738,7 @@ public partial class ChronoJumpWindow
 
                        if(needToRefreshTreeviewCapture) 
                        {
-                               if(! encoderRhythmExecute.FirstPhaseDone)
+                               if(encoderRhythmExecute != null && ! encoderRhythmExecute.FirstPhaseDone)
                                {
                                        bool upOrDown = true;
                                        string myEccon = findEccon(false);
@@ -7045,7 +7052,7 @@ public partial class ChronoJumpWindow
                        label_encoder_rhythm_rest.Text = encoderRhythmExecute.TextRest;
                        image_encoder_rhythm_rest.Visible = encoderRhythmExecute.TextRest != "";
                }
-               else if(encoderRhythm.UseClusters())  //hi ha bugs pq a vegades es deixa de veure el 
comptador!, imprimir els valors del seguent if !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+               else if(encoderRhythm.UseClusters())
                {
                        //just for show cluster rest (so on feedback gui, rhythm will be unactive but cluster 
rest active)
                        if(! encoderRhythmExecute.FirstPhaseDone)
@@ -7053,7 +7060,6 @@ public partial class ChronoJumpWindow
                                encoder_pulsebar_rhythm_eccon.Fraction = 0;
                                label_encoder_rhythm_rest.Text = "";
                                image_encoder_rhythm_rest.Visible = false;
-                               //encoder_pulsebar_rhythm_eccon.Text = "Waiting 1st phase";
                                return;
                        }
 
@@ -7061,7 +7067,8 @@ public partial class ChronoJumpWindow
                        bool showRest = false;
                        if(radio_encoder_eccon_concentric.Active && repsDone % encoderRhythm.RepsCluster == 0)
                                showRest = true;
-                       else if(repsDone > 1 && radio_encoder_eccon_eccentric_concentric.Active && repsDone % 
(2 * encoderRhythm.RepsCluster) == 0) //TODO: add the info if start up or down, looking at FirstPhaseDo
+                       else if(repsDone > 1 && radio_encoder_eccon_eccentric_concentric.Active &&
+                                       repsDone % (2 * encoderRhythm.RepsCluster) == 0) //TODO: add the info 
if start up or down, looking at FirstPhaseDo
                                showRest = true;
 
                        if(showRest)
@@ -7086,8 +7093,6 @@ public partial class ChronoJumpWindow
                                }
                        }
                }
-
-               //TODO: remember to stop ClusterRestSeconds at end of capture
        }
 
        // -------------- drawingarea_encoder_analyze_instant
@@ -7494,7 +7499,9 @@ public partial class ChronoJumpWindow
                                                Catalog.GetString("Set corrected. string was not fully 
extended at the beginning."));
                        }
 
-                       if(encoderRhythm != null && encoderRhythm.UseClusters() && encoderRhythmExecute != 
null)
+                       if(encoderRhythm != null &&
+                                       ! encoderRhythm.ActiveRhythm && encoderRhythm.UseClusters() &&
+                                       encoderRhythmExecute != null)
                                encoderRhythmExecute.ClusterRestStop ();
 
                } else { //ANALYZE


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