public void DibujarNuevoFP(ListFlightPlan listfp) //cuando añades algun FP a la lista cal incluir su dibujo en el panel
        {
            int i = 0;

            while (i < listfp.getcount())
            {
                FlightPlan FP = listfp.getposicion(i);

                //Configuramos los parámetros de la picturebox
                PictureBox pp = new PictureBox();
                pp.Width      = 20;
                pp.Height     = 20;
                pp.ClientSize = new Size(20, 20);

                //Configuramos los parámetros de la leyenda
                Label leyenda = new Label();
                leyenda.Text = FP.GetID();

                // Obtenemos los puntos correspondientes en el panel
                //Para picturebox
                int   xif   = Convert.ToInt32(FP.GetAX()) - 10;
                int   yif   = Convert.ToInt32(FP.GetAY()) - 10;
                Point pDraw = new Point(xif, yif);
                //Para leyenda
                int   xil    = Convert.ToInt32(FP.GetAX()) + 15;
                int   yil    = Convert.ToInt32(FP.GetAY()) - 15;
                Point pLabel = new Point(xil, yil);

                //Colocamos cada cosa en su punto
                pp.Location      = pDraw;
                leyenda.Location = pLabel;

                //Ajustamos y mostramos
                pp.SizeMode = PictureBoxSizeMode.StretchImage;
                Bitmap image = new Bitmap("avion.jpg");
                pp.Image = (System.Drawing.Image)image;
                panel1.Controls.Add(pp);
                imagenes.Add(pp);
                pp.Click += new System.EventHandler(this.showinfo);
                pp.Tag    = num;
                num       = num + 1;
                panel1.Invalidate();

                leyendas.Add(leyenda);
                panel1.Controls.Add(leyenda);
                leyenda.BackColor = Color.Transparent;

                i++;
            }
        }
        public void DibujarFP(ListFlightPlan listFP) //cuando mueves los FP cal actualizar su posicion en el panel
        {
            int i = 0;

            while (i < listFP.getcount())
            {
                FlightPlan p = listFP.getposicion(i);

                // Obtenemos los puntos correspondientes en el panel
                int   newxf  = Convert.ToInt32(p.GetAX()) - 10;
                int   newyf  = Convert.ToInt32(p.GetAY()) - 10;
                int   newxl  = Convert.ToInt32(p.GetAX()) + 15;
                int   newyl  = Convert.ToInt32(p.GetAY()) - 15;
                Point pDraw  = new Point(newxf, newyf);
                Point pLabel = new Point(newxl, newyl);

                //Actualizamos
                imagenes[i].Location = pDraw;
                leyendas[i].Location = pLabel;
                panel1.Refresh();

                i = i + 1;
            }
        }
Example #3
0
        private void Form4_Load(object sender, EventArgs e) //insertamos en cada TextBox su valor
        {
            //Ponemos en cada textbox el valor correspondiente
            idbox.Text    = Convert.ToString(myfp.GetID());
            compbox.Text  = Convert.ToString(myfp.GetCompañia());
            velbox.Text   = Convert.ToString(myfp.GetVelocidad());
            posinbox.Text = "(" + Convert.ToString(myfp.GetIX()) + "," + Convert.ToString(myfp.GetIY()) + ")";
            decimal posactualx = Decimal.Round(Convert.ToDecimal(myfp.GetAX()), 2);
            decimal posactualy = Decimal.Round(Convert.ToDecimal(myfp.GetAY()), 2);

            posactbox.Text = "(" + Convert.ToString(posactualx) + "," + Convert.ToString(posactualy) + ")";
            posfinbox.Text = "(" + Convert.ToString(myfp.GetFX()) + "," + Convert.ToString(myfp.GetFY()) + ")";

            //Abrimos la bbdd para coger los datos de las compañías
            baseops misops = new baseops();

            misops.open();

            //Cogemos el nombre de la compañía (que es un atributo de la clase flightplan
            string name = Convert.ToString(myfp.GetCompañia());

            //Comprobamos que esté en la bbdd
            bool check = misops.compruebacomp(name);

            //Si está:
            if (check == true)
            {
                //Cogemos los datos de la compañía con nombre name
                DataTable res = misops.GetCompañia(name);

                //Los escribimos en los textbox
                emailbox.Text = Convert.ToString(res.Rows[0]["Email"]);
                telefbox.Text = Convert.ToString(res.Rows[0]["Telefono"]);

                //Para añadir el logo:
                string direclogo = Convert.ToString(res.Rows[0]["Logo"]);

                if (direclogo != null) //Si hay un logo disponible lo usamos
                {
                    try
                    {
                        string path = Path.Combine(Application.StartupPath, @"..\..\Resources", direclogo);
                        Bitmap logo = (Bitmap)Image.FromFile(path);
                        panelogo.BackgroundImage       = logo;
                        panelogo.BackgroundImageLayout = ImageLayout.Stretch;
                    }
                    catch
                    {
                        panelogo.BackgroundImage       = Properties.Resources.missing;
                        panelogo.BackgroundImageLayout = ImageLayout.Stretch;
                    }
                }
                if (direclogo == "missing" || direclogo == null)
                {
                    panelogo.BackgroundImage = Properties.Resources.missing;
                }
            }

            //Si no está:
            else
            {
                panelogo.BackgroundImage       = Properties.Resources.missing;
                panelogo.BackgroundImageLayout = ImageLayout.Stretch;

                emailbox.Text = "(No disponible)";
                telefbox.Text = "(No disponible)";
            }

            //Cerramos la bbdd
            misops.close();
        }
        private void panel1_Paint(object sender, PaintEventArgs e) //Para hacer los dibujos (círculo de distancia de seguridad, raya de la trayectoria y pintar círculo en caso de conflicto)
        {
            int i = 0;
            int c = 0;

            while (i < listFP.getcount())
            {
                System.Drawing.Graphics graphics = e.Graphics;

                //Cogemos el FP y recogemos sus posiciones
                FlightPlan FP = listFP.getposicion(i);

                int x = Convert.ToInt32(FP.GetAX());
                int y = Convert.ToInt32(FP.GetAY());

                int xi = Convert.ToInt32(FP.GetIX());
                int yi = Convert.ToInt32(FP.GetIY());

                int xf = Convert.ToInt32(FP.GetFX());
                int yf = Convert.ToInt32(FP.GetFY());

                //Mostramos círulo de distancia de seguridad
                int xact = x - dseg / 2;
                int yact = y - dseg / 2;

                //Definimos h como una raya de color azul para dibujar la distancia de seguridad
                Pen h = new Pen(Color.Blue, 1);

                //Definimos brush de color rojo para pintar el círculo en caso de conflicto
                SolidBrush brush = new SolidBrush(Color.Red);

                //Creamos un rectangulo con centro en la posición actual y longitud de los lados=distancia de seguridad
                System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(xact, yact, dseg, dseg);

                //Dibujamos
                if (listFP.getcount() > 1)        //Si hay más de un FP, hemos de comprobar los conflictos
                {
                    while (c < listFP.getcount()) //Recorre la lista de FP
                    {
                        try
                        {
                            //si hay conflicto entre dos o más aviones el círculo se pinta de color rojo al tocarse las distancias de seguridad entre ellas
                            if (listFP.getposicion(i).Estaenconflicto(listFP.getposicion(c), dseg) == -1 && (c != i))
                            {
                                e.Graphics.FillEllipse(brush, rectangle);
                                brush.Dispose();
                            }
                        }
                        catch
                        {
                        }
                        //Si no están en conflicto, dibujamos la raya que marca la distancia de seguridad
                        if (dseg < listFP.getposicion(i).Distance(listFP.getposicion(c)) && (c != i))
                        {
                            graphics.DrawEllipse(h, rectangle);
                        }
                        c = c + 1;
                    }
                }
                else //Si solo hay un FP, dibuja el círculo de radio distancia de seguridad
                {
                    graphics.DrawEllipse(h, rectangle);
                }
                c = 0;

                i++;

                //dibujamos la linea de trayectoria desde la posición inicial hasta la final
                Pen b = new Pen(Color.Black, 1);
                e.Graphics.DrawLine(b, xi, yi, xf, yf);
            }
        }