コード例 #1
0
ファイル: Race.cs プロジェクト: helios57/anrl
 public Race()
     : base()
 {
     competitors = new CompetitorCollection();
     competitorGroups = new CompetitorGroupCollection();
     flights = new FlightCollection();
     date = new DateTime();
     map = new Map();
     takeOffGate = new Gate();
     defaultRunway = true;
     defaultTargetFlightDuration = new TimeSpan(0);
     timeToStartGateDefault = new TimeSpan(0);
     timeToStartGateAlternative = new TimeSpan(0);
 }
コード例 #2
0
ファイル: Race.cs プロジェクト: helios57/anrl
 public void SetMap(string path)
 {
     Bitmap image = new Bitmap(path);
     GpsPoint topLeftPoint;
     GpsPoint bottomRightPoint;
     double topLeftLatitude;
     double topLeftLongitude;
     double bottomRightLatitude;
     double bottomRightLongitude;
     string[] coordinatesFromPath = path.Remove(path.LastIndexOf(".")).Substring(path.LastIndexOf(@"\") + 1).Split("_".ToCharArray());
     foreach (string coordinate in coordinatesFromPath)
     {
         if (coordinate.Length != 6 || coordinate == null || coordinate == string.Empty)
         {
             throw (new FormatException("Coordinates in image name not in correct format!"));
         }
     }
     topLeftLongitude = Convert.ToDouble(coordinatesFromPath[0]);
     topLeftLatitude = Convert.ToDouble(coordinatesFromPath[1]);
     bottomRightLongitude = Convert.ToDouble(coordinatesFromPath[2]);
     bottomRightLatitude = Convert.ToDouble(coordinatesFromPath[3]);
     topLeftPoint = new GpsPoint(topLeftLatitude, topLeftLongitude, GpsPointFormatImport.Swiss);
     bottomRightPoint = new GpsPoint(bottomRightLatitude, bottomRightLongitude, GpsPointFormatImport.Swiss);
     map = new Map(image, topLeftPoint, bottomRightPoint);
 }
コード例 #3
0
ファイル: Common.cs プロジェクト: helios57/anrl
        public static Image drawGroupFlights(Map map, Parcours parcours, CompetitorGroup group)
        {
            int competitorCounter = 0;

            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();
            foreach (Competitor competitor in group.Competitors)
            {
                //Flight flight = competitor.getFlight(group);
                // ToDo: get flight
                Flight flight = null;
                Pen[] pens = new Pen[]{new Pen(Brushes.Blue, 3.0f), new Pen(Brushes.Aquamarine, 3.0f), new Pen(Brushes.BlueViolet, 3.0f), new Pen(Brushes.DeepSkyBlue, 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(pens[competitorCounter], points);

                foreach (List<Point> penaltyPts in penaltyPointsList)
                {
                    Point[] pointarray = penaltyPts.ToArray();
                    gr.DrawLines(penInZone, pointarray);
                }
                competitorCounter++;
            }
            return pg;
        }
コード例 #4
0
ファイル: Common.cs プロジェクト: helios57/anrl
        /// <summary>
        /// Creates an Image of the specified Parcours, including all ForbiddenZones, Gates and the NoBackLine
        /// </summary>
        /// <param name="map"></param>
        /// <param name="parcours"></param>
        /// <returns></returns>
        public static Image drawParcours(Map map, Parcours parcours)
        {
            // create a canvas for painting on
            Image img = (Image)map.Image.Clone();
            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(new SolidBrush(Color.FromArgb(150, 250, 00, 20)), 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;

            foreach (ForbiddenZone fz in parcours.ForbiddenZones)
            {
                Point[] points = new Point[fz.GpsPoints.Count];
                int i = 0;

                foreach (GpsPoint gpsPoint in fz.GpsPoints)
                {
                    double currentPointLongitudeDifference = gpsPoint.Longitude - map.TopLeftPoint.Longitude;
                    double currentPointLatitudeDifference = map.TopLeftPoint.Latitude - gpsPoint.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());
                    points[i] = new Point(mapPointX, mapPointY);
                    i++;
                }
                gr.FillPolygon(sb, points);
                gr.DrawPolygon(pen, points);
            }
            Pen pen2 = new Pen(Brushes.Black, 10.0f);
            for (int i = 0; i < parcours.Gates.Count / 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    double currentPoint1LongitudeDifference = parcours.Gates[i, j].LeftPoint.Longitude - map.TopLeftPoint.Longitude;
                    double currentPoint1LatitudeDifference = map.TopLeftPoint.Latitude - parcours.Gates[i, j].LeftPoint.Latitude;

                    double currentPoint2LongitudeDifference = parcours.Gates[i, j].RightPoint.Longitude - map.TopLeftPoint.Longitude;
                    double currentPoint2LatitudeDifference = map.TopLeftPoint.Latitude - parcours.Gates[i, j].RightPoint.Latitude;

                    double currentPoint1ImageY = (currentPoint1LatitudeDifference / imagePointsLatitudeDifference) * pg.Height;
                    double currentPoint1ImageX = (currentPoint1LongitudeDifference / imagePointsLongitudeDifference) * pg.Width;

                    double currentPoint2ImageY = (currentPoint2LatitudeDifference / imagePointsLatitudeDifference) * pg.Height;
                    double currentPoint2ImageX = (currentPoint2LongitudeDifference / imagePointsLongitudeDifference) * pg.Width;

                    int mapPoint1X = int.Parse(Math.Ceiling(currentPoint1ImageX).ToString());
                    int mapPoint1Y = int.Parse(Math.Ceiling(currentPoint1ImageY).ToString());
                    int mapPoint2X = int.Parse(Math.Ceiling(currentPoint2ImageX).ToString());
                    int mapPoint2Y = int.Parse(Math.Ceiling(currentPoint2ImageY).ToString());
                    gr.DrawLine(pen2, new Point(mapPoint1X, mapPoint1Y), new Point(mapPoint2X, mapPoint2Y));
                }
            }

            try
            {
                double currentNbLinePoint1LatitudeDifference = map.TopLeftPoint.Latitude - parcours.NbLine.LeftPoint.Latitude;
                double currentNbLinePoint1LongitudeDifference = parcours.NbLine.LeftPoint.Longitude - map.TopLeftPoint.Longitude;

                double currentNbLinePoint2LatitudeDifference = parcours.NbLine.RightPoint.Latitude - map.TopLeftPoint.Latitude;
                double currentNbLinePoint2LongitudeDifference = parcours.NbLine.RightPoint.Longitude - map.TopLeftPoint.Longitude;

                double currentNbLinePoint1ImageX = (currentNbLinePoint1LatitudeDifference / imagePointsLatitudeDifference) * pg.Width;
                double currentNbLinePoint1ImageY = (currentNbLinePoint1LongitudeDifference / imagePointsLongitudeDifference) * pg.Height;

                double currentNbLinePoint2ImageX = (currentNbLinePoint2LatitudeDifference / imagePointsLatitudeDifference) * pg.Width;
                double currentNbLinePoint2ImageY = (currentNbLinePoint2LongitudeDifference / imagePointsLongitudeDifference) * pg.Height;

                int mapNbLinePoint1X = int.Parse(Math.Ceiling(currentNbLinePoint1ImageX).ToString());
                int mapNbLinePoint1Y = int.Parse(Math.Ceiling(currentNbLinePoint1ImageY).ToString());
                int mapNbLinePoint2X = int.Parse(Math.Ceiling(currentNbLinePoint2ImageX).ToString());
                int mapNbLinePoint2Y = int.Parse(Math.Ceiling(currentNbLinePoint2ImageY).ToString());

                gr.DrawLine(new Pen(Brushes.DarkBlue), new Point(mapNbLinePoint1X, mapNbLinePoint1Y), new Point(mapNbLinePoint2X, mapNbLinePoint2Y));
            }
            catch { }
            return pg;
        }
コード例 #5
0
ファイル: ImportTest.cs プロジェクト: helios57/anrl
        static void Main(string[] args)
        {
            Console.WriteLine("Import Test, testparcours.dxf");
            Race r = new Race();
            r.Location = "Birrfeld";
            r.Date = DateTime.Now;
            r.Name = "Schweizermeisterschaft";
            r.TargetFlightDuration = new TimeSpan(0);

            Parcours p = new Parcours(@"..\..\testparcours2.dxf");

            Competitor comp = new Competitor();
            comp.AcCallsign = "gibb";
            comp.Country = "Switzerland";
            comp.PilotFirstName = "Quack";
            comp.PilotName = "Crashpilot";
            comp.NavigatorFirstName = "Christopher";
            comp.NavigatorName = "Columbus";
            r.Competitors.Add(comp);

            Competitor newComp = new Competitor();
            comp.AcCallsign = "HellouHellou";
            comp.Country = "Switzerland";
            comp.PilotFirstName = "Emilio";
            comp.PilotName = "Sigrist";
            comp.NavigatorFirstName = "Gartenzwerg";
            comp.NavigatorName = "Mutzli";
            r.Competitors.Add(newComp);

            CompetitorGroup group = new CompetitorGroup();
            group.Competitors.Add(comp);

            r.ImportFlight(group, comp, @"..\..\Track1_c172.GAC");
            Flight f = r.Flights.GetFlightByGroupAndCompetitorId(group.Id, comp.Id);
            Console.WriteLine(f.Track[0].ToString(GpsPointFormatString.Swiss, GpsPointComponent.Latitude));
            Console.WriteLine(f.Track[0].ToString(GpsPointFormatString.Swiss, GpsPointComponent.Longitude));

            Map m = new Map(new Bitmap(Image.FromFile(@"..\..\635320_251980_668600_230020.jpg")),
                new GpsPoint(251980, 635320, GpsPointFormatImport.Swiss),
                new GpsPoint(230020, 668600, GpsPointFormatImport.Swiss));
            r.Map = m;

            r.SetMap(@"..\..\635320_251980_668600_230020.jpg");

            Image img = Common.drawParcours(m,p);
            img.Save(@"C:\p.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
            Process.Start(@"C:\p.bmp");

            Flight flight = r.Flights.GetFlightByGroupAndCompetitorId(group.Id, comp.Id);
            Image img2 = Common.drawFlight(m, p, flight);

            #region

            ////img.Save(@"C:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            //// Save object to a file named CarData.dat in binary.
            //BinaryFormatter binFormat = new BinaryFormatter();
            //Stream fStream = new FileStream(@"C:\tRace.anrx", FileMode.Create, FileAccess.Write, FileShare.None);
            //binFormat.Serialize(fStream, r);

            //Stream fStream2 = new FileStream(@"C:\tParcours.anrx", FileMode.Create, FileAccess.Write, FileShare.None);
            //binFormat.Serialize(fStream2, p);

            //Stream fStream3 = new FileStream(@"C:\tGroup.anrx", FileMode.Create, FileAccess.Write, FileShare.None);
            //binFormat.Serialize(fStream3, group);

            //Console.WriteLine("Number of forbidden Zones" + p.ForbiddenZones.Count);
            //foreach(ForbiddenZone f in p.ForbiddenZones)
            //{
            //    Console.WriteLine("Zone: \n");
            //    foreach (GpsPoint pt in f.GpsPoints)
            //    {
            //        Console.WriteLine("\t Point: " + pt.Longitude + " / " + pt.Latitude + "\n");
            //    }
            //}

            //for(int i =0;i<p.Gates.Length / 2; i++)
            //{
            //    Console.WriteLine("Track: \n");
            //    Console.WriteLine("Starting Gate: \n");
            //    Console.WriteLine("\t Point: " + p.Gates[i,0].LeftPoint.Longitude + " / " + p.Gates[i,0].LeftPoint.Latitude + "\n");
            //    Console.WriteLine("\t Point: " + p.Gates[i,0].RightPoint.Longitude + " / " + p.Gates[i,0].RightPoint.Latitude + "\n");
            //    Console.WriteLine("Finishing Gate:");
            //    Console.WriteLine("\t Point: " + p.Gates[i, 1].LeftPoint.Longitude + " / " + p.Gates[i, 1].LeftPoint.Latitude + "\n");
            //    Console.WriteLine("\t Point: " + p.Gates[i, 1].RightPoint.Longitude + " / " + p.Gates[i, 1].RightPoint.Latitude + "\n");

            //    Console.WriteLine("\t Point in CH Coord " + m.TopLeftPoint.ToString(GpsPointFormatString.Swiss, GpsPointComponent.Longitude));
            //    Console.WriteLine("\t Point in CH Coord " + m.TopLeftPoint.ToString(GpsPointFormatString.Swiss, GpsPointComponent.Latitude));

            //}

            //Console.WriteLine("NbLine: \n");
            //try
            //{
            //    Console.WriteLine("\t Point: " + p.NbLine.LeftPoint.Longitude + " / " + p.NbLine.LeftPoint.Latitude + "\n");
            //    Console.WriteLine("\t Point: " + p.NbLine.RightPoint.Longitude + " / " + p.NbLine.RightPoint.Latitude + "\n");
            //}
            //catch
            //{
            //    Console.WriteLine("No NbLine defined!");
            //}

            //Console.Write("Total Forbidden Zones: \t" + p.ForbiddenZones.Count + " \n");
            //Console.Write("Total Gates : \t\t" + p.Gates.Length / 2 + " \n");

            //int v = 0;
            //int w = 0;
            //foreach (TrackPoint point in comp.getFlight(group).Track)
            //{
            //    if (p.isPointOffTrack(point))
            //    {
            //        Console.WriteLine("Point was off Track: " + point.Latitude.ToString() + " / " + point.Longitude.ToString() + " Timestamp: " + point.TimeStamp.ToString());
            //        v++;
            //    }
            //    else
            //    {
            //        Console.WriteLine("Point was NOT off Track: " + point.Latitude.ToString() + " / " + point.Longitude.ToString() + " Timestamp: " + point.TimeStamp.ToString());
            //        w++;
            //    }
            //}
            //Console.WriteLine("Total Points: " + comp.getFlight(group).Track.Count + "off track: " + v.ToString() + "in track: " + w.ToString());

            //Console.WriteLine("Passed Gate at: " + comp.getFlight(group).PassedGate(p).ToString());

            #endregion

            foreach (Penalty penalty in flight.Penalties)
            {
                Console.WriteLine(penalty.PenaltyPoints.ToString() + " " + penalty.PenaltyType.ToString() + " " + penalty.Comment.ToString());
            }

            for (int i = 0; i < flight.Track.Count - 2; i++)
            {
                for(int j = 0; j<4;j++)
                {
                    for (int k = 0; k <= 1; k++)
                    {
                        //Gate gate = p.Gates[j, k];
                        // ToDo: get flights
                        //if (Common.gatePassed(gate, comp.getFlight(group).Track[i], comp.getFlight(group).Track[i + 1]))
                        //{
                        //    if (k == 0)
                        //    {
                        //        Console.WriteLine("passed Start Gate " + j + " at :" + comp.getFlight(group).Track[i].TimeStamp.ToString());
                        //    }
                        //    else
                        //    {
                        //        Console.WriteLine("passed finishing Gate " + j + " at :" +comp.getFlight(group).Track[i].TimeStamp.ToString());
                        //    }
                        //}
                    }
                }
            }

            // ToDo: get flight
            //comp.getFlight(group).Penalties.AddRange(list);
            //PdfSharp.Pdf.PdfDocument doc = Common.createPdf(comp, comp.getFlight(group), r, p);
            //doc.Save("C:\\test.pdf");
            Process.Start("C:\\test.pdf");
            Console.ReadLine();
        }