コード例 #1
0
        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////
        /// DO NOT CHANGE THE ORDER OF CALLS BELOW !!!
        /// 
        /// </summary>
        private static void UpdateGlobalList()
        {
            foreach (TargetType CurrentTarget in CurrentTargetList)
            {
                CurrentTarget.TrackTerminateTreshold = 0;
                if (CurrentTarget.TrackNumber != -1)
                {
                    GlobalTargetList[CurrentTarget.TrackNumber].ModeA = CurrentTarget.ModeA;
                    GlobalTargetList[CurrentTarget.TrackNumber].ModeC_Previous_Cycle = "";
                    if (GlobalTargetList[CurrentTarget.TrackNumber].ModeC != null)
                        GlobalTargetList[CurrentTarget.TrackNumber].ModeC_Previous_Cycle = "" + GlobalTargetList[CurrentTarget.TrackNumber].ModeC;
                    GlobalTargetList[CurrentTarget.TrackNumber].ModeC = CurrentTarget.ModeC;
                    GlobalTargetList[CurrentTarget.TrackNumber].CALC_GSPD = CurrentTarget.CALC_GSPD;
                    if (CurrentTarget.DAP_GSPD != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].DAP_GSPD = CurrentTarget.DAP_GSPD;
                    GlobalTargetList[CurrentTarget.TrackNumber].ACID_Mode_S = CurrentTarget.ACID_Mode_S;
                    if (CurrentTarget.Mode_S_Addr != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].Mode_S_Addr = CurrentTarget.Mode_S_Addr;
                    if (CurrentTarget.DAP_HDG != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].DAP_HDG = CurrentTarget.DAP_HDG;
                    GlobalTargetList[CurrentTarget.TrackNumber].CALC_HDG = CurrentTarget.CALC_HDG;
                    if (CurrentTarget.IAS != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].IAS = CurrentTarget.IAS;
                    if (CurrentTarget.TRK != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].TRK = CurrentTarget.TRK;
                    if (CurrentTarget.MACH != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].MACH = CurrentTarget.MACH;
                    if (CurrentTarget.TAS != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].TAS = CurrentTarget.TAS;
                    if (CurrentTarget.Roll_Ang != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].Roll_Ang = CurrentTarget.Roll_Ang;
                    if (CurrentTarget.SelectedAltitude_ShortTerm != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].SelectedAltitude_ShortTerm = CurrentTarget.SelectedAltitude_ShortTerm;
                    if (CurrentTarget.SelectedAltitude_LongTerm != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].SelectedAltitude_LongTerm = CurrentTarget.SelectedAltitude_LongTerm;
                    if (CurrentTarget.Rate_Of_Climb != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].Rate_Of_Climb = CurrentTarget.Rate_Of_Climb;
                    if (CurrentTarget.Barometric_Setting != "N/A")
                        GlobalTargetList[CurrentTarget.TrackNumber].Barometric_Setting = CurrentTarget.Barometric_Setting;
                    GlobalTargetList[CurrentTarget.TrackNumber].Lat = CurrentTarget.Lat;
                    GlobalTargetList[CurrentTarget.TrackNumber].Lon = CurrentTarget.Lon;
                    GlobalTargetList[CurrentTarget.TrackNumber].TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Handle history points
                    if (GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Count > 0)
                    {
                        // select a reference elllipsoid
                        Ellipsoid reference = Ellipsoid.WGS84;
                        // instantiate the calculator
                        GeodeticCalculator geoCalc = new GeodeticCalculator();
                        GlobalPosition Track_1 = new GlobalPosition(new GlobalCoordinates(CurrentTarget.Lat, CurrentTarget.Lon));
                        GlobalPosition Track_2 = new GlobalPosition(new GlobalCoordinates(GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Last().LatLong.Lat,
                            GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Last().LatLong.Lng));

                        // Calculate distance traveled
                        double DistanceTraveled = geoCalc.CalculateGeodeticMeasurement(reference, Track_1, Track_2).PointToPointDistance;
                        DistanceTraveled = DistanceTraveled * 0.00053996; // Convert to nautical miles
                        double BetweenTwoUpdates = CurrentTarget.TimeSinceMidnight - GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Last().TimeSinceMidnight;

                        int Miliseconds = (int)(((BetweenTwoUpdates - Math.Floor(BetweenTwoUpdates)) * 10.0));
                        TimeSpan TimeDifference = new TimeSpan(0, 0, 0, (int)Math.Floor(BetweenTwoUpdates), Miliseconds);

                        // Only update history position if there was actually a change in the distance
                        if (DistanceTraveled > 0)
                        {
                            if (GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Count > Max_History_Points)
                                GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Dequeue();
                            GMapTargetandLabel.HistoryPointsType HP = new GMapTargetandLabel.HistoryPointsType();
                            HP.LatLong = new PointLatLng(CurrentTarget.Lat, CurrentTarget.Lon);
                            HP.TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;
                            GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Enqueue(HP);
                        }
                    }
                    else
                    {
                        GMapTargetandLabel.HistoryPointsType HP = new GMapTargetandLabel.HistoryPointsType();
                        HP.LatLong = new PointLatLng(CurrentTarget.Lat, CurrentTarget.Lon);
                        HP.TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;
                        GlobalTargetList[CurrentTarget.TrackNumber].MyMarker.HistoryPoints.Enqueue(HP);
                    }
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    GlobalTargetList[CurrentTarget.TrackNumber].TrackNumber = CurrentTarget.TrackNumber;
                    GlobalTargetList[CurrentTarget.TrackNumber].TrackTerminateTreshold = CurrentTarget.TrackTerminateTreshold;
                }
                else
                {
                    int ModeAIndex = int.Parse(CurrentTarget.ModeA.ToString());
                    GlobalTargetList[ModeAIndex].ModeA = CurrentTarget.ModeA;
                    GlobalTargetList[ModeAIndex].ModeC_Previous_Cycle = "";
                    if (GlobalTargetList[ModeAIndex].ModeC != null)
                        GlobalTargetList[ModeAIndex].ModeC_Previous_Cycle = "" + GlobalTargetList[ModeAIndex].ModeC;
                    GlobalTargetList[ModeAIndex].ModeC = CurrentTarget.ModeC;
                    if (CurrentTarget.DAP_GSPD != "N/A")
                        GlobalTargetList[ModeAIndex].DAP_GSPD = CurrentTarget.DAP_GSPD;
                    GlobalTargetList[ModeAIndex].CALC_GSPD = CurrentTarget.CALC_GSPD;
                    GlobalTargetList[ModeAIndex].ACID_Mode_S = CurrentTarget.ACID_Mode_S;
                    if (CurrentTarget.Mode_S_Addr != "N/A")
                        GlobalTargetList[ModeAIndex].Mode_S_Addr = CurrentTarget.Mode_S_Addr;
                    if (CurrentTarget.DAP_HDG != "N/A")
                        GlobalTargetList[ModeAIndex].DAP_HDG = CurrentTarget.DAP_HDG;
                    GlobalTargetList[ModeAIndex].CALC_HDG = CurrentTarget.CALC_HDG;
                    if (CurrentTarget.IAS != "N/A")
                        GlobalTargetList[ModeAIndex].IAS = CurrentTarget.IAS;
                    if (CurrentTarget.TRK != "N/A")
                        GlobalTargetList[ModeAIndex].TRK = CurrentTarget.TRK;
                    if (CurrentTarget.MACH != "N/A")
                        GlobalTargetList[ModeAIndex].MACH = CurrentTarget.MACH;
                    if (CurrentTarget.TAS != "N/A")
                        GlobalTargetList[ModeAIndex].TAS = CurrentTarget.TAS;
                    if (CurrentTarget.Roll_Ang != "N/A")
                        GlobalTargetList[ModeAIndex].Roll_Ang = CurrentTarget.Roll_Ang;
                    if (CurrentTarget.SelectedAltitude_ShortTerm != "N/A")
                        GlobalTargetList[ModeAIndex].SelectedAltitude_ShortTerm = CurrentTarget.SelectedAltitude_ShortTerm;
                    if (CurrentTarget.SelectedAltitude_LongTerm != "N/A")
                        GlobalTargetList[ModeAIndex].SelectedAltitude_LongTerm = CurrentTarget.SelectedAltitude_LongTerm;
                    if (CurrentTarget.Rate_Of_Climb != "N/A")
                        GlobalTargetList[ModeAIndex].Rate_Of_Climb = CurrentTarget.Rate_Of_Climb;
                    if (CurrentTarget.Barometric_Setting != "N/A")
                        GlobalTargetList[ModeAIndex].Barometric_Setting = CurrentTarget.Barometric_Setting;
                    GlobalTargetList[ModeAIndex].Lat = CurrentTarget.Lat;
                    GlobalTargetList[ModeAIndex].Lon = CurrentTarget.Lon;
                    GlobalTargetList[ModeAIndex].TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;

                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Handle history points
                    if (GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Count > 0)
                    {
                        // select a reference elllipsoid
                        Ellipsoid reference = Ellipsoid.WGS84;
                        // instantiate the calculator
                        GeodeticCalculator geoCalc = new GeodeticCalculator();
                        GlobalPosition Track_1 = new GlobalPosition(new GlobalCoordinates(CurrentTarget.Lat, CurrentTarget.Lon));
                        GlobalPosition Track_2 = new GlobalPosition(new GlobalCoordinates(GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Last().LatLong.Lat,
                            GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Last().LatLong.Lng));

                        // Calculate distance traveled
                        double DistanceTraveled = geoCalc.CalculateGeodeticMeasurement(reference, Track_1, Track_2).PointToPointDistance;
                        DistanceTraveled = DistanceTraveled * 0.00053996; // Convert to nautical miles
                        double BetweenTwoUpdates = CurrentTarget.TimeSinceMidnight - GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Last().TimeSinceMidnight;

                        int Miliseconds = (int)(((BetweenTwoUpdates - Math.Floor(BetweenTwoUpdates)) * 10.0));
                        TimeSpan TimeDifference = new TimeSpan(0, 0, 0, (int)Math.Floor(BetweenTwoUpdates), Miliseconds);

                        // Only update history position if there was actually a change in the distance
                        if (DistanceTraveled > 0)
                        {
                            if (GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Count > Max_History_Points)
                                GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Dequeue();
                            GMapTargetandLabel.HistoryPointsType HP = new GMapTargetandLabel.HistoryPointsType();
                            HP.LatLong = new PointLatLng(CurrentTarget.Lat, CurrentTarget.Lon);
                            HP.TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;
                            GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Enqueue(HP);
                        }
                    }
                    else
                    {
                        GMapTargetandLabel.HistoryPointsType HP = new GMapTargetandLabel.HistoryPointsType();
                        HP.LatLong = new PointLatLng(CurrentTarget.Lat, CurrentTarget.Lon);
                        HP.TimeSinceMidnight = CurrentTarget.TimeSinceMidnight;
                        GlobalTargetList[ModeAIndex].MyMarker.HistoryPoints.Enqueue(HP);
                    }
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    GlobalTargetList[ModeAIndex].TrackNumber = ModeAIndex;
                    GlobalTargetList[ModeAIndex].TrackTerminateTreshold = CurrentTarget.TrackTerminateTreshold;
                }
            }

            CurrentTargetList.Clear();
            foreach (TargetType GlobalTarget in GlobalTargetList)
            {
                if (GlobalTarget.TrackTerminateTreshold < Properties.Settings.Default.TrackCoast)
                {
                    TargetType NewTarget = new TargetType();
                    GlobalTarget.TrackTerminateTreshold++;
                    NewTarget.ModeA = GlobalTarget.ModeA;
                    NewTarget.ModeC_Previous_Cycle = GlobalTarget.ModeC_Previous_Cycle;
                    NewTarget.ModeC = GlobalTarget.ModeC;
                    NewTarget.CALC_GSPD = GlobalTarget.CALC_GSPD;
                    NewTarget.DAP_GSPD = GlobalTarget.DAP_GSPD;
                    NewTarget.ACID_Mode_S = GlobalTarget.ACID_Mode_S;
                    NewTarget.Mode_S_Addr = GlobalTarget.Mode_S_Addr;
                    NewTarget.TRK = GlobalTarget.TRK;
                    NewTarget.TAS = GlobalTarget.TAS;
                    NewTarget.Roll_Ang = GlobalTarget.Roll_Ang;
                    NewTarget.SelectedAltitude_ShortTerm = GlobalTarget.SelectedAltitude_ShortTerm;
                    NewTarget.SelectedAltitude_LongTerm = GlobalTarget.SelectedAltitude_LongTerm;
                    NewTarget.Rate_Of_Climb = GlobalTarget.Rate_Of_Climb;
                    NewTarget.MACH = GlobalTarget.MACH;
                    NewTarget.DAP_HDG = GlobalTarget.DAP_HDG;
                    NewTarget.CALC_HDG = GlobalTarget.CALC_HDG;
                    NewTarget.IAS = GlobalTarget.IAS;
                    NewTarget.Barometric_Setting = GlobalTarget.Barometric_Setting;
                    NewTarget.Lat = GlobalTarget.Lat;
                    NewTarget.Lon = GlobalTarget.Lon;
                    NewTarget.TimeSinceMidnight = GlobalTarget.TimeSinceMidnight;
                    NewTarget.TrackNumber = GlobalTarget.TrackNumber;
                    NewTarget.TrackTerminateTreshold = GlobalTarget.TrackTerminateTreshold;
                    NewTarget.MyMarker = GlobalTarget.MyMarker;
                    CurrentTargetList.Add(NewTarget);
                }
                else
                {
                    if (GlobalTarget.MyMarker != null)
                        GlobalTarget.MyMarker.TerminateTarget();
                }
            }

            if (Properties.Settings.Default.DisplayPSR == true)
            {
                // Now append all the PSR tracks to the end of the display list
                foreach (TargetType PSRTgtList in PSRTargetList)
                {
                    TargetType NewTarget = new TargetType();
                    NewTarget.ModeC_Previous_Cycle = PSRTgtList.ModeC_Previous_Cycle;
                    NewTarget.Lat = PSRTgtList.Lat;
                    NewTarget.Lon = PSRTgtList.Lon;
                    NewTarget.TrackNumber = PSRTgtList.TrackNumber;
                    NewTarget.TrackTerminateTreshold = 0;
                    NewTarget.MyMarker = PSRTgtList.MyMarker;
                    CurrentTargetList.Add(NewTarget);
                }
            }
        }