Ejemplo n.º 1
0
        public static void AddVertex(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Temp = new Edge();

                int _localX = CursorX;
                int _localY = CursorY;
                using (dialoge form = new dialoge())
                {
                    form.Text = "Введите имя вершины";
                    DialogResult result = form.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        if (GDEXControl.dex.graph.Find(x => x.name == form.value) != null)
                        {
                            MessageBox.Show("Такая вершина уже существует!", "Ошибка", MessageBoxButtons.OK);
                            return;
                        }

                        Button button = new Button();
                        button.Size                  = new Size(50, 50);
                        button.Location              = new Point(_localX - button.Size.Width / 2, _localY - button.Size.Height / 2);
                        button.BackColor             = Color.Transparent;
                        button.FlatStyle             = FlatStyle.Flat;
                        button.BackgroundImage       = Properties.Resources.sircle;
                        button.BackgroundImageLayout = ImageLayout.Zoom;
                        button.Text                  = form.value;
                        button.ForeColor             = Color.White;
                        if (form.value.Length <= 2)
                        {
                            button.Font = new Font(button.Font.Name, 14);
                        }
                        else
                        {
                            button.Font = new Font(button.Font.Name, 8);
                        }

                        button.MouseClick += AddEdge;
                        button.MouseDown  += GDEXControl.RemoveEdges;

                        GDEXControl.AddVertex(form.value.Trim(), new Point(_localX, _localY), button);
                        buttonsList.Add(button);

                        Program.form1.Invoke(new Action(() =>
                        {
                            Program.form1.panel1.Controls.Add(button);
                        }));
                    }
                }
                GUI.UpdateGUI(); // for windows < 10
            }
        }
Ejemplo n.º 2
0
 public static void RemoveVertex()
 {
     dex.pathVertexes.Clear();
     using (dialoge form = new dialoge())
     {
         form.Text = "Введите имя вершины для удаления";
         DialogResult result = form.ShowDialog();
         if (result == DialogResult.OK)
         {
             if (dex.FindVertex(form.value))
             {
                 _RemoveVertex(form.value);
             }
         }
     }
     GUI.UpdateGUI(); // for windows < 10
 }
Ejemplo n.º 3
0
        public static void RemoveEdges(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                foreach (Dex.Vertex ver in dex.graph)
                {
                    if (sender == ver.button)
                    {
                        using (dialoge form = new dialoge())
                        {
                            form.Text = "Введите имя ребра для удаления";
                            DialogResult result = form.ShowDialog();
                            if (result == DialogResult.OK)
                            {
                                for (int i = 0; i < ver.edges.Count; i++)
                                {
                                    if (ver.edges[i].vertex.name == form.value)
                                    {
                                        for (int j = 0; j < ver.edges[i].vertex.edges.Count; j++)
                                        {
                                            if (ver.edges[i].vertex.edges[j].vertex.name == ver.name)
                                            {
                                                ver.edges[i].vertex.edges.RemoveAt(j);
                                            }
                                        }
                                        Program.form1.Invoke(new Action(() =>
                                        {
                                            Program.form1.panel1.Controls.Remove(ver.edges[i].labelPrice);
                                        }));
                                        ver.edges.RemoveAt(i);
                                    }
                                }

                                GUI.UpdateGUI();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void AddEdge(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                foreach (Dex.Vertex ver in GDEXControl.dex.graph)
                {
                    if (sender == ver.button)
                    {
                        if (!Temp.Fstart)
                        {
                            Temp.Fstart = true;
                            Temp.ver1   = ver.name;
                            Temp.start  = ver.position;
                        }
                        else if (!Temp.Fstop)
                        {
                            if (Temp.ver1 != ver.name)
                            {
                                Temp.Fstop = true;
                                Temp.ver2  = ver.name;
                                Temp.stop  = ver.position;
                            }
                        }

                        if (Temp.Fstop && Temp.Fstart)
                        {
                            if (!findPath)
                            {
                                using (dialoge form = new dialoge())
                                {
                                    form.type         = "int";
                                    form.maxlen       = 9;
                                    form.default_rich = ((int)Math.Sqrt(Math.Pow(GDEXControl.GetVertex(Temp.ver2).button.Location.X - GDEXControl.GetVertex(Temp.ver1).button.Location.X, 2) +
                                                                        Math.Pow(GDEXControl.GetVertex(Temp.ver2).button.Location.Y - GDEXControl.GetVertex(Temp.ver1).button.Location.Y, 2)) / 4).ToString();
                                    form.Text = "Введите цену ребра " + Temp.ver1 + " => " + Temp.ver2;
                                    DialogResult result = form.ShowDialog();
                                    if (result == DialogResult.OK)
                                    {
                                        int price = 0;
                                        if (Int32.TryParse(form.value, out int res))
                                        {
                                            price = res;
                                        }

                                        GDEXControl.addEdge(Temp.ver1, Temp.ver2, price, null);

                                        UpdateGUI();
                                    }
                                }
                            }
                            else
                            {
                                GDEXControl.MathGraph(Temp.ver1, Temp.ver2);
                            }
                            GUI.UpdateGUI(); // for windows < 10
                            Temp = new Edge();
                        }
                    }
                }
            }
        }