示例#1
0
        public async Task<DataModel.XFlightPlan> CreateFlightPlan(DataModel.XAirportInfo departure, DataModel.XAirportInfo approch, List<String> points)
        {
            if (!isInit)
                await InitNavData();

            DataModel.XFlightPlan rtn = new DataModel.XFlightPlan(departure, approch);

            List<DataModel.XNavpoint> listpoint = new List<DataModel.XNavpoint>();
            Dictionary<string, DataModel.XNavpoint> dictpoint = new Dictionary<string, DataModel.XNavpoint>();
            for(int i =0;i<=points.Count-1;i++)
            {
                listpoint.Add(new DataModel.XNavpoint()
                {
                    PointName = points[i].ToUpper().Trim(),
                    PointType = TypeofNavpoint(points[i],i),
                });
            }
            rtn.Waypoints.InsertRange(1, listpoint);

            #region Find all waypoint
            for(int i=0;i<=rtn.Waypoints.Count -1;i++)
            {
                if(rtn.Waypoints[i].PointType==0 && !dictpoint.ContainsKey(rtn.Waypoints[i].PointName))
                    dictpoint.Add(rtn.Waypoints[i].PointName, rtn.Waypoints[i]);

                if (rtn.Waypoints[i].PointType == 3 && rtn.Waypoints[i].Longtitude.Length == 0 && !dictpoint.ContainsKey(rtn.Waypoints[i].PointName))
                {
                    DataModel.XNavpoint p = await GetWaypoint(rtn.Waypoints[i].PointName);
                    dictpoint.Add(p.PointName, p);
                }
                    //rtn.Waypoints[i] = await GetWaypoint(rtn.Waypoints[i].PointName);

                if(rtn.Waypoints[i].PointType == 2)
                {
                    List<DataModel.XNavpoint> atsinfo = await GetATSInfo(rtn.Waypoints[i - 1].PointName, rtn.Waypoints[i + 1].PointName, rtn.Waypoints[i].PointName);
                    foreach(DataModel.XNavpoint p in atsinfo)
                    {
                        if(!dictpoint.ContainsKey(p.PointName))
                            dictpoint.Add(p.PointName, p);
                    }
                        
                }
            }
            #endregion
            rtn.Waypoints = dictpoint.Values.ToList();

            return rtn;
        }
示例#2
0
 private void btn_CancelRoute_Click(object sender, RoutedEventArgs e)
 {
     flightplan = null;
     navpoints.Clear();
     txt_Departure_Description.Text = string.Empty;
     txt_Approch_Description.Text = string.Empty;
     txt_Approch_ICAO.Text = string.Empty;
     txt_Departure_ICAO.Text = string.Empty;
     txt_Waypoint_Source.Text = string.Empty;
 }
示例#3
0
        private async void btn_AppendNavpoint_Click(object sender, RoutedEventArgs e)
        {
            #region Init RouteBuilder
            Utils.RouteBuilder routebuilder = new Utils.RouteBuilder(list_Cycles.SelectedItem.ToString());
            #endregion

            #region Find departure/approch airport infomation.
            DataModel.XAirportInfo departureairport = await routebuilder.GetAirportInfo(txt_Departure_ICAO.Text);
            if(txt_Departure_ICAO.Text.Length != 4 || txt_Approch_ICAO.Text.Length != 4)
            {
                msgbox.Content = "Departure ICAO and Approch ICAO code length Must be 4";
                await msgbox.ShowAsync();
                return;
            }

            if (departureairport != null)
            {
                txt_Departure_Description.Text = departureairport.Airportname + "\r\n" +
                    "Longtitude " + departureairport.Longtitude + "\r\n" +
                    "Latitude   " + departureairport.Latitude + "\r\n" +
                    "Altitude   " + departureairport.Altitude;
            }
            else
            {
                this.msgbox.Content = "Can't Find Departure ICAO \"" + txt_Departure_ICAO.Text + "\"";
                await msgbox.ShowAsync();
                return;
            }

            DataModel.XAirportInfo approchairport = await routebuilder.GetAirportInfo(txt_Approch_ICAO.Text);
            if(approchairport != null)
            {
                txt_Approch_Description.Text = approchairport.Airportname + "\r\n" +
                    "Longtitude " + approchairport.Longtitude + "\r\n" +
                    "Latitude   " + approchairport.Latitude + "\r\n" +
                    "Altitude   " + approchairport.Altitude;
            }
            else
            {
                this.msgbox.Content = "Can't Find Approch ICAO \"" + txt_Approch_ICAO.Text + "\"";
                await msgbox.ShowAsync();
                return;
            }
            #endregion

            #region Find Route
            List<String> waypoints = new List<string>();
            foreach(string s in txt_Waypoint_Source.Text.Split(" ".ToCharArray()))
            {
                string st = s.Trim().ToUpper();
                if (st != "DCT" && st != "SID" && st != "STAR" && st.Length>0)
                    waypoints.Add(st);
            }

            flightplan = await routebuilder.CreateFlightPlan(departureairport, approchairport, waypoints);
            navpoints.Clear();

            DrawFlightPlane();

            lst_Waypoints.ItemsSource = navpoints;
            msgbox.Content = "Done";
            await msgbox.ShowAsync();
            #endregion
        }