예제 #1
0
 //SELECCIONAR VERTICE
 public void SeleccionarVertice(Graphics g, int vid)
 {
     for (int i = 0; i < vertices.Count; i++)
     {
         if (vertices[i].ID == vid)
         {
             vselec = vertices[i];
         }
     }
     vselec.Seleccionar(g);
 }
예제 #2
0
        //CLICK
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            switch (tipo)
            {
            case 0:     // Agregar vértices
                grafo.AgregaVertice(lienzo, e.X, e.Y, pictureBox1.Width, pictureBox1.Height);
                up2Date = false;
                break;

            case 82:     // eliminar vertice
                for (int i = 0; i < grafo.Vertices.Count; i++)
                {
                    Vertice v = grafo.Vertices[i];
                    if (v.Seleccion(e.X, e.Y))
                    {
                        grafo.elimAr(v.ID);
                        grafo.Vertices.RemoveAt(i);
                        break;
                    }
                }
                DibujarG();
                break;

            case 4:     //Agregar aristas
                foreach (Vertice v in grafo.Vertices)
                {
                    if (v.Seleccion(e.X, e.Y) && toque == 0)
                    {
                        v1    = v;
                        toque = 1;
                        v1.Seleccionar(lienzo);
                    }
                    else if (v.Seleccion(e.X, e.Y) && toque == 1)
                    {
                        v2 = v;
                        v2.Seleccionar(lienzo);
                        if (!v1.Equals(v2))
                        {
                            grafo.AgregaArista(lienzo, v1, v2);
                            up2Date = false;
                            toque   = 0;
                        }
                    }
                }
                break;
            }
        }
예제 #3
0
        public void VerticesD()
        {
            string a, b;
            int    c = 0;

            a = Interaction.InputBox("Vertice inicial: ", "Arista dirigida", "0", 100, 50);
            b = Interaction.InputBox("Vertice final: ", "Arista dirigida", "0", 100, 50);
            try
            {
                auxv1 = Convert.ToInt32(a);
                auxv2 = Convert.ToInt32(b);
            }
            catch (Exception e) { }
            foreach (Vertice v in grafo.Vertices)
            {
                tipo = 2;
                if (auxv1 != auxv2 && (v.ID + 1) == auxv1 && c == 0)
                {
                    v1 = v;
                    v1.Seleccionar(lienzo);
                    c = 1;
                    Console.WriteLine("entre ejejejeje");
                }
            }
            foreach (Vertice v in grafo.Vertices)
            {
                if (auxv1 != auxv2 && (v.ID + 1) == auxv2 && c == 1)
                {
                    v2 = v;
                    v2.Seleccionar(lienzo);
                    grafo.AgregarAristaDir(lienzo, v1, v2);
                    up2Date = false;
                    toque   = 0;
                    Console.WriteLine("entre 2 ejejejeje");
                }
            }
            if (auxv1 == auxv2)
            {
                MessageBox.Show("No pueden ser iguales");
            }
            Console.WriteLine(grafo.Aristas.Count);
        }