//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(); }
//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(); }
//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); }
// about private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e) { _selectedVerticle = null; foreach (var ve in listOfVerticles) { ve.isSelected = false; } Drawing_panel.Invalidate(); var abForm = new AboutForm(); abForm.ShowDialog(); }
// help private void помощьToolStripMenuItem_Click(object sender, EventArgs e) { _selectedVerticle = null; foreach (var ve in listOfVerticles) { ve.isSelected = false; } Drawing_panel.Invalidate(); var hForm = new HelpForm(); hForm.ShowDialog(); }
private void lb_verticle_SelectedIndexChanged(object sender, EventArgs e) { if (_selectedVerticle != null) { _selectedVerticle.isSelected = false; } if (lb_verticle.SelectedIndex == -1) { return; } _selectedVerticle = listOfVerticles[lb_verticle.SelectedIndex]; _selectedVerticle.isSelected = true; Drawing_panel.Invalidate(); }
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; } }