Ejemplo n.º 1
0
        public static Graph FileToGraph(string[] s)
        {
            Graph g = new Graph();

            for (int i = 0; i < s.Length / 2; i++)
            {
                string[] t    = s[i].Split(' ');
                Vert     temp = new Vert(int.Parse(t[0]), int.Parse(t[1]))
                {
                    color = int.Parse(t[2]), index = int.Parse(t[3]), degree = int.Parse(t[4])
                };
                g.VList.Add(temp);
            }

            for (int i = s.Length / 2; i < s.Length; i++)
            {
                string[] t = s[i].Split(' ');
                for (int j = 0; j < g.VList[i - s.Length / 2].degree; j++)
                {
                    int x = int.Parse(t[j * 2]), y = int.Parse(t[j * 2 + 1]);
                    g.AddE(g.OnClick(x, y), g.VList[i - s.Length / 2]);
                }
            }
            return(g);
        }
Ejemplo n.º 2
0
 public void AddE(Vert A, Vert B)
 {
     if (A != B && !A.IncVerts.Contains(B))
     {
         A.IncVerts.Add(B);
         B.IncVerts.Add(A);
     }
 }
Ejemplo n.º 3
0
 public void DelVert(Vert p)
 {
     VList.Remove(p);
     for (int i = 0; i < VList.Count; i++)
     {
         if (VList[i].IncVerts.Contains(p))
         {
             VList[i].IncVerts.Remove(p);
         }
     }
 }
Ejemplo n.º 4
0
        private void MagicClick(object sender, MouseEventArgs mouse)
        {
            if (AddVertRadio.Checked)
            {
                TheGraph.AddV(mouse.X, mouse.Y);
                DPanel.CreateGraphics().DrawImage(TheGraph.DrawGraph(DPanel.Width, DPanel.Height), new Point(0, 0));
            }
            else

            if (AddEdgeRadio.Checked)
            {
                if (A == null)
                {
                    A = TheGraph.OnClick(mouse.X, mouse.Y);
                    if (A != null)
                    {
                        InfoLabel.Text = "Choose 2'nd vert";
                    }
                    else
                    {
                        InfoLabel.Text = "...";
                    }
                }
                else if (B == null)
                {
                    B = TheGraph.OnClick(mouse.X, mouse.Y);
                    if (B != null)
                    {
                        TheGraph.AddE(A, B);
                        DPanel.CreateGraphics().DrawImage(TheGraph.DrawGraph(DPanel.Width, DPanel.Height), new Point(0, 0));
                        InfoLabel.Text = "Operation complete";
                    }
                    else
                    {
                        InfoLabel.Text = "...";
                    }
                    A = B = null;
                }
            }
            else

            if (DelEdgeRadio.Checked)
            {
                if (A == null)
                {
                    A = TheGraph.OnClick(mouse.X, mouse.Y);
                    if (A != null)
                    {
                        InfoLabel.Text = "Choose 2'nd vert";
                    }
                    else
                    {
                        InfoLabel.Text = "...";
                    }
                }
                else
                if (B == null)
                {
                    B = TheGraph.OnClick(mouse.X, mouse.Y);
                    if (B != null)
                    {
                        TheGraph.DelEdge(A, B);
                        DPanel.CreateGraphics().DrawImage(TheGraph.DrawGraph(DPanel.Width, DPanel.Height), new Point(0, 0));
                        InfoLabel.Text = "Operation complete";
                    }
                    else
                    {
                        InfoLabel.Text = "...";
                    }
                    A = B = null;
                }
            }
            else

            if (DelVertRadio.Checked)
            {
                A = TheGraph.OnClick(mouse.X, mouse.Y);
                if (A != null)
                {
                    TheGraph.DelVert(A);
                    DPanel.CreateGraphics().DrawImage(TheGraph.DrawGraph(DPanel.Width, DPanel.Height), new Point(0, 0));
                    A = null;
                    InfoLabel.Text = "Operation complete";
                }
                else
                {
                    InfoLabel.Text = "Wrong input";
                }
            }
            else

            if (MoveModeRadio.Checked)
            {
                if (A == null)
                {
                    A = TheGraph.OnClick(mouse.X, mouse.Y);
                    if (A != null)
                    {
                        InfoLabel.Text = "Point new location";
                    }
                    else
                    {
                        InfoLabel.Text = "Wrong input";
                    }
                }
                else if (A != null)
                {
                    A.vpoint.X = mouse.X; A.vpoint.Y = mouse.Y;
                    DPanel.CreateGraphics().DrawImage(TheGraph.DrawGraph(DPanel.Width, DPanel.Height), new Point(0, 0));
                    A = null;
                    InfoLabel.Text = "Operation complete";
                }
            }
        }
Ejemplo n.º 5
0
 public void DelEdge(Vert c, Vert d)
 {
     c.IncVerts.Remove(d);
     d.IncVerts.Remove(c);
 }