public void SaveParcours() { Parcours p = new Parcours { JouetObjets = new List <JouetObjet>() }; foreach (GameObject go in lesGOs) { p.JouetObjets.Add(JouetObjet.toJouetObjet(go)); } if (gameData == null) { gameData = new GameData { Parcours = new List <Parcours>() }; } else if (gameData.Parcours == null) { gameData.Parcours = new List <Parcours>(); } gameData.Parcours.Add(p); SaveJson(); }
// Start is called before the first frame update void Start() { indiceUsed = false; //Chargement des questions parcours = new Parcours(); //Initialisation des objets resultCanvas = canvas.transform.Find("Result").gameObject; questionCanvas = canvas.transform.Find("Question").gameObject; indiceCanvas = canvas.transform.Find("Indice").gameObject; getIndiceButton = canvas.transform.Find("IndiceAction").gameObject; //Initialisation des textes resultCanvas.GetComponent <Text>().text = ""; indiceCanvas.GetComponent <Text>().text = ""; questionCanvas.GetComponent <Text>().text = ""; getIndiceButton.SetActive(false); indiceCanvas.SetActive(false); trackableBehaviour = GetComponent <TrackableBehaviour>(); if (trackableBehaviour) { trackableBehaviour.RegisterTrackableEventHandler(this); } }
/*public async Task<ActionResult> AddModule(int? id) * { * * }*/ public async Task <ActionResult> RetraitModule(int?IdModule, int?IdParcours) { if (IdModule == null || IdParcours == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = await db.Parcours.FindAsync(IdParcours); Module module = await db.Modules.FindAsync(IdModule); if (parcours == null || module == null) { return(HttpNotFound()); } if (parcours.Modules.Any(x => (x.Id == IdModule))) { parcours.Modules.Remove(module); } await db.SaveChangesAsync(); ParcoursVM parcoursVm = new ParcoursVM(); parcoursVm.Designation = parcours.Designation; parcoursVm.Id = parcours.Id; parcoursVm.NbHeures = parcours.NbHeures; parcoursVm.Modules = parcours.Modules; return(RedirectToAction("Edit", parcoursVm)); }
public async Task <ActionResult> AjoutModule(int?IdModule, int?IdParcours) { if (IdModule == null || IdParcours == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = await db.Parcours.FindAsync(IdParcours); Module module = await db.Modules.FindAsync(IdModule); if (parcours == null || module == null) { return(HttpNotFound()); } if (!parcours.Modules.Any(x => (x.Id == IdModule))) { parcours.Modules.Add(module); } await db.SaveChangesAsync(); ParcoursVM parcoursVm = new ParcoursVM(); parcoursVm.Designation = parcours.Designation; parcoursVm.Id = parcours.Id; parcoursVm.NbHeures = parcours.NbHeures; parcoursVm.Modules = parcours.Modules; return(RedirectToAction("Edit", parcoursVm)); // L'élément sélectionné par défaut doit être resélectionné pour être pris en compte }
// GET: Parcours/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = await db.Parcours.FindAsync(id); if (parcours == null) { return(HttpNotFound()); } List <Module> modules = db.Modules.ToList(); ViewBag.IdModule = new SelectList(modules, "Id", "Resume"); ParcoursVM parcoursVm = new ParcoursVM(); parcoursVm.Designation = parcours.Designation; parcoursVm.Id = parcours.Id; parcoursVm.NbHeures = parcours.NbHeures; parcoursVm.Modules = parcours.Modules; return(View(parcoursVm)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Nom,Slogan,Logo")] ParcoursMVC parcoursMVC) { Parcours parcours = new Parcours(); //Créer une configuration de Mapper --cas de Mappage avec classe source et dest var config = new MapperConfiguration(cfg => cfg.CreateMap <ParcoursMVC, Parcours>()); //Créer un Mapper en lui passant en param la config crée var mapper = new Mapper(config); // faire l'affectation parcours = mapper.Map <Parcours>(parcoursMVC); if (ModelState.IsValid) { // Affecter parcoursMVC dans parcours et pour cela on utilise AutoMapper // parcours.Nom = parcoursMVC.Nom; // db.Parcours.Add(parcours); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(parcoursMVC)); }
// Start is called before the first frame update void Start() { Button btn = GetComponent <Button>(); btn.onClick.AddListener(OnClick); parcours = new Parcours(); }
public ActionResult DeleteConfirmed(int id) { Parcours parcours = db.Parcours.Find(id); db.Parcours.Remove(parcours); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(int id) { Parcours parcours = await db.Parcours.FindAsync(id); db.Parcours.Remove(parcours); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
// Start is called before the first frame update void Start() { instruction = GameObject.Find("Instructions"); score = GameObject.Find("Score"); ranking = GameObject.Find("Ranking"); nameInput = GameObject.Find("InputField"); sendForm = GameObject.Find("Submit"); sendForm.GetComponent <Button>().onClick.AddListener(OnClick); parcours = new Parcours(); }
public ActionResult Edit([Bind(Include = "ParcoursId")] Parcours parcours) { if (ModelState.IsValid) { db.Entry(parcours).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(parcours)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,NbHeures")] Parcours parcours) { if (ModelState.IsValid) { db.Entry(parcours).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(parcours)); }
public ActionResult Create([Bind(Include = "ParcoursId")] Parcours parcours) { if (ModelState.IsValid) { db.Parcours.Add(parcours); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(parcours)); }
// Action Mon Parcours public ActionResult MonParcours() { // Retourner un Parcours p à ce vue Parcours p = new Parcours(); p.Id = 1; p.Nom = "Dot net"; p.Slogan = "The best"; p.Logo = "mon logo"; return(View(p)); // Comment la Vue va utiliser cet objet p }
public ActionResult SaisieBootstrap(Parcours p) { if (!ModelState.IsValid) { return(View(p)); } else { parcours.Add(p); return(View()); } }
public async Task <ActionResult> Create([Bind(Include = "Id,Nom,Slogan,Logo")] Parcours parcours) { if (ModelState.IsValid) { db.Parcours.Add(parcours); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(parcours)); }
public ActionResult SaisieHelperRazor(Parcours p) { //Ajouter à la liste if (!ModelState.IsValid) { return(View(p)); } else { parcours.Add(p); return(View()); } }
// GET: Parcours/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = db.Parcours.Find(id); if (parcours == null) { return(HttpNotFound()); } return(View(parcours)); }
public ActionResult ModifParcours(Parcours p) { // Modifier le parcours Parcours AModifier = parcours.SingleOrDefault(x => x.Id == p.Id); if (AModifier != null) { //AModifier.Nom = p.Nom; AModifier.Slogan = p.Slogan; AModifier.Logo = p.Logo; parcours.Remove(AModifier); parcours.Add(p); // puisque la liste est static: Modif = Supp +Ajout } return (View("Liste", parcours)); }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = await db.Parcours.FindAsync(id); if (parcours == null) { return(HttpNotFound()); } return(View(parcours)); }
public JsonResult Supprimer(int id) { Parcours parcoursASupp = db.Parcours.SingleOrDefault(p => p.Id == id); if (parcoursASupp.Module.ToList().Count > 0) { return(Json(new { Suppression = "Non" })); } db.Parcours.Remove(parcoursASupp); db.SaveChanges(); return(Json(new { Suppression = "Ok" })); }
// Modification get suivi de Poste public ActionResult ModifParcours(int id) { Parcours parcoursAModifier = parcours.SingleOrDefault(p => p.Id == id); if (parcoursAModifier == null) { return(View("Erreur")); } else { return(View(parcoursAModifier)); } //Suppression Get puis Post }
//Suppression Get puis Post public JsonResult Supprimer(int id) { Parcours ASupp = parcours.SingleOrDefault(p => p.Id == id); if (ASupp != null) { //supprimer parcours.Remove(ASupp); return(Json(new { Suppression = "Ok" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Erreur = "Non trouvé" }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Create([Bind(Include = "id,Nom,idParcours")] ModuleView module) { if (ModelState.IsValid) { Module m = new Module(); //AutoMapper m.id = module.id; m.Nom = module.Nom; Parcours parcoursSelectionne = db.Parcours.SingleOrDefault(x => x.Id == module.idParcours); m.Parcours = parcoursSelectionne; db.Modules.Add(m); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(module)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Nom,Slogan,Logo")] ParcoursMVC parcoursMVC) { var config = new MapperConfiguration(cfg => cfg.CreateMap <ParcoursMVC, Parcours>()); var mapper = new Mapper(config); Parcours parcours = new Parcours(); parcours = mapper.Map <Parcours>(parcoursMVC); if (ModelState.IsValid) { db.Entry(parcours).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(parcoursMVC)); }
public static Race getTestRace() { Competition comp = new Competition(); comp.Location = "Birrfeld"; Race r = new Race(); r.Date = DateTime.Now; r.Name = "Schweizermeisterschaft"; string localPath = System.IO.Directory.GetCurrentDirectory(); Parcours p = new Parcours(localPath + @"\Tests\testparcours2.dxf"); r.ParcoursCollection.Add(p); r.TargetFlightDuration = new TimeSpan(0); 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); CompetitorGroup group = new CompetitorGroup(); group.Competitors.Add(comp); r.CompetitorGroups.Add(group); Flight f = new Flight(localPath + @"\Tests\Track1_c172.GAC", p.Routes[0], p); f.CompetitorGroup = group; f.Competitor = comp; r.Flights = new FlightCollection(); r.Flights.Add(f); //r.ImportFlight(group, comp, localPath + @"\Tests\Track1_c172.GAC"); //Flight f = r.Flights.GetFlightByGroupAndCompetitorId(group.Id, comp.Id); Map m = new Map(new Bitmap(Image.FromFile(localPath + @"\Tests\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"); return r; }
public async Task <ActionResult> Create([Bind(Include = "Id,DateDebut,DateFin,Nom,NbPlacesTotal,IdParcours")] SessionVM sessionVm) { if (ModelState.IsValid) { MapperConfiguration config = new MapperConfiguration(cfg => cfg.CreateMap <SessionVM, Session>()); // 2 : créer un Mapper Mapper mapper = new Mapper(config); // 3 : mappage Session session = mapper.Map <Session>(sessionVm); Parcours parcours = db.Parcours.SingleOrDefault(x => x.Id == sessionVm.IdParcours); session.Parcours = parcours; db.Sessions.Add(session); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(sessionVm)); }
// GET: Parcours/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Parcours parcours = await db.Parcours.FindAsync(id); if (parcours == null) { return(HttpNotFound()); } // Envoyer un parcoursMVC ParcoursMVC parcoursMVC = new ParcoursMVC(); var config = new MapperConfiguration(x => x.CreateMap <Parcours, ParcoursMVC>()); var mapper = new Mapper(config); parcoursMVC = mapper.Map <ParcoursMVC>(parcours); return(View(parcoursMVC)); }
//Action liste des parcours public ActionResult ListeParcours() { // Créer une liste de parcours List <Parcours> _list = new List <Parcours>(); Random r = new Random(); int j = 0; for (int k = 0; k < 30; k++) { Parcours p = new Parcours(); j = r.Next(j, 101); p.Id = j; p.Nom = "Nom du Parcours" + j; p.Slogan = "Slogan du Parcours " + j; p.Logo = "Logo du Parcours " + j; _list.Add(p); } return(View(_list)); //Contruire la vue pourquelle affiche la liste }
public async Task <ActionResult> Create([Bind(Include = "Id,Designation,NbHeures,IdModule")] ParcoursVM parcoursVm) { if (ModelState.IsValid) { MapperConfiguration config = new MapperConfiguration(cfg => cfg.CreateMap <ParcoursVM, Parcours>()); // 2 : créer un Mapper Mapper mapper = new Mapper(config); // 3 : mappage Parcours parcours = mapper.Map <Parcours>(parcoursVm); Module module = db.Modules.SingleOrDefault(x => x.Id == parcoursVm.IdModule); parcours.Modules = new List <Module>(); parcours.Modules.Add(module); db.Parcours.Add(parcours); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(parcoursVm)); }
public override void Initialize() { base.Initialize(); parcours = transform.parent.GetComponentInChildren <Parcours>(); parcours.Initialize(); }
/// <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); }
/// <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); }
/// <summary> /// Imports a DxfFile that is in the specified Format. Any changes on the import schema may cause Errors! /// </summary> /// <param name="filepath"></param> public static Parcours importFromDxf(string filepath) { Parcours parcours = new Parcours(); StreamReader sr = new StreamReader(filepath); List<string> lineList = new List<string>(); while (!sr.EndOfStream) { lineList.Add(sr.ReadLine()); } string[] lines = lineList.ToArray(); for (int i = 1; i < lines.Length; i++) //Looping through Array, starting with 1 (lines[0] is "0") { //Find Lines Containing a new Element Definition if (lines[i] == "LWPOLYLINE" && lines[i - 1] == " 0") // { //Reading out Layer ( "8" [\n] layerName) = Type of Element if (lines[i + 5] == " 8" && lines[i + 6].Contains("PROH")) // "Prohibited Zone" = ForbiddenZone { if (lines[i + 9] == " 90") { int numberOfVertexes = int.Parse(lines[i + 10]); ForbiddenZone forbiddenZone = new ForbiddenZone(); for (int j = 0; j < numberOfVertexes; j++) { forbiddenZone.AddGpsPoint(new GpsPoint(double.Parse(lines[i + (j * 4) + 18]) * 1000, double.Parse(lines[i + (j * 4) + 16]) * 1000, GpsPointFormatImport.Swiss)); } parcours.ForbiddenZones.Add(forbiddenZone); } } else if (lines[i + 5] == " 8" && lines[i + 6].Contains("STARTPOINT-")) { Gate g = new Gate(new GpsPoint(double.Parse(lines[i + 18]) * 1000, double.Parse(lines[i + 16]) * 1000, GpsPointFormatImport.Swiss), new GpsPoint(double.Parse(lines[i + 22]) * 1000, double.Parse(lines[i + 20]) * 1000, GpsPointFormatImport.Swiss)); int gatenr = int.Parse(lines[i + 6].Substring(11, 1)) - 1; // ToDo: add gate //parcours.addGate(g, gatenr, 0); } else if (lines[i + 5] == " 8" && lines[i + 6].Contains("ENDPOINT-")) { Gate g = new Gate(new GpsPoint(double.Parse(lines[i + 18]) * 1000, double.Parse(lines[i + 16]) * 1000, GpsPointFormatImport.Swiss), new GpsPoint(double.Parse(lines[i + 22]) * 1000, double.Parse(lines[i + 20]) * 1000, GpsPointFormatImport.Swiss)); int gatenr = int.Parse(lines[i + 6].Substring(9, 1)) - 1; // ToDo: add gate //parcours.addGate(g, gatenr, 1); //parcours.gates[gatenr, 1] = g; } else if (lines[i + 5] == " 8" && lines[i + 6].Contains("NBLINE")) { if (lines[i + 9] == " 90" && double.Parse(lines[10]) == 2) { parcours.NbLine = new Gate(new GpsPoint(double.Parse(lines[i + 18]) * 1000, double.Parse(lines[i + 16]) * 1000, GpsPointFormatImport.Swiss), new GpsPoint(double.Parse(lines[i + 22]) * 1000, double.Parse(lines[i + 20]) * 1000, GpsPointFormatImport.Swiss)); } } } } return parcours; }
/// <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; }
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; }
/// <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; }
/// <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; }
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(); }