示例#1
0
        private void CheckBgThread(object state)
        {
            try
            {
                if (m_ObjectDesignation != null)
                {
                    if (!string.IsNullOrEmpty(m_ObsCode))
                    {
                        Position = MPEph2.GetCoordinatesForSingleDate(m_ObsCode, m_ObjectDesignation, m_UtcTime);
                    }
                    else if (!double.IsNaN(m_Lambda) && !double.IsNaN(m_Phi))
                    {
                        Position = MPEph2.GetCoordinatesForSingleDate(m_Lambda, m_Phi, m_ObjectDesignation, m_UtcTime);
                    }
                }
                else
                {
                    IdentifiedObjects = MPCheck.CheckRegion(m_UtcTime, m_Fit.RA0Deg, m_Fit.DE0Deg, m_FovArcMin, m_MagLimit, string.IsNullOrEmpty(m_ObsCode) ? "500" : m_ObsCode);


                    // MPCheck is a low positional precision service. Check each object position with the more accurate MPEph2 service
                    foreach (var entry in IdentifiedObjects)
                    {
                        MPEph2.MPEphEntry position = null;
                        if (!string.IsNullOrEmpty(m_ObsCode))
                        {
                            position = MPEph2.GetCoordinatesForSingleDate(m_ObsCode, entry.ObjectName, m_UtcTime);
                        }
                        else if (!double.IsNaN(m_Lambda) && !double.IsNaN(m_Phi))
                        {
                            position = MPEph2.GetCoordinatesForSingleDate(m_Lambda, m_Phi, entry.ObjectName, m_UtcTime);
                        }

                        if (position != null)
                        {
                            entry.RAHours = position.RAHours;
                            entry.DEDeg   = position.DEDeg;
                            entry.Mag     = position.Mag;
                        }
                    }
                }

                Invoke(new MethodInvoker(Done));
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                Invoke(new WaitCallback(Error), ex.Message);
            }
        }
示例#2
0
        private bool CheckInputAndLoadStars()
        {
            if (!TangraContext.Current.HasImageLoaded)
            {
                MessageBox.Show(this, "There is no loaded frame/image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            m_RAHours = double.NaN;
            m_DEDeg   = double.NaN;

            Context.ObsCode = tbxObsCode.Text;

            if (rbKnownCenter.Checked)
            {
                try
                {
                    m_RAHours = AstroConvert.ToRightAcsension(cbxRA.Text);
                }
                catch
                {
                    MessageBox.Show(this, "Enter a valid RA value", "Validation Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    cbxRA.Focus();
                    cbxRA.Select();
                    return(false);
                }

                try
                {
                    m_DEDeg = AstroConvert.ToDeclination(cbxDE.Text);
                }
                catch
                {
                    MessageBox.Show(this, "Enter a valid DE value", "Validation Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    cbxDE.Focus();
                    cbxDE.Select();
                    return(false);
                }

                cbxRA.Persist();
                cbxDE.Persist();
            }
            else if (rbKnownObject.Checked)
            {
                // Connect to MPC to find the object coordinates
                MPEph2.MPEphEntry position = null;
                Cursor  = Cursors.WaitCursor;
                Enabled = false;
                try
                {
                    if (!TangraConfig.Settings.HasSiteCoordinatesOrCOD && string.IsNullOrEmpty(tbxObsCode.Text))
                    {
                        m_VideoController.ShowTangraSettingsDialog(false, true);

                        if (!TangraConfig.Settings.HasSiteCoordinatesOrCOD)
                        {
                            return(false);
                        }
                    }


                    Refresh();

                    frmIdentifyObjects frm;

                    if (TangraConfig.Settings.Astrometry.UseMPCCode || !string.IsNullOrEmpty(tbxObsCode.Text))
                    {
                        Context.ObsCode = tbxObsCode.Text;
                        frm             = new frmIdentifyObjects(cbxObject.Text, Context.UtcTime, Context.ObsCode);
                    }
                    else
                    {
                        frm = new frmIdentifyObjects(
                            cbxObject.Text, Context.UtcTime,
                            TangraConfig.Settings.Generic.Longitude,
                            TangraConfig.Settings.Generic.Latitude);
                    }


                    if (m_VideoController.ShowDialog(frm) == DialogResult.OK)
                    {
                        position = frm.Position;
                    }
                }
                finally
                {
                    Enabled = true;
                    Cursor  = Cursors.Default;
                }

                if (position == null)
                {
                    MessageBox.Show(
                        this,
                        string.Format(string.Format("Could not retrieve the position of '{0}' from MPC. Is your internet connection active? Is the designation correct?", cbxObject.Text)),
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    cbxObject.Focus();
                    cbxObject.Select();
                    return(false);
                }
                else
                {
                    m_RAHours = position.RAHours;
                    m_DEDeg   = position.DEDeg;

                    cbxObject.Persist();

                    Context.FoundObject = position;
                }
            }

            Context.RADeg   = m_RAHours * 15;
            Context.DEDeg   = m_DEDeg;
            Context.ErrFoVs = (double)nudError.Value;

            Context.Method = RecognitionMethod.KnownCenter;

            Context.LimitMagn = (double)nudFaintestMag.Value;

            float epoch = Context.UtcTime.Year + Context.UtcTime.DayOfYear / 365.25f;


            if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceInfo())
            {
                Trace.WriteLine(string.Format("Loading stars in region ({0}, {1})",
                                              AstroConvert.ToStringValue(Context.RADeg / 15, "REC"),
                                              AstroConvert.ToStringValue(Context.DEDeg, "DEC")));
            }

            var facade = new StarCatalogueFacade(TangraConfig.Settings.StarCatalogue);

            m_CatalogueStars = facade.GetStarsInRegion(
                Context.RADeg,
                Context.DEDeg,
                (Context.ErrFoVs + 1.0) * m_Image.GetMaxFOVInArcSec() / 3600.0,
                Context.LimitMagn,
                epoch);

            Context.CatalogueStars      = m_CatalogueStars;
            Context.StarCatalogueFacade = facade;

            Context.DetermineAutoLimitMagnitude = rbAutomaticLimitMagnitude.Checked;
            Context.AutoLimitMagnitude          = double.NaN;

            return(true);
        }