File indexing completed on 2024-04-21 03:43:34

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 "skypoint.h"
0010 #include <lilxml.h>
0011 #include <memory>
0012 
0013 namespace Ekos
0014 {
0015 
0016 /**
0017  * @brief The MosaicTilesModel class holds the data representation of the mosaic tiles. These represent metadata describing the
0018  * overall mosaic, and tile-per-tile specific metadata.
0019  */
0020 class MosaicTilesModel : public QObject
0021 {
0022         Q_OBJECT
0023         Q_PROPERTY(double focalLength MEMBER m_FocalLength READ focalLength WRITE setFocalLength NOTIFY focalLengthChanged)
0024         Q_PROPERTY(double focalReducer MEMBER m_FocalReducer READ focalReducer WRITE setFocalReducer NOTIFY focalReducerChanged)
0025         Q_PROPERTY(double positionAngle MEMBER m_PositionAngle READ positionAngle WRITE setPositionAngle NOTIFY positionAngleChanged)
0026         Q_PROPERTY(QSize cameraSize MEMBER m_CameraSize READ cameraSize WRITE setCameraSize NOTIFY cameraSizeChanged)
0027         Q_PROPERTY(QSizeF pixelSize MEMBER m_PixelSize READ pixelSize WRITE setPixelSize NOTIFY pixelSizeChanged)
0028         Q_PROPERTY(QSizeF pixelScale MEMBER m_PixelScale READ pixelScale WRITE setPixelScale NOTIFY pixelScaleChanged)
0029         Q_PROPERTY(QSize gridSize MEMBER m_GridSize READ gridSize WRITE setGridSize NOTIFY gridSizeChanged)
0030         Q_PROPERTY(double overlap MEMBER m_Overlap READ overlap WRITE setOverlap NOTIFY overlapChanged)
0031         Q_PROPERTY(SkyPoint skycenter MEMBER m_SkyCenter READ skyCenter WRITE setSkyCenter NOTIFY skycenterChanged)
0032 
0033     public:
0034         MosaicTilesModel(QObject *parent = nullptr);
0035         ~MosaicTilesModel() override;
0036 
0037         /***************************************************************************************************
0038          * Import/Export Functions.
0039          ***************************************************************************************************/
0040         /**
0041          * @brief toXML
0042          * @param output
0043          * @return
0044          */
0045         bool toXML(const QTextStream &output);
0046 
0047         /**
0048          * @brief fromXML
0049          * @param root
0050          * @return
0051          */
0052         bool fromXML(XMLEle *root);
0053 
0054         /**
0055          * @brief toJSON
0056          * @param output
0057          * @return
0058          */
0059         bool toJSON(QJsonObject &output);
0060 
0061         /**
0062          * @brief fromJSON
0063          * @param input
0064          * @return
0065          */
0066         bool fromJSON(const QJsonObject &input);
0067 
0068         /***************************************************************************************************
0069          * Tile Functions.
0070          ***************************************************************************************************/
0071         typedef struct
0072         {
0073             QPointF pos;
0074             QPointF center;
0075             SkyPoint skyCenter;
0076             double rotation;
0077             int index;
0078         } OneTile;
0079 
0080         void appendTile(const OneTile &value);
0081         void appendEmptyTile();
0082         void clearTiles();
0083 
0084         // Getters
0085 
0086         // Return Camera Field of View in arcminutes
0087         Q_INVOKABLE QSizeF cameraFOV() const
0088         {
0089             return m_cameraFOV;
0090         }
0091         // Return Mosaic Field of View in arcminutes
0092         Q_INVOKABLE QSizeF mosaicFOV() const
0093         {
0094             return m_MosaicFOV;
0095         }
0096 
0097         // Return Sky Point
0098         double focalLength() const {return m_FocalLength;}
0099         double focalReducer() const {return m_FocalReducer;}
0100         double positionAngle() const {return m_PositionAngle;}
0101         QSize cameraSize() const {return m_CameraSize;}
0102         QSizeF pixelSize() const {return m_PixelSize;}
0103         QSizeF pixelScale() const {return m_PixelScale;}
0104         QSize gridSize() const {return m_GridSize;}
0105         double overlap() const {return m_Overlap;}
0106         const SkyPoint &skyCenter() const {return m_SkyCenter;}
0107 
0108         // Setters
0109         void setFocalLength(double value) {m_FocalLength = value;}
0110         void setFocalReducer(double value) {m_FocalReducer = value;}
0111         void setPositionAngle(double value);
0112         void setCameraSize(const QSize &value) { m_CameraSize = value;}
0113         void setPixelSize(const QSizeF &value) { m_PixelSize = value;}
0114         void setPixelScale(const QSizeF &value) { m_PixelScale = value;}
0115         void setGridSize(const QSize &value) {m_GridSize = value;}
0116         void setSkyCenter(const SkyPoint &value) { m_SkyCenter = value;}
0117         void setOverlap(double value);
0118 
0119         // Titles
0120         const QList<std::shared_ptr<OneTile>> & tiles() const {return m_Tiles;}
0121         std::shared_ptr<MosaicTilesModel::OneTile> oneTile(int row, int col);
0122 
0123     protected:
0124 
0125     signals:
0126         void focalLengthChanged();
0127         void focalReducerChanged();
0128         void cameraSizeChanged();
0129         void pixelSizeChanged();
0130         void pixelScaleChanged();
0131         void gridSizeChanged();
0132         void overlapChanged();
0133         void positionAngleChanged();
0134         void skycenterChanged();
0135 
0136     private:
0137 
0138         // Overall properties
0139         double m_FocalLength {0};
0140         double m_FocalReducer {1};
0141         QSize m_CameraSize;
0142         QSizeF m_PixelSize, m_PixelScale, m_cameraFOV, m_MosaicFOV;
0143         QSize m_GridSize {1,1};
0144         double m_Overlap {10};
0145         double m_PositionAngle {0};
0146         SkyPoint m_SkyCenter;
0147 
0148         QList<std::shared_ptr<OneTile>> m_Tiles;
0149 };
0150 }