[chronojump] run double contacts WIP



commit e7369627f866dc62b092037c31f3608df8a0fa58
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Apr 13 20:47:24 2018 +0200

    run double contacts WIP

 src/execute/run.cs        |   84 ++++++++++-----
 src/execute/runObjects.cs |  260 +++++++++++++++++++++++++++++++--------------
 src/gui/eventExecute.cs   |   38 ++++---
 3 files changed, 264 insertions(+), 118 deletions(-)
---
diff --git a/src/execute/run.cs b/src/execute/run.cs
index 7e4740b..86c7708 100644
--- a/src/execute/run.cs
+++ b/src/execute/run.cs
@@ -47,7 +47,8 @@ public class RunExecute : EventExecute
        protected Constants.DoubleContact checkDoubleContactMode;
        protected int checkDoubleContactTime;
        
-       protected bool speedStartArrival; //if speedStartArrival then race time includes reaction time
+       protected bool speedStart;        //if we started before the contact
+       protected bool speedStartArrival; //(preferences) if true then race time includes reaction time
        protected bool measureReactionTime;
        protected double reactionTimeMS; //reaction time in milliseconds
 
@@ -65,6 +66,8 @@ public class RunExecute : EventExecute
        protected static bool success;
        protected RunExecuteInspector.Types runEIType;
 
+//     protected bool firstTrackDone;
+
        public RunExecute() {
        }
 
@@ -215,6 +218,7 @@ public class RunExecute : EventExecute
                success = false;
                timerCount = 0;
                lastTc = 0;
+               //firstTrackDone = false;
 
                double timestamp = 0;
                bool ok;
@@ -237,7 +241,8 @@ public class RunExecute : EventExecute
                //initialize runDC
                runDC = new RunDoubleContact(
                                checkDoubleContactMode,
-                               checkDoubleContactTime
+                               checkDoubleContactTime,
+                               speedStartArrival
                                );
                runPTL = new RunPhaseTimeList();
 
