Esempio n. 1
0
 private void picturebox_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Node n = graph.CreateNewNode(e.Location);
         n.Draw(g);
         n.Selected   += Node_Selected;
         n.Deselected += Node_Deselected;
         objects.Insert(0, n);
         //UpdateMatrices();
     }
 }
Esempio n. 2
0
        private void openGraph_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "Text|*.txt";
            open.Title  = "Окрыть";
            open.ShowDialog();
            if (open.FileName != "")
            {
                StreamReader reader = new StreamReader(open.OpenFile());
                string[]     items  = reader.ReadLine().Split(' ');
                int          n      = int.Parse(items[0]);
                int          m      = int.Parse(items[1]);
                int          maxId  = int.Parse(items[2]);
                graph                 = new Graph.Graph();
                graph.MaxId           = maxId;
                selectButton.Checked  = true;
                nodeButton.Checked    = false;
                edgeButton.Checked    = false;
                weightTextbox.Enabled = false;
                g.Clear(Color.White);
                objects.Clear();

                for (int i = 0; i < n; i++)
                {
                    items = reader.ReadLine().Split(' ');
                    int  id   = int.Parse(items[0]);
                    int  x    = int.Parse(items[1]);
                    int  y    = int.Parse(items[2]);
                    Node node = graph.CreateNewNode(new Point(x, y), id);
                    node.Draw(g);
                    node.Selected   += Node_Selected;
                    node.Deselected += Node_Deselected;
                    objects.Insert(0, node);
                }

                for (int i = 0; i < m; i++)
                {
                    items = reader.ReadLine().Split(' ');
                    int  u     = int.Parse(items[0]);
                    int  v     = int.Parse(items[1]);
                    int  w     = int.Parse(items[2]);
                    Node nodeu = graph.FindNodeWithId(u);
                    Node nodev = graph.FindNodeWithId(v);
                    Edge edge  = graph.CreateNewEdge(nodeu, nodev, w);
                    edge.Selected   += Edge_Selected;
                    edge.Deselected += Edge_Deselected;
                    objects.Add(edge);
                    int count = graph.CountEdge(edge);
                    edge.Draw(g, count);
                }

                //UpdateMatrices();
                reader.Close();
            }
        }