/// <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(Competition competition, 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 + ", " + competition.Date.ToString("dd.MM.yyyy") + " in " + competition.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: " + flight.TakeOffTime.ToString("HH.mm.ss"); gfx.DrawString(takeoffTime, font2, XBrushes.Black, new XPoint(50, 130), XStringFormat.TopLeft); string startTime = "Start Time: " + flight.StartGateTime.ToString("HH.mm.ss"); gfx.DrawString(startTime, font2, XBrushes.Black, new XPoint(50, 150), XStringFormat.TopLeft); string finishTime = "Finish Time: " + flight.FinishGateTime.ToString("HH.mm.ss"); gfx.DrawString(finishTime, font2, XBrushes.Black, new XPoint(250, 150), XStringFormat.TopLeft); Image image = Common.drawFlight(parcours.ParentMap, 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.AutomaticPenalties) { 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; }
/// <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(Competition competition, Competitor competitor, Flight flight, Race race, Parcours parcours, string filename) { createPdf(competition, competitor, flight, race, parcours).Save(filename); }
/// <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(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; DateTime expectedFinishingTime = flight.StartGateTime.AddMinutes(parcours.DefaultTargetFlightDuration.TotalMinutes + 1); 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(); if (flight.Route.EndGate.gatePassed(trackPoint, flight.Track[i + 1])) { passedFinishingGate = true; } if (trackPoint.TimeStamp > expectedFinishingTime) { 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; }
private void updateFlightView() { this.Cursor = Cursors.WaitCursor; flightDataGridPenalties.Rows.Clear(); flightImageFlight.Image = new Bitmap(flightImageFlight.Width, flightImageFlight.Width); if (flightCurrentCompetitor != null && flightCurrentGroup != null) { flightCurrentFlight = flightCurrentRace.Flights.GetFlightByGroupAndCompetitorId(flightCurrentGroup, flightCurrentCompetitor); if (flightCurrentFlight != null) { flightLblCompetitor.Text = flightCurrentCompetitor.PilotName + " / " + flightCurrentCompetitor.NavigatorName; flightLblFilename.Text = flightCurrentFlight.Filename; flightLblStartgatePlan.Text = flightCurrentFlight.PlannedStartGateTime.ToString("HH:mm:ss"); flightLblStartgatePassed.Text = flightCurrentFlight.StartGateTime.ToString("HH:mm:ss"); flightLblEndgatePlan.Text = flightCurrentFlight.PlannedFinishGateTime.ToString("HH:mm:ss"); flightLblEndgatePassed.Text = flightCurrentFlight.FinishGateTime.ToString("HH:mm:ss"); flightLblTakeoffTimePlan.Text = flightCurrentFlight.PlannedTakeOffTime.ToString("HH:mm:ss"); flightLblTakeoffTime.Text = flightCurrentFlight.TakeOffTime.ToString("HH:mm:ss"); flightImageFlight.Image = Common.drawFlight(flightCurrentRace.Map, flightCurrentGroup.Parcours, flightCurrentFlight); flightCurrentFlight.resetPenalties(); flightUpdatePenaltyGrid(); this.Cursor = Cursors.Default; } } else { flightImageFlight.Image = new Bitmap(1, 1); flightLblCompetitor.Text = string.Empty; flightLblFilename.Text = string.Empty; flightLblStartgatePassed.Text = string.Empty; flightLblEndgatePassed.Text = string.Empty; flightLblTakeoffTime.Text = string.Empty; } }
private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { ////currentCompetitor = null; ////currentMap = null; ////currentParcours = null; ////raceCurrentRace = null; ////raceCurrentCompetitorGroup = null; ////raceCurrentButton = null; ////flightCurrentCompetitor = null; ////flightCurrentFlight = null; ////flightCurrentGroup = null; ////flightCurrentRace = null; ////resCurrentRace = null; if(tabControl.SelectedTab == Teilnehmer) { compUpdateGrid(); } if(tabControl.SelectedTab == tabPageRaces) { racesUpdateGrid(); raceUpdateCmbRaces(); } if (tabControl.SelectedTab == FlugVerw) { flightCurrentFlight = null; flightUpdateTree(); flightUpdatePenaltyView(); } if (tabControl.SelectedTab == Rangliste) { resUpdateRaces(); } if (tabControl.SelectedTab == Gruppen) { raceUpdateCmbRaces(); } if (tabControl.SelectedTab == Wettkampf) { competitionUpdateBaseData(); UpdateCompetitionMapsCmbSelectMaps(); UpdateCompetitionParcoursCmbParcoursSelection(); } }
private void ImportFlight_FileOk(object sender, CancelEventArgs e) { string filename = ((OpenFileDialog)sender).FileName; Competitor localCompetitor = raceCurrentCompetitorGroup.CompetitorRouteAssignmentCollection[raceAddFlightSelectedRoute].Competitor; if (raceCurrentRace.Flights.GetFlightByGroupAndCompetitorId(raceCurrentCompetitorGroup, localCompetitor) != null) { raceCurrentRace.Flights.Remove(raceCurrentRace.Flights.GetFlightByGroupAndCompetitorId(flightCurrentGroup, flightCurrentCompetitor)); } Flight newFlight = new Flight(); newFlight.Competitor = raceCurrentCompetitorGroup.CompetitorRouteAssignmentCollection[raceAddFlightSelectedRoute].Competitor; newFlight.CompetitorGroup = raceCurrentCompetitorGroup; newFlight.Map = raceCurrentRace.Map; newFlight.Parcours = raceCurrentCompetitorGroup.Parcours; newFlight.dataFromGAC(filename); newFlight.Route = raceAddFlightSelectedRoute; newFlight.Filename = new FileInfo(filename).Name; raceCurrentRace.Flights.Add(newFlight); raceUpdateGroupGrid(); }