@@ -253,6 +258,7 @@ public class RunExecute : EventExecute
                        {
                                if( ! firstFromChronopicReceived )
                                {
+                                       speedStart = has_arrived();
                                        runDC.SpeedStart = has_arrived();
                                        firstFromChronopicReceived = true;
                                }
@@ -297,7 +303,6 @@ public class RunExecute : EventExecute
                                                //prevent double contact stuff
                                                if(runDC.UseDoubleContacts())
                                                {
-                                                       LogB.Information("CALLED-DONETF");
                                                        runDC.DoneTF (timestamp);
                                                        timerLastTf = DateTime.Now;
                                                        needCheckIfTrackEnded = true;
@@ -326,6 +331,15 @@ public class RunExecute : EventExecute
                                                initializeTimer(); //timerCount = 0
                                                runEI.ChangePhase(RunExecuteInspector.Phases.OUT, "Timer 
start");
 
+                                               /*
+                                                * Stored the TC because we need it to decide
+                                                * if time will starts after this contact or
+                                                * other double contacts that will come just after
+                                                * depending on biggest tc
+                                                */
+                                               runDC.DoneTC(timestamp, false);
+                                               runPTL.AddTC(timestamp);
+
                                                feedbackMessage = "";
                                                needShowFeedbackMessage = true;
                                        }
@@ -339,7 +353,7 @@ public class RunExecute : EventExecute
                                                        lastTc = timestamp / 1000.0;
                                                        runEI.ChangePhase(RunExecuteInspector.Phases.OUT,
                                                                string.Format("SpeedStartArrival, tc = {0}", 
Math.Round(lastTc, 3)));
-                                                       runDC.DoneTC(timestamp);
+                                                       runDC.DoneTC(timestamp, true);
                                                        runPTL.AddTC(timestamp);
                                                }
 
@@ -350,13 +364,10 @@ public class RunExecute : EventExecute
                                                                string.Format("SpeedStartArrival, timestamp = 
{0}", timestamp));
 
                                                if(runDC.UseDoubleContacts())
-                                               {
-                                                       LogB.Information("CALLED-DONETC");
-                                                       runDC.DoneTC(timestamp);
-                                               }
-                                               else {
+                                                       runDC.DoneTC(timestamp, true);
+                                               else
                                                        lastTc = timestamp / 1000.0;
-                                               }
+
                                                runPTL.AddTC(timestamp);
 
                                                onlyInterval_SetRSAVariables();
@@ -433,15 +444,15 @@ public class RunExecute : EventExecute
 
        protected override bool lastTfCheckTimeEnded()
        {
-               LogB.Information("In lastTfCheckTimeEnded()");
+               //LogB.Information("In lastTfCheckTimeEnded()");
                TimeSpan span = DateTime.Now - timerLastTf;
                if(span.TotalMilliseconds > checkDoubleContactTime * 1.5)
                {
                        timerLastTf = DateTime.Now;
-                       LogB.Information("... ended success");
+                       LogB.Information("lastTfCheckTimeEnded: success");
                        return true;
                }
-               LogB.Information("... ended NOT success");
+               //LogB.Information("... ended NOT success");
                return false;
        }
 
@@ -454,23 +465,44 @@ public class RunExecute : EventExecute
                LogB.Information("In trackDone()");
                //double myTrackTime = 0;
                if(runDC.UseDoubleContacts())
+               {
+                       if(! runDC.FirstTrackDone)
+                       {
+                               //TODO: take care because maybe more data can come than just the start, eg:
+                               //
+                               //_ __ _   (300ms < > 450ms)      _ _ _        (450ms...)
+                               //
+                               //all above line can be processed at once
+                               //so IsStartDoubleContact will be false
+                               //because all the tc,tf are processed and tf in the middle is greater than 
300ms
+                               //so start will be marked in the first _
+                               //when should be done in the second _
+                               if(runDC.IsStartDoubleContact())
+                               {
+                                       int posOfBiggestTC = runDC.GetPosOfBiggestTC(false);
+
+                                       if(speedStart && ! speedStartArrival)
+                                               runPTL.FirstRPIs = posOfBiggestTC +1;
+                                       else
+                                               runPTL.FirstRPIs = posOfBiggestTC;
+
+                                       runDC.UpdateStartPos(posOfBiggestTC);
+                                       return;
+                               }
+
+                               //if is not double contact then track will be created
+                       }
+
                        trackTime = runDC.GetTrackTimeInSecondsAndUpdateStartPos(); //will come in seconds
+                       runDC.FirstTrackDone = true;
+               }
                else {
-                       //note in double contacts mode timestamp can have added DCFlightTimes and 
DCContactTimes. So contact time is not only on lastTc
+                       //note in double contacts mode timestamp can have added
+                       //DCFlightTimes and DCContactTimes.
+                       //So contact time is not only on lastTc
                        trackTime = lastTc + lastTf/1000.0;
                }
 
-               //check if start is double contact
-               if(trackTime < 0)
-               {
-                       if( ! runDC.SpeedStart )
-                               runPTL.FirstRPI = 0;
-                       else
-                               runPTL.FirstRPI = Convert.ToInt32(Math.Abs(trackTime)); //TODO: take care, is 
better GetTrackTimInSeconds... returns some int, read another value, or if trackTime == -1 then read a 
variable that will come with the FirstRPI value
-
-                       return;
-               }
-
                LogB.Information("trackTime: " + trackTime.ToString());
                //solve possible problems of bad copied data between threads on start
                if(trackTime == 0)
@@ -797,7 +829,7 @@ public class RunIntervalExecute : RunExecute
 
        protected override void trackDoneRunSpecificStuff ()
        {
-               LogB.Information(string.Format("RACE ({0}) TC: {1}; TV: {2}; TOTALTIME: {3}", tracks, lastTc, 
lastTf/1000.0, trackTime));
+               LogB.Information(string.Format("RACE TRACK ({0}) TC: {1}; TV: {2}; TOTALTIME: {3}", tracks, 
lastTc, lastTf/1000.0, trackTime));
 
                if(intervalTimesString.Length > 0) { equal = "="; }
                intervalTimesString = intervalTimesString + equal + trackTime.ToString();
diff --git a/src/execute/runObjects.cs b/src/execute/runObjects.cs
index 35bf8c8..1a0714f 100644
--- a/src/execute/runObjects.cs
+++ b/src/execute/runObjects.cs
@@ -83,21 +83,64 @@ public class RunPhaseInfoManage
        }
 
        /*
+        * check first TF if exists or all TC+TF pairs to see if all are lower than checkTime (eg 300ms)
+        * return true if all are <= checkTime
+        */
+       public bool IsStartDoubleContact(int checkTime)
+       {
+               LogB.Information("At rpim IsStartDoubleContact A");
+               int startAt = 0;
+
+               //first TF if exists
+               if(list.Count > 0)
+               {
+                       RunPhaseInfo firstRPI = (RunPhaseInfo) list[0];
+                       if(! firstRPI.IsContact()) //is TF
+                       {
+                               if(firstRPI.Duration > checkTime)
+                                       return false;
+
+                               startAt = 1;
+                       }
+               }
+               LogB.Information("At rpim IsStartDoubleContact B");
+
+               //TC+TF pairs
+               RunPhaseInfo tcRPI;
+               RunPhaseInfo tfRPI;
+               for(int i = startAt +1; i < list.Count; i +=2)
+               {
+                       tcRPI = (RunPhaseInfo) list[i-1];
+                       tfRPI = (RunPhaseInfo) list[i];
+
+                       LogB.Information("At rpim IsStartDoubleContact C");
+                       if(tcRPI.Duration + tfRPI.Duration > checkTime)
+                               return false;
+               }
+               LogB.Information("At rpim IsStartDoubleContact D");
+
+               return true;
+       }
+
+       /*
         * check double contacts at start:
         * if ! speedStart: start at contact first contact will be TF (race starts at beginning)
         * if   speedStart: start before contact (race starts related to biggest_TC
         *      if(speedStartArrival)   first contact will be TC (start at beginning of biggest_TC)
         *      else                    first contact will be TF (start at end of biggest_TC)
         */
+               /*
+                * aixo sera la funciĆ³ start double contact position()
+                * maybe not used because GetPosOfBiggestTC will be recicled
+                *
+                *
        //return the double contact tc+tf at beginning
-       public int IsStartDoubleContact(bool speedStart, int checkTime)
-       {
                if(! speedStart)
                        return 0;
 
                //--- from now on speedStart
 
-               bool first = true;
+               //bool first = true;
                int startAt = 0;
 
                double maxTCDuration = 0;
@@ -144,8 +187,9 @@ public class RunPhaseInfoManage
                else
                        return maxTCPosition;
        }
+       */
 
-       public int GetPosOfBiggestTC ()
+       public int GetPosOfBiggestTC (bool started)
        {
                LogB.Information("startPos at GetPosOfBiggestTC: " + startPos.ToString());
 
@@ -153,23 +197,28 @@ public class RunPhaseInfoManage
                if(countTCs() == 1 && oneTCAfterTheTf())
                        return startPos +1;
 
-               //if there's no tc, return -1, track duration will be tf duration
-               //if there's one tc, return -1, track duration will be tc+tf duration
-               if(countTCs() < 2)
-                       return -1;
-
-               //if there's more than one tc, return the pos of bigger tc,
-               //but first tc cannot be the biggest, because first tc will be always added (and first tf)
+               /*
+                * if there's more than one tc, return the pos of bigger tc,
+                * but first tc cannot be the biggest,
+                * because first tc will be always added (and first tf)
+                */
                double max = 0;
                int pos = 0;
                int posBiggest = 0;
                foreach(RunPhaseInfo rpi in list)
                {
-                       //pos > startPos +1 to not allow first tc to be the biggest
-                       if(pos > startPos +1 && rpi.IsContact() && rpi.Duration > max)
+                       if(rpi.IsContact() && rpi.Duration > max)
                        {
-                               max = rpi.Duration;
-                               posBiggest = pos;
+                               /*
+                                * first time we need to know if first TC is greater than the others
+                                * but once started, we care for endings of each track,
+                                * do not use the first value because it's the TC of previous track
+                                */
+                               if( (started && pos >= startPos +1) || (! started && pos >= startPos) )
+                               {
+                                       max = rpi.Duration;
+                                       posBiggest = pos;
+                               }
                        }
 
                        pos ++;
@@ -178,47 +227,61 @@ public class RunPhaseInfoManage
        }
 
        //if pos == -1 return all
-       public double SumUntilPos(int pos)
+       public double SumUntilPos(int pos, bool firstTrackDone, bool speedStartArrival)
+       //public double SumUntilPos(int pos)
        {
+               LogB.Information(string.Format("SumUntilPos: startAt: {0}, until pos: {1}, firstTrackDone: 
{2}, speedStartArrival: {3}",
+                                       startPos, pos, firstTrackDone, speedStartArrival));
+
                int countStart = 0;
                double sum = 0;
+               string strSum = "";
 
-               if(pos == -1)
+               int countEnd = 0;
+               string plusSign = "";
+               foreach(RunPhaseInfo rpi in list)
                {
-                       foreach(RunPhaseInfo rpi in list)
-                               if(countStart ++ >= startPos)
-                                       sum += rpi.Duration;
-               } else {
-                       int countEnd = 0;
-                       foreach(RunPhaseInfo rpi in list)
+                       if(countStart >= startPos && countEnd < pos)
                        {
-                               if(countStart >= startPos && countEnd < pos)
+                               //if it has not firstTrackDone 1st track take care of leaving or not to count 
the related tc)
+                               if(! firstTrackDone && sum == 0 && rpi.IsContact() && ! speedStartArrival)
+                               {
+                                       //do nothing
+                               }
+                               else {
                                        sum += rpi.Duration;
 
-                               countStart ++;
-                               countEnd ++;
+                                       //debug
+                                       strSum += string.Format("{0}{1}", plusSign, rpi.Duration);
+                                       plusSign = " + ";
+                               }
                        }
+
+                       countStart ++;
+                       countEnd ++;
                }
 
+               LogB.Information("SumUntilPosProcess: " + strSum);
+
                return sum;
        }
 
        public void UpdateStartPos (int bigTCPosition)
        {
-               //if bigTCPosition == -1 , startPos will be one element more than list
-               //else bigTCPosition is the pos of the tc that cut the track. This tc has to be added on next 
track
+               /*
+                * bigTCPosition is the pos of the tc that cut the track.
+                * This tc has to be added on next track
+                */
 
-               if(bigTCPosition == -1)
-                       startPos = list.Count;
-               else
-                       startPos = bigTCPosition;
+               startPos = bigTCPosition;
        }
 
        public string PrintList()
        {
                string str = "\n";
+               int count = 0;
                foreach(RunPhaseInfo rpi in list)
-                       str += "\n" + rpi.ToString();
+                       str += "\n" + (count ++).ToString() + ": " + rpi.ToString();
 
                return str;
        }
@@ -269,9 +332,12 @@ public class RunPhaseInfoManage
 //manage double contacts in runs
 public class RunDoubleContact
 {
+       public bool SpeedStart;         //comes with speed or started in contact with the photocell
+       public bool FirstTrackDone;     //the manage of speedStartArrival has been done
+
        private Constants.DoubleContact mode;
        private int checkTime;
-       public bool SpeedStart; //comes with speed or started in contact with the photocell
+       private bool speedStartArrival;
 
        private RunPhaseInfoManage rpim;
 
@@ -281,19 +347,20 @@ public class RunDoubleContact
        private double timeAcumulated;
 
        private List<RunPhaseInfo> listCaptureThread; //this list contains TCs and TFs from capture thread
-       private bool firstTrackDone;
+
 
        //constructor ------------------------------------------
-       public RunDoubleContact (Constants.DoubleContact mode, int checkTime)
+       public RunDoubleContact (Constants.DoubleContact mode, int checkTime, bool speedStartArrival)
        {
                this.mode = mode;
                this.checkTime = checkTime;
+               this.speedStartArrival = speedStartArrival;
 
                lastTc = 0;
                timeAcumulated = 0;
                rpim = new RunPhaseInfoManage();
                listCaptureThread = new List<RunPhaseInfo>();
-               firstTrackDone = false;
+               FirstTrackDone = false;
        }
 
        //public methods ---------------------------------------
@@ -307,16 +374,20 @@ public class RunDoubleContact
                return (mode != Constants.DoubleContact.NONE);
        }
 
-       public void DoneTC (double timestamp)
+       public void DoneTC (double timestamp, bool timeStarted)
        {
+               LogB.Information("DONETC timestamp: " + timestamp + timestamp.ToString());
                lastTc = timestamp;
                listCaptureThread.Add(new RunPhaseInfo(RunPhaseInfo.Types.CONTACT, timeAcumulated, 
timestamp));
-               timeAcumulated += timestamp;
+               if(timeStarted)
+                       timeAcumulated += timestamp;
+
                LogB.Information(string.Format("DoneTC -> lastTc: {0}", lastTc));
        }
 
        public void DoneTF (double timestamp)
        {
+               LogB.Information("DONETF timestamp: " + timestamp + timestamp.ToString());
                LogB.Information(string.Format(
                                        "lastTc + timestamp <= checkTime ?, lastTc: {0}; timestamp: {1}; 
checkTime: {2}",
                                        lastTc, timestamp, checkTime));
@@ -339,32 +410,57 @@ public class RunDoubleContact
                rpim.UpdateListUsing (listCaptureThread);
        }
 
-       //this wait will be done by C#
-       public double GetTrackTimeInSecondsAndUpdateStartPos()
+       public bool IsStartDoubleContact()
        {
-               if(! firstTrackDone)
-               {
-                       //count TCs coming from double contacts at start
-                       int countDC_TCsAtStart = rpim.IsStartDoubleContact(SpeedStart, checkTime);
-                       //should work for many double contacts at start
-                       LogB.Information(string.Format("IsStartDoubleContact: {0}", countDC_TCsAtStart));
+               LogB.Information("At RunDC IsStartDoubleContact");
+               //return rpim.IsStartDoubleContact(checkTime);
 
-                       if(countDC_TCsAtStart > 0)
-                       {
-                               rpim.UpdateStartPos(countDC_TCsAtStart);
+               bool isDC = rpim.IsStartDoubleContact(checkTime);
+               LogB.Information("IsStartDoubleContact: " + isDC.ToString());
+               return isDC;
+       }
 
-                               firstTrackDone = true;
-                               return -1 * countDC_TCsAtStart;
-                       }
-                       else if(! SpeedStart)
-                       {
-                               firstTrackDone = true;
-                               return -1000; //TODO: fix this, separate GetTrackTimeIn... in two functions, 
don't return negative positions as double
-                       }
+       /*
+       public int GetStartPosition()
+       {
+               //count TCs coming from double contacts at start
+               int countDC_TCsAtStart = rpim.IsStartDoubleContact(SpeedStart, checkTime);
+               //should work for many double contacts at start
+               LogB.Information(string.Format("IsStartDoubleContact: {0}", countDC_TCsAtStart));
+//             FirstTrackDone = true;
+
+               if(countDC_TCsAtStart > 0)
+               {
+                       LogB.Information(" GetStartPosition A ");
+                       rpim.UpdateStartPos(countDC_TCsAtStart);
+
+                       return countDC_TCsAtStart;
                }
+               else if(! SpeedStart)
+               {
+                       LogB.Information(" GetStartPosition B ");
+                       return 0;
+               }
+
+               LogB.Information(" GetStartPosition C ");
+               return 0;
+       }
+       */
+
+       public int GetPosOfBiggestTC(bool started)
+       {
+               //return rpim.GetPosOfBiggestTC();
+
+               int pos = rpim.GetPosOfBiggestTC(started);
+               LogB.Information(string.Format("GetPosOfBiggestTC list: {0}, pos: {1}", rpim.PrintList(), 
pos));
+
+               return pos;
+       }
 
+       //this wait will be done by C#
+       public double GetTrackTimeInSecondsAndUpdateStartPos()
+       {
                double trackTime = getDCBiggestTC();
-               firstTrackDone = true;
 
                //in seconds
                if(trackTime > 0)
@@ -373,6 +469,11 @@ public class RunDoubleContact
                return trackTime;
        }
 
+       public void UpdateStartPos(int newPos)
+       {
+               rpim.UpdateStartPos(newPos);
+       }
+
        /*
         * <---------------------- end of called by GTK thread --------------
         */
@@ -381,11 +482,9 @@ public class RunDoubleContact
        
        private double getDCBiggestTC()
        {
-               int bigTCPosition = rpim.GetPosOfBiggestTC();
-               double sum = rpim.SumUntilPos(bigTCPosition);
-
-               LogB.Information(string.Format("\n----------------\ngetDCBiggestTC, list: {0}, startPos: {1}, 
bigTCPosition: {2}, sum: {3}",
-                                       rpim.PrintList(), rpim.StartPos, bigTCPosition, sum));
+               int bigTCPosition = GetPosOfBiggestTC(true);
+               double sum = rpim.SumUntilPos(bigTCPosition, FirstTrackDone, speedStartArrival);
+               LogB.Information(string.Format("trackDoing getDBBiggestTC bigTCPosition: {0}, Sum: {1}", 
bigTCPosition, sum));
 
                //fix problem of a tc + tf lower than checkTime
                if(sum < checkTime)
@@ -393,12 +492,12 @@ public class RunDoubleContact
                        while (sum < checkTime && bigTCPosition +2 <= rpim.LastPositionOfList)
                        {
                                bigTCPosition += 2;
-                               sum = rpim.SumUntilPos(bigTCPosition);
+                               sum = rpim.SumUntilPos(bigTCPosition, FirstTrackDone, speedStartArrival);
                                LogB.Information(string.Format("SUM was < checkTime. New bigTCPosition: {0}, 
New Sum: {1}", bigTCPosition, sum));
                        }
                }
 
-               rpim.UpdateStartPos(bigTCPosition);
+               UpdateStartPos(bigTCPosition);
 
                return sum;
        }
@@ -409,13 +508,13 @@ public class RunPhaseTimeList
 {
        private List<PhaseTime> listPhaseTime;
 
-       //if there are double contacts at start, first run phase info (0) will not be used
-       public int FirstRPI;
+       //if there are double contacts at start, first run phase infos will not be used
+       public int FirstRPIs;
 
        public RunPhaseTimeList()
        {
                listPhaseTime = new List<PhaseTime>();
-               FirstRPI = 0;
+               FirstRPIs = 0;
        }
        
        public void AddTC(double timestamp)
@@ -459,30 +558,31 @@ public class RunPhaseTimeList
                 * but 2nd TC has to be the end of the first track
                 * we need this to synchronize correctly
                 */
-               bool startedIn = false;
+//             bool startedIn = false;
                if(listPhaseTimeShallowCloned.Count >= 1)
                {
                        PhaseTime ptFirst = (PhaseTime) listPhaseTimeShallowCloned[0];
-                       if(ptFirst.IsContact)
-                               startedIn = true;
+//             if(ptFirst.IsContact)
+//                             startedIn = true;
                }
 
-               //if FirstRPI is 1 then inverted the startedIn
-               if(FirstRPI == 1)
-                       startedIn = ! startedIn;
+               //if FirstRPIs is 1 then inverted the startedIn
+//             if(FirstRPIs == 1)
+//                     startedIn = ! startedIn;
 
                // 3) add elements to the list
                LogB.Information("InListForPainting foreach:");
                int count = 0;
                double negativeValues = 0; //double contacts times at start
+               PhaseTime ptLast = null;
                foreach(PhaseTime pt in listPhaseTimeShallowCloned)
                {
                        LogB.Information(pt.ToString());
 
-                       if(FirstRPI > count)
+                       if(FirstRPIs > count)
                        {
                                negativeValues += pt.Duration/1000.0;
-                               LogB.Information("InListForPaainting negativeValues = " + 
negativeValues.ToString());
+                               LogB.Information("InListForPainting negativeValues = " + 
negativeValues.ToString());
                        }
 
                        if(pt.IsContact)
@@ -495,10 +595,14 @@ public class RunPhaseTimeList
                        LogB.Information(string.Format("End of iteration: {0}, pt.IsContact: {1}, startInMS: 
{2}, currentMS: {3}",
                                                count, pt.IsContact, startInMS, currentMS));
 
+                       ptLast = pt;
                        count ++;
-
                }
 
+               //when track ends, last phase is a TC, add it
+               if(ptLast != null && ptLast.IsContact)
+                       list_in.Add(currentMS/1000.0 + ":" + (currentMS + ptLast.Duration)/1000.0); //in 
seconds
+
                //manage the negative values
                if(negativeValues > 0)
                {
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 69a7f30..7847f5b 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -1465,21 +1465,31 @@ public partial class ChronoJumpWindow
                        }
                        */
 
-                       double negativePTLTime = 0;
-                       double timeTotalWithNegativePTL = timeTotal;
+                       double negativePTLTime = 0; //negativePTL at beginning and last TC at end
+                       double timeTotalWithExtraPTL = timeTotal;
 
                        List<string> runPTLInListForPainting = runPTL.InListForPainting();
                        if(runPTLInListForPainting.Count > 0)
                        {
+                               //last TC value
+                               string [] inPTLLastFull = 
runPTLInListForPainting[runPTLInListForPainting.Count -1].Split(new char[] {':'});
+                               double lastValue = Convert.ToDouble(inPTLLastFull[1]);
+
+                               timeTotalWithExtraPTL = lastValue;
+
+                               //negative values
                                string [] inPTL0Full = runPTLInListForPainting[0].Split(new char[] {':'});
                                double firstValue = Convert.ToDouble(inPTL0Full[0]);
+
                                if(firstValue < 0)
                                {
                                        negativePTLTime = Math.Abs(firstValue);
-                                       timeTotalWithNegativePTL += negativePTLTime;
+                                       timeTotalWithExtraPTL += negativePTLTime;
                                }
+
                        }
                        LogB.Information("negativePTLTime: " + negativePTLTime);
+                       LogB.Information("timeTotalWithExtraPTL: " + timeTotalWithExtraPTL);
 
 
                        //paint reference guide black and green if needed
@@ -1501,13 +1511,13 @@ public partial class ChronoJumpWindow
                        {
                                string [] inPTLFull = inPTL.Split(new char[] {':'});
                                int xStart = event_execute_rightMargin + Convert.ToInt32((ancho - 
2*event_execute_rightMargin) *
-                                                       (Convert.ToDouble(inPTLFull[0]) + negativePTLTime) / 
timeTotalWithNegativePTL);
+                                                       (Convert.ToDouble(inPTLFull[0]) + negativePTLTime) / 
timeTotalWithExtraPTL);
 
                                int xEnd = event_execute_rightMargin + Convert.ToInt32((ancho - 
2*event_execute_rightMargin) *
-                                               (Convert.ToDouble(inPTLFull[1]) + negativePTLTime) / 
timeTotalWithNegativePTL);
+                                               (Convert.ToDouble(inPTLFull[1]) + negativePTLTime) / 
timeTotalWithExtraPTL);
 
                                //don't plot the TCs after current track
-                               if(Convert.ToDouble(inPTLFull[0]) + negativePTLTime < 
timeTotalWithNegativePTL)
+                               //if(Convert.ToDouble(inPTLFull[0]) + negativePTLTime < timeTotalWithExtraPTL)
                                        event_execute_pixmap.DrawRectangle(pen_gris, true,
                                                        new Rectangle (xStart, alto-bottomMargin-4, 
xEnd-xStart, 4));
                        }
@@ -1534,30 +1544,30 @@ public partial class ChronoJumpWindow
                                int xStart = event_execute_rightMargin;
                                if(myTimeDoubleAccumulated - myTimeDouble > 0 || negativePTLTime > 0)
                                        xStart = event_execute_rightMargin + Convert.ToInt32((ancho - 
2*event_execute_rightMargin) * 
-                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithNegativePTL);
+                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithExtraPTL);
 
                                int xEnd = event_execute_rightMargin;
                                if(myTimeDoubleAccumulated > 0)
                                        xEnd = event_execute_rightMargin + Convert.ToInt32((ancho - 
2*event_execute_rightMargin) * 
-                                                       (myTimeDoubleAccumulated + negativePTLTime) / 
timeTotalWithNegativePTL);
+                                                       (myTimeDoubleAccumulated + negativePTLTime) / 
timeTotalWithExtraPTL);
 
                                /*
-                               LogB.Information(string.Format("ancho: {0}, (ancho - 
2*event_execute_rightMargin): {1}, timeTotal: {2}, timeTotalWithNegativePTL: {3}",
-                                                       ancho, (ancho - 2*event_execute_rightMargin), 
timeTotal, timeTotalWithNegativePTL ));
+                               LogB.Information(string.Format("ancho: {0}, (ancho - 
2*event_execute_rightMargin): {1}, timeTotal: {2}, timeTotalWithExtraPTL: {3}",
+                                                       ancho, (ancho - 2*event_execute_rightMargin), 
timeTotal, timeTotalWithExtraPTL ));
 
                                LogB.Information(string.Format("xStart: {0}, b: {1}, c: {2}, num: {3}, 
numDenom: {4}, numDenom*anchoright: {5}, xStartCalc: {6}, xStart: {7}",
                                                        myTimeDoubleAccumulated, negativePTLTime, 
myTimeDouble,
                                                        (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble),
-                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithNegativePTL,
-                                                       Convert.ToInt32((ancho - 2*event_execute_rightMargin) 
* (myTimeDoubleAccumulated + negativePTLTime) / timeTotalWithNegativePTL),
+                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithExtraPTL,
+                                                       Convert.ToInt32((ancho - 2*event_execute_rightMargin) 
* (myTimeDoubleAccumulated + negativePTLTime) / timeTotalWithExtraPTL),
                                                        event_execute_rightMargin + Convert.ToInt32((ancho - 
2*event_execute_rightMargin) *
-                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithNegativePTL),
+                                                       (myTimeDoubleAccumulated + negativePTLTime - 
myTimeDouble) / timeTotalWithExtraPTL),
                                                        xStart
                                                        ));
                                LogB.Information(string.Format("xEnd: {0}, b: {1}, num: {2}, numDenom: {3}, 
xEnd: {4}",
                                                        myTimeDoubleAccumulated, negativePTLTime,
                                                        (myTimeDoubleAccumulated + negativePTLTime),
-                                                       (myTimeDoubleAccumulated + negativePTLTime) / 
timeTotalWithNegativePTL,
+                                                       (myTimeDoubleAccumulated + negativePTLTime) / 
timeTotalWithExtraPTL,
                                                        xEnd
                                                        ));
                                */


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