예제 #1
0
파일: Common.cs 프로젝트: helios57/anrl
 /// <summary>
 /// returns the DateTime when a TakeOffGate was passed
 /// </summary>
 /// <param name="race"></param>
 /// <param name="flight"></param>
 /// <returns></returns>
 public static DateTime takeoffGatePassingTime(Race race, Flight flight)
 {
     for (int i = 0; i < flight.Track.Count - 2; i++)
     {
         if (Common.gatePassed(race.TakeOffGate, flight.Track[i], flight.Track[i + 1]))
         {
             return flight.Track[i + 1].TimeStamp;
         }
     }
     return new DateTime(0);
 }
예제 #2
0
파일: Common.cs 프로젝트: helios57/anrl
 /// <summary>
 /// Saves the specified PdfDocument to a specified Location.
 /// </summary>
 /// <param name="doc">PfdDocument to save</param>
 /// <param name="filename">Filepath (e.g. C:\flight.pdf). String must contain file Ending</param>
 public static void savePdf(Competitor competitor, Flight flight, Race race, Parcours parcours, string filename)
 {
     createPdf(competitor, flight, race, parcours).Save(filename);
 }
예제 #3
0
파일: Common.cs 프로젝트: helios57/anrl
 /// <summary>
 /// returns the DateTime a Starting Gate was passed
 /// </summary>
 /// <param name="parcours"></param>
 /// <param name="flight"></param>
 /// <returns></returns>
 public static DateTime startingGatePassingTime(Parcours parcours, Flight flight)
 {
     for ( int i = 0; i< flight.Track.Count-2; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             if(Common.gatePassed(parcours.Gates[j, 0], flight.Track[i], flight.Track[i+1]))
             {
                 return flight.Track[i+1].TimeStamp;
             }
         }
     }
     return new DateTime(0);
 }
예제 #4
0
파일: Common.cs 프로젝트: helios57/anrl
        /// <summary>
        /// Returns the Penalties for a flight on a Parcours (Forbidden Zones only)
        /// </summary>
        /// <param name="parcours"></param>
        /// <param name="flight"></param>
        /// <returns></returns>
        public static PenaltyCollection calculateForbiddenZonePenalties(Parcours parcours, Flight flight)
        {
            bool lastPointWasOffTrack = false;
            bool finishingGatePassed = false;
            List<GpsPoint> penaltyPoints = new List<GpsPoint>();

            List<List<GpsPoint>> penaltyPointsList = new List<List<GpsPoint>>();

            for (int i = 0; i< flight.Track.Count-1; i++)
            {
                if(!finishingGatePassed)
                {
                    TrackPoint trackpoint = flight.Track[i];
                    for(int j = 0; j<4;j++)
                    {
                        // ToDo: get gate
                        //if(Common.gatePassed(parcours.Gates[j,1] ,trackpoint, flight.Track[i+1]))
                        //{
                        //    finishingGatePassed = true;
                        //    break;
                        //}
                        if (parcours.IsPointOffTrack(trackpoint))
                        {
                            lastPointWasOffTrack = true;
                            penaltyPoints.Add(trackpoint);
                        }
                        else
                        {
                            if (lastPointWasOffTrack)
                            {
                                penaltyPointsList.Add(penaltyPoints);
                                penaltyPoints = new List<GpsPoint>();
                            }
                            lastPointWasOffTrack = false;
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            PenaltyCollection penalties = new PenaltyCollection();
            foreach (List<GpsPoint> penaltySequence in penaltyPointsList)
            {
                int durance = penaltySequence.Count;
                Rules.RestrictedAreaDuration restrictedAreaDuration;

                if(durance <= 2)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.ZeroToTwo;
                else if(durance >=3 && durance <= 4)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.ThreeToFour;
                else if(durance >=5 && durance <= 6)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.FiveToSix;
                else if(durance >=7 && durance <= 8)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.SevenToEight;
                else if(durance >=9 && durance <=10)
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.NineToTen;
                else
                    restrictedAreaDuration = Rules.RestrictedAreaDuration.MoreOrEqEleven;

                Penalty newPenalty = new Penalty();
                // ToDo: assign penalty point, comment, etc.
                penalties.Add(newPenalty);
            }
            return penalties;
        }
예제 #5
0
파일: Common.cs 프로젝트: helios57/anrl
 /// <summary>
 /// Imports a GAC File of a Flight.
 /// </summary>
 /// <param name="filepath"></param>
 /// <returns>The created Flight object</returns>
 public static Flight importFromGAC(string filename)
 {
     Flight newFlight = new Flight();
     StreamReader gacFileStreamReader = new StreamReader(filename);
     string line = string.Empty;
     DateTime newPointTimeStamp = DateTime.Now;
     double newPointLatitude = 0;
     double newPointLongitude = 0;
     line = gacFileStreamReader.ReadLine();
     while (!line.Substring(0, 1).Equals("I") && !gacFileStreamReader.EndOfStream)
     {
         line = gacFileStreamReader.ReadLine();
     }
     {
         while (!gacFileStreamReader.EndOfStream)
         {
             line = gacFileStreamReader.ReadLine();
             if (line.Substring(0, 1).Equals("B"))
             {
                 // timestamp
                 newPointTimeStamp = new DateTime(1, 1, 1, Convert.ToInt32(line.Substring(1, 2)), Convert.ToInt32(line.Substring(3, 2)), Convert.ToInt32(line.Substring(5, 2)));
                 // latitude
                 newPointLatitude = Convert.ToDouble(line.Substring(7, 2)) * 3600 + Convert.ToDouble(line.Substring(9, 2)) * 60 + Convert.ToDouble(line.Substring(11, 3)) * 60 / 1000;
                 switch (line.Substring(14, 1))
                 {
                     case "N":
                         break;
                     case "S":
                         newPointLatitude *= (-1);
                         break;
                     default:
                         // TODO: Error
                         break;
                 }
                 // longitude
                 newPointLongitude = Convert.ToDouble(line.Substring(15, 3)) * 3600 + Convert.ToDouble(line.Substring(18, 2)) * 60 + Convert.ToDouble(line.Substring(20, 3)) * 60 / 1000;
                 switch (line.Substring(23, 1))
                 {
                     case "E":
                         break;
                     case "W":
                         newPointLongitude *= (-1);
                         break;
                     default:
                         // ToDo: Error
                         break;
                 }
                 TrackPoint newTrackPoint = new TrackPoint(newPointLongitude, newPointLatitude, newPointTimeStamp, GpsPointFormatImport.WGS84);
                 newFlight.Track.Add(newTrackPoint);
             }
         }
     }
     return newFlight;
 }
예제 #6
0
파일: Common.cs 프로젝트: helios57/anrl
        /// <summary>
        /// Creates an Image of the specified Flight of a Competitor of a Group in the specified Parcours 
        /// </summary>
        /// <param name="map"></param>
        /// <param name="parcours"></param>
        /// <param name="competitor"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static Image drawFlight(Map map, Parcours parcours, Flight flight)
        {
            Image img = drawParcours(map, parcours);
            Bitmap pg = new Bitmap(img.Width, img.Height);
            Graphics gr = Graphics.FromImage(pg);

            // clear the canvas to white
            Rectangle pgRect = new Rectangle(0, 0, pg.Width, pg.Height);
            SolidBrush solidWhite = new SolidBrush(Color.White);
            gr.FillRectangle(solidWhite, pgRect);
            // load a new image and draw it centered on our canvas

            Rectangle rc = new Rectangle(0, 0, img.Width, img.Height);
            gr.DrawImage(img, rc);
            img.Dispose();

            Pen pen = new Pen(Brushes.Blue, 3.0f);
            Pen penInZone = new Pen(Brushes.LawnGreen, 5.0f);
            SolidBrush sb = new SolidBrush(Color.FromArgb(50, 250, 00, 20));
            double imagePointsLongitudeDifference = map.BottomRightPoint.Longitude - map.TopLeftPoint.Longitude;
            double imagePointsLatitudeDifference = map.TopLeftPoint.Latitude - map.BottomRightPoint.Latitude;

            Point[] points = new Point[flight.Track.Count];

            int i = 0;
            bool lastPointWasOffTrack = false;
            bool passedFinishingGate = false;
            List<Point> penaltyPoints = new List<Point>();
            List<List<Point>> penaltyPointsList = new List<List<Point>>();
            foreach (TrackPoint trackPoint in flight.Track)
            {

                double currentPointLongitudeDifference = trackPoint.Longitude - map.TopLeftPoint.Longitude;
                double currentPointLatitudeDifference = map.TopLeftPoint.Latitude - trackPoint.Latitude;
                double currentPointImageX = (currentPointLongitudeDifference / imagePointsLongitudeDifference) * pg.Width;
                double currentPointImageY = (currentPointLatitudeDifference / imagePointsLatitudeDifference) * pg.Height;

                int mapPointX = int.Parse(Math.Ceiling(currentPointImageX).ToString());
                int mapPointY = int.Parse(Math.Ceiling(currentPointImageY).ToString());

                GraphicsPath p = new GraphicsPath();
                for (int j = 0; j < 4; j++)
                {
                    if (Common.gatePassed(parcours.Gates[j, 1], trackPoint, flight.Track[i + 1]))
                    {
                        passedFinishingGate = true;
                    }
                }
                if (!passedFinishingGate && parcours.IsPointOffTrack(trackPoint))
                {
                    lastPointWasOffTrack = true;
                    penaltyPoints.Add(new Point(mapPointX, mapPointY));
                }
                else
                {
                    if (lastPointWasOffTrack)
                    {
                        penaltyPointsList.Add(penaltyPoints);
                        penaltyPoints = new List<Point>();
                    }
                    lastPointWasOffTrack = false;
                }

                points[i] = new Point(mapPointX, mapPointY);
                if (i < flight.Track.Count-2)
                {
                    i++;
                }
            }
                gr.DrawLines(pen, points);

            foreach (List<Point> penaltyPts in penaltyPointsList)
            {
                Point[] pointarray = penaltyPts.ToArray();
                gr.DrawLines(penInZone, pointarray);
            }

            return pg;
        }
예제 #7
0
파일: Common.cs 프로젝트: helios57/anrl
        /// <summary>
        /// Creates a Flight Data Sheet for the specified Flight in the PdfSharp.PdfDocument Format.
        /// </summary>
        /// <param name="competitor"></param>
        /// <param name="flight"></param>
        /// <param name="race"></param>
        /// <param name="parcours"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static PdfDocument createPdf(Competitor competitor, Flight flight, Race race, Parcours parcours)
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
            XFont font2 = new XFont("Verdana", 10, XFontStyle.Regular);
            XFont font3 = new XFont("Verdana", 10, XFontStyle.Regular);

            // Draw the text
            string headingText = "Results for " + race.Name + ", " + race.Date.ToString("dd.MM.yyyy") + " in " + race.Location;
            gfx.DrawString(headingText, font, XBrushes.DarkMagenta, new XPoint(50, 50), XStringFormat.TopLeft);

            string pilotLine = "Pilot: " + competitor.PilotName + ", " + competitor.PilotFirstName;
            gfx.DrawString(pilotLine, font2, XBrushes.Black, new XPoint(50, 90), XStringFormat.TopLeft);

            string copilotLine = "Navigator: " + competitor.NavigatorName + ", " + competitor.NavigatorFirstName;
            gfx.DrawString(copilotLine, font2, XBrushes.Black, new XPoint(50, 110), XStringFormat.TopLeft);

            string takeoffTime = "Takeoff time: " + Common.startingGatePassingTime(parcours, flight).ToString("HH.mm.ss");
            gfx.DrawString(takeoffTime, font2, XBrushes.Black, new XPoint(50, 130), XStringFormat.TopLeft);

            string startTime = "Start Time: " + Common.startingGatePassingTime(parcours, flight).ToString("HH.mm.ss");
            gfx.DrawString(startTime, font2, XBrushes.Black, new XPoint(50, 150), XStringFormat.TopLeft);

            string finishTime = "Finish Time: " + Common.finishingGatePassingTime(parcours, flight).ToString("HH.mm.ss");
            gfx.DrawString(finishTime, font2, XBrushes.Black, new XPoint(250, 150), XStringFormat.TopLeft);

            Image image = Common.drawFlight(race.Map, parcours, flight);
            int originalHeight = image.Height;
            int originalWidth = image.Width;
            XImage xImage = XImage.FromGdiPlusImage(image);
            double ratio = (double)image.Height / (double)image.Width;
            int height = (int)Math.Ceiling((page.Width.Point - 100) * ratio);
            gfx.DrawImage(xImage, 50, 180, page.Width.Point - 100, height);

            gfx.DrawString("Penalties", font2, XBrushes.Black, 50, height + 200);
            int position = height + 220;
            int i = 0;

            foreach (Penalty penalty in flight.Penalties)
            {
                if ((position + i * 20) <= page.Height.Point - 50)
                {
                    gfx.DrawString(penalty.PenaltyPoints.ToString(), font3, XBrushes.Gray, 60, (position + i * 20));
                    gfx.DrawString(penalty.PenaltyType.ToString() + ", " + penalty.Comment, font2, XBrushes.Gray, 120, (position + i * 20));
                    i++;
                }
                else
                {
                    page = document.AddPage();
                    gfx = XGraphics.FromPdfPage(page);
                    i = 0;
                    position = 50;
                }
            }
            return document;
        }
예제 #8
0
 public bool Contains(Flight item)
 {
     return items.Contains(item);
 }
예제 #9
0
 public void Add(Flight item)
 {
     items.Add(item);
 }
예제 #10
0
 public void Remove(Flight item)
 {
     items.Remove(item);
 }