コード例 #1
0
        //starting Prim method
        private void методПримаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _selectedVerticle = null;
            if (!GraphIsConnected(true))
            {
                return;
            }
            foreach (var ve in listOfVerticles)
            {
                ve.isSelected = false;
            }
            Drawing_panel.Invalidate();
            Drawing_panel.Refresh();
            var pForm = new PrimsMethodForm {
                Verticles = listOfVerticles, Edges = listOfEdges
            };

            pForm.Size        = Size;
            pForm.WindowState = WindowState;
            pForm.ShowDialog();
            foreach (var edge in listOfEdges)
            {
                edge.condition = Condition.Waiting;
            }
            RecalculateDrawingCoordinates();
        }
コード例 #2
0
        //adding edge
        private void btn_add_edge_Click(object sender, EventArgs e)
        {
            _selectedVerticle = null;
            foreach (var ve in listOfVerticles)
            {
                ve.isSelected = false;
            }
            Drawing_panel.Invalidate();
            var aef = new AddEdgeForm {
                Verticles = listOfVerticles, Edges = listOfEdges
            };

            if (listOfVerticles.Count < 2)
            {
                MessageBox.Show("В графе менее 2 вершин, создать ребро нельзя.", "Ошибка!");
                return;
            }

            aef.ShowDialog();
            if (aef.DialogResult != DialogResult.OK)
            {
                return;
            }
            listOfEdges.Add(aef.Return);
            listOfVerticles.Find(x => x.Equals(aef.Return.A)).connections++;
            listOfVerticles.Find(x => x.Equals(aef.Return.B)).connections++;
            RenewLists();
            RandomizeWeightsPositions(listOfEdges);
            Drawing_panel.Refresh();
        }
コード例 #3
0
        //graph autogeneration
        private void bibaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _selectedVerticle = null;
            foreach (var ve in listOfVerticles)
            {
                ve.isSelected = false;
            }
            Drawing_panel.Invalidate();
            var ggForm = new GraphGenerateForm();

            if (ggForm.ShowDialog() == DialogResult.OK)
            {
                ClearGraph();
                GenerateGraph(ggForm.Count, ggForm.GenerateEdges);
            }

            Drawing_panel.Refresh();
            if (ggForm.Count <= 10 || WindowState == FormWindowState.Maximized)
            {
                return;
            }
            if (MessageBox.Show("Развернуть окно для лучшего отображения графа?", "Большой граф",
                                MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                WindowState = FormWindowState.Maximized;
            }
            AddVerticle_btn.Enabled = (listOfVerticles.Count < 15);
        }
コード例 #4
0
 //clear all
 private void очиститьToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Удалить все элементы графа?", "Вы уверены?", MessageBoxButtons.YesNo) ==
         DialogResult.Yes)
     {
         ClearGraph();
         Drawing_panel.Refresh();
     }
 }
コード例 #5
0
        //adding verticle
        private void AddVerticle_btn_Click(object sender, EventArgs e)
        {
            if (listOfVerticles.Count >= 15)
            {
                AddVerticle_btn.Enabled = false;
                return;
            }

            var newvwrt = new Verticle("V" + ++_maxVertNum);

            listOfVerticles.Add(newvwrt);
            RecalculateDrawingCoordinates();
            RandomizeWeightsPositions(listOfEdges);
            RenewLists();
            Drawing_panel.Refresh();
        }
コード例 #6
0
        //delete edge
        private void удалитьToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Удaлить ребро?", "Вы уверены?",
                                MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
            var del = listOfEdges[lb_edges.SelectedIndex];

            listOfEdges.Remove(del);
            del.A.connections--;
            del.B.connections--;

            if (_selectedVerticle != null)
            {
                _selectedVerticle.isSelected = false;
            }
            _selectedVerticle = null;
            RenewLists();
            RecalculateDrawingCoordinates();
            Drawing_panel.Refresh();
        }
コード例 #7
0
        //delete verticle
        private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Удaлить вершину?", "Вы уверены?",
                                MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
            listOfVerticles.Remove(_selectedVerticle);
            while (_selectedVerticle.connections > 0)
            {
                var del = listOfEdges.First(x => Equals(x.A, _selectedVerticle) ||
                                            Equals(x.B, _selectedVerticle));
                del.A.connections--;
                del.B.connections--;
                listOfEdges.Remove(del);
            }

            _selectedVerticle.isSelected = false;
            _selectedVerticle            = null;
            AddVerticle_btn.Enabled      = true;
            RenewLists();
            RecalculateDrawingCoordinates();
            Drawing_panel.Refresh();
        }
コード例 #8
0
 private void Form1_Resize(object sender, EventArgs e)
 {
     RecalculateDrawingCoordinates();
     Drawing_panel.Refresh();
 }
コード例 #9
0
 private void исправитьНаложениеВесовToolStripMenuItem_Click(object sender, EventArgs e)
 {
     RandomizeWeightsPositions(listOfEdges);
     Drawing_panel.Refresh();
 }
コード例 #10
0
        private void Drawing_panel_MouseDown(object sender, MouseEventArgs e)
        {
            if (lb_verticle.SelectedIndex != -1)
            {
                lb_verticle.SetSelected(lb_verticle.SelectedIndex, false);
            }
            if (lb_edges.SelectedIndex != -1)
            {
                lb_edges.SetSelected(lb_edges.SelectedIndex, false);
            }
            if (e.Button != MouseButtons.Left)
            {
                wwClick = WhereWasClick.DrawingPanel;
                return;
            }

            Verticle select = null;

            foreach (var verticle in listOfVerticles)
            {
                int dx = e.X - verticle.point.X, dy = e.Y - verticle.point.Y;
                if (!(Math.Sqrt(dx * dx + dy * dy) <= verticleRadius))
                {
                    continue;
                }
                select = verticle;
                break;
            }

            if (Equals(_selectedVerticle, select) || select == null)
            {
                if (_selectedVerticle != null)
                {
                    _selectedVerticle.isSelected = false;
                    _selectedVerticle            = null;
                    Drawing_panel.Invalidate();
                }
                return;
            }
            if (_selectedVerticle == null)
            {
                _selectedVerticle = select;
                if (_selectedVerticle != null)
                {
                    _selectedVerticle.isSelected = true;
                }
                Drawing_panel.Invalidate();
            }
            else
            {
                if (listOfEdges.Any(ed => Equals(ed.A, select) && Equals(ed.B, _selectedVerticle) ||
                                    Equals(ed.A, _selectedVerticle) && Equals(ed.B, select)))
                {
                    return;
                }

                var aef = new AddEdgeForm
                {
                    Verticles           = listOfVerticles,
                    Edges               = listOfEdges,
                    SetDefaultVerticles = true,
                    Va = _selectedVerticle,
                    Vb = select
                };
                aef.ShowDialog();
                if (aef.DialogResult != DialogResult.OK)
                {
                    if (_selectedVerticle != null)
                    {
                        _selectedVerticle.isSelected = false;
                    }
                    _selectedVerticle.isSelected = false;
                    _selectedVerticle            = null;
                    Drawing_panel.Invalidate();
                    return;
                }

                listOfEdges.Add(aef.Return);
                listOfVerticles.Find(x => x.Equals(aef.Return.A)).connections++;
                listOfVerticles.Find(x => x.Equals(aef.Return.B)).connections++;
                RandomizeWeightsPositions(listOfEdges);
                RenewLists();
                if (_selectedVerticle != null)
                {
                    _selectedVerticle.isSelected = false;
                }
                Drawing_panel.Refresh();
                _selectedVerticle = null;
            }
        }