private void AcquireGpsForm_Load2(object sender, EventArgs e)
        {
            this.Icon = Properties.Resources.Map;

            #if !(PocketPC || WindowsCE || Mobile)
            if (Values.Settings.DeviceOptions.GetGpsOnStart)
            {
                using (DeviceSetupForm dsf = new DeviceSetupForm())
                {
                    dsf.ShowDialog();
                }
            }
            #endif

            if (!Values.GPSA.IsBusy)
            {
                Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
            }

            gpsInfoAdvCtrl.SetZone(currentZone);
            gpsInfoAdvCtrl.StartControl();
        }
        public void Load2()
        {
            #if (PocketPC || WindowsCE || Mobile)
            if (!Values.Settings.DeviceOptions.GpsConfigured)
            {
                DialogResult dr = MessageBox.Show("GPS is not currently configured. Would you like to configure now?", "Configure GPS", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    using (DeviceSetupForm form = new DeviceSetupForm())
                    {
                        form.ShowDialog();
                    }
                }
                else
                    CloseForm();
            }
            #else
            if (Values.Settings.DeviceOptions.GetGpsOnStart)
            {
                using (DeviceSetupForm form = new DeviceSetupForm())
                {
                    form.ShowDialog();
                }
            }
            #endif

            if (!Values.GPSA.IsBusy)
                Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
        }
        private void laserError()
        {
            //remove delegates
            laserEnded();

            //resolve current error
            switch (Values.LaserA.Error)
            {
                case LaserErrorType.ComNotExist:
                    {
                        if (MessageBox.Show("The Laser is not connected to this COM port. Would you like to set up the Laser now?", "Invalid COM Port", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            using (DeviceSetupForm form = new DeviceSetupForm())
                            {
                                form.ShowDialog();
                            }
                        }
                        break;
                    }
                case LaserErrorType.LaserTimeout:



                    break;
                case LaserErrorType.NoError:
                    break;
                case LaserErrorType.UnknownError:
                default:
                    {
                        MessageBox.Show("An unknown error has occurred.", "Unknown Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        break;
                    }
            }

            LaserAquireOpen = false;
        }
        private void btnNav_Click2(object sender, EventArgs e)
        {
            if (!_navigating)
            {
                if (!Values.Settings.DeviceOptions.GpsConfigured)
                {
                    using (DeviceSetupForm dsf = new DeviceSetupForm())
                    {
                        dsf.ShowDialog();

                        if (!Values.Settings.DeviceOptions.GpsConfigured)
                            return;
                    }
                }

                if (radFromPoint.Checked)
                {
                    if (_FromPoint == null)
                    {
                        AutoClosingMessageBox.Show("No From Point", "From Point Missing", 1000);
                        return;
                    }
                    else
                    {
                        if (radToPoint.Checked)
                        {
                            if (_ToPoint == null)
                            {
                                AutoClosingMessageBox.Show("No To Point", "To Point Missing", 1000);
                                return;
                            }
                            else
                            {
                                if (_ToPoint.CN == _FromPoint.CN)
                                {
                                    AutoClosingMessageBox.Show("You can not travel to the same point you come from.", "", 1000);
                                    return;
                                }
                                else
                                {
                                    navCtrl.Init(new DoublePoint(_FromPoint.AdjX, _FromPoint.AdjY),
                                        new DoublePoint(_ToPoint.AdjX, _ToPoint.AdjY));
                                }

                            }
                        }
                        else
                        {
                            navCtrl.Init(new DoublePoint(_FromPoint.AdjX, _FromPoint.AdjY),
                                    new DoublePoint(_UtmXTo, _UtmYTo));
                        }
                    }
                }
                else
                {
                    if (radToPoint.Checked)
                    {
                        if (_ToPoint == null)
                        {
                            AutoClosingMessageBox.Show("No To Point", "To Point Missing", 1000);
                            return;
                        }
                        else
                        {
                            navCtrl.Init(new DoublePoint(_UtmXFrom, _UtmYFrom),
                                new DoublePoint(_ToPoint.AdjX, _ToPoint.AdjY));
                        }
                    }
                    else
                    {
                        navCtrl.Init(new DoublePoint(_UtmXFrom, _UtmYFrom),
                                new DoublePoint(_UtmXTo, _UtmYTo));
                    }
                }

                navCtrl.BringToFront();

                StartGps();

                btnNav.Text = "Stop";
                panel1.Visible = false;
                panel2.Visible = false;
                navCtrl.Visible = true;

                _navigating = true;
                _LastPos = new DoublePoint(0,0);
            }
            else
            {
                btnNav.Text = "Navigate";
                navCtrl.Visible = false;
                panel1.Visible = true;
                panel2.Visible = true;
                _navigating = false;

                if (!UseMyPos)
                {
                    StopGps();
                    if (radFromPoint.Checked)
                        ChangeFromPoint(cboFromPoint.SelectedIndex);
                }
            }
        }
        private void StartGps()
        {
            if (!_init)
            {
                if (!Values.Settings.DeviceOptions.GpsConfigured)
                {
                    DialogResult dr = MessageBox.Show("GPS is not currently configured. Would you like to configure now?", "Configure GPS", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    if (dr == DialogResult.Yes)
                    {
                        using (DeviceSetupForm form = new DeviceSetupForm())
                        {
                            form.ShowDialog();
                            if (!Values.Settings.DeviceOptions.GpsConfigured)
                                return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                try
                {
                    Values.GPSA.BurstReceived += GPSA_BurstReceived;
                    /*
                    Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound;
                    Values.GPSA.ComTimeout += GPSA_ComTimeout;
                    Values.GPSA.GpsStarted += GPSA_GpsStarted;
                    Values.GPSA.GpsEnded += GPSA_GpsEnded;
                    Values.GPSA.GpsError += GPSA_GpsError;
                    */
                    _init = true;

                    if (!Values.GPSA.IsBusy)
                    {
                        Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
                    }
                }
                catch (Exception ex)
                {
                    TtUtils.WriteError(ex.Message, "WhereIsForm:StartGps", ex.StackTrace);
                }
            }
        }
        private void btnCapture_Click2(object sender, EventArgs e)
        {
            if (takingSideshot)
            {
                AddSideshot();
            }
            else
            {
                if (!logging)
                {
            #if !(PocketPC || WindowsCE || Mobile)
                    if (Values.Settings.DeviceOptions.GetGpsOnStart)
                    {
                        using (DeviceSetupForm dsf = new DeviceSetupForm())
                        {
                            dsf.ShowDialog();
                        }
                    }

                    System.Threading.Thread.Sleep(1000);
                    if (!Values.GPSA.IsBusy)
                    {
                        Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
                    }
            #endif
                    //moved from create new
                    if (!lastPointSaved)
                    {
                        SaveLastPoint(CurrentPoint);
                        lastPointSaved = true;
                    }

                    logging = true;
                    logged = 0;
                    ignore = 0;
                    txtPID.Text = "";
                    txtComment.Text = "";
                    btnCapture.Enabled = false;
                    progCapture.Value = logged;

                    gpsInfoAdvCtrl.ClearUtmRange();
                    gpsInfoAdvCtrl.UtmRange = true;
                }
            }
        }
        public void Init(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint currentPoint, int currIndex)
        {
            this.Icon = Properties.Resources.Map;
            TtUtils.ShowWaitCursor();
            #if (PocketPC || WindowsCE || Mobile)
            lblLabel.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString();
            #endif
            btnCapture.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString();
            this.Text = "Take " + Values.Settings.DeviceOptions.Take5NmeaAmount.ToString() + " Point Capture";

            Values.GPSA.BurstReceived += GPSA_BurstReceived;
            Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound;
            Values.GPSA.ComTimeout += GPSA_ComTimeout;
            Values.GPSA.GpsStarted += GPSA_GpsStarted;
            Values.GPSA.GpsEnded += GPSA_GpsEnded;
            Values.GPSA.GpsError += GPSA_GpsError;

            travInfoControl1.UseLaser = false;

            Polygon = poly;
            DAL = dal;
            CurrMeta = meta;

            logging = false;
            this.DialogResult = DialogResult.Cancel;
            OnBound = true;
            _index = 0;
            ignore = 0;

            progCapture.Value = 0;
            progCapture.Minimum = 0;
            progCapture.Maximum = Values.Settings.DeviceOptions.Take5NmeaAmount;

            logged = 0;
            _locked = true;

            CurrentNmea = new List<NmeaBurst>();
            LastNmea = new List<NmeaBurst>();
            CurrentPoint = null;

            _index = currIndex;
            LastPoint = currentPoint;

            gpsInfoAdvCtrl.SetZone(CurrMeta.Zone);
            gpsInfoAdvCtrl.StartControl();

            if (Values.GPSA.UsesFile && Values.Settings.DeviceOptions.GetGpsOnStart)
            {
                using (DeviceSetupForm dsf = new DeviceSetupForm())
                {
                    dsf.ShowDialog();
                }
            }

            T5Group = new TtGroup();
            T5Group.Name = String.Format("Take5_{0}", T5Group.CN.Truncate(8));
            T5Group.GroupType = GroupType.Take5;

            if(!Values.GPSA.IsBusy)
                Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
            TtUtils.HideWaitCursor();

            if (dal.GetPointCount(poly.CN) < 1)
            {
                checkMeta = true;
            }
        }
        public void LoadSettings()
        {
            Values.BadDataLimit = 5;
            Values.CurrentDbVersion = false;
            Values.Settings = new SettingsLogic();
            Values.DataExport = new DataOutput();
            //Values.GroupManager = new GroupManager();
            Values.GPSA = new TwoTrails.GpsAccess.GpsAccess();

            #if !(PocketPC || WindowsCE || Mobile)

            Values.UpdateToolStripStatus = new UpdateToolStripDelegate(UpdateToolStringStatus);
            Values.UpdateToolStripProgress = new UpdateToolStripProgressDelegate(UpdateToolProgressBar);
            Values.UpdateInfo = new UpdateInfoDelegate(UpdateInfo);

            Values.UpdateStatusText("Settings Loaded");
            Values.GPSA.LogFilename = Path.Combine(Directory.GetCurrentDirectory(), "GPS_Log.txt");
            #else
            Values.GPSA.LogFilename = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase),
                "GPS_Log.txt");
            #endif

            TtUtils.SetLogFileDestination(Values.Settings.LogFilePath);

            if (!Values.Settings.ReadDeviceSettings())
            {
                Values.Settings.WriteDeviceSettings();
            }

            if (!Values.Settings.ReadProjectSettings())
            {
                Values.Settings.WriteProjectSettings();
            }

            #if DEBUG && (PocketPC || WindowsCE || Mobile)
            Values.Settings.DeviceOptions.UseSelection = true;
            #endif

            #region update program based on settings
            if (Values.Settings.DeviceOptions.KeepGpsOn)
            {
                radGpsAlwaysOnNo.Checked = false;
                radGpsAlwaysOnYes.Checked = true;
            }
            else
            {
                radGpsAlwaysOnNo.Checked = true;
                radGpsAlwaysOnYes.Checked = false;
            }

            #if !(PocketPC || WindowsCE || Mobile)
            chkChangeGpsOnStart.Checked = Values.Settings.DeviceOptions.GetGpsOnStart;
            #endif

            cboRecOpen.Items.Clear();

            cboRecOpen.Items.Add(Values.Settings.ProjectOptions.RecOpen[0].File);

            if (Values.Settings.ProjectOptions.RecOpen.Count > 0)
            {
                foreach (RecentProject rec in Values.Settings.ProjectOptions.RecOpen)
                {
                    if(rec.Name != "___")
                        cboRecOpen.Items.Add(System.IO.Path.GetFileName(rec.File));
                }

                for (int d = 0; d < cboRecOpen.Items.Count; d++)
                {
                    //cboRecOpen.Items[d].Attributes.Add("title", cboRecOpen.Items[d].Text);
                }
            }
            else
            {
                #if (PocketPC || WindowsCE || Mobile)
                btnRecOpen.Enabled = false;
                #endif
                cboRecOpen.Enabled = false;
            }

            #if (PocketPC || WindowsCE || Mobile)
            cboRecOpen.Visible = Values.Settings.DeviceOptions.UseSelection;
            btnRecOpen.Visible = Values.Settings.DeviceOptions.UseSelection;
            #endif

            chkOnKeyboard.Checked = Values.Settings.DeviceOptions.UseOnScreenKeyboard;
            chkUseCombo.Checked = !Values.Settings.DeviceOptions.UseSelection;
            #endregion

            Values.LaserA = new TwoTrails.LaserAccess.LaserAccess();

            #region Init GPS

            DialogResult r;

            if (Values.Settings.DeviceOptions.GpsComPort.ToLower() != "file"  && Values.Settings.DeviceOptions.GpsConfigured)
            {
                Values.GPSA.TestGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);

                //wait for gps to load
                System.Threading.Thread.Sleep(1000);

                //if error ask to configure
                if (Values.GPSA.Error != GpsErrorType.NoError)
                {
                    Values.Settings.DeviceOptions.KeepGpsOn = false;
                    radGpsAlwaysOnNo.Checked = true;
                    radGpsAlwaysOnYes.Checked = false;

                    switch (Values.GPSA.Error)
                    {
                        case GpsErrorType.ComNotExist:
                        case GpsErrorType.GpsTimeout:
                        case GpsErrorType.UnknownError:
                        default:
                            {
                                r = MessageBox.Show("An error occured trying to start GPS. Would you like to configure the GPS now?", "Keep GPS On Error", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                                if (r == DialogResult.Yes)
                                {
                                    using (DeviceSetupForm form = new DeviceSetupForm())
                                    {
                                        form.ShowDialog();
                                    }
                                }
                            }
                            break;
                    }
                }
                else
                {
                    //no error
                    Values.Settings.DeviceOptions.GpsConfigured = true;

                    if (!Values.Settings.DeviceOptions.KeepGpsOn)
                    {
                        Values.GPSA.CloseGps();
                    }
                }
            }
            #if (PocketPC || WindowsCE || Mobile)
            else if (!Values.Settings.DeviceOptions.GpsConfigured)
            {
                r = MessageBox.Show("The GPS is not configured. Would you like to configure the GPS now?", "Gps not configured.", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                if (r == DialogResult.Yes)
                {
                    using (DeviceSetupForm form = new DeviceSetupForm())
                    {
                        form.ShowDialog();
                    }
                }
            }
            else   //gps is configured and is a file
            {
                Values.Settings.DeviceOptions.GpsConfigured = true;
            }
            #endif
            #endregion

            if (!Program.Filename.IsEmpty())
            {
                OpenTtFile(Program.Filename);
            }
            else
            {
            #if DEBUG
            if(Values.Settings.ProjectOptions.RecOpen.Count > 1)
                OpenTtFile(Values.Settings.ProjectOptions.RecOpen[1].File);
            #endif
            }

            cboRecOpen.SelectedIndex = 0;
        }
 public void btnDeviceSetup_Click2(object sender, EventArgs e)
 {
     using (DeviceSetupForm form = new DeviceSetupForm())
     {
         form.ShowDialog();
     }
 }
        private void WalkSetup()
        {
            if (Values.Settings.DeviceOptions.GpsConfigured)
            {
                try
                {
                    SavePoint();
                    using (WalkForm form = new WalkForm(pointInfoCtrl.Polygon, DAL, CurrMeta, CurrPointIndex))
                    {
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            LoadPoints();
                            MoveToLastPoint();
                            pointNavigationCtrl.UpdatePointList(_PointCNs, CurrPointIndex);
                            AdjustNavControls();
                            LockControls(true);
                            TtUtils.HideWaitCursor();
                            _adjust = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    TtUtils.HideWaitCursor();
                    TtUtils.WriteError(ex.Message, "PointEditLogic:WalkSetup", ex.StackTrace);
                    MessageBox.Show("Walk Form Error");
                }
                finally
                {
                    GC.Collect();
                }
            }
            else
            {
                DialogResult dr = MessageBox.Show("GPS is not currently configured. Would you like to configure now?", "Configure GPS",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    using (DeviceSetupForm form = new DeviceSetupForm())
                    {
                        form.ShowDialog();
                    }

                    WalkSetup();
                }
            }
        }
        private void gpsWayInputCtrl1_OnAcquire()
        {
            try
            {
                if (loaded && UpdatedPoint != null)
                {
                    if (Values.Settings.DeviceOptions.GpsConfigured)    //if gps is configured
                    {
                        try
                        {
                            using (AcquireGpsForm form = new AcquireGpsForm(UpdatedPoint, CurrMeta.Zone, DAL))
                            {
                                List<GpsAccess.NmeaBurst> currNmea = DAL.GetNmeaBurstsByPointCN(UpdatedPoint.CN);

                                if (currNmea.Count > 0)
                                {
                                    DialogResult dr = MessageBox.Show("This Point already has Nmea data. Would you like to add to this data?", "Add to Nmea",
                                        MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                                    if (dr == DialogResult.Yes)
                                        form.AddToNmea(currNmea);
                                    else if (dr == DialogResult.Cancel)
                                    {
                                        form.Dispose();
                                        return;
                                    }
                                }

                                form.ShowDialog();

                                if (form.IsCalc) //if form gathered data and calculated a point
                                {
                                    GpsPoint gpsPoint = form._GpsPoint;

                                    GpsPoint up = ((GpsPoint)UpdatedPoint);

                                    up.Time = DateTime.Now;
                                    up.UnAdjX = gpsPoint.UnAdjX;
                                    up.UnAdjY = gpsPoint.UnAdjY;
                                    up.UnAdjZ = gpsPoint.UnAdjZ;
                                    //up.X = gpsPoint.X;
                                    //up.Y = gpsPoint.Y;
                                    //up.Z = gpsPoint.Z;
                                    up.RMSEr = gpsPoint.RMSEr;

                                    GetConversion(ref _UpdatedPoint);

                                    gpsInfoControl1.CurrentPoint = (GpsPoint)UpdatedPoint;
                                    _dirty = true;
                                }

                                LockControls(true);
                            }
                        }
                        catch (Exception ex)
                        {
                            TtUtils.WriteError(ex.Message, "PointEditFormLogic", ex.StackTrace);
                            MessageBox.Show("Aquire GPS Form error.");
                        }
                    }
                    else
                    {
                        DialogResult dr = MessageBox.Show("GPS is not currently configured. Would you like to configure now?", "Configure GPS",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                        if (dr == DialogResult.Yes)
                        {
                            using (DeviceSetupForm form = new DeviceSetupForm())
                            {
                                form.ShowDialog();
                            }

                            gpsWayInputCtrl1_OnAcquire();
                        }
                    }
                }
                else
                {
                    DialogResult dr = MessageBox.Show("There is no point selected. Would you like to create a new point?", "No Point Selected",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    if (dr == DialogResult.Yes)
                    {
                        CreateNewPoint();
                    }
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "PointEdit:gpsWayInputCtrl1_OnAcquire", ex.StackTrace);
            }
        }
        private void btnHelp_Click2(object sender, EventArgs e)
        {
            if (!Values.GPSA.IsBusy)
            {
                if (!Values.Settings.DeviceOptions.GpsConfigured)
                {
                    if (MessageBox.Show("Gps is not configured. Would you like to configure now?", "Configure Gps", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        using (DeviceSetupForm form = new DeviceSetupForm())
                        {
                            form.ShowDialog();

                            if (Values.Settings.DeviceOptions.GpsConfigured)
                            {
                                btnHelp_Click2(sender, e);
                            }
                        }
                    }
                }
                else
                {
                    Values.GPSA.BurstReceived += GPSA_BurstReceived;
                    DelInit = true;

                    TtUtils.ShowWaitCursor();
                    calcBursts = true;
                    bursts.Clear();
                    Values.GPSA.OpenGps(Values.Settings.DeviceOptions.GpsComPort, Values.Settings.DeviceOptions.GpsBaud);
                }
            }
            else
            {
                calcBursts = true;
                bursts.Clear();
            }
        }