Exemplo n.º 1
0
        //Разбитие карты на подкарты
        public void ShowMyDialogBox(NavigationDLL.Coords l_u, NavigationDLL.Coords r_d)
        {
            DialogResult res = MessageBox.Show("Map on one panel?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            stopwatchLoad.Start();
            if (res == DialogResult.OK)
            {
                map = new NavMap(pictureBox_navmap.Width, pictureBox_navmap.Height, l_u, r_d);
            }
            if (res == DialogResult.Cancel)
            {
                map = new NavMap(l_u, r_d, 0.0001);
            }
        }
Exemplo n.º 2
0
        //BackgroundWorker двупоточного поиска пути и открытия файла
        private void OpenFileOrTwoWaySearchBackgroubdThread(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("ru-UA");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-UA");
            int count_proc = (int)e.Argument;

            switch (count_proc)
            {
            //Поиск пути
            case 1:
            {
                map.Drop();
                pictureBox_navmap.Image = map.temp_map;
                tree.A.Refresh_Search();
                dist         = 0;
                dist_2       = 0;
                bonus_thread = new Thread(() =>
                    {
                        way = tree.A.getWay_A(start, end, out dist, ref Not_Look, ref Look);
                    });
                bonus_thread_2 = new Thread(() =>
                    {
                        way_2 = tree.A.getWay_A(end, start, out dist_2, ref Not_Look_2, ref Look_2, true);
                    });
                stopwatchSearch.Restart();
                bonus_thread.Start();
                bonus_thread_2.Start();
                while (bonus_thread.IsAlive)
                {
                    //Остановка поиска пути
                    if (backgroundWorker1.CancellationPending)
                    {
                        bonus_thread.Abort();
                        if (bonus_thread_2.IsAlive)
                        {
                            bonus_thread_2.Abort();
                        }
                        stopwatchSearch.Stop();
                        break;
                    }
                }
                //bonus_thread.Join();
                //bonus_thread_2.Join();
                stopwatchSearch.Stop();
                backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(TwoWaySearchCompleted);
                break;
            }

            //Загрузка карты
            default:
            {
                using (StreamReader myStream = new StreamReader(file_name))
                {
                    tree.A = new NavigationDLL.Graf(myStream.ReadLine().Split(' ')[1].Split('"')[1]);
                    while (!myStream.EndOfStream)
                    {
                        string data = myStream.ReadLine().Split(' ')[1].Split('"')[1];
                        tree.A.AddNode(new GrafNode(data, '/', ';'));
                    }
                }
                double min_lat = double.MaxValue;
                double min_lon = double.MaxValue;
                double max_lat = double.MinValue;
                double max_lon = double.MinValue;
                foreach (var item in tree.A.tree)
                {
                    if (min_lat > item.Value.parametrs.coords.latitude)
                    {
                        min_lat = item.Value.parametrs.coords.latitude;
                    }
                    if (min_lon > item.Value.parametrs.coords.longitude)
                    {
                        min_lon = item.Value.parametrs.coords.longitude;
                    }
                    if (max_lat < item.Value.parametrs.coords.latitude)
                    {
                        max_lat = item.Value.parametrs.coords.latitude;
                    }
                    if (max_lon < item.Value.parametrs.coords.longitude)
                    {
                        max_lon = item.Value.parametrs.coords.longitude;
                    }
                }
                NavigationDLL.Coords l_u = new NavigationDLL.Coords(max_lat, min_lon);
                NavigationDLL.Coords r_d = new NavigationDLL.Coords(min_lat, max_lon);
                //stopwatch.Stop();
                //ShowMyDialogBox(l_u, r_d);
                //stopwatch.Start();
                map       = new NavMap(pictureBox_navmap.Width, pictureBox_navmap.Height, l_u, r_d);
                map_index = 0;
                map.SetAllPoint(tree.A, map_index);
                map.getLine(tree.A, map_index);
                map.setBackColor(map_index, Color.Olive);
                map.Save();
                backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FileOpenCompleted);
                break;
            }
            }
        }