File indexing completed on 2024-07-14 10:52:00

0001 /*
0002     SPDX-FileCopyrightText: 2004 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006     Some code fragments were adapted from Peter Kirchgessner's FITS plugin
0007     SPDX-FileCopyrightText: Peter Kirchgessner <http://members.aol.com/pkirchg>
0008 */
0009 
0010 #pragma once
0011 
0012 #include "fitscommon.h"
0013 #include "fitsviewer/stretch.h"
0014 
0015 #include <KLed>
0016 #include <KXmlGui/KXmlGuiWindow>
0017 #include <KActionMenu>
0018 
0019 #include <QLabel>
0020 #include <QList>
0021 #include <QMap>
0022 #include <QUrl>
0023 
0024 #ifdef WIN32
0025 // avoid compiler warning when windows.h is included after fitsio.h
0026 #include <windows.h>
0027 #endif
0028 
0029 #include <fitsio.h>
0030 
0031 class QCloseEvent;
0032 class QUndoGroup;
0033 
0034 class QTabWidget;
0035 
0036 class FITSDebayer;
0037 class FITSTab;
0038 class FITSView;
0039 class FITSData;
0040 
0041 /**
0042  * @class FITSViewer
0043  * @short Primary window to view monochrome and color FITS images.
0044  * The FITSviewer can open multiple images each in a separate. It supports simple filters, histogram transforms, flip and rotation operations, and star detection.
0045  *
0046  * @author Jasem Mutlaq
0047  * @version 1.0
0048  */
0049 class FITSViewer : public KXmlGuiWindow
0050 {
0051         Q_OBJECT
0052 
0053     public:
0054         /** Constructor. */
0055         explicit FITSViewer(QWidget *parent);
0056         ~FITSViewer() override;
0057 
0058         void loadFile(const QUrl &imageName, FITSMode mode = FITS_NORMAL, FITSScale filter = FITS_NONE,
0059                       const QString &previewText = QString());
0060 
0061         bool loadData(const QSharedPointer<FITSData> &data, const QUrl &imageName, int *tab_uid,
0062                       FITSMode mode = FITS_NORMAL, FITSScale filter = FITS_NONE,
0063                       const QString &previewText = QString());
0064 
0065         void updateFile(const QUrl &imageName, int fitsUID, FITSScale filter = FITS_NONE);
0066         bool updateData(const QSharedPointer<FITSData> &data, const QUrl &imageName, int fitsUID, int *tab_uid,
0067                         FITSScale filter = FITS_NONE, FITSMode mode = FITS_UNKNOWN);
0068         bool removeFITS(int fitsUID);
0069 
0070         bool isStarsMarked()
0071         {
0072             return markStars;
0073         }
0074 
0075         bool empty() const
0076         {
0077             return m_Tabs.empty();
0078         }
0079         const QList<QSharedPointer<FITSTab>> tabs() const
0080         {
0081             return m_Tabs;
0082         }
0083         bool getView(int fitsUID, QSharedPointer<FITSView> &view);
0084         bool getCurrentView(QSharedPointer<FITSView> &view);
0085 
0086         static QStringList filterTypes;
0087 
0088     protected:
0089         void closeEvent(QCloseEvent *) override;
0090         void hideEvent(QHideEvent *) override;
0091         void showEvent(QShowEvent *) override;
0092 
0093     public slots:
0094         void changeAlwaysOnTop(Qt::ApplicationState state);
0095         void openFile();
0096         void blink();
0097         void nextBlink();
0098         void previousBlink();
0099         void saveFile();
0100         void saveFileAs();
0101         void copyFITS();
0102         void statFITS();
0103         void toggleSelectionMode();
0104         void headerFITS();
0105         void debayerFITS();
0106         void histoFITS();
0107         void tabFocusUpdated(int currentIndex);
0108         void updateStatusBar(const QString &msg, FITSBar id);
0109         void ZoomIn();
0110         void ZoomOut();
0111         void ZoomAllIn();
0112         void ZoomAllOut();
0113         void ZoomDefault();
0114         void ZoomToFit();
0115         void updateAction(const QString &name, bool enable);
0116         void updateTabStatus(bool clean, const QUrl &imageURL);
0117         void closeTab(int index);
0118         void toggleStars();
0119         void nextTab();
0120         void previousTab();
0121         void toggleCrossHair();
0122         void toggleClipping();
0123         void toggleEQGrid();
0124         void toggleObjects();
0125         void togglePixelGrid();
0126         void toggle3DGraph();
0127         void toggleHiPSOverlay();
0128         void starProfileButtonOff();
0129         void centerTelescope();
0130         void updateWCSFunctions();
0131         void applyFilter(int ftype);
0132         void rotateCW();
0133         void rotateCCW();
0134         void flipHorizontal();
0135         void flipVertical();
0136         void setDebayerAction(bool);
0137         void updateScopeButton();
0138         void ROIFixedSize(int s);
0139         void customROIInputWindow();
0140 
0141 
0142     private:
0143         void updateButtonStatus(const QString &action, const QString &item, bool showing);
0144         // Shared utilites between the standard and "FromData" addFITS and updateFITS.
0145         bool addFITSCommon(const QSharedPointer<FITSTab> &tab, const QUrl &imageName,
0146                            FITSMode mode, const QString &previewText);
0147         bool updateFITSCommon(const QSharedPointer<FITSTab> &tab, const QUrl &imageName);
0148 
0149         QTabWidget *fitsTabWidget { nullptr };
0150         QUndoGroup *undoGroup { nullptr };
0151         FITSDebayer *debayerDialog { nullptr };
0152         KLed led;
0153         QLabel fitsPosition, fitsValue, fitsResolution, fitsZoom, fitsWCS, fitsHFR, fitsClip;
0154         QAction *saveFileAction { nullptr };
0155         QAction *saveFileAsAction { nullptr };
0156         QList<QSharedPointer<FITSTab>> m_Tabs;
0157         int fitsID { 0 };
0158         bool markStars { false };
0159         QMap<int, QSharedPointer<FITSTab>> fitsMap;
0160         QUrl lastURL;
0161         KActionMenu *roiActionMenu { nullptr };
0162         KActionMenu* roiMenu { nullptr };
0163 
0164         void loadFiles();
0165         QList<QUrl> m_urls;
0166         void changeBlink(bool increment);
0167         static bool m_BlinkBusy;
0168 
0169     signals:
0170         void trackingStarSelected(int x, int y);
0171         void loaded(int tabUID);
0172         void closed(int tabUID);
0173         void failed(const QString &errorMessage);
0174         void terminated();
0175 
0176 };