File indexing completed on 2024-04-21 14:45:51

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "fitscommon.h"
0010 
0011 #include <QUndoStack>
0012 #include <QSplitter>
0013 #include <QToolBox>
0014 #include <QUrl>
0015 #include <QWidget>
0016 #include "ui_fitsheaderdialog.h"
0017 #include "ui_statform.h"
0018 #include "ui_platesolve.h"
0019 #include <QFuture>
0020 #include <QPointer>
0021 #include <QListWidget>
0022 #include <QLabel>
0023 #include <QPushButton>
0024 #include <memory>
0025 #include "ekos/auxiliary/solverutils.h"
0026 
0027 class FITSHistogramEditor;
0028 class FITSView;
0029 class FITSViewer;
0030 class FITSData;
0031 class FITSStretchUI;
0032 
0033 /**
0034  * @brief The FITSTab class holds information on the current view (drawing area) in addition to the undo/redo stacks
0035  *  and status of current document (clean or dirty). It also creates the corresponding histogram associated with the
0036  *  image data that is stored in the FITSView class.
0037  * @author Jasem Mutlaq
0038  */
0039 class FITSTab : public QWidget
0040 {
0041         Q_OBJECT
0042     public:
0043         explicit FITSTab(FITSViewer *parent);
0044         virtual ~FITSTab() override;
0045 
0046         enum
0047         {
0048             STAT_WIDTH,
0049             STAT_HEIGHT,
0050             STAT_BITPIX,
0051             STAT_HFR,
0052             STAT_MIN,
0053             STAT_MAX,
0054             STAT_MEAN,
0055             STAT_MEDIAN,
0056             STAT_STDDEV
0057         };
0058 
0059         void clearRecentFITS();
0060         void selectRecentFITS(int i);
0061         void loadFile(const QUrl &imageURL, FITSMode mode = FITS_NORMAL, FITSScale filter = FITS_NONE);
0062         bool loadData(const QSharedPointer<FITSData> &data, FITSMode mode = FITS_NORMAL, FITSScale filter = FITS_NONE);
0063 
0064         // Methods to setup and control blinking--loading a directory of images one-by-one
0065         // into a single tab.
0066         void initBlink(const QList<QString> &filenames)
0067         {
0068             m_BlinkFilenames = filenames;
0069         }
0070         const QList<QString> &blinkFilenames() const
0071         {
0072             return m_BlinkFilenames;
0073         }
0074         int blinkUpto() const
0075         {
0076             return m_BlinkIndex;
0077         };
0078         void setBlinkUpto(int index)
0079         {
0080             if (index >= 0 && index < m_BlinkFilenames.size())
0081                 m_BlinkIndex = index;
0082         };
0083 
0084         bool saveImage(const QString &filename);
0085 
0086         inline QUndoStack *getUndoStack()
0087         {
0088             return undoStack;
0089         }
0090         inline QUrl *getCurrentURL()
0091         {
0092             return &currentURL;
0093         }
0094         inline const QSharedPointer<FITSView> &getView()
0095         {
0096             return m_View;
0097         }
0098         inline QPointer<FITSHistogramEditor> getHistogram()
0099         {
0100             return m_HistogramEditor;
0101         }
0102         inline QPointer<FITSViewer> getViewer()
0103         {
0104             return viewer;
0105         }
0106 
0107         bool saveFile();
0108         bool saveFileAs();
0109         void copyFITS();
0110         void loadFITSHeader();
0111         void headerFITS();
0112         void histoFITS();
0113         void statFITS();
0114 
0115         Q_SCRIPTABLE void setStretchValues(double shadows, double midtones, double highlights);
0116 
0117         void setUID(int newID)
0118         {
0119             uid = newID;
0120         }
0121         int getUID()
0122         {
0123             return uid;
0124         }
0125 
0126         void saveUnsaved();
0127         void tabPositionUpdated();
0128         void selectGuideStar();
0129 
0130         QString getPreviewText() const;
0131         void setPreviewText(const QString &value);
0132         bool shouldComputeHFR() const;
0133 
0134     public slots:
0135         void modifyFITSState(bool clean = true, const QUrl &imageURL = QUrl());
0136         void ZoomIn();
0137         void ZoomOut();
0138         void ZoomDefault();
0139         void displayStats(bool roi = false);
0140         void extractImage();
0141         void solveImage();
0142     protected:
0143         virtual void closeEvent(QCloseEvent *ev) override;
0144 
0145     private:
0146         bool setupView(FITSMode mode, FITSScale filter);
0147         void processData();
0148         void imageSolved(bool success);
0149 
0150         /** Ask user whether he wants to save changes and save if he do. */
0151 
0152         /// The FITSTools Toolbox
0153         QPointer<QToolBox> fitsTools;
0154         /// The Splitter for th FITSTools Toolbox
0155         QPointer<QSplitter> fitsSplitter;
0156         /// The FITS Header Panel
0157         QPointer<QDialog> fitsHeaderDialog;
0158         Ui::fitsHeaderDialog header;
0159         /// The Statistics Panel
0160         QPointer<QDialog> statWidget;
0161         Ui::statForm stat;
0162         /// The Plate Solving UI
0163         QPointer<QDialog> m_PlateSolveWidget;
0164         Ui::PlateSolveUI m_PlateSolveUI;
0165         /// FITS Histogram
0166         QPointer<FITSHistogramEditor> m_HistogramEditor;
0167         QPointer<FITSViewer> viewer;
0168 
0169         QPointer<QListWidget> recentImages;
0170 
0171         /// FITS image object
0172         QSharedPointer<FITSView> m_View;
0173 
0174         /// History for undo/redo
0175         QUndoStack *undoStack { nullptr };
0176         /// FITS File name and path
0177         QUrl currentURL;
0178 
0179         bool mDirty { false };
0180         QString previewText;
0181         int uid { 0 };
0182 
0183         std::unique_ptr<FITSStretchUI> stretchUI;
0184 
0185         // Used for solving an image.
0186         void setupSolver(bool extractOnly = false);
0187         void solverDone(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
0188         void extractorDone(bool timedOut, bool success, const FITSImage::Solution &solution, double elapsedSeconds);
0189         void initSolverUI();
0190         QSharedPointer<SolverUtils> m_Solver;
0191 
0192         QList<QString> m_BlinkFilenames;
0193         int m_BlinkIndex { 0 };
0194 
0195     signals:
0196         void debayerToggled(bool);
0197         void newStatus(const QString &msg, FITSBar id);
0198         void changeStatus(bool clean, const QUrl &imageUrl);
0199         void loaded();
0200         void updated();
0201         void failed(const QString &errorMessage);
0202 };