Exemplo n.º 1
0
        public void DrawSignals(SharpGPS.NMEA.GPGSV gpgsv, SharpGPS.NMEA.GPGSA gpgsa)
        {
            //Generate signal level readout
            int    SatCount   = gpgsv.SatsInView;
            Bitmap imgSignals = new Bitmap(picGSVSignals.Width, picGSVSignals.Height);

            using (Graphics g = Graphics.FromImage(imgSignals))
            {
                g.Clear(Color.White);
                Pen penBlack = new Pen(Color.Black, 1);
                Pen penGray  = new Pen(Color.LightGray, 1);
                int iMargin  = 4;                //Distance to edge of image
                int iPadding = 4;                //Distance between signal bars
                g.DrawRectangle(penBlack, 0, 0, imgSignals.Width - 1, imgSignals.Height - 1);

                StringFormat sFormat  = new StringFormat();
                int          barWidth = 1;
                if (SatCount > 0)
                {
                    barWidth = (imgSignals.Width - 2 * iMargin - iPadding * (SatCount - 1)) / SatCount;
                }

                //Draw horisontal lines
                for (int i = imgSignals.Height - 15; i > iMargin; i -= (imgSignals.Height - 15 - iMargin) / 5)
                {
                    g.DrawLine(penGray, 1, i, imgSignals.Width - 2, i);
                }
                sFormat.Alignment = StringAlignment.Center;
                //Draw satellites
                for (int i = 0; i < SatCount; i++)
                {
                    SharpGPS.NMEA.GPGSV.Satellite sat = gpgsv.Satellites[i];
                    int startx = i * (barWidth + iPadding) + iMargin;
                    int starty = imgSignals.Height - 15;
                    int height = (imgSignals.Height - 15 - iMargin) / 50 * sat.SNR;
                    g.FillRectangle(new System.Drawing.SolidBrush(Colors[i]), startx, starty - height, barWidth, height + 1);
                    if (gpgsa.PRNInSolution.Contains(sat.PRN))
                    {
                        g.DrawRectangle(penBlack, startx, starty - height, barWidth, height);
                    }

                    sFormat.LineAlignment = StringAlignment.Near;
                    g.DrawString(sat.PRN, new Font("Verdana", 9, FontStyle.Regular), new System.Drawing.SolidBrush(Color.Black), startx + barWidth / 2, imgSignals.Height - 15, sFormat);
                    sFormat.LineAlignment = StringAlignment.Far;
                    g.DrawString(sat.SNR.ToString(), new Font("Verdana", 9, FontStyle.Regular), new System.Drawing.SolidBrush(Color.Black), startx + barWidth / 2, starty - height, sFormat);
                }
            }
            picGSVSignals.Image = imgSignals;
        }
Exemplo n.º 2
0
        public void DrawGSV(SharpGPS.NMEA.GPGSV gpgsv, SharpGPS.NMEA.GPGSA gpgsa)
        {
            Pen penBlack = new Pen(Color.Black, 1);
            Pen penGray  = new Pen(Color.LightGray, 1);
            int iMargin  = 4;            //Distance to edge of image

            StringFormat sFormat = new StringFormat();
            //Generate sky view
            Bitmap imgSkyview = new Bitmap(picGSVSkyview.Width, picGSVSkyview.Height);

            using (Graphics g = Graphics.FromImage(imgSkyview))
            {
                g.Clear(Color.Transparent);
                g.FillEllipse(Brushes.White, 0, 0, imgSkyview.Width - 1, imgSkyview.Height - 1);
                g.DrawEllipse(penGray, 0, 0, imgSkyview.Width - 1, imgSkyview.Height - 1);
                g.DrawEllipse(penGray, imgSkyview.Width / 4, imgSkyview.Height / 4, imgSkyview.Width / 2, imgSkyview.Height / 2);
                g.DrawLine(penGray, imgSkyview.Width / 2, 0, imgSkyview.Width / 2, imgSkyview.Height);
                g.DrawLine(penGray, 0, imgSkyview.Height / 2, imgSkyview.Width, imgSkyview.Height / 2);
                sFormat.LineAlignment = StringAlignment.Near;
                sFormat.Alignment     = StringAlignment.Near;
                float radius = 6f;
                for (int i = 0; i < gpgsv.Satellites.Count; i++)
                {
                    SharpGPS.NMEA.GPGSV.Satellite sat = gpgsv.Satellites[i];
                    double ang = 90.0 - sat.Azimuth;
                    ang = ang / 180.0 * Math.PI;
                    int x = imgSkyview.Width / 2 + (int)Math.Round((Math.Cos(ang) * ((90.0 - sat.Elevation) / 90.0) * (imgSkyview.Width / 2.0 - iMargin)));
                    int y = imgSkyview.Height / 2 - (int)Math.Round((Math.Sin(ang) * ((90.0 - sat.Elevation) / 90.0) * (imgSkyview.Height / 2.0 - iMargin)));
                    g.FillEllipse(new System.Drawing.SolidBrush(Colors[i]), x - radius * 0.5f, y - radius * 0.5f, radius, radius);

                    if (gpgsa.PRNInSolution.Contains(sat.PRN))
                    {
                        g.DrawEllipse(penBlack, x - radius * 0.5f, y - radius * 0.5f, radius, radius);
                        g.DrawString(sat.PRN, new Font("Verdana", 9, FontStyle.Bold), new System.Drawing.SolidBrush(Color.Black), x, y, sFormat);
                    }
                    else
                    {
                        g.DrawString(sat.PRN, new Font("Verdana", 8, FontStyle.Italic), new System.Drawing.SolidBrush(Color.Gray), x, y, sFormat);
                    }
                }
            }
            picGSVSkyview.Image = imgSkyview;
        }