Esempio n. 1
0
        public override void MouseDown(Point location)
        {
            if (m_SelectedCalibrationStar != null)
            {
                frmIdentifyCalibrationStar frmIdentifyCalibrationStar = new frmIdentifyCalibrationStar(m_CatalogueStars, m_UserStarIdentification);
                DialogResult res = m_VideoController.ShowDialog(frmIdentifyCalibrationStar);
                if (res == DialogResult.Abort)
                {
                    m_UserStarIdentification.Clear();
                }
                else if (res == DialogResult.OK &&
                         frmIdentifyCalibrationStar.SelectedStar != null)
                {
                    m_UserStarIdentification.Add(m_SelectedCalibrationStar, frmIdentifyCalibrationStar.SelectedStar);
                    if (m_UserStarIdentification.Keys.Count > 0 &&
                        m_UserStarIdentification.Keys.Count < 3)
                    {
                        m_VideoController.ShowMessageBox(
                            string.Format("Identify another {0} star(s) to attempt calibration", 3 - m_UserStarIdentification.Keys.Count),
                            "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (m_UserStarIdentification.Keys.Count > 2)
                    {
                        List <PSFFit> keysList = m_UserStarIdentification.Keys.ToList();
                        IStar         star1    = m_UserStarIdentification[keysList[0]];
                        IStar         star2    = m_UserStarIdentification[keysList[1]];
                        IStar         star3    = m_UserStarIdentification[keysList[2]];
                        double        ArcSec1  = 1 / 3600.0;
                        bool          badRA    = false;
                        bool          badDE    = false;
                        if (Math.Abs(star1.RADeg - star2.RADeg) < ArcSec1 || Math.Abs(star1.RADeg - star3.RADeg) < ArcSec1 || Math.Abs(star2.RADeg - star3.RADeg) < ArcSec1)
                        {
                            badRA = true;
                        }

                        if (Math.Abs(star1.DEDeg - star2.DEDeg) < ArcSec1 || Math.Abs(star1.DEDeg - star3.DEDeg) < ArcSec1 || Math.Abs(star2.DEDeg - star3.DEDeg) < ArcSec1)
                        {
                            badDE = true;
                        }

                        if (badRA)
                        {
                            m_VideoController.ShowMessageBox(
                                "Two of the stars have almost identical Right Ascension. Please try again with different stars.",
                                "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            m_UserStarIdentification.Clear();
                        }
                        else if (badDE)
                        {
                            m_VideoController.ShowMessageBox(
                                "Two of the stars have almost identical Declination. Please try again with different stars.",
                                "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);

                            m_UserStarIdentification.Clear();
                        }
                        else
                        {
                            ThreeStarAstrometry threeStarSolution = ThreeStarAstrometry.SolveByThreeStars(m_Image, m_UserStarIdentification, m_Tolerance);
                            if (threeStarSolution != null)
                            {
                                m_SolvedPlate = threeStarSolution;

                                m_PlatesolveController.UpdateFocalLength((int)Math.Round(threeStarSolution.Image.EffectiveFocalLength));
                                m_RADegCenter = threeStarSolution.RA0Deg;
                                m_DEDegCenter = threeStarSolution.DE0Deg;
                                m_Image.EffectiveFocalLength = threeStarSolution.Image.EffectiveFocalLength;

                                m_UserStarIdentification.Clear();

                                m_AstrometryController.RunCalibrationWithCurrentPreliminaryFit();
                            }
                            else
                            {
                                m_VideoController.ShowMessageBox(
                                    "Cannot complete calibration. Please try again with higher initial fit tolerance and/or with different stars. Be sure that the stars are well separated.",
                                    "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                m_UserStarIdentification.Remove(m_UserStarIdentification.Keys.ToList()[2]);
                            }
                        }
                    }
                }

                DrawCatalogStarsFit();
            }
            else
            {
                m_StarPoint = new Point(location.X, location.Y);
                m_Panning   = true;
                m_VideoController.SetPictureBoxCursor(CustomCursors.PanEnabledCursor);
            }
        }