Example #1
0
 public Mark(string name, string markType, Course course)
 {
     _name = name;
     _markType=markType;
     _courseId = course.Id;
     
     _new = true;
     _changed = true;
 }
Example #2
0
        public Race(string name, Lake lake, Course course, DateTime start, DateTime end)
        {
            _name = name;
            _lakeId = lake.Id;
            _courseId = course.Id;
            _start = start;
            _end = end;
            _startSequence = new TimeSpan(0, 0, 0);
            SetReplayTimes();
            _boats = new List<Boat>();

            _new = true;
            _changed = true;
        }
Example #3
0
 public EditCourses(Race race)
 {
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
     InitializeComponent();
     LoadPaths(race);
     _lake = race.Lake;
     try
     {
         _image = AmphibianSoftware.VisualSail.Library.SatelliteImageryHelper.GetImageForLake(_lake);
     }
     catch (Exception)
     {
         _image = null;
     }
     
     _course = race.Course;
     LoadCourse();
 }
Example #4
0
 private void newCourseBTN_Click(object sender, EventArgs e)
 {
     Course oldCourse = _race.Course;
     Course c = new Course("New Course", _race.UtcStart, _race.Lake);
     c.Save();
     _race.Course = c;
     _race.Save();
     EditCourses ec = new EditCourses(_race);
     ec.ShowDialog();
     if (ec.DialogResult == DialogResult.OK)
     {
         LoadCourses();
     }
     else
     {
         if (oldCourse != null)
         {
             _race.Course = oldCourse;
             _race.Save();
             c.Delete();
         }
     }
 }
Example #5
0
 private Course AutoGenerateCourse()
 {
     Course c = new Course(_race.Name + " Course", _race.LocalStart, _race.Lake);
     c.Save();
     return c;
 }
