Exemplo n.º 1
0
 public void OutputStringAsExpected()
 {
     Assert.IsTrue(Format5Letter.ToString(36.0, -150.0).Equals("36N50"));
     Assert.IsTrue(Format5Letter.ToString(36.0, 150.0).Equals("36E50"));
     Assert.IsTrue(Format5Letter.ToString(-36.0, -150.0).Equals("36W50"));
     Assert.IsTrue(Format5Letter.ToString(-36.0, 150.0).Equals("36S50"));
 }
Exemplo n.º 2
0
        /// <exception cref="ArgumentException"></exception>
        public static Route ToRoute(this IEnumerable <ICoordinate> coordinates)
        {
            var items = coordinates.ToList();

            if (items.Count < 2)
            {
                throw new ArgumentException();
            }

            var result = new Route();

            foreach (var i in items)
            {
                double lat = i.Lat;
                double lon = i.Lon;

                string latLonTxt =
                    Format5Letter.ToString(lat, lon) ??
                    FormatDecimal.ToString(lat, lon);

                var wpt = new Waypoint(latLonTxt, lat, lon);
                result.AddLastWaypoint(wpt, "DCT");
            }

            return(result);
        }
Exemplo n.º 3
0
        private static string FormatIdAttribute(string id)
        {
            var c = Formatter.ParseLatLon(id);

            if (c == null)
            {
                return(id);
            }
            return(Format5Letter.ToString(Math.Round(c.Lat), Math.Round(c.Lon)));
        }
Exemplo n.º 4
0
 private static void AddLatLons(WaypointList wptList)
 {
     for (int lon = -180; lon <= 180; lon++)
     {
         for (int lat = -90; lat <= 90; lat++)
         {
             wptList.AddWaypoint(
                 new Waypoint(Format5Letter.ToString(lat, lon), lat, lon));
         }
     }
 }
Exemplo n.º 5
0
        /// <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));
        }
Exemplo n.º 6
0
        /// <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));
        }
Exemplo n.º 7
0
        public static string AutoChooseFormat(this LatLon item)
        {
            string result = Format5Letter.To5LetterFormat(item.Lat, item.Lon);

            return(result ?? FormatDecimal.ToDecimalFormat(item.Lat, item.Lon));
        }
Exemplo n.º 8
0
 private static LatLon ParseLatLon(string s)
 {
     return(Format5Letter.Parse(s) ??
            Format7Letter.Parse(s) ??
            FormatDecimal.Parse(s));
 }
Exemplo n.º 9
0
        /// <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));
        }