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

0001 /*  Ekos Mount Model
0002     SPDX-FileCopyrightText: 2018 Robert Lancaster
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 
0010 #include "ui_mountmodel.h"
0011 #include "ekos/ekos.h"
0012 #include "skypoint.h"
0013 
0014 #include <QDialog>
0015 #include <QUrl>
0016 
0017 class QProgressIndicator;
0018 class SkyObject;
0019 class StarObject;
0020 
0021 namespace Ekos
0022 {
0023 
0024 class Align;
0025 
0026 class MountModel : public QDialog, public Ui::mountModel
0027 {
0028         Q_OBJECT
0029 
0030     public:
0031         explicit MountModel(Align *parent);
0032         ~MountModel();
0033 
0034         enum ModelObjectType
0035         {
0036             OBJECT_ANY_STAR,
0037             OBJECT_NAMED_STAR,
0038             OBJECT_ANY_OBJECT,
0039             OBJECT_FIXED_DEC,
0040             OBJECT_FIXED_GRID
0041         };
0042 
0043         void setTelescopeCoord(const SkyPoint &newCoord)
0044         {
0045             telescopeCoord = newCoord;
0046         }
0047 
0048         bool isRunning() const
0049         {
0050             return m_IsRunning;
0051         }
0052 
0053         void setAlignStatus(Ekos::AlignState state);
0054 
0055     protected:
0056         void slotWizardAlignmentPoints();
0057         void slotStarSelected(const QString selectedStar);
0058         void slotLoadAlignmentPoints();
0059         void slotSaveAlignmentPoints();
0060         void slotClearAllAlignPoints();
0061         void slotRemoveAlignPoint();
0062         void slotAddAlignPoint();
0063         void slotFindAlignObject();
0064         void resetAlignmentProcedure();
0065         void startStopAlignmentProcedure();
0066         void startAlignmentPoint();
0067         void finishAlignmentPoint(bool solverSucceeded);
0068         void moveAlignPoint(int logicalIndex, int oldVisualIndex, int newVisualIndex);
0069         void alignTypeChanged(int alignType);
0070         void togglePreviewAlignPoints();
0071         void slotSortAlignmentPoints();
0072 
0073 
0074     private:
0075 
0076         void generateAlignStarList();
0077         bool alignmentPointsAreBad();
0078         bool loadAlignmentPoints(const QString &fileURL);
0079         bool saveAlignmentPoints(const QString &path);
0080 
0081         bool isVisible(const SkyObject *so);
0082         double getAltitude(const SkyObject *so);
0083         const SkyObject *getWizardAlignObject(double ra, double de);
0084         void calculateAngleForRALine(double &raIncrement, double &initRA, double initDEC, double lat, double raPoints,
0085                                      double minAlt);
0086         void calculateAZPointsForDEC(dms dec, dms alt, dms &AZEast, dms &AZWest);
0087         void updatePreviewAlignPoints();
0088         int findNextAlignmentPointAfter(int currentSpot);
0089         int findClosestAlignmentPointToTelescope();
0090         void swapAlignPoints(int firstPt, int secondPt);
0091 
0092         /**
0093              * @brief Get formatted RA & DEC coordinates compatible with astrometry.net format.
0094              * @param ra Right ascension
0095              * @param dec Declination
0096              * @param ra_str will contain the formatted RA string
0097              * @param dec_str will contain the formatted DEC string
0098              */
0099         void getFormattedCoords(double ra, double dec, QString &ra_str, QString &dec_str);
0100 
0101     signals:
0102         void newLog(const QString &);
0103         void aborted();
0104 
0105     private:
0106 
0107         Align *m_AlignInstance {nullptr};
0108         int currentAlignmentPoint { 0 };
0109         bool m_IsRunning { false };
0110         bool previewShowing { false };
0111         QVector<const StarObject *> alignStars;
0112         QUrl alignURL;
0113         SkyPoint telescopeCoord;
0114 
0115 
0116 };
0117 }