Example #6
0
        public void Move(DateTime time,Course course,float windDirection,DateTime raceStart)
        {
            //cheat and jump to the time for the very first move.
            //kindof hacky, but it keeps the user from having to wait for the boats to get 
            //intialized when the race starts.  Also, we probably don't want stats for <race time
            if (!_positionInitialized)
            {
                while (_boatDataRows[_currentBoatDataRow].datetime < raceStart && _currentBoatDataRow < _boatDataRows.Count - 2)
                {
                    _currentBoatDataRow++;
                }
                //if (_currentBoatDataRow > 0)
                //{
                //    _currentBoatDataRow = _currentBoatDataRow - 1;
                //}
                _positionInitialized = true;
            }

            windAngle = windDirection;

            if (_lastUpdate == null)
            {
                _lastUpdate = time;
            }
            
            CoordinatePoint cp;
            ProjectedPoint current=null;

            CoordinatePoint np;
            ProjectedPoint next=null;

            long ticksBetween;
            long actualTicks;
            double percent=0.0;


            //bool changedIndex = false;
            bool doMove = false;
            if (_lastUpdate.Ticks < time.Ticks && _currentBoatDataRow < _boatDataRows.Count - 2)
            {
                doMove = true;
                direction = BoatDirection.Forward;
                while (_boatDataRows[_currentBoatDataRow].datetime < time && _currentBoatDataRow < _boatDataRows.Count - 2)
                {
                    _currentBoatDataRow++;
                    //changedIndex = true;

                    if ((_lowWaterMark == null || _highWaterMark == null) || (time < _lowWaterMark || time > _highWaterMark))
                    {

                        cp = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow + 1].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow + 1].longitude), 0);
                        current = cp.Project();

                        np = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow].longitude), 0);
                        next = np.Project();

                        ProjectedPoint = current;

                        if (_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) < course.Route.Count)
                        {
                            NavigateCourse(_boatDataRows[_currentBoatDataRow].datetime, course, cp, np);
                        }
                        double distance = CoordinatePoint.TwoDimensionalDistance(current.Easting, current.Northing, next.Easting, next.Northing);
                        TimeSpan ts = _boatDataRows[_currentBoatDataRow + 1].datetime - _boatDataRows[_currentBoatDataRow].datetime;
                        double kmh = ((distance / 1000.0) / ts.TotalHours);
                        speed = (float)kmh;
                        //float oldWindAngle = RelativeAngleToWind;
                        arrowAngle = (float)AngleHelper.FindAngle(current, next);
                        float newWindAngle = RelativeAngleToWind;
                        if (CurrentRacingStatus == RacingStatus.Racing)
                        {
                            float deadZone = MathHelper.PiOver4 / 2f;//use to be /4f;
                            Tack.TackDirection newTack = Tack.TackDirection.Undetermined;
                            if (newWindAngle < -deadZone && newWindAngle > -MathHelper.Pi + deadZone)
                            {
                                newTack = Tack.TackDirection.Starboard;
                            }
                            else if (newWindAngle > deadZone && newWindAngle < MathHelper.Pi - deadZone)
                            {
                                newTack = Tack.TackDirection.Port;
                            }

                            if (newTack != Tack.TackDirection.Undetermined && (_tacks.Count - 1 < _currentTackIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) || _tacks[_currentTackIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime)].Direction != newTack))
                            {
                                PerformTack(_boatDataRows[_currentBoatDataRow].datetime);
                            }
                        }
                        //set the current and previous marks
                        if (_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) < course.Route.Count)
                        {
                            _currentMark = course.Route[_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime)];
                        }
                        else
                        {
                            _currentMark = null;
                        }
                        if (_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) > 0 && course.Route.Count > 0)
                        {
                            _previousMark = course.Route[_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) - 1];
                        }
                        else
                        {
                            _previousMark = null;
                        }
                        UpdateStatistics(_boatDataRows[_currentBoatDataRow].datetime, distance / 1000.0);
                        Thread.Sleep(0);
                    }
                }
            }
            else if (_lastUpdate.Ticks > time.Ticks && _currentBoatDataRow > 0)
            {
                doMove = true;
                direction = BoatDirection.Backwards;
                while (_boatDataRows[_currentBoatDataRow].datetime > time && _currentBoatDataRow > 1)
                {
                    _currentBoatDataRow--;
                    //changedIndex = true;

                    if ((_lowWaterMark == null || _highWaterMark == null) || (time < _lowWaterMark || time > _highWaterMark))
                    {

                        cp = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow - 1].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow - 1].longitude), 0);
                        current = cp.Project();

                        np = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow].longitude), 0);
                        next = np.Project();

                        //ProjectedPoint = cp.Project();

                        //double distance = CoordinatePoint.TwoDimensionalDistance(current.easting, current.northing, next.easting, next.northing);
                        //TimeSpan ts = _boatDataRows[_currentBoatDataRow].datetime - _boatDataRows[_currentBoatDataRow - 1].datetime;
                        //double kmh = ((distance / 1000.0) / ts.TotalHours);
                        //speed = (float)kmh;
                        arrowAngle = (float)AngleHelper.FindAngle(current, next);
                        //UpdateStatistics(_boatDataRows[_currentBoatDataRow].datetime, distance / 1000.0);
                        Thread.Sleep(0);
                    }
                }
            }

            //set the current and previous marks
            if (_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) < course.Route.Count)
            {
                _currentMark = course.Route[_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime)];
            }
            else
            {
                _currentMark = null;
            }
            if (_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) > 0 && course.Route.Count > 0)
            {
                _previousMark = course.Route[_currentMarkIndex.GetValue(_boatDataRows[_currentBoatDataRow].datetime) - 1];
            }
            else
            {
                _previousMark = null;
            }
            
            if (doMove && _currentBoatDataRow > 0 && _currentBoatDataRow < _boatDataRows.Count - 2)
            {
                int currentOffset;
                if (direction == BoatDirection.Forward)
                {
                    currentOffset = -1;
                }
                else
                {
                    currentOffset = 1;
                }

                cp = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow + currentOffset].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow + currentOffset].longitude), 0);
                current = cp.Project();

                np = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow].longitude), 0);
                next = np.Project();

                CoordinatePoint pp = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow - currentOffset].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow - currentOffset].longitude), 0);
                ProjectedPoint previous = pp.Project();

                ticksBetween = _boatDataRows[_currentBoatDataRow].datetime.Ticks - _boatDataRows[_currentBoatDataRow + currentOffset].datetime.Ticks;
                actualTicks = time.Ticks - _boatDataRows[_currentBoatDataRow + currentOffset].datetime.Ticks;
                percent = (double)actualTicks / (double)ticksBetween;

                double northingDiff = next.Northing - current.Northing;
                double eastingDiff = next.Easting - current.Easting;

                double northing = current.Northing + (northingDiff * percent);
                double easting = current.Easting + (eastingDiff * percent);

                ProjectedPoint actual = new ProjectedPoint();
                actual.Easting = easting;
                actual.Northing = northing;

                ProjectedPoint = actual;

                double distance = CoordinatePoint.TwoDimensionalDistance(current.Easting, current.Northing, next.Easting, next.Northing);
                TimeSpan ts = new TimeSpan(ticksBetween);
                double kmh = ((distance / 1000.0) / ts.TotalHours);
                speed = (float)kmh;

                if (Math.Abs(kmh) > 2)
                {
                    float startingAngle = (float)AngleHelper.FindAngle(previous, current);
                    float desiredAngle = (float)AngleHelper.FindAngle(next, current);
                    desiredAngle = AngleHelper.NormalizeAngle(desiredAngle);
                    float deltaAngle = AngleHelper.AngleDifference(startingAngle, desiredAngle);
                    arrowAngle = startingAngle + (deltaAngle * (float)percent);
                    arrowAngle = AngleHelper.NormalizeAngle(arrowAngle);
                    
                }

                SetHeel(time,kmh);
                SetSailCurve(time);
                SetBoomAngle(time);
                
                //if (changedIndex)
                //{
                //    _updateStatistics();
                //}
                _lastUpdate = time;
            }
            else if(_currentBoatDataRow==0||_currentBoatDataRow==_boatDataRows.Count-1)
            {
                ProjectedPoint = new CoordinatePoint(new Coordinate(_boatDataRows[_currentBoatDataRow].latitude), new Coordinate(_boatDataRows[_currentBoatDataRow].longitude), 0).Project();
            }

            if (_lowWaterMark==null||time < _lowWaterMark)
            {
                _lowWaterMark = time;
            }
            if (_highWaterMark == null || time > _highWaterMark)
            {
                _highWaterMark = time;
            }

        }
Example #7
0
        private void NavigateCourse(DateTime time, Course course,CoordinatePoint a,CoordinatePoint b)
        {
            //if (course.Route[CurrentMarkIndex.GetValue(time)].DistanceTo(location.Project()) < _markRoundDistance)
            //{
            //    CurrentMarkIndex.AddValue(time, CurrentMarkIndex.GetValue(time) + 1);
            //    #warning possible bad increment of tack count
            //    //not sure this should increment tack count, technically rounding a mark is not a tack.
            //    if (CurrentMarkIndex.GetValue(time) < course.Route.Count)
            //    {
            //        PerformTack(time);
            //    }
            //}

            Mark previous = null;
            Mark next = null;
            if (CurrentMarkIndex.GetValue(time) > 0)
            {
                previous = course.Route[CurrentMarkIndex.GetValue(time) - 1];
            }
            if (CurrentMarkIndex.GetValue(time) < course.Route.Count - 1)
            {
                next = course.Route[CurrentMarkIndex.GetValue(time) + 1];
            }

            if (course.Route[CurrentMarkIndex.GetValue(time)].IsRounding(a.Project(),b.Project(),previous,next))
            {
                CurrentMarkIndex.AddValue(time, CurrentMarkIndex.GetValue(time) + 1);
                if (CurrentMarkIndex.GetValue(time) < course.Route.Count)
                {
                    PerformTack(time);
                }
            }
        }
Example #8
0
        public static List<Mark> FindAllByCourse(Course course)
        {
            var query = from r in Persistance.Data.Mark.AsEnumerable()
                        where (int)r["course_id"] == course.Id
                        select r;

            List<Mark> marks = new List<Mark>();
            foreach (SkipperDataSet.MarkRow rr in query)
            {
                marks.Add(new Mark(rr));
            }
            return marks;
        }