File indexing completed on 2024-04-28 15:09:03

0001 /*
0002     SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003     SPDX-FileCopyrightText: 2017 Robert Lancaster <rlancaste@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "opsastrometry.h"
0009 
0010 #include "align.h"
0011 #include "kstars.h"
0012 #include "Options.h"
0013 
0014 #include <KConfigDialog>
0015 
0016 namespace Ekos
0017 {
0018 OpsAstrometry::OpsAstrometry(Align *parent) : QWidget(KStars::Instance())
0019 {
0020     setupUi(this);
0021 
0022     alignModule = parent;
0023 
0024     //Get a pointer to the KConfigDialog
0025     m_ConfigDialog = KConfigDialog::exists("alignsettings");
0026 
0027     dms ra, de;
0028     ra.setD(Options::astrometryPositionRA());
0029     de.setD(Options::astrometryPositionDE());
0030 
0031     estRA->setText(ra.toHMSString());
0032     estDec->setText(de.toDMSString());
0033 
0034     imageWarningLabel->setHidden(kcfg_AstrometryAutoUpdateImageScale->isChecked());
0035     positionWarningLabel->setHidden(kcfg_AstrometryAutoUpdatePosition->isChecked());
0036 
0037     connect(kcfg_AstrometryAutoUpdateImageScale, SIGNAL(toggled(bool)), imageWarningLabel, SLOT(setHidden(bool)));
0038     connect(kcfg_AstrometryAutoUpdatePosition, SIGNAL(toggled(bool)), positionWarningLabel, SLOT(setHidden(bool)));
0039 
0040     connect(m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(slotApply()));
0041     connect(m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(slotApply()));
0042 
0043     connect(updateScale, SIGNAL(clicked()), this, SLOT(slotUpdateScale()));
0044     connect(updatePosition, SIGNAL(clicked()), this, SLOT(slotUpdatePosition()));
0045     updateScale->setIcon(QIcon::fromTheme("edit-copy"));
0046     updateScale->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0047     updatePosition->setIcon(QIcon::fromTheme("edit-copy"));
0048     updatePosition->setAttribute(Qt::WA_LayoutUsesWidgetRect);
0049 }
0050 
0051 void OpsAstrometry::showEvent(QShowEvent *)
0052 {
0053     dms ra, de;
0054     ra.setD(Options::astrometryPositionRA());
0055     de.setD(Options::astrometryPositionDE());
0056 
0057     estRA->setText(ra.toHMSString());
0058     estDec->setText(de.toDMSString());
0059 }
0060 
0061 //This updates the telescope/image field scale in the astrometry options editor to match the currently connected devices.
0062 void OpsAstrometry::slotUpdateScale()
0063 {
0064     double fov_w, fov_h, fov_pixscale;
0065 
0066     // Values in arcmins. Scale in arcsec per pixel
0067     alignModule->getCalculatedFOVScale(fov_w, fov_h, fov_pixscale);
0068 
0069     if (fov_w == 0 || fov_h == 0)
0070     {
0071         kcfg_AstrometryImageScaleLow->setValue(0);
0072         kcfg_AstrometryImageScaleHigh->setValue(0);
0073         return;
0074     }
0075 
0076     switch (kcfg_AstrometryImageScaleUnits->currentIndex())
0077     {
0078         case SSolver::DEG_WIDTH:
0079             fov_w /= 60;
0080             fov_h /= 60;
0081             kcfg_AstrometryImageScaleLow->setValue(qMin(fov_w, fov_h));
0082             kcfg_AstrometryImageScaleHigh->setValue(qMax(fov_w, fov_h));
0083             break;
0084 
0085         case SSolver::ARCMIN_WIDTH:
0086             kcfg_AstrometryImageScaleLow->setValue(qMin(fov_w, fov_h));
0087             kcfg_AstrometryImageScaleHigh->setValue(qMax(fov_w, fov_h));
0088             break;
0089 
0090         case SSolver::ARCSEC_PER_PIX:
0091             // 10% range
0092             kcfg_AstrometryImageScaleLow->setValue(fov_pixscale * 0.9);
0093             kcfg_AstrometryImageScaleHigh->setValue(fov_pixscale * 1.1);
0094             break;
0095 
0096         default:
0097             return;
0098     }
0099 }
0100 
0101 //This updates the RA and DEC position in the astrometry options editor to match the current telescope position.
0102 void OpsAstrometry::slotUpdatePosition()
0103 {
0104     estRA->setText(alignModule->ScopeRAOut->text());
0105     estDec->setText(alignModule->ScopeDecOut->text());
0106 }
0107 
0108 void OpsAstrometry::slotApply()
0109 {
0110     //if (Options::solverBackend() != 1)
0111     //    return;
0112 
0113     bool raOK = false, deOK = false;
0114     dms RA = estRA->createDms(&raOK);
0115     dms DE = estDec->createDms(&deOK);
0116 
0117     if (raOK && deOK)
0118     {
0119         Options::setAstrometryPositionRA(RA.Degrees());
0120         Options::setAstrometryPositionDE(DE.Degrees());
0121     }
0122 
0123     //alignModule->generateArgs();
0124 }
0125 }