File indexing completed on 2024-04-28 03:50:26

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
0004 //
0005 
0006 //
0007 // This class is a stars plugin.
0008 //
0009 
0010 #ifndef MARBLESTARSPLUGIN_H
0011 #define MARBLESTARSPLUGIN_H
0012 
0013 #include <QVector>
0014 #include <QHash>
0015 #include <QMap>
0016 #include <QVariant>
0017 #include <QBrush>
0018 
0019 #include "RenderPlugin.h"
0020 #include "Quaternion.h"
0021 #include "DialogConfigurationInterface.h"
0022 
0023 class QMenu;
0024 
0025 class SolarSystem;
0026 
0027 namespace Ui
0028 {
0029     class StarsConfigWidget;
0030 }
0031 
0032 namespace Marble
0033 {
0034 
0035 class StarPoint
0036 {
0037 public:
0038     StarPoint() {}
0039     /**
0040      * @brief create a starpoint from right ascension and declination
0041      * @param  id identifier
0042      * @param  rect right ascension
0043      * @param  decl declination
0044      * @param  mag magnitude
0045      * (default for Radian: north pole at pi/2, southpole at -pi/2)
0046      * @param  colorId color
0047      */
0048     StarPoint(int id, qreal rect, qreal decl, qreal mag, int colorId) :
0049         m_id( id ),
0050         m_magnitude( mag ),
0051         m_colorId( colorId )
0052     {
0053         m_q = Quaternion::fromSpherical( rect, decl );
0054     }
0055 
0056     ~StarPoint() {}
0057 
0058     qreal magnitude() const
0059     {
0060         return m_magnitude;
0061     }
0062 
0063     const Quaternion &quaternion() const
0064     {
0065         return m_q;
0066     }
0067 
0068     int id() const
0069     {
0070         return m_id;
0071     }
0072     
0073     int colorId() const
0074     {
0075         return m_colorId;
0076     } 
0077 
0078 private:
0079     int         m_id;
0080     qreal       m_magnitude;
0081     Quaternion  m_q;
0082     int         m_colorId;
0083 };
0084 
0085 class DsoPoint
0086 {
0087 public:
0088     DsoPoint() {}
0089     /**
0090      * @brief create a dsopoint from right ascension and declination
0091      * @param  id point identifier
0092      * @param  rect right ascension
0093      * @param  decl declination
0094      * (default for Radian: north pole at pi/2, southpole at -pi/2)
0095      */
0096     DsoPoint(const QString& id, qreal rect, qreal decl) {
0097         m_id = id;
0098         m_q = Quaternion::fromSpherical( rect, decl );
0099     }
0100 
0101     QString id() const
0102     {
0103         return m_id;
0104     }  
0105 
0106     const Quaternion &quaternion() const
0107     {
0108         return m_q;
0109     }
0110 
0111 private:
0112     QString    m_id;
0113     Quaternion  m_q;
0114 };
0115 
0116 /**
0117  * @short The class that specifies the Marble layer interface of a plugin.
0118  *
0119  */
0120 
0121 class Constellation;
0122 
0123 class StarsPlugin : public RenderPlugin, public DialogConfigurationInterface
0124 {
0125     Q_OBJECT
0126     Q_PLUGIN_METADATA(IID "org.kde.marble.StarsPlugin")
0127     Q_INTERFACES(Marble::RenderPluginInterface)
0128     Q_INTERFACES( Marble::DialogConfigurationInterface )
0129     MARBLE_PLUGIN(StarsPlugin)
0130 public:
0131     explicit StarsPlugin( const MarbleModel *marbleModel=nullptr );
0132     ~StarsPlugin() override;
0133 
0134     QStringList backendTypes() const override;
0135 
0136     QString renderPolicy() const override;
0137 
0138     QStringList renderPosition() const override;
0139 
0140     RenderType renderType() const override;
0141 
0142     QString name() const override;
0143 
0144     QString guiString() const override;
0145 
0146     QString nameId() const override;
0147 
0148     QString version() const override;
0149 
0150     QString description() const override;
0151 
0152     QString copyrightYears() const override;
0153 
0154     QVector<PluginAuthor> pluginAuthors() const override;
0155 
0156     QIcon icon() const override;
0157 
0158     void initialize() override;
0159 
0160     bool isInitialized() const override;
0161 
0162     bool render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer = nullptr ) override;
0163 
0164     QDialog *configDialog() override;
0165 
0166     QHash<QString,QVariant> settings() const override;
0167 
0168     void setSettings( const QHash<QString,QVariant> &settings ) override;
0169 
0170     QString assembledConstellation(const QString &name);
0171 
0172 protected:
0173     bool eventFilter( QObject *object, QEvent *e ) override;
0174 
0175 private Q_SLOTS:
0176     void requestRepaint();
0177     void toggleSunMoon(bool on);
0178     void togglePlanets(bool on);
0179     void toggleDsos(bool on);
0180     void toggleConstellations(bool on);
0181     void executeConfigDialog();
0182 
0183 public Q_SLOTS:
0184     void readSettings();
0185     void writeSettings();
0186     void constellationGetColor();
0187     void constellationLabelGetColor();
0188     void dsoLabelGetColor();
0189     void eclipticGetColor();
0190     void celestialEquatorGetColor();
0191     void celestialPoleGetColor();
0192 
0193 private:
0194     template<class T>
0195     T readSetting( const QHash<QString, QVariant> &settings, const QString &key, const T &defaultValue )
0196     {
0197         if ( !settings.contains( key ) ) {
0198             return defaultValue;
0199         }
0200 
0201         return settings[key].value<T>();
0202     }
0203 
0204     QPixmap starPixmap(qreal mag, int colorId) const;
0205 
0206     void prepareNames();
0207     QHash<QString, QString> m_abbrHash;
0208     QHash<QString, QString> m_nativeHash;
0209     int m_nameIndex;
0210 
0211     void renderPlanet(const QString &planetId,
0212                       GeoPainter *painter,
0213                       SolarSystem &sys,
0214                       ViewportParams *viewport,
0215                       qreal skyRadius,
0216                       matrix &skyAxisMatrix) const;
0217     void createStarPixmaps();
0218     void loadStars();
0219     void loadConstellations();
0220     void loadDsos();
0221     QPointer<QDialog> m_configDialog;
0222     Ui::StarsConfigWidget *ui_configWidget;
0223     bool m_renderStars;
0224     bool m_renderConstellationLines;
0225     bool m_renderConstellationLabels;
0226     bool m_renderDsos;
0227     bool m_renderDsoLabels;
0228     bool m_renderSun;
0229     bool m_renderMoon;
0230     QMap<QString, bool> m_renderPlanet;
0231     bool m_renderEcliptic;
0232     bool m_renderCelestialEquator;
0233     bool m_renderCelestialPole;
0234     bool m_starsLoaded;
0235     bool m_starPixmapsCreated;
0236     bool m_constellationsLoaded;
0237     bool m_dsosLoaded;
0238     bool m_zoomSunMoon;
0239     bool m_viewSolarSystemLabel;
0240     QVector<StarPoint> m_stars;
0241     QPixmap m_pixmapSun;
0242     QPixmap m_pixmapMoon;
0243     QVector<Constellation> m_constellations;
0244     QVector<DsoPoint> m_dsos;
0245     QHash<int,int> m_idHash;
0246     QImage m_dsoImage;
0247     int m_magnitudeLimit;
0248     int m_zoomCoefficient;
0249     QBrush m_constellationBrush;
0250     QBrush m_constellationLabelBrush;
0251     QBrush m_dsoLabelBrush;
0252     QBrush m_eclipticBrush;
0253     QBrush m_celestialEquatorBrush;
0254     QBrush m_celestialPoleBrush;
0255     QVector<QPixmap> m_pixN1Stars;
0256     QVector<QPixmap> m_pixP0Stars;
0257     QVector<QPixmap> m_pixP1Stars;
0258     QVector<QPixmap> m_pixP2Stars;
0259     QVector<QPixmap> m_pixP3Stars;
0260     QVector<QPixmap> m_pixP4Stars;
0261     QVector<QPixmap> m_pixP5Stars;
0262     QVector<QPixmap> m_pixP6Stars;
0263     QVector<QPixmap> m_pixP7Stars;
0264 
0265     /* Context menu */
0266     QPointer<QMenu> m_contextMenu;
0267     QAction* m_constellationsAction;
0268     QAction* m_sunMoonAction;
0269     QAction* m_planetsAction;
0270     QAction* m_dsoAction;
0271 
0272     bool m_doRender;
0273 };
0274 
0275 class Constellation
0276 {
0277 public:
0278     Constellation() {}
0279     Constellation(StarsPlugin *plugin, const QString &name, const QString &stars) :
0280         m_plugin( plugin ),
0281         m_name( name )
0282     {
0283         const QStringList starlist = stars.split(QLatin1Char(' '));
0284         for (int i = 0; i < starlist.size(); ++i) {
0285             m_stars << starlist.at(i).toInt();
0286         }
0287 
0288     }
0289 
0290     int size() const
0291     {
0292         return m_stars.size();
0293     }
0294 
0295     int at(const int index) const
0296     {
0297         if (index < 0) {
0298             return -1;
0299         }
0300         if (index >= m_stars.size()) {
0301             return -1;
0302         }
0303         return m_stars.at(index);
0304     }
0305 
0306     QString name() const
0307     {
0308         return m_plugin->assembledConstellation(m_name);
0309     }
0310 
0311 private:
0312     StarsPlugin *m_plugin;
0313     QString m_name;
0314     QVector<int> m_stars;
0315 
0316 };
0317 
0318 }
0319 
0320 #endif // MARBLESTARSPLUGIN_H