Exemplo n.º 1
0
        private bool LoadT2f(string filename, bool showSummary, bool append)
        {
            bool loaded_ok = false;
            IFileSupport fs = null;
            int Plot2ndCount_old;
            int WaypointsCountOld;
            if (append)
            {
                Plot2ndCount_old = Plot2ndCount;
                WaypointsCountOld = WayPointsT2F.Count;
            }
            else
            {
                Plot2ndCount_old = 0;
                WaypointsCountOld = 0;
            }
            switch (Path.GetExtension(filename).ToLower())
            {
                case ".gcc":
                    fs = new GccSupport(); break;
                case ".gpx":
                    fs = new GpxSupport(); break;
                case ".kml":
                    fs = new KmlSupport(); break;
                default:
                    MessageBox.Show("wrong extension");
                    return false;
            }
            if (fs != null)
            {
                mapUtil.clearNav(false);
                loaded_ok = fs.Load(filename, ref WayPointsT2F, PlotDataSize, ref Plot2ndLat, ref Plot2ndLong, ref Plot2ndZ, ref Plot2ndT, ref Plot2ndD, ref T2fSummary, ref Plot2ndCount, append);
                graph.scaleCmd = Graph.ScaleCmd.DoAutoscaleNoUndo;
            }
            if (loaded_ok)  // loaded OK
            {
                // If a new track-to-follow loaded (and main track not exist) - need to reset map zoom/shift vars
                if ((Plot2ndCount + WayPointsT2F.Count != 0) && (PlotCount == 0)) { ResetMapPosition(); }

                labelFileNameT2F.SetText("Track to Follow: " + Path.GetFileName(filename));

                if (Plot2ndCount - Plot2ndCount_old == 0 && WayPointsT2F.Count - WaypointsCountOld > 0)        //if no track -> copy WP-data to T2F
                {
                    if (DialogResult.Yes == MessageBox.Show("Use waypoints as track to navigate?", "File only has Waypoints", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
                    {
                        double OldLong, OldLat;
                        if (Plot2ndCount > 0)
                        {
                            OldLong = Plot2ndLong[Plot2ndCount - 1];
                            OldLat = Plot2ndLat[Plot2ndCount - 1];
                        }
                        else
                        {
                            OldLong = WayPointsT2F.lon[WaypointsCountOld];
                            OldLat = WayPointsT2F.lat[WaypointsCountOld];
                        }
                        double deltax, deltay;
                        UtmUtil utmUtil2 = new UtmUtil();       //use extra utmUtil
                        utmUtil2.setReferencePoint(OldLat, OldLong);
                        for (int i = WaypointsCountOld; i < WayPointsT2F.Count; i++)
                        {
                            if (Plot2ndCount >= PlotDataSize)     // check if we need to decimate arrays
                            {
                                for (int j = 0; j < PlotDataSize / 2; j++)
                                {
                                    Plot2ndLat[j] = Plot2ndLat[j * 2];
                                    Plot2ndLong[j] = Plot2ndLong[j * 2];
                                    Plot2ndZ[j] = Plot2ndZ[j * 2];
                                    Plot2ndT[j] = Plot2ndT[j * 2];
                                    Plot2ndD[j] = Plot2ndD[j * 2];
                                }
                                Plot2ndCount = PlotDataSize / 2;
                                //Decimation *= 2;  //use all new data
                            }
                            Plot2ndLong[Plot2ndCount] = WayPointsT2F.lon[i];
                            Plot2ndLat[Plot2ndCount] = WayPointsT2F.lat[i];
                            deltax = (Plot2ndLong[Plot2ndCount] - OldLong) * utmUtil2.longit2meter;
                            deltay = (Plot2ndLat[Plot2ndCount] - OldLat) * utmUtil2.lat2meter;
                            T2fSummary.Distance += Math.Sqrt(deltax * deltax + deltay * deltay);
                            OldLong = Plot2ndLong[Plot2ndCount]; OldLat = Plot2ndLat[Plot2ndCount];
                            Plot2ndD[Plot2ndCount] = (int)T2fSummary.Distance;
                            Plot2ndT[Plot2ndCount] = Plot2ndCount == 0 ? 0 : Plot2ndT[Plot2ndCount - 1] + 1;
                            Plot2ndZ[Plot2ndCount] = 0;
                            Plot2ndCount++;
                        }
                    }
                }
                Plot2ndCountUndo = Plot2ndCount;
                updateNavData();
                if (showSummary) loaded_ok = DialogResult.OK == ShowTrackSummary(T2fSummary);
            }
            else
            {
                labelFileNameT2F.SetText("Track to Follow: " + Path.GetFileName(filename) + " load ERROR");
                T2fSummary.desc = "Error loading file";
                MessageBox.Show("Error reading file or it does not have track data", "Error loading file",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            return loaded_ok;
        }