File indexing completed on 2024-04-28 03:43:16

0001 /*
0002     SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "ui_captureprocessoverlay.h"
0010 
0011 #include "indi/indicommon.h"
0012 
0013 #include <QWidget>
0014 
0015 class FITSData;
0016 
0017 class CaptureProcessOverlay : public QWidget,  public Ui::CaptureProcessOverlay
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     explicit CaptureProcessOverlay(QWidget *parent = nullptr);
0023 
0024     // data describing a single frame
0025     struct FrameData
0026     {
0027         QString target;
0028         CCDFrameType frameType;
0029         QString filterName;
0030         QString filename;
0031         double exptime;
0032         double targetdrift;
0033         QPoint binning;
0034         int width;
0035         int height;
0036         double gain;
0037         double offset;
0038         QString iso;
0039     };
0040 
0041     // structs for frame statistics
0042     // map (frame type, filter) --> (exp time * 100, counter)
0043     typedef QMap<QPair<CCDFrameType, QString>, QList<QPair<int, int>*>> FrameStatistics;
0044     // map target --> frame statistics
0045     typedef QMap<QString, FrameStatistics> TargetStatistics;
0046 
0047     /**
0048      * @brief Navigator through the capture history.
0049      */
0050     class CaptureHistory {
0051     public:
0052         /**
0053          * @brief Add a newly captured frame to the history
0054          * @param data frame data
0055          * @return true iff this is a new frame, i.e. its filename does not exist in the history
0056          */
0057         bool addFrame(FrameData data);
0058 
0059         /**
0060          * @brief Delete the current frame and (if possible) the corresponding file.
0061          * If the last one has been deleted, navigate to the frame before, if possible.
0062          * @return true iff deleting was successful
0063          */
0064         bool deleteFrame(int pos);
0065 
0066         /**
0067          * @brief the currently pointed capture frame
0068          */
0069         const FrameData currentFrame() {return m_history.at(m_position);}
0070 
0071         /**
0072          * @brief The current navigation position in the capture history
0073          */
0074         int position() {return m_position;}
0075         /**
0076          * @brief Obtain the frame from the given position in the history
0077          */
0078         const FrameData getFrame(int pos) {return m_history.at(pos);}
0079         /**
0080          * @brief Capture history size
0081          */
0082         int size() {return m_history.size();}
0083         /**
0084          * @brief Reset the history
0085          */
0086         void reset();
0087         /**
0088          * @brief Move one step forward in the history
0089          * @return true iff the move was possible within the limits
0090          */
0091         bool forward();
0092         /**
0093          * @brief Move one step backwards in the history
0094          * @return true iff the move was possible within the limits
0095          */
0096         bool backward();
0097         /**
0098          * @brief Iterate over the current target history and add all
0099          *        those where the corresponding file exists.
0100          */
0101         void updateTargetStatistics();
0102 
0103         // capture statistics
0104         TargetStatistics statistics;
0105 
0106     private:
0107         QList<FrameData> m_history;
0108         int m_position = -1;
0109 
0110         /**
0111          * @brief Add a new frame to the statistics
0112          * @param target current target being processed
0113          * @param frameType type of the currently captured frame
0114          * @param filter selected filter for the captured frame
0115          * @param exptime exposure time of the captured frame
0116          */
0117         void countNewFrame(QString target, CCDFrameType frameType, QString filter, double exptime);
0118     };
0119 
0120     bool addFrameData(FrameData data);
0121     /**
0122      * @brief Update the overlay with the meta data of the current frame and add it to the history
0123      */
0124     void updateFrameData();
0125 
0126     /**
0127      * @brief Update the current target distance.
0128      * @param targetDiff distance to the target in arcseconds.
0129      */
0130     void updateTargetDistance(double targetDiff);
0131 
0132     /**
0133      * @brief Obtain the position of the current frame from the history
0134      */
0135     int currentPosition() {return m_captureHistory.position();}
0136 
0137     /**
0138      * @brief Retrieve the currently selected frame
0139      */
0140     const FrameData currentFrame() {return m_captureHistory.currentFrame();}
0141 
0142     /**
0143      * @brief Obtain the frame from the given position in the history
0144      */
0145     const FrameData getFrame(int pos) {return m_captureHistory.getFrame(pos);}
0146 
0147     /**
0148      * @brief Obtain the position of the current frame from the history
0149      */
0150 
0151     /**
0152      * @brief Returns true iff there are frames in the capture history
0153      */
0154     bool hasFrames() {return m_captureHistory.size() > 0;}
0155 
0156     /**
0157      * @brief Update the statistics display for captured frames
0158      */
0159     void displayTargetStatistics();
0160 
0161     /**
0162      * @brief Loads a new frame into the view and displays meta data in the overlay
0163      * @param data pointer to FITSData object
0164      */
0165     bool addFrame(const QSharedPointer<FITSData> &data);
0166 
0167     /**
0168      * @brief Show the next frame from the capture history
0169      */
0170     bool showNextFrame();
0171 
0172     /**
0173      * @brief Show the previous frame from the capture history
0174      */
0175     bool showPreviousFrame();
0176 
0177     /**
0178      * @brief Delete the currently displayed frame
0179      */
0180     bool deleteFrame(int pos);
0181 
0182 private:
0183     //capture history
0184     CaptureHistory m_captureHistory;
0185 
0186 };