1 /*
2     SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "culturelist.h"
10 #include "ksnumbers.h"
11 #include "skycomposite.h"
12 #include "skylabeler.h"
13 #include "skymesh.h"
14 #include "skyobject.h"
15 
16 #include <QList>
17 
18 #include <memory>
19 
20 class QPolygonF;
21 
22 class ArtificialHorizonComponent;
23 class ConstellationArtComponent;
24 class ConstellationBoundaryLines;
25 class ConstellationLines;
26 class ConstellationNamesComponent;
27 class ConstellationsArt;
28 class CatalogsComponent;
29 class DeepStarComponent;
30 class Ecliptic;
31 class Equator;
32 class EquatorialCoordinateGrid;
33 class FlagComponent;
34 class HorizontalCoordinateGrid;
35 class LocalMeridianComponent;
36 class HorizonComponent;
37 class KSPlanet;
38 class KSPlanetBase;
39 class MilkyWay;
40 class SatellitesComponent;
41 class SkyMap;
42 class SkyObject;
43 class SolarSystemComposite;
44 class StarComponent;
45 class SupernovaeComponent;
46 class TargetListComponent;
47 class HIPSComponent;
48 class TerrainComponent;
49 
50 /**
51  * @class SkyMapComposite
52  *
53  * SkyMapComposite is the root object in the object hierarchy of the sky map.
54  * All requests to update, init, draw etc. will be done with this class.
55  * The requests will be delegated to it's children.
56  * The object hierarchy will created by adding new objects via addComponent().
57  *
58  * @author Thomas Kabelmann
59  * @version 0.1
60  */
61 class SkyMapComposite : public QObject, public SkyComposite
62 {
63     Q_OBJECT
64 
65   public:
66     /**
67          * Constructor
68          * @p parent pointer to the parent SkyComponent
69          */
70     explicit SkyMapComposite(SkyComposite *parent = nullptr);
71 
72     virtual ~SkyMapComposite() override = default;
73 
74     void update(KSNumbers *num = nullptr) override;
75 
76     /**
77          * @short Delegate planet position updates to the SolarSystemComposite
78          *
79          * Planet positions change over time, so they need to be recomputed
80          * periodically, but not on every call to update().  This function
81          * will recompute the positions of all solar system bodies except the
82          * Earth's Moon, Jupiter's Moons AND Saturn Moons (because these objects' positions
83          * change on a much more rapid timescale).
84          * @p num Pointer to the KSNumbers object
85          * @sa update()
86          * @sa updateMoons()
87          * @sa SolarSystemComposite::updatePlanets()
88          */
89     void updateSolarSystemBodies(KSNumbers *num) override;
90 
91     /**
92          * @short Delegate moon position updates to the SolarSystemComposite
93          *
94          * Planet positions change over time, so they need to be recomputed
95          * periodically, but not on every call to update().  This function
96          * will recompute the positions of the Earth's Moon and Jupiter's four
97          * Galilean moons.  These objects are done separately from the other
98          * solar system bodies, because their positions change more rapidly,
99          * and so updateMoons() must be called more often than updatePlanets().
100          * @p num Pointer to the KSNumbers object
101          * @sa update()
102          * @sa updatePlanets()
103          * @sa SolarSystemComposite::updateMoons()
104          */
105     void updateMoons(KSNumbers *num) override;
106 
107     /**
108          * @short Delegate draw requests to all sub components
109          * @p psky Reference to the QPainter on which to paint
110          */
111     void draw(SkyPainter *skyp) override;
112 
113     /**
114          * @return the object nearest a given point in the sky.
115          * @param p The point to find an object near
116          * @param maxrad The maximum search radius, in Degrees
117          * @note the angular separation to the matched object is returned
118          * through the maxrad variable.
119          */
120     SkyObject *objectNearest(SkyPoint *p, double &maxrad) override;
121 
122     /**
123          * @return the star nearest a given point in the sky.
124          * @param p The point to find a star near
125          * @param maxrad The maximum search radius, in Degrees
126          * @note the angular separation to the matched star is returned
127          * through the maxrad variable.
128          */
129     SkyObject *starNearest(SkyPoint *p, double &maxrad);
130 
131     /**
132          * @short Search the children of this SkyMapComposite for
133          * a SkyObject whose name matches the argument.
134          *
135          * The objects' primary, secondary and long-form names will
136          * all be checked for a match.
137          * @note Overloaded from SkyComposite.  In this version, we search
138          * the most likely object classes first to be more efficient.
139          * @p name the name to be matched
140          * @return a pointer to the SkyObject whose name matches
141          * the argument, or a nullptr pointer if no match was found.
142          */
143     SkyObject *findByName(const QString &name) override;
144 
145     /**
146          * @return the list of objects in the region defined by skypoints
147          * @param p1 first sky point (top-left vertex of rectangular region)
148          * @param p2 second sky point (bottom-right vertex of rectangular region)
149          */
150     QList<SkyObject *> findObjectsInArea(const SkyPoint &p1, const SkyPoint &p2);
151 
152     bool addNameLabel(SkyObject *o);
153     bool removeNameLabel(SkyObject *o);
154 
155     void reloadDeepSky();
156     void reloadAsteroids();
157     void reloadComets();
158     void reloadCLines();
159     void reloadCNames();
160     void reloadConstellationArt();
161 #ifndef KSTARS_LITE
162     FlagComponent *flags();
163 #endif
164     SatellitesComponent *satellites();
165     SupernovaeComponent *supernovaeComponent();
166     ArtificialHorizonComponent *artificialHorizon();
167 
168     /** Getters for SkyComponents **/
horizon()169     inline HorizonComponent *horizon() { return m_Horizon; }
170 
constellationBoundary()171     inline ConstellationBoundaryLines *constellationBoundary() { return m_CBoundLines; }
constellationLines()172     inline ConstellationLines *constellationLines() { return m_CLines; }
173 
ecliptic()174     inline Ecliptic *ecliptic() { return m_Ecliptic; }
equator()175     inline Equator *equator() { return m_Equator; }
176 
equatorialCoordGrid()177     inline EquatorialCoordinateGrid *equatorialCoordGrid()
178     {
179         return m_EquatorialCoordinateGrid;
180     }
horizontalCoordGrid()181     inline HorizontalCoordinateGrid *horizontalCoordGrid()
182     {
183         return m_HorizontalCoordinateGrid;
184     }
localMeridianComponent()185     inline LocalMeridianComponent *localMeridianComponent()
186     {
187         return m_LocalMeridianComponent;
188     }
189 
constellationArt()190     inline ConstellationArtComponent *constellationArt() { return m_ConstellationArt; }
191 
solarSystemComposite()192     inline SolarSystemComposite *solarSystemComposite() { return m_SolarSystem; }
193 
constellationNamesComponent()194     inline ConstellationNamesComponent *constellationNamesComponent() { return m_CNames; }
195 
catalogsComponent()196     inline CatalogsComponent *catalogsComponent() { return m_Catalogs; }
197 
milkyWay()198     inline MilkyWay *milkyWay() { return m_MilkyWay; }
199 
200     //Accessors for StarComponent
201     SkyObject *findStarByGenetiveName(const QString name);
202     void emitProgressText(const QString &message) override;
labelObjects()203     QList<SkyObject *> &labelObjects() { return m_LabeledObjects; }
204 
205     const QList<SkyObject *> &constellationNames() const;
206     const QList<SkyObject *> &stars() const;
207     const QList<SkyObject *> &asteroids() const;
208     const QList<SkyObject *> &comets() const;
209     const QList<SkyObject *> &supernovae() const;
210     QList<SkyObject *> planets();
211     //    QList<SkyObject*> moons();
212 
213     const QList<SkyObject *> *getSkyObjectsList(SkyObject::TYPE t);
214 
215     KSPlanet *earth();
216     KSPlanetBase *planet(int n);
217     QStringList getCultureNames();
218     QString getCultureName(int index);
219     QString currentCulture();
220     void setCurrentCulture(QString culture);
221     bool isLocalCNames();
222 
getStarHopRouteList()223     inline TargetListComponent *getStarHopRouteList() { return m_StarHopRouteList; }
224   signals:
225     void progressText(const QString &message);
226 
227   private:
228     QHash<int, QStringList> &getObjectNames() override;
229     QHash<int, QVector<QPair<QString, const SkyObject *>>> &getObjectLists() override;
230 
231     std::unique_ptr<CultureList> m_Cultures;
232     ConstellationBoundaryLines *m_CBoundLines{ nullptr };
233     ConstellationNamesComponent *m_CNames{ nullptr };
234     ConstellationLines *m_CLines{ nullptr };
235     ConstellationArtComponent *m_ConstellationArt{ nullptr };
236     EquatorialCoordinateGrid *m_EquatorialCoordinateGrid{ nullptr };
237     HorizontalCoordinateGrid *m_HorizontalCoordinateGrid{ nullptr };
238     LocalMeridianComponent *m_LocalMeridianComponent{ nullptr };
239     CatalogsComponent *m_Catalogs{ nullptr };
240     Equator *m_Equator{ nullptr };
241     ArtificialHorizonComponent *m_ArtificialHorizon{ nullptr };
242     Ecliptic *m_Ecliptic{ nullptr };
243     HorizonComponent *m_Horizon{ nullptr };
244     MilkyWay *m_MilkyWay{ nullptr };
245     SolarSystemComposite *m_SolarSystem{ nullptr };
246     StarComponent *m_Stars{ nullptr };
247 #ifndef KSTARS_LITE
248     FlagComponent *m_Flags{ nullptr };
249     HIPSComponent *m_HiPS{ nullptr };
250     TerrainComponent *m_Terrain{ nullptr };
251 #endif
252     TargetListComponent *m_ObservingList{ nullptr };
253     TargetListComponent *m_StarHopRouteList{ nullptr };
254     SatellitesComponent *m_Satellites{ nullptr };
255     SupernovaeComponent *m_Supernovae{ nullptr };
256 
257     SkyMesh *m_skyMesh;
258     std::unique_ptr<SkyLabeler> m_skyLabeler;
259 
260     KSNumbers m_reindexNum;
261 
262     QList<DeepStarComponent *> m_DeepStars;
263 
264     QList<SkyObject *> m_LabeledObjects;
265     QHash<int, QStringList> m_ObjectNames;
266     QHash<int, QVector<QPair<QString, const SkyObject *>>> m_ObjectLists;
267     QHash<QString, QString> m_ConstellationNames;
268 };
269