File indexing completed on 2024-04-21 14:46:44

0001 /*
0002     SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "skyobject.h"
0010 #include "config-kstars.h"
0011 
0012 #include <QBrush>
0013 #include <QPen>
0014 #include <memory>
0015 
0016 #ifdef HAVE_INDI
0017 #include <lilxml.h>
0018 #endif
0019 
0020 class QPainter;
0021 
0022 class MosaicTiles : public SkyObject
0023 {
0024     public:
0025         MosaicTiles();
0026         ~MosaicTiles();
0027 
0028     public:
0029 
0030         /***************************************************************************************************
0031          * Import/Export Functions.
0032          ***************************************************************************************************/
0033 #ifdef HAVE_INDI
0034         /**
0035          * @brief fromXML Load Scheduler XML file and parse it to create tiles in operation mode.
0036          * @param filename full path to filename
0037          * @return True if parsing is successful, false otherwise.
0038          */
0039         bool fromXML(const QString &filename);
0040 #endif
0041 
0042         /**
0043          * @brief toJSON
0044          * @param output
0045          * @return
0046          */
0047         //bool toJSON(QJsonObject &output);
0048 
0049         /**
0050          * @brief fromJSON
0051          * @param input
0052          * @return
0053          */
0054         //bool fromJSON(const QJsonObject &input);
0055 
0056         /***************************************************************************************************
0057          * Operation Modes
0058          ***************************************************************************************************/
0059         typedef enum
0060         {
0061             MODE_PLANNING,
0062             MODE_OPERATION
0063         } OperationMode;
0064 
0065         OperationMode m_OperationMode {MODE_PLANNING};
0066         OperationMode operationMode() const { return m_OperationMode;}
0067         void setOperationMode(OperationMode value) {m_OperationMode = value;}
0068 
0069         /***************************************************************************************************
0070          * Tile Functions.
0071          ***************************************************************************************************/
0072         typedef struct
0073         {
0074             QPointF pos;
0075             QPointF center;
0076             SkyPoint skyCenter;
0077             double rotation;
0078             int index;
0079         } OneTile;
0080 
0081         bool isValid() const;
0082         void createTiles(bool s_shaped);
0083         void appendTile(const OneTile &value);
0084         void appendEmptyTile();
0085         void clearTiles();
0086         void draw(QPainter *painter);
0087 
0088         /**
0089          * @brief syncFOVs Update camera and mosaic overall FOV from current settings.
0090          */
0091         void syncFOVs();
0092 
0093         // Getters
0094         // Return Sky Point
0095         double focalLength() const
0096         {
0097             return m_FocalLength;
0098         }
0099         double focalReducer() const
0100         {
0101             return m_FocalReducer;
0102         }
0103         double positionAngle() const
0104         {
0105             return m_PositionAngle;
0106         }
0107         QSize cameraSize() const
0108         {
0109             return m_CameraSize;
0110         }
0111         QSizeF pixelSize() const
0112         {
0113             return m_PixelSize;
0114         }
0115         QSize gridSize() const
0116         {
0117             return m_GridSize;
0118         }
0119         double overlap() const
0120         {
0121             return m_Overlap;
0122         }
0123         // Return Camera Field of View in arcminutes
0124         QSizeF cameraFOV() const
0125         {
0126             return m_CameraFOV;
0127         }
0128         // Return Mosaic Field of View in arcminutes
0129         QSizeF mosaicFOV() const
0130         {
0131             return m_MosaicFOV;
0132         }
0133 
0134         // Setters
0135         void setFocalLength(double value)
0136         {
0137             m_FocalLength = value;
0138         }
0139         void setFocalReducer(double value)
0140         {
0141             m_FocalReducer = value;
0142         }
0143         void setPositionAngle(double value);
0144         void setCameraSize(const QSize &value)
0145         {
0146             m_CameraSize = value;
0147         }
0148         void setPixelSize(const QSizeF &value)
0149         {
0150             m_PixelSize = value;
0151         }
0152         void setGridSize(const QSize &value)
0153         {
0154             m_GridSize = value;
0155         }
0156         void setOverlap(double value);
0157         void setCameraFOV(const QSizeF &value)
0158         {
0159             m_CameraFOV = value;
0160         }
0161         void setMosaicFOV(const QSizeF &value)
0162         {
0163             m_MosaicFOV = value;
0164         }
0165         void setPainterAlpha(int value)
0166         {
0167             m_PainterAlpha = value;
0168         }
0169         void setPainterAlphaAuto(bool value)
0170         {
0171             m_PainterAlphaAuto = value;
0172         }
0173         const QString &targetName() const {return m_TargetName;}
0174         void setTargetName(const QString &value)
0175         {
0176             m_TargetName = value;
0177         }
0178         const QString &group() const {return m_Group;}
0179         void setGroup(const QString &value)
0180         {
0181             m_Group = value;
0182         }
0183         const QString &completionCondition(QString *arg) const {
0184             *arg = m_CompletionConditionArg;
0185             return m_CompletionCondition;
0186         }
0187         void setCompletionCondition(const QString &value, const QString &arg = "")
0188         {
0189             m_CompletionCondition = value;
0190             m_CompletionConditionArg = arg;
0191         }
0192 
0193         const QString &sequenceFile() const {return m_SequenceFile;}
0194         void setSequenceFile(const QString &value)
0195         {
0196             m_SequenceFile = value;
0197         }
0198         const QString &outputDirectory() const {return m_OutputDirectory;}
0199         void setOutputDirectory(const QString &value)
0200         {
0201             m_OutputDirectory = value;
0202         }
0203         int focusEveryN() const {return m_FocusEveryN;}
0204         void setFocusEveryN(int value)
0205         {
0206             m_FocusEveryN = value;
0207         }
0208         int alignEveryN() const {return m_AlignEveryN;}
0209         void setAlignEveryN(int value)
0210         {
0211             m_AlignEveryN = value;
0212         }
0213         bool isTrackChecked() const {return m_TrackChecked;}
0214         bool isFocusChecked() const {return m_FocusChecked;}
0215         bool isAlignChecked() const {return m_AlignChecked;}
0216         bool isGuideChecked() const {return m_GuideChecked;}
0217         void setStepChecks(bool track, bool focus, bool align, bool guide)
0218         {
0219             m_TrackChecked = track;
0220             m_FocusChecked = focus;
0221             m_AlignChecked = align;
0222             m_GuideChecked = guide;
0223         }
0224 
0225         // Titles
0226         const QList<std::shared_ptr<OneTile>> &tiles() const
0227         {
0228             return m_Tiles;
0229         }
0230         std::shared_ptr<OneTile> oneTile(int row, int col);
0231 
0232     private:
0233 
0234         // Overall properties
0235         double m_FocalLength {0};
0236         double m_FocalReducer {1};
0237         QSize m_CameraSize;
0238         QSizeF m_PixelSize, m_CameraFOV, m_MosaicFOV;
0239         QSize m_GridSize {1, 1};
0240         double m_Overlap {10};
0241         double m_PositionAngle {0};
0242         bool m_SShaped {false};
0243         int m_PainterAlpha {50};
0244         bool m_PainterAlphaAuto {true};
0245         QString m_TargetName;
0246         QString m_Group;
0247         QString m_CompletionCondition;
0248         QString m_CompletionConditionArg;
0249         QString m_SequenceFile;
0250         QString m_OutputDirectory;
0251         int m_FocusEveryN {1};
0252         int m_AlignEveryN {1};
0253         bool m_TrackChecked {true}, m_FocusChecked {true}, m_AlignChecked {true}, m_GuideChecked {true};
0254 
0255         QBrush m_Brush;
0256         QPen m_Pen;
0257         QBrush m_TextBrush;
0258         QPen m_TextPen;
0259 
0260         QList<std::shared_ptr<OneTile>> m_Tiles;
0261 
0262         /**
0263            * @brief adjustCoordinate This uses the mosaic center as reference and the argument resolution of the sky map at that center.
0264            * @param tileCoord point to adjust
0265            * @return Returns scaled offsets for a pixel local coordinate.
0266            */
0267         QSizeF adjustCoordinate(QPointF tileCoord);
0268         void updateTiles();
0269 
0270         bool processJobInfo(XMLEle *root, int index);
0271 
0272         QPointF rotatePoint(QPointF pointToRotate, QPointF centerPoint, double paDegrees);
0273 
0274         QSizeF calculateTargetMosaicFOV() const;
0275         QSize mosaicFOVToGrid() const;
0276         QSizeF calculateCameraFOV() const;
0277 
0278 
0279     private:
0280 };
0281