/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var route = input.Route; if (route.Count < 2) { throw new ArgumentException(); } var from = route.FirstWaypoint.ID.Substring(0, 4); var to = route.LastWaypoint.ID.Substring(0, 4); var str = route.ToString(true); if (str == "DCT") { return($"{from} {to}"); } // Replace SID/STAR with DCT. var split = str.Split(' '); if (split.Length < 3) { throw new ArgumentException(); } var middle = string.Join(" ", split.WithoutFirstAndLast().FormatWaypointIds()); return($"{from} DCT {middle} DCT {to}"); }
/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var route = input.Route; const string start = @"[RTE] ORIGIN_AIRPORT=ABCD DEST_AIRPORT=EFGH "; const string end = @" [CDU] CRZ_ALT= COST_INDEX= "; const string template = @" [RTE.{id}] RouteName={route} Name={wpt} Latitude={lat} Longitude={lon} CrossThisPoint=0 Heading=0 Speed=0 Altitude=0 Frequency= FrequencyID= "; if (route.Count < 2) { throw new ArgumentException(); } var list = new List <string>(); var current = route.First; var index = 0; while (current.Next != route.Last) { var next = current.Next; var airway = current.Value.AirwayToNext.Airway; var airwayStr = (index == 0 || airway == "DCT") ? "" : airway; var wpt = next.Value.Waypoint; var val = template.Replace("{id}", index.ToString()) .Replace("{route}", airwayStr) .Replace("{wpt}", wpt.ID.FormatWaypointId()) .Replace("{lat}", wpt.Lat.ToString("0.000000")) .Replace("{lon}", wpt.Lon.ToString("0.000000")); list.Add(val); current = next; index++; } var startStr = start.Replace("ABCD", route.FirstWaypoint.ID.Substring(0, 4)) .Replace("EFGH", route.LastWaypoint.ID.Substring(0, 4)); return(string.Join("", startStr, string.Join("", list), end)); }
/// <summary> /// Returns the text of the file to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var(route, airports) = (input.Route, input.Airports); if (route.Count < 2) { throw new ArgumentException(); } var orig = route.FirstWaypoint; var origId = orig.ID; var origIcao = origId.Substring(0, 4); var origAirport = airports[origIcao]; var origLatLonAlt = LatLonAlt(orig, origAirport.Elevation); var origLine = $"{origIcao}, A, {origLatLonAlt}, "; var dest = route.LastWaypoint; var destId = dest.ID; var destIcao = destId.Substring(0, 4); var destAirport = airports[destIcao]; var destLatLonAlt = LatLonAlt(dest, destAirport.Elevation); var destLine = $"{destIcao}, A, {destLatLonAlt}, "; var result = new StringBuilder(); result.AppendLine("[flightplan]"); result.AppendLine($"title={origIcao} to {destIcao}"); result.AppendLine($"description={origIcao}, {destIcao}"); result.AppendLine(@"type=IFR routetype=3 cruising_altitude=10000"); result.AppendLine($"departure_id={origIcao}, {origLatLonAlt}"); result.AppendLine($"destination_id={destIcao}, {destLatLonAlt}"); result.AppendLine($"departure_name={origAirport.Name}"); result.AppendLine($"destination_name={destAirport.Name}"); var lines = new List <string>(); lines.Add(origLine); var wptLines = route .WithoutFirstAndLast() .Select(n => { var id = n.Waypoint.ID.FormatWaypointId(); return($"{id}, I, {LatLonAlt(n.Waypoint, 0.0)}, "); }); lines.AddRange(wptLines); lines.Add(destLine); ConvertLines(lines); lines.ForEach(i => result.AppendLine(i)); return(result.ToString()); }
private static XElement GetWaypointNode(Waypoint wpt, ExportInput input) { var node = new XElement("ATCWaypoint", new XElement("ATCWaypointType", "Intersection"), new XElement("WorldPosition", LatLonAlt(wpt, 0.0)), new XElement("ICAO", new XElement("ICAOIdent", wpt.ID.FormatWaypointId()))); node.SetAttributeValue("id", FormatIdAttribute(wpt.ID)); return(node); }
/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var route = input.Route; if (route.Count < 2) { throw new ArgumentException(); } var from = route.FirstWaypoint.ID; var to = route.LastWaypoint.ID; var lines = List( "[CoRte]", $"ArptDep={from.Substring(0, 4)}", $"ArptArr={to.Substring(0, 4)}", $"RwyDep={from}", $"RwyArr={to}"); var current = route.First; var index = 1; while (current.Next != route.Last) { var next = current.Next; var airway = current.Value.AirwayToNext.Airway; var isDirect = (index == 1 || airway == "DCT"); var currentWpt = current.Value.Waypoint; var nextWpt = next.Value.Waypoint; if (isDirect) { var id = nextWpt.ID.FormatWaypointId(); var lat = nextWpt.Lat.ToString("0.000000"); var lon = nextWpt.Lon.ToString("0.000000"); lines.Add($"DctWpt{index}={id}"); lines.Add($"DctWpt{index}Coordinates={lat},{lon}"); } else { lines.Add($"Airway{index}={airway}"); lines.Add($"Airway{index}FROM={currentWpt.ID}"); lines.Add($"Airway{index}TO={nextWpt.ID}"); } current = current.Next; index++; } lines.Add(""); return(string.Join("\n", lines)); }
/// <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)); }
/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var(route, w) = (input.Route, input.WindTables); var altitudes = List(6000, 9000, 12000, 18000, 24000, 30000, 34000, 39000, 44000, 49000); return(string.Join("\n", route.Select(node => { var wpt = node.Waypoint; var id = (node == route.First.Value || node == route.Last.Value) ? wpt.ID.Substring(0, 4) : wpt.ID.FormatWaypointId(); var altitudesStr = altitudes.Select(a => GetWindTemp(w, wpt, a)).ToList(); return string.Join("\t", List(id).Concat(altitudesStr.Take(5))) + "\n\t" + string.Join("\t", altitudesStr.Skip(5)); }))); }
// In the waypoint part, each line contain a waypoint and a true heading. // E.g. // ... // ... WPT0 ... heading0 // ... WPT1 ... heading1 // // heading0 is the direct heading from WPT0 to WPT1, at WPT0. public static string GetExportText(ExportInput input) { var route = input.Route; if (route.Count < 2) { throw new ArgumentException(); } var linesPart1 = List( route.FirstWaypoint.ID.Substring(0, 4), route.LastWaypoint.ID.Substring(0, 4), route.FirstWaypoint.ID.Substring(4) ).Concat(Repeat("", 7)) .Concat(List("-1", "", "", "", "", "0")); var linesPart2 = new List <string>(); var prev = route.First; var current = prev.Next; while (current != route.Last) { var airway = prev.Value.AirwayToNext.Airway; bool isDirect = (prev == route.First) || (airway == "DCT"); var w = current.Value.Waypoint; var heading = EarthGeometry.TrueHeading(prev.Value.Waypoint, w); linesPart2.Add(string.Format( "{0},{1},0, {2} {3},0,0, {4},0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0", isDirect ? "DIRECT,3" : $"{airway},2", w.ID.FormatWaypointId(), w.Lat.ToString("0.000000"), w.Lon.ToString("0.000000"), heading.ToString("0.00000"))); prev = current; current = current.Next; } linesPart2.Add(""); return(string.Join(",\n", linesPart1.Concat(linesPart2))); }
/// <summary> /// Returns a string represents the PMDG .rte file. /// SIDs, STARs are not included. /// </summary> public static string GetExportText(ExportInput input) { var route = input.Route; var airports = input.Airports; int numWpts = route.Count; // Including dep/arr airports string icaoOrig = route.FirstWaypoint.ID.Substring(0, 4); string icaoDest = route.LastWaypoint.ID.Substring(0, 4); var result = new StringBuilder(); AppendOrigAirportPart(numWpts, icaoOrig, result, airports); var node = route.First.Next; while (node != route.Last) { var airway = node.Value.AirwayToNext.Airway; var wpt = node.Value.Waypoint; if (airway == "DCT" || node.Next == route.Last) { airway = "DIRECT"; } result.Append(wpt.ID.FormatWaypointId() + "\n5\n" + airway + "\n1 "); result.AppendLine(PmdgLatLonFormat(wpt.Lat, wpt.Lon) + " 0\n0\n0\n0"); result.AppendLine(); node = node.Next; } AppendDestAirportPart(icaoDest, result, airports); return(result.ToString()); }
/// <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)); }
/// <summary> /// Returns the text of the file to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var(route, airports) = (input.Route, input.Airports); if (route.Count < 2) { throw new ArgumentException(); } var version = new XElement("AppVersion", new XElement("AppVersionMajor", "10"), new XElement("AppVersionBuild", "61637")); var orig = route.FirstWaypoint; var origId = orig.ID; var origIcao = origId.Substring(0, 4); var origRwy = origId.Substring(4); var origAirport = airports[origIcao]; var origLatLonAlt = LatLonAlt(orig, origAirport.Elevation); var dest = route.LastWaypoint; var destId = dest.ID; var destIcao = destId.Substring(0, 4); var destAirport = airports[destIcao]; var destLatLonAlt = LatLonAlt(dest, destAirport.Elevation); var origNode = new XElement("ATCWaypoint", new XElement("ATCWaypointType", "Airport"), new XElement("WorldPosition", origLatLonAlt), new XElement("ICAO", new XElement("ICAOIdent", origIcao))); origNode.SetAttributeValue("id", origIcao); var destNode = new XElement("ATCWaypoint", new XElement("ATCWaypointType", "Airport"), new XElement("WorldPosition", destLatLonAlt), new XElement("ICAO", new XElement("ICAOIdent", destIcao))); destNode.SetAttributeValue("id", destIcao); var waypoints = route.Select(n => n.Waypoint).ToArray(); var wptNodes = waypoints.WithoutFirstAndLast() .Select(x => GetWaypointNode(x, input)); var flightPlanChild = new XElement[] { new XElement("Title", origIcao + " to " + destIcao), new XElement("FPType", "IFR"), new XElement("RouteType", "HighAlt"), new XElement("CruisingAlt", "10000"), new XElement("DepartureID", origIcao), new XElement("DepartureLLA", origLatLonAlt), new XElement("DestinationID", destIcao), new XElement("DestinationLLA", destLatLonAlt), new XElement("Descr", origIcao + ", " + destIcao), new XElement("DeparturePosition", origRwy), new XElement("DepartureName", origAirport.Name), new XElement("DestinationName", destAirport.Name), version }; var flightPlanNode = new XElement("FlightPlan.FlightPlan", flightPlanChild, origNode, wptNodes, destNode); var root = new XElement("SimBase.Document", new XElement("Descr", "AceXML Document"), flightPlanNode); root.SetAttributeValue("Type", "AceXML"); root.SetAttributeValue("version", "1,0"); var doc = new XDocument(root); return(doc.ToString()); }