File indexing completed on 2024-03-24 15:17:41

0001 /*
0002     SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SIMPLEFOVEXPORTER_H
0008 #define SIMPLEFOVEXPORTER_H
0009 
0010 #include "QList"
0011 
0012 class SkyPoint;
0013 class FOV;
0014 class KStarsData;
0015 class SkyMap;
0016 class QPaintDevice;
0017 
0018 /**
0019   * \class SimpleFovExporter
0020   * \brief SimpleFovExporter class is used for FOV representation exporting.
0021   * Central point is defined by passed pointer to SkyPoint instance and field-of-view parameters
0022   * are defined by FOV class instance. Fragment of sky is painted on passed QPaintDevice subclass.
0023   * SimpleFovExporter class can be used for export of FOV representations in user-interactive mode as well as
0024   * for export of multiple FOVs at once, without user interaction.
0025   * \note Please note that SimpleFovExporter class instances may pause simulation clock if they're configured
0026   * to do so (via setClockStopping() method).
0027   * \note FOV representation's shape can be overridden (i.e. FOV image will be always rectangular) using
0028   * setFovShapeOverriden() method.
0029   */
0030 class SimpleFovExporter
0031 {
0032   public:
0033     /**
0034           * \brief Constructor
0035           */
0036     SimpleFovExporter();
0037 
0038     /**
0039           * \brief Paint FOV representation on passed QPaintDevice subclass.
0040           * \param point central point of the exported FOV.
0041           * \param fov represented field-of-view.
0042           * \param pd paint device on which the representation of the FOV will be painted.
0043           */
0044     void exportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd);
0045 
0046     /**
0047           * \brief Paint FOV representation on passed QPaintDevice subclass.
0048           * \param fov represented field-of-view.
0049           * \param pd paint device on which the representation of the FOV will be painted.
0050           */
0051     void exportFov(FOV *fov, QPaintDevice *pd);
0052 
0053     /**
0054           * \brief Paint FOV representation on passed QPaintDevice subclass.
0055           * \param pd paint device on which the representation of the FOV will be painted.
0056           */
0057     void exportFov(QPaintDevice *pd);
0058 
0059     /**
0060           * \brief Export multiple FOV representations.
0061           * \param points list of central points.
0062           * \param fovs list of fields-of-view.
0063           * \param pds list of paint devices on which the representation of the FOV will be painted.
0064           */
0065     void exportFov(const QList<SkyPoint *> &points, const QList<FOV *> &fovs, const QList<QPaintDevice *> &pds);
0066 
0067     /**
0068           * \brief Export multiple FOV representations.
0069           * \param points list of central points.
0070           * \param fov list of fields-of-view.
0071           * \param pds list of paint devices on which the representation of the FOV will be painted.
0072           */
0073     void exportFov(const QList<SkyPoint *> &points, FOV *fov, const QList<QPaintDevice *> &pds);
0074 
0075     /**
0076           * \brief Check if FOV export will cause simulation clock to be stopped.
0077           * \return true if clock will be stopped for FOV export.
0078           * \note If changed, previous clock state will be restored after FOV export is done.
0079           */
0080     inline bool isClockStopping() const { return m_StopClock; }
0081 
0082     /**
0083           * \brief Check if FOV representation will be always rectangular.
0084           * \return true if FOV shape is overridden.
0085           */
0086     inline bool isFovShapeOverriden() const { return m_OverrideFovShape; }
0087 
0088     /**
0089           * \brief Check if FOV symbol will be drawn.
0090           * \return true if FOV symbol will be drawn.
0091           */
0092     inline bool isFovSymbolDrawn() const { return m_DrawFovSymbol; }
0093 
0094     /**
0095           * \brief Enable or disable stopping simulation for FOV export.
0096           * \param stopping should be true if stopping is to be enabled.
0097           */
0098     inline void setClockStopping(bool stopping) { m_StopClock = stopping; }
0099 
0100     /**
0101           * \brief Enable or disable FOV shape overriding.
0102           * \param overrideFovShape should be true if FOV representation is to be always rectangular.
0103           */
0104     inline void setFovShapeOverriden(bool overrideFovShape) { m_OverrideFovShape = overrideFovShape; }
0105 
0106     /**
0107           * \brief Enable or disable FOV symbol drawing.
0108           * \param draw should be true if FOV symbol is to be drawn.
0109           */
0110     inline void setFovSymbolDrawn(bool draw) { m_DrawFovSymbol = draw; }
0111 
0112     /**
0113           * \brief Calculate zoom level at which given angular length will occupy given length in pixels.
0114           * \param pixelSize size in pixels.
0115           * \param degrees angular length.
0116           * \return zoom level.
0117           */
0118     static inline double calculateZoomLevel(int pixelSize, float degrees) { return (pixelSize * 57.3 * 60) / degrees; }
0119 
0120     /**
0121           * \brief Calculate pixel size of given angular length at given zoom level.
0122           * \param degrees angular length.
0123           * \param zoomLevel zoom level.
0124           * \return size in pixels.
0125           */
0126     static inline double calculatePixelSize(float degrees, double zoomLevel)
0127     {
0128         return degrees * zoomLevel / (57.3 * 60.0);
0129     }
0130 
0131   private:
0132     /**
0133           * \brief Save SkyMap state.
0134           * \param savePos should be true if current position is to be saved.
0135           */
0136     void saveState(bool savePos);
0137 
0138     /**
0139           * \brief Restore saved SkyMap state.
0140           * \param restorePos should be true if saved position is to be restored.
0141           */
0142     void restoreState(bool restorePos);
0143 
0144     /**
0145           * \brief Private FOV export method.
0146           * \param point central point of the exported FOV.
0147           * \param fov represented field-of-view.
0148           * \param pd paint device on which the representation of the FOV will be painted.
0149           * \note Call to this method will not change SkyMap's state.
0150           */
0151     void pExportFov(SkyPoint *point, FOV *fov, QPaintDevice *pd);
0152 
0153     KStarsData *m_KSData;
0154     SkyMap *m_Map;
0155 
0156     bool m_StopClock;
0157     bool m_OverrideFovShape;
0158     bool m_DrawFovSymbol;
0159 
0160     bool m_PrevClockState;
0161     bool m_PrevSlewing;
0162     SkyPoint *m_PrevPoint;
0163     double m_PrevZoom;
0164 };
0165 
0166 #endif // SIMPLEFOVEXPORTER_H