Ejemplo n.º 1
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (visualization == false)
            {
                MessageBox.Show("Визуализация выключена!", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            var str = "";
            //находим файл через диалог, читаем текст

            Stream fileStream =
                new FileStream(@"C:\Users\Denis\source\repos\PathFindingApp\PathFindingApp\29x29Maze.txt",
                               FileMode.Open);

            using (var sr = new StreamReader(fileStream))
            {
                str = sr.ReadToEnd();
            }

            fileStream.Close();
            var data = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            InitTable(data.Length, data[0].Length);

            GraphParser.ParsePanel(data, tableLayoutPanel2);
            backstageViewControl1.Close();
        }
Ejemplo n.º 2
0
        private void openFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var str = "";

            //находим файл через диалог, читаем текст
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter      = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                ofd.FilterIndex = 1;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Stream fileStream = ofd.OpenFile();
                    using (var sr = new StreamReader(fileStream))
                    {
                        str = sr.ReadToEnd();
                    }

                    fileStream.Close();
                }
            }
            //разбиваем текст по строкам

            var data = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (data.Length > 50)
            {
                MessageBox.Show("Слишком большой лабиринт для редактирования!", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            InitTable(data.Length, data[0].Length);

            GraphParser.ParsePanel(data, tableLayoutPanel2);
        }
Ejemplo n.º 3
0
        private void loadButton_ItemClick(object sender, ItemClickEventArgs e)
        {
            string str = string.Empty;

            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter      = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                ofd.FilterIndex = 1;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Stream fileStream = ofd.OpenFile();
                    using (var sr = new StreamReader(fileStream))
                    {
                        str = sr.ReadToEnd();
                    }

                    fileStream.Close();
                }
            }

            try
            {
                data = str.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                _dGraph                     = GraphParser.ParseGraph(data);
                _bGraph                     = GraphParser.ParseGraph(data);
                _aGraph                     = GraphParser.ParseGraph(data);
                AStar.condition             = true;
                BreadthFirst.found          = false;
                DijkstraAlgorithm.condition = true;

                if (data.Length > 100)
                {
                    speedUp.Enabled   = false;
                    speedDown.Enabled = false;
                    dijkstraPanel.Controls.Clear();
                    dijkstraPanel.RowCount    = 2;
                    dijkstraPanel.ColumnCount = 1;
                    dijkstraPanel.ColumnStyles.Clear();
                    dijkstraPanel.RowStyles.Clear();
                    dijkstraPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    dijkstraPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 90));
                    dijkstraPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 10));
                    dijkstraPanel.Controls.Add(LargeMazePictureBox1);
                    LargeMazeSize1.Text = "Размерность лабиринта:" + data.Length.ToString();
                    dijkstraPanel.Controls.Add(LargeMazeSize1);

                    bFirstPanel.Controls.Clear();
                    bFirstPanel.RowCount    = 2;
                    bFirstPanel.ColumnCount = 1;
                    bFirstPanel.ColumnStyles.Clear();
                    bFirstPanel.RowStyles.Clear();
                    bFirstPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    bFirstPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 90));
                    bFirstPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 10));
                    bFirstPanel.Controls.Add(LargeMazePictureBox2);
                    LargeMazeSize2.Text = "Размерность лабиринта:" + data.Length.ToString();
                    bFirstPanel.Controls.Add(LargeMazeSize2);

                    aStarPanel.Controls.Clear();
                    aStarPanel.RowCount    = 2;
                    aStarPanel.ColumnCount = 1;
                    aStarPanel.ColumnStyles.Clear();
                    aStarPanel.RowStyles.Clear();
                    aStarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                    aStarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 90));
                    aStarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 10));
                    aStarPanel.Controls.Add(LargeMazePictureBox3);
                    LargeMazeSize3.Text = "Размерность лабиринта:" + data.Length.ToString();
                    aStarPanel.Controls.Add(LargeMazeSize3);
                    return;
                }

                speedUp.Enabled         = true;
                speedDown.Enabled       = true;
                AStar.speed             = 501;
                DijkstraAlgorithm.speed = 1001;
                AStar.speed             = 501;
                int rows    = data.Length;
                int coloums = data[0].Length;

                //foreach (var control in tableLayoutPanel1.Controls)
                //{
                //    var table = control as TableLayoutPanel;
                //    if (table == null) continue;
                //    foreach (var panel in table.Controls)
                //    {
                //        var p = panel as PanelControl;
                //        if (p == null)
                //            continue;
                //        //foreach (var labelControl in p.Controls)
                //        //{
                //        //    var label = labelControl as System.Windows.Forms.Label;
                //        //    if (label == null) continue;
                //        //    label.Dispose();
                //        //}

                //        //p.Controls.Clear();
                //        p.Dispose();
                //    }
                //}

                dijkstraPanel.Controls.Clear();
                dijkstraPanel.RowCount    = rows;
                dijkstraPanel.ColumnCount = coloums;
                dijkstraPanel.ColumnStyles.Clear();
                dijkstraPanel.RowStyles.Clear();
                for (int i = 0; i < coloums; i++)
                {
                    dijkstraPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < rows; i++)
                {
                    dijkstraPanel.RowStyles.Add(new RowStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < dijkstraPanel.ColumnCount; i++)
                {
                    for (int j = 0; j < dijkstraPanel.RowCount; j++)
                    {
                        PanelControl p = new PanelControl
                        {
                            BorderStyle = BorderStyles.UltraFlat,
                            LookAndFeel =
                            {
                                UseDefaultLookAndFeel = false,
                                Style                 = LookAndFeelStyle.Office2003
                            },
                            Dock   = DockStyle.Fill,
                            Margin = Padding.Empty
                        };
                        if (data.Length < 25)
                        {
                            p.Controls.Add(new System.Windows.Forms.Label
                            {
                                Text     = "",
                                AutoSize = true,
                                Dock     = DockStyle.Fill,
                                Size     = SizeFromClientSize(Parent.Size),
                                Font     = new Font("Times New Roman", 14)
                            });
                        }

                        dijkstraPanel.Controls.Add(p);
                    }
                }

                GraphParser.ParsePanel(data, dijkstraPanel);

                bFirstPanel.Controls.Clear();
                bFirstPanel.RowCount    = rows;
                bFirstPanel.ColumnCount = coloums;
                bFirstPanel.ColumnStyles.Clear();
                bFirstPanel.RowStyles.Clear();
                for (int i = 0; i < coloums; i++)
                {
                    bFirstPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < rows; i++)
                {
                    bFirstPanel.RowStyles.Add(new RowStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < bFirstPanel.ColumnCount; i++)
                {
                    for (int j = 0; j < bFirstPanel.RowCount; j++)
                    {
                        PanelControl p = new PanelControl
                        {
                            BorderStyle = BorderStyles.UltraFlat,
                            LookAndFeel =
                            {
                                UseDefaultLookAndFeel = false,
                                Style                 = LookAndFeelStyle.Office2003
                            },
                            Dock   = DockStyle.Fill,
                            Margin = Padding.Empty
                        };
                        if (data.Length < 25)
                        {
                            p.Controls.Add(new System.Windows.Forms.Label
                            {
                                Text     = "",
                                AutoSize = true,
                                Dock     = DockStyle.Fill,
                                Size     = SizeFromClientSize(Parent.Size),
                                Font     = new Font("Times New Roman", 14)
                            });
                        }

                        bFirstPanel.Controls.Add(p);
                    }
                }

                GraphParser.ParsePanel(data, bFirstPanel);


                aStarPanel.Controls.Clear();
                aStarPanel.RowCount    = rows;
                aStarPanel.ColumnCount = coloums;
                aStarPanel.ColumnStyles.Clear();
                aStarPanel.RowStyles.Clear();
                for (int i = 0; i < coloums; i++)
                {
                    aStarPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < rows; i++)
                {
                    aStarPanel.RowStyles.Add(new RowStyle(SizeType.Percent, (float)100 / coloums));
                }

                for (int i = 0; i < aStarPanel.ColumnCount; i++)
                {
                    for (int j = 0; j < aStarPanel.RowCount; j++)
                    {
                        PanelControl p = new PanelControl
                        {
                            BorderStyle = BorderStyles.UltraFlat,
                            LookAndFeel =
                            {
                                UseDefaultLookAndFeel = false,
                                Style                 = LookAndFeelStyle.Office2003
                            },
                            Dock   = DockStyle.Fill,
                            Margin = Padding.Empty
                        };
                        if (data.Length < 25)
                        {
                            p.Controls.Add(new System.Windows.Forms.Label
                            {
                                Text     = "",
                                AutoSize = true,
                                Dock     = DockStyle.Fill,
                                Size     = SizeFromClientSize(Parent.Size),
                                Font     = new Font("Times New Roman", 14)
                            });
                        }

                        aStarPanel.Controls.Add(p);
                    }
                }

                GraphParser.ParsePanel(data, aStarPanel);

                if (allAlgsButton.Down)
                {
                    allAlgsButton.PerformClick();
                }

                if (bfsButton.Down)
                {
                    bfsButton.PerformClick();
                }

                if (astarButton.Down)
                {
                    astarButton.PerformClick();
                }

                if (dijkstraButton.Down)
                {
                    dijkstraButton.PerformClick();
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                MessageBox.Show(msg, "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }