Newer
Older
RbFreqStand / RbFreqStandMeasure / status / StatusCtrlForm.cs
yangqianqian on 30 Apr 2021 5 KB 4.30
using Casic.Birmm.RbFreqStandMeasure.Properties;
using Casic.Birmm.RbFreqStandMeasure.tools;
using Casic.Birmm.RbFreqStandMeasure.Tools;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure
{
    public partial class StatusCtrlForm : UserControl
    {
        public static StatusCtrlForm statusCtrlForm;
        public static Coordinate coo ;
        private readonly object obj = new object();
        public static Graphics gp;
        private static bool created = false;
        public StatusCtrlForm()
        {
            InitializeComponent();
            statusCtrlForm = this;

            //label_date.Text = DateTime.Now.ToString("yyyy-MM-dd");
            //label_time.Text = DateTime.Now.ToString("HH:mm:ss");

            ////if (!created)
            //{
            //    gp = coo.CreateGraphics();
            //    created = true;
            //}
            coo = new Coordinate();
            panelSite.Controls.Add(coo);
            coo.Show();

            //new Thread(() =>
            //{
            lock (obj)
            {
                if (!FreshStatus.isStarted)
                {
                    FreshStatus.startClockFresh();
                    FreshStatus.startSatelliteFresh();
                }
                Thread.Sleep(500);
                label_clockStatus.Text = FreshStatus.clockStatus;
                label_receiverStatus.Text = FreshStatus.receiverStatus;

                label_date.Text = FreshStatus.date;
                label_time.Text = FreshStatus.time;
                label_mjd.Text = FreshStatus.mjd;
                label_lat.Text = FreshStatus.lat;
                label_lng.Text = FreshStatus.lng;
                label_x.Text = FreshStatus.x;
                label_y.Text = FreshStatus.y;
                label_z.Text = FreshStatus.z;
                label_usaTotal.Text = FreshStatus.totalGP+"";
                label_chnTotal.Text = FreshStatus.totalBD+"";
                LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "界面初始化。。。。。。");

                draw(FreshStatus.bdList, FreshStatus.gpList);
            }

            //}).Start();            

        }

        public void draw(List<string> bdList, List<string> gpList)
        {
            try
            {
                LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "开始画啦 ::::::bd:" + bdList.Count);
                LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "开始画啦 ::::::gp:" + gpList.Count);

                if (bdList.Count > 0 || gpList.Count>0)
                {
                    if (this.InvokeRequired)
                    {
                        Invoke(new MethodInvoker(delegate ()
                        {
                            //coo = new Coordinate();
                            //panelSite.Controls.Add(coo);
                            //coo.Show();
                            drawFunc(bdList);
                            drawFunc(gpList);
                        }
                        ));

                    }
                   
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "draw error:" + ex.Message);
            }

        }

        private void drawFunc(List<string> gvsList)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    Invoke(new MethodInvoker(delegate ()
                    {
                        if (gvsList.Count > 0)
                        {

                            Graphics gp = coo.CreateGraphics();
                            gp.SmoothingMode = SmoothingMode.HighQuality;

                            foreach (string gsv in gvsList)
                            {
                                string[] arr = gsv.Split(',');
                                int length = arr.Length;
                                for (int i = 4; i < arr.Length; i = i + 3)
                                {
                                    if ((i + 3) < arr.Length)
                                    {
                                        int Elevation = Convert.ToInt32(arr[i + 1]);
                                        int azimuth = Convert.ToInt32(arr[i + 2]);
                                        double cosLen = Math.Cos(Elevation * Math.PI / 180) * (575 / 2);
                                        double xCor = Math.Cos(azimuth * Math.PI / 180) * cosLen;
                                        double yCor = Math.Sin(azimuth * Math.PI / 180) * cosLen;

                                        int x = (int)Math.Floor(600 / 2 + xCor);
                                        int y = (int)Math.Floor(610 / 2 - yCor);
                                        string type = "CHN";
                                        if (gsv.Contains("GPGSV")) type = "USA";
                                        gp.DrawImage((Bitmap)Resources.ResourceManager.GetObject(type), x, y);                                        
                                    }
                                }
                            }
                            gp.Dispose();
                        }
                    }
                    ));

                }
            }
            catch (Exception e)
            {
                LogHelper.WriteInfoLog(MethodBase.GetCurrentMethod().DeclaringType, "drawFunc错误:" + e.Message);
            }
        }

    }
}