using Cursach.Parameters; using Cursach.Realisations; namespace Cursach { public partial class FormCreate : Form { private AdjacencyList _adjacencyList; private Node startNode = new Node(0); public event Action? parameterDelegate; private VizulizatorGraph? visualizatorGraph; public FormCreate() { InitializeComponent(); _adjacencyList = new AdjacencyList(); visualizatorGraph = new VizulizatorGraph(); Draw(); } private void buttonAddNode_Click(object sender, EventArgs e) { } private void buttonAddEdge_Click(object sender, EventArgs e) { if (!_adjacencyList.AddBind(new Bind( node1: _adjacencyList.GetByNameNode(comboBoxNode1.SelectedItem.ToString()), node2: _adjacencyList.GetByNameNode(comboBoxNode2.SelectedItem.ToString()) ))) { MessageBox.Show("Неверное ребро"); return; } treeView.Nodes.Clear(); foreach (var parentNode in _adjacencyList.Keys()) { TreeNode smartNode = new TreeNode(parentNode.ToString()); foreach (var childNode in _adjacencyList.Values(parentNode)) { smartNode.Nodes.Add(childNode.ToString()); } treeView.Nodes.Add(smartNode); } treeView.ExpandAll(); Draw(); } private void buttonStart_Click(object sender, EventArgs e) { try { _adjacencyList.Mirror(); BFSParameters parameter = new BFSParameters(startNode, _adjacencyList); parameterDelegate?.Invoke(parameter); Close(); } catch (Exception exception) { MessageBox.Show("Граф пустой"); } } private void pictureBox1_Click(object sender, EventArgs e) { MouseEventArgs me = (MouseEventArgs)e; Point coordinates = me.Location; _adjacencyList.AddNode(new Node(_adjacencyList.Keys().Count(), coordinates)); comboBoxNode1.Items.Clear(); comboBoxNode2.Items.Clear(); foreach (var item in _adjacencyList.Keys()) { comboBoxNode1.Items.Add(item); comboBoxNode2.Items.Add(item); } EnableAddEdgeButton(); Draw(); } private void Draw() { Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height); Graphics gr = Graphics.FromImage(bmp); if (visualizatorGraph != null) { visualizatorGraph.Draw(gr, _adjacencyList); } pictureBox1.Image = bmp; } private void treeView_AfterSelect_1(object sender, TreeViewEventArgs e) { startNode = _adjacencyList.GetByNameNode(e.Node?.Text); } private void comboBoxNode1_SelectedIndexChanged(object sender, EventArgs e) { EnableAddEdgeButton(); } private void comboBoxNode2_SelectedIndexChanged(object sender, EventArgs e) { EnableAddEdgeButton(); } private void EnableAddEdgeButton() { buttonAddEdge.Enabled = comboBoxNode1.Text.Length > 0 && comboBoxNode2.Text.Length > 0; } } }