Example #1
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            Grafo g2;

            pm = e.Location;
            p  = pm;
            switch (e.Button.ToString())
            {
            case "Left":
                if (accion != 0 && accion != 1)
                {
                    band = true;
                    Form1_Paint(this, null);
                    band = false;
                }
                break;

            case "Right":
                int total = grafo.Aristas.Count;
                for (int i = 0; i < total; i++)
                {
                    arista = grafo.Aristas[i];
                    if (arista.toca(pm))
                    {
                        MenuArista.Enabled    = true;
                        MenuArista.ClientSize = new Size(50, 50);
                        MenuArista.Visible    = true;
                        MenuArista.Show(Cursor.Position);
                        break;
                    }
                }
                break;
            }
        }
Example #2
0
        /// <summary>
        /// From principal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            BackColor = Color.White;
            bandcam   = false;
            camin     = 1;
            icam      = 0;
            //    ckwn = 0;
            numero = 0;
            tck    = false;
            CCE    = new List <NodoP>();

            flo = 1;

            resp  = Color.White;
            g2    = new Grafo();
            a     = new Arista();
            fl    = new Pen(Brushes.Green);
            bmp1  = new Bitmap(800, 600);
            g     = CreateGraphics();
            file  = new BinaryFormatter();
            grafo = new Grafo();
            band  = false;

            accion     = 0;
            gactivo    = false;
            pm         = new Point();
            nombre     = 'A';
            mov        = false;
            time       = new Timer();
            time.Tick += time_Tick;
        }
Example #3
0
 public Arista(Arista a)
 {
     tipo     = a.tipo;
     origen   = a.origen;
     destino  = a.destino;
     peso     = a.PESO;
     visitada = a.VISITADA;
 }
Example #4
0
 private void MenuArista_Closing(object sender, ToolStripDropDownClosingEventArgs e)
 {
     if (toolStripTextBox1.Text.Length > 0)
     {
         arista.PESO            = int.Parse(toolStripTextBox1.Text);
         arista                 = null;
         toolStripTextBox1.Text = "";
     }
 }
Example #5
0
 private void Form1_MouseDown(object sender, MouseEventArgs e)
 {
     if (nuevoAri)
     {
         /*foreach(Vertice v in grafos[0].Vertices) {
          *  numArista++;
          *  if (e.X > v.X - 35 && e.X < v.X + 35 && e.Y > v.Y - 35 && e.Y < v.Y + 35) {
          *      origen = v.Nombre;
          *      xo = v.X;
          *      yo = v.Y;
          *      clicado = true;
          *  }
          * }*/
         for (int i = 0; i < grafos[0].Vertices.Count; i++)
         {
             if (e.X > grafos[0].Vertices[i].X - 35 && e.X <grafos[0].Vertices[i].X + 35 && e.Y> grafos[0].Vertices[i].Y - 35 && e.Y < grafos[0].Vertices[i].Y + 35)
             {
                 Arista arista = new Arista();
                 grafos[0].Vertices[i].Aristas.Add(arista);
                 grafos[0].Vertices[i].Aristas[grafos[0].Vertices[i].Aristas.Count - 1].Origen = grafos[0].Vertices[i].Nombre;
                 grafos[0].Vertices[i].Aristas[grafos[0].Vertices[i].Aristas.Count - 1].X      = grafos[0].Vertices[i].X;
                 grafos[0].Vertices[i].Aristas[grafos[0].Vertices[i].Aristas.Count - 1].Y      = grafos[0].Vertices[i].Y;
                 grafos[0].Vertices[i].Aristas[grafos[0].Vertices[i].Aristas.Count - 1].Tipo   = grafos[0].Tipo;
                 numArista = i;
                 clicado   = true;
             }
         }
     }
     if (mueveVer)
     {
         dx = 0;
         dy = 0;
         foreach (Vertice v in grafos[0].Vertices)
         {
             if (e.X > v.X - 35 && e.X < v.X + 35 && e.Y > v.Y - 35 && e.Y < v.Y + 35 && !soltado)
             {
                 dx         = e.X - v.X;
                 dy         = e.Y - v.Y;
                 movido     = v.Nombre;
                 soltado    = true;
                 presionado = true;
             }
         }
     }
     if (mueveGraf)
     {
         dvx  = new List <int>();
         dvy  = new List <int>();
         daxO = new List <int>();
         dayO = new List <int>();
         daxF = new List <int>();
         dayF = new List <int>();
         foreach (Vertice v in grafos[0].Vertices)
         {
             dvx.Add(e.X - v.X);
             dvy.Add(e.Y - v.Y);
             foreach (Arista a in v.Aristas)
             {
                 daxO.Add(e.X - a.X);
                 dayO.Add(e.Y - a.Y);
                 daxF.Add(e.X - a.XF);
                 dayF.Add(e.Y - a.YF);
             }
         }
         presionado2 = true;
     }
 }
Example #6
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics au;

            au = Graphics.FromImage(bmp1);
            au.Clear(BackColor);

            if (bandComplemento == 1)
            {
                Grafo aux = new Grafo();
                aux             = grafo;
                grafo           = new Grafo(aux);
                bandComplemento = 0;
            }

            if (band)
            {
                //au.Clear(BackColor);
                switch (accion)
                {
                case 1:
                    bool num;
                    int  iaux;
                    if (grafo.Count > 0)
                    {
                        if ((int.TryParse(grafo[0].NOMBRE.ToString(), out iaux)) == true)
                        {
                            num = true;
                        }
                        else
                        {
                            num = false;
                        }
                    }
                    else
                    {
                        num = false;
                    }
                    if (num == false)
                    {
                        nu = new NodoP(pm, nombre);
                        nombre++;
                    }
                    else
                    {
                        nu        = new NodoP(pm, nombre);
                        nu.NOMBRE = numero.ToString();
                        numero++;
                    }
                    if (grafo.Count == 0)
                    {
                        //           Dirigida.Enabled = NoDirigida.Enabled = true;
                    }
                    if (grafo.Count > 1)
                    {
                        nu.COLOR = grafo[0].COLOR;
                    }
                    grafo.AgregaNodo(nu);
                    AgregaRelacion.Enabled = true;
                    gactivo = true;
                    nu      = null;
                    break;

                case 2:
                    nu = (NodoP)grafo.Find(delegate(NodoP a) { if (pm.X > a.POS.X - 15 && pm.X < a.POS.X + 30 && pm.Y > a.POS.Y - 15 && pm.Y < a.POS.Y + 30)
                                                               {
                                                                   return(true);
                                                               }
                                                               else
                                                               {
                                                                   return(false);
                                                               } });
                    break;

                case 3:
                    nu = (NodoP)grafo.Find(delegate(NodoP a) { if (pm.X > a.POS.X - 15 && pm.X < a.POS.X + 30 && pm.Y > a.POS.Y - 15 && pm.Y < a.POS.Y + 30)
                                                               {
                                                                   return(true);
                                                               }
                                                               else
                                                               {
                                                                   return(false);
                                                               } });
                    p = pm;

                    break;

                case 5:
                    Grafo aux = new Grafo();
                    aux = grafo;
                    aux.Sort(delegate(NodoP a, NodoP b) { return(a.POS.X.CompareTo(b.POS.X)); });
                    if (pm.X > aux.ToArray()[0].POS.X && pm.X < aux.ToArray()[aux.Count - 1].POS.X)
                    {
                        aux.Sort(delegate(NodoP a, NodoP b) { return(a.POS.Y.CompareTo(b.POS.Y)); });
                        if (pm.Y > aux.ToArray()[0].POS.Y && pm.Y < aux.ToArray()[aux.Count - 1].POS.Y)
                        {
                            mov = true;
                        }
                        else
                        {
                            mov = false;
                        }
                    }
                    else
                    {
                        mov = false;
                    }
                    break;

                case 6:
                    int    total = grafo.Aristas.Count;
                    Arista arista;
                    for (int i = 0; i < total; i++)
                    {
                        arista = grafo.Aristas[i];
                        if (arista.toca(pm))
                        {
                            grafo.RemueveArista(arista);

                            break;
                        }
                    }
                    break;

                case 14:
                    Arista ari;
                    NodoP  o, d;
                    o = d = null;
                    if (bandcam == true)
                    {
                        ari   = new Arista();;
                        grafo = new Grafo(g2);
                        grafo.Aristas.Clear();
                        foreach (NodoP rel in grafo)
                        {
                            rel.relaciones.Clear();
                        }
                        bandcam = false;
                        au.Clear(BackColor);
                    }

                    if (tck == true)
                    {
                        accion = 0;
                        tck    = false;
                        if (icam > 0)
                        {
                            grafo.Find(delegate(NodoP dx) { if (dx.NOMBRE == CCE[icam].NOMBRE)
                                                            {
                                                                return(true);
                                                            }
                                                            else
                                                            {
                                                                return(false);
                                                            } }).insertaRelacion(grafo.Find(delegate(NodoP ox) { if (ox.NOMBRE == CCE[icam - 1].NOMBRE)
                                                                                                                 {
                                                                                                                     return(true);
                                                                                                                 }
                                                                                                                 else
                                                                                                                 {
                                                                                                                     return(false);
                                                                                                                 } }), grafo.Aristas.Count);
                            d = grafo.Find(delegate(NodoP dx) { if (dx.NOMBRE == CCE[icam].NOMBRE)
                                                                {
                                                                    return(true);
                                                                }
                                                                else
                                                                {
                                                                    return(false);
                                                                } });
                            o = grafo.Find(delegate(NodoP ox) { if (ox.NOMBRE == CCE[icam - 1].NOMBRE)
                                                                {
                                                                    return(true);
                                                                }
                                                                else
                                                                {
                                                                    return(false);
                                                                } });
                            d.COLOR = Color.Blue;
                            o.COLOR = Color.Blue;
                            Pen penn = new Pen(Brushes.Red);
                            penn.Width = 4;
                            g.DrawEllipse(penn, new Rectangle(d.POS.X - 16, d.POS.Y - 16, 30, 30));

                            ari = new Arista(1, d, o, "e" + (CCE.Count - icam).ToString());

                            grafo.AgregaArista(ari);
                        }
                        grafo.pinta(g);
                    }
                    break;
                }
                if (gis != null)
                {
                    gis.pinta(au);
                    g.DrawImage(bmp1, 0, 0);
                }
                grafo.pinta(au);
                g.DrawImage(bmp1, 0, 0);
            }
            else
            {
                switch (accion)
                {
                case 1:
                    break;

                case 2:
                    if (nu != null)
                    {
                        nu.POS = pm;
                        au.Clear(BackColor);
                    }
                    break;

                case 3:
                    au.Clear(BackColor);
                    if (nu != null)
                    {
                        au.DrawLine(fl, p, pm);
                    }

                    break;

                case 5:
                    if (mov)
                    {
                        Point po = new Point(pm.X - p.X, pm.Y - p.Y);
                        foreach (NodoP n in grafo)
                        {
                            Point nue = new Point(n.POS.X + po.X, n.POS.Y + po.Y);
                            n.POS = nue;
                        }

                        p = pm;
                        au.Clear(BackColor);
                    }

                    break;
                }
                if (gis != null)
                {
                    gis.pinta(au);
                    g.DrawImage(bmp1, 0, 0);
                }
                grafo.pinta(au);
                g.DrawImage(bmp1, 0, 0);
            }
        }
Example #7
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            NodoP    des;
            Graphics au;

            au = Graphics.FromImage(bmp1);
            au.Clear(BackColor);
            switch (accion)
            {
            case 1:
                p    = pm;
                pm   = e.Location;
                band = true;
                Form1_Paint(this, null);
                band = false;
                break;

            case 2:
                nu = null;
                break;

            case 3:
                des = (NodoP)grafo.Find(delegate(NodoP a) { if (e.Location.X > a.POS.X - 15 && e.Location.X < a.POS.X + 30 && e.Location.Y > a.POS.Y - 15 && e.Location.Y < a.POS.Y + 30)
                                                            {
                                                                return(true);
                                                            }
                                                            else
                                                            {
                                                                return(false);
                                                            } });
                if (des != null && nu != null)
                {
                    if (nu.insertaRelacion(des, grafo.Aristas.Count))
                    {
                        a = new Arista(tipoarista, nu, des, "e" + grafo.Aristas.Count.ToString());
                        grafo.AgregaArista(a);
                        nu.GRADO++;
                        des.GRADO++;
                        nu.GradoExterno++;
                        des.GradoInterno++;
                    }
                    if (tipoarista == 2 && a.Destino.NOMBRE != a.Origen.NOMBRE)
                    {
                        des.insertaRelacion(nu, grafo.Aristas.Count - 1);
                        des.GradoExterno++;
                        nu.GradoInterno++;
                    }

                    grafo.pinta(au);
                    band = false;
                    nu   = null;
                }
                else
                {
                    grafo.pinta(au);
                }
                g.DrawImage(bmp1, 0, 0);
                break;

            case 4:
                nu = (NodoP)grafo.Find(delegate(NodoP a) { if (e.Location.X > a.POS.X - 15 && e.Location.X < a.POS.X + 30 && e.Location.Y > a.POS.Y - 15 && e.Location.Y < a.POS.Y + 30)
                                                           {
                                                               return(true);
                                                           }
                                                           else
                                                           {
                                                               return(false);
                                                           } });
                if (nu != null)
                {
                    grafo.RemueveNodo(nu);
                    band = true;
                    if (grafo.Count == 0)
                    {
                        nombre  = 'A';
                        gactivo = false;
                    }
                    Form1_Paint(this, null);
                    band = false;
                }
                break;

            case 7:
            case 9:
            case 8:
                SeleccionaNodos();
                break;
            }
        }