Exemple #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;
        }
Exemple #2
0
        // Create GPS event handlers on form load
        private void Form1_Load(object sender, System.EventArgs e)
        {
            // load settings -----------------
            IoFilesDirectory = CurrentDirectory + "tracks";
            MapsFilesDirectory = CurrentDirectory + "maps";

            // check if there are any args - then load the file
            string parameterExt = Path.GetExtension(FirstArgument);
            if (parameterExt == ".dat")
                LoadSettings(FirstArgument);
            else
                LoadSettings(CurrentDirectory + "GpsCycleComputer.dat");
            
            CreateArrays();
            ApplyCustomBackground();

            if (parameterExt == ".gcc")
                LoadGcc(FirstArgument);

            if (parameterExt != null)
            {
                IFileSupport fs = null;
                if (parameterExt == ".gpx")
                    fs = new GpxSupport();
                else if (parameterExt == ".kml")
                    fs = new KmlSupport();

                if (fs != null)
                    if (fs.Load(FirstArgument, ref WayPointsT2F, PlotDataSize, ref Plot2ndLat, ref Plot2ndLong, ref Plot2ndZ, ref Plot2ndT, ref Plot2ndD, ref T2fSummary, ref Plot2ndCount, false))
                    {
                        labelFileNameT2F.SetText("Track to Follow: " + Path.GetFileName(FirstArgument));   //loaded ok
                        T2fSummary.filename = FirstArgument;        //with path!  todo
                    }
                    else
                    {
                        labelFileNameT2F.SetText("Track to Follow: " + Path.GetFileName(FirstArgument) + " load ERROR");
                        T2fSummary.filename = "";
                    }
            }

            // send indication to GPS driver to wake-up (if it is OFF)
            gps.startGpsService();

            // select option pages to show and apply map bkground option
            FillPagesToShow();
            checkMapsWhiteBk_Click(checkMapsWhiteBk, EventArgs.Empty);

            MenuExec(MenuPage.BFkt.main);

            listBoxFiles.Items.Clear();
            //listBoxFiles.Focus();           //remark: this command disturbs FormWindowState.Maximized, therefore after FormWindowState.Maximized

            if (importantNewsId != 404)
            {
                MessageBox.Show("You can use context menu to configure some fields in main page or modify some commands in menu page", "GCC - Important News");
                importantNewsId = 404;
            }
            LoadState(false);
            /*    tests to prevent windows title bar from overlaying gcc in full screen - all not working
            this.BringToFront();
            button1.Focus();
            this.Focus();
            NoBkPanel.BringToFront();
            NoBkPanel.Show();
            NoBkPanel.Focus();*/
        }