File indexing completed on 2024-12-08 06:30:40

0001 /*
0002     SPDX-FileCopyrightText: 2023 Hy Murveit <hy@murveit.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "imageoverlaycomponent.h"
0010 #include "skycomponent.h"
0011 #include <QSharedPointer>
0012 #include <QImage>
0013 #include <QObject>
0014 #include <QLabel>
0015 #include <QTimer>
0016 #include <QPushButton>
0017 #include <QPlainTextEdit>
0018 #include <QGroupBox>
0019 #include <QComboBox>
0020 #include <QAbstractItemView>
0021 #include "fitsviewer/fitsdata.h"
0022 
0023 class QTableWidget;
0024 class SolverUtils;
0025 
0026 class ImageOverlay
0027 {
0028     public:
0029         enum Status
0030         {
0031             UNPROCESSED = 0,
0032             BAD_FILE,
0033             PLATE_SOLVE_FAILURE,
0034             OTHER_ERROR,
0035             AVAILABLE,
0036             NUM_STATUS
0037         };
0038 
0039         ImageOverlay(const QString &filename = "", bool enabled = true, const QString &nickname = "",
0040                      Status status = UNPROCESSED, double orientation = 0, double ra = 0, double dec = 0,
0041                      double pixelsPerArcsec = 0, bool eastToTheRight = true, int width = 0, int height = 0)
0042             : m_Filename(filename), m_Enabled(enabled), m_Nickname(nickname), m_Status(status),
0043               m_Orientation(orientation), m_RA(ra), m_DEC(dec), m_ArcsecPerPixel(pixelsPerArcsec),
0044               m_EastToTheRight(eastToTheRight), m_Width(width), m_Height(height)
0045         {
0046         }
0047 
0048         QString m_Filename;
0049         bool m_Enabled = true;
0050         QString m_Nickname;
0051         Status m_Status = UNPROCESSED;
0052         double m_Orientation = 0.0;
0053         double m_RA = 0.0;
0054         double m_DEC = 0.0;
0055         double m_ArcsecPerPixel = 0.0;
0056         bool m_EastToTheRight = true;
0057         int m_Width = 0;
0058         int m_Height = 0;
0059         QSharedPointer<QImage> m_Img = nullptr;
0060 };
0061 
0062 /**
0063  * @class ImageOverlayComponent
0064  * Represents the ImageOverlay overlay
0065  * @author Hy Murveit
0066  * @version 1.0
0067  */
0068 class ImageOverlayComponent : public QObject, public SkyComponent
0069 {
0070     Q_OBJECT
0071 
0072   public:
0073     explicit ImageOverlayComponent(SkyComposite *);
0074 
0075     virtual ~ImageOverlayComponent() override;
0076 
0077     bool selected() override;
0078     void draw(SkyPainter *skyp) override;
0079     void setWidgets(QTableWidget *table, QPlainTextEdit *statusDisplay, QPushButton *solveButton,
0080                     QGroupBox *tableTitleBox, QComboBox *solverProfile);
0081     void updateTable();
0082 
0083     const QList<ImageOverlay> imageOverlays() const {
0084         return m_Overlays;
0085     }
0086 
0087     public slots:
0088     void startSolving();
0089     void abortSolving();
0090     void show();
0091     void reload();  // not currently implemented.
0092     QString directory()
0093     {
0094         return m_Directory;
0095     };
0096 
0097  signals:
0098     void updateLog(const QString &message);
0099 
0100 private slots:
0101     void tryAgain();
0102     void updateStatusDisplay(const QString &message);
0103 
0104 private:
0105     void loadFromUserDB();
0106     void saveToUserDB();
0107     void solveImage(const QString &filename);
0108     void solverDone(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
0109     void initializeGui();
0110     int numAvailable();
0111     void cellChanged(int row, int col);
0112     void statusCellChanged(int row);
0113     void selectionChanged();
0114     void initSolverProfiles();
0115 
0116     // Methods that load the image files in the background.
0117     void loadAllImageFiles();
0118     void loadImageFileLoop();
0119     bool loadImageFile();
0120     QImage *loadImageFile (const QString &fullFilename, bool mirror);
0121 
0122 
0123     QTableWidget *m_ImageOverlayTable;
0124     QGroupBox *m_TableGroupBox;
0125     QAbstractItemView::EditTriggers m_EditTriggers;
0126     QPlainTextEdit *m_StatusDisplay;
0127     QPushButton *m_SolveButton;
0128     QComboBox *m_SolverProfile;
0129     QStringList m_LogText;
0130     bool m_Initialized = false;
0131 
0132     QList<ImageOverlay> m_Overlays;
0133     QMap<QString, int> m_Filenames;
0134     QSharedPointer<SolverUtils> m_Solver;
0135     QList<int> m_RowsToSolve;
0136     QString m_Directory;
0137     QTimer m_TryAgainTimer;
0138     QFuture<void> m_LoadImagesFuture;
0139 };