Пример #1
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();
            }
        }
Пример #2
0
        private void Node_Selected(object sender)
        {
            Node n = (Node)sender;

            if (selectButton.Checked)
            {
            }
            else if (edgeButton.Checked)
            {
                if (from == null)
                {
                    from = n;
                }
                else
                {
                    if (from == n)
                    {
                        n.Deselect();
                        from = null;
                    }
                    else
                    {
                        Edge edge = graph.CreateNewEdge(from, n);
                        edge.Selected   += Edge_Selected;
                        edge.Deselected += Edge_Deselected;
                        objects.Add(edge);
                        from = null;
                        n.Deselect();
                    }
                }
            }
            else if (nodeButton.Checked)
            {
            }
            weightTextbox.Text    = "";
            weightTextbox.Enabled = false;
            currentObj            = n;
        }