/// <summary> /// If the waypoint is in format like 1030N, then return id. Otherwise, try /// to parse the waypoint id as a coordinate. If success, returns /// the coordinate in ... format (e.g. 4820N15054E). Otherwise, returns /// the id. /// </summary> public static string FormatWaypointId(this string id) { if (Format5Letter.Parse(id) != null) { return(id); } var c = Formatter.ParseLatLon(id); if (c == null) { return(id); } return(FormatDegMinNoSymbol.ToString(c)); }
/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var(route, navaids, wptList) = (input.Route, input.Navaids, input.Waypoints); if (route.Count < 2) { throw new ArgumentException(); } var from = route.FirstWaypoint; var to = route.LastWaypoint; var s = @"I 3 version 1 " + (route.Count - 1); var firstLine = GetLine(from.ID.Substring(0, 4), from, 1); var lastLine = GetLine(to.ID.Substring(0, 4), to, 1); var middleLines = route.WithoutFirstAndLast().Select(n => { var w = n.Waypoint; var id = w.ID; var navaid = navaids.Find(id, w); if (navaid != null && navaid.IsVOR) { return(GetLine(id, w, 3)); } if (navaid != null && navaid.IsNDB) { return(GetLine(id, w, 2)); } var coordinate = id.ParseLatLon(); if (coordinate == null || Format5Letter.Parse(w.ID) != null) { return(GetLine(id, w, 11)); } return(GetLine(coordinate.FormatLatLon(), w, 28)); }); var lines = List(s, firstLine) .Concat(middleLines) .Concat(lastLine) .Concat(Enumerable.Repeat("0 ---- 0 0.000000 0.000000", 4)) .Concat(""); return(string.Join("\n", lines)); }
private static LatLon ParseLatLon(string s) { return(Format5Letter.Parse(s) ?? Format7Letter.Parse(s) ?? FormatDecimal.Parse(s)); }
/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var(route, navaids, wptList) = (input.Route, input.Navaids, input.Waypoints); if (route.Count < 2) { throw new ArgumentException(); } var from = route.FirstWaypoint; var navdatapath = OptionManager.ReadFromFile().NavDataLocation; var cycle = AiracTools.AiracCyclePeriod(navdatapath); var to = route.LastWaypoint; var s = @"I 1100 Version CYCLE " + cycle.Cycle; s += "\r\nADEP " + from.ID.Substring(0, 4); s += "\r\nDEPRWY RW" + from.ID.Substring(4); var sid = route.First.Value.AirwayToNext.Airway; if (sid != "DCT") { var sidtrans = sid.Split('.'); s += "\r\nSID " + sidtrans[0]; if (sidtrans.Length > 1) { s += "\r\nSIDTRANS " + sidtrans[1]; } } s += "\r\nADES " + to.ID.Substring(0, 4); s += "\r\nDESRWY RW" + to.ID.Substring(4); var star = route.Last.Previous.Value.AirwayToNext.Airway; if (star != "DCT") { var startrans = star.Split('.'); s += "\r\nSTAR " + startrans[0]; if (startrans.Length > 1) { s += "\r\nSTARTRANS " + startrans[1]; } } s += "\r\nNUMENR " + (route.Count); var firstLine = GetLine(from.ID.Substring(0, 4), "ADEP", from, 1); var lastLine = GetLine(to.ID.Substring(0, 4), "ADES", to, 1); var middleLines = route.WithoutFirstAndLast().Select(n => { var w = n.Waypoint; var a = n.AirwayToNext.Airway; var id = w.ID; var navaid = navaids.Find(id, w); if (navaid != null && navaid.IsVOR) { return(GetLine(id, a, w, 3)); } if (navaid != null && navaid.IsNDB) { return(GetLine(id, a, w, 2)); } var coordinate = id.ParseLatLon(); if (coordinate == null || Format5Letter.Parse(w.ID) != null) { return(GetLine(id, a, w, 11)); } return(GetLine(coordinate.FormatLatLon(), a, w, 28)); }); var lines = List(s, firstLine) .Concat(middleLines) .Concat(lastLine) .Concat(""); return(string.Join("\n", lines)); }