Kstars

skyobject.h
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "dms.h"
10#include "skypoint.h"
11
12#include <QSharedDataPointer>
13#include <QString>
14#include <QStringList>
15
16#include <ki18n_version.h>
17#if KI18N_VERSION >= QT_VERSION_CHECK(5, 89, 0)
18#include <KLazyLocalizedString>
19#define kde_translate kli18n
20#else
21#include <KLocalizedString>
22#define kde_translate ki18n
23#endif
24
25class QPoint;
26class GeoLocation;
27class KSPopupMenu;
28
29namespace
30{
31const auto emptyString = QStringLiteral();
32const auto unnamedString = kde_translate("unnamed");
33const auto unnamedObjectString = kde_translate("unnamed object");
34const auto starString = kde_translate("star");
35}
36
37// Set the faintest sane magnitude to 36.0 (faintest visual magnitude visible with E-ELT, acc. to Wikipedia on Apparent Magnitude.)
38constexpr const float FAINTEST_MAGNITUDE = 36.0;
39
40/**
41 * @class SkyObject
42 * Provides all necessary information about an object in the sky:
43 * its coordinates, name(s), type, magnitude, and QStringLists of
44 * URLs for images and webpages regarding the object.
45 * @short Information about an object in the sky.
46 * @author Jason Harris
47 * @version 1.0
48 */
49class SkyObject : public SkyPoint
50{
51 public:
52 /**
53 * @short Type for Unique object IDenticator.
54 *
55 * Each object has unique ID (UID). For different objects UIDs must be different.
56 */
57 typedef qint64 UID;
58
59 /** @short Kind of UID */
60 static const UID UID_STAR;
61 static const UID UID_GALAXY;
62 static const UID UID_DEEPSKY;
63 static const UID UID_SOLARSYS;
64
65 /** Invalid UID. Real sky object could not have such UID */
66 static const UID invalidUID;
67
68 /**
69 * Constructor. Set SkyObject data according to arguments.
70 * @param t Type of object
71 * @param r catalog Right Ascension
72 * @param d catalog Declination
73 * @param m magnitude (brightness)
74 * @param n Primary name
75 * @param n2 Secondary name
76 * @param lname Long name (common name)
77 */
78 explicit SkyObject(int t = TYPE_UNKNOWN, dms r = dms(0.0), dms d = dms(0.0), float m = 0.0,
79 const QString &n = QString(), const QString &n2 = QString(), const QString &lname = QString());
80 /**
81 * Constructor. Set SkyObject data according to arguments. Differs from
82 * above function only in data type of RA and Dec.
83 * @param t Type of object
84 * @param r catalog Right Ascension
85 * @param d catalog Declination
86 * @param m magnitude (brightness)
87 * @param n Primary name
88 * @param n2 Secondary name
89 * @param lname Long name (common name)
90 */
91 SkyObject(int t, double r, double d, float m = 0.0, const QString &n = QString(), const QString &n2 = QString(),
92 const QString &lname = QString());
93
94 /** Destructor (empty) */
95 virtual ~SkyObject() override = default;
96
97 /**
98 * @short Create copy of object.
99 * This method is virtual copy constructor. It allows for safe
100 * copying of objects. In other words, KSPlanet object stored in
101 * SkyObject pointer will be copied as KSPlanet.
102 *
103 * Each subclass of SkyObject MUST implement clone method. There
104 * is no checking to ensure this, though.
105 *
106 * @return pointer to newly allocated object. Caller takes full responsibility
107 * for deallocating it.
108 */
109 virtual SkyObject *clone() const;
110
111 /**
112 * @enum TYPE
113 * The type classification of the SkyObject.
114 * @note Keep TYPE_UNKNOWN at 255. To find out how many known
115 * types exist, keep the NUMBER_OF_KNOWN_TYPES at the highest
116 * non-Unknown value. This is a fake type that can be used in
117 * comparisons and for loops.
118 */
119 enum TYPE
120 {
121 STAR = 0,
122 CATALOG_STAR = 1,
123 PLANET = 2,
124 OPEN_CLUSTER = 3,
125 GLOBULAR_CLUSTER = 4,
126 GASEOUS_NEBULA = 5,
127 PLANETARY_NEBULA = 6,
128 SUPERNOVA_REMNANT = 7,
129 GALAXY = 8,
130 COMET = 9,
131 ASTEROID = 10,
132 CONSTELLATION = 11,
133 MOON = 12,
134 ASTERISM = 13,
135 GALAXY_CLUSTER = 14,
136 DARK_NEBULA = 15,
137 QUASAR = 16,
138 MULT_STAR = 17,
139 RADIO_SOURCE = 18,
140 SATELLITE = 19,
141 SUPERNOVA = 20,
142 NUMBER_OF_KNOWN_TYPES = 21,
143 TYPE_UNKNOWN = 255
144 };
145 /**
146 * @return A translated string indicating the type name for a given type number
147 * @param t The type number
148 * @note Note the existence of a SkyObject::typeName( void ) method that is not static and returns the type of this object.
149 */
150 static QString typeName(const int t);
151 static QString typeShortName(const int t);
152
153 /** @return object's primary name. */
154 inline virtual QString name(void) const
155 {
156 return hasName() ? Name : unnamedString.toString();
157 }
158
159 /** @return object's primary name, translated to local language. */
160 inline QString translatedName() const
161 {
162 return i18n(
163 name()
164 .toUtf8()); // FIXME: Hmm... that's funny. How does the string extraction work, if we are UTF8-ing the name first? Does the string extraction change to UTF8?
165 }
166
167 /** @return object's secondary name */
168 inline QString name2(void) const
169 {
170 return (hasName2() ? Name2 : emptyString);
171 }
172
173 /** @return object's secondary name, translated to local language. */
175 {
176 return (hasName2() ? i18n(Name2.toUtf8()) : emptyString);
177 }
178
179 /**
180 * @return object's common (long) name
181 */
182 virtual QString longname(void) const
183 {
184 return hasLongName() ? LongName : unnamedObjectString.toString();
185 }
186
187 /**
188 * @return object's common (long) name, translated to local language.
189 */
191 {
192 return i18n(longname().toUtf8());
193 }
194
195 /**
196 * Set the object's long name.
197 * @param longname the object's long name.
198 */
199 void setLongName(const QString &longname = QString());
200
201 /**
202 * @return the string used to label the object on the map
203 * In the default implementation, this just returns translatedName()
204 * Overridden by StarObject.
205 */
206 virtual QString labelString() const;
207
208 /**
209 * @return object's type identifier (int)
210 * @see enum TYPE
211 */
212 inline int type(void) const
213 {
214 return (int)Type;
215 }
216
217 /**
218 * Set the object's type identifier to the argument.
219 * @param t the object's type identifier (e.g., "SkyObject::PLANETARY_NEBULA")
220 * @see enum TYPE
221 */
222 inline void setType(int t)
223 {
224 Type = (unsigned char)t;
225 }
226
227 /**
228 * @return the type name for this object
229 * @note This just calls the static method by the same name, with the appropriate type number. See SkyObject::typeName( const int )
230 */
231 QString typeName() const;
232
233 /**
234 * @return object's magnitude
235 */
236 inline float mag() const
237 {
238 return sortMagnitude;
239 }
240
241 /**
242 * @return the object's position angle. This is overridden in KSPlanetBase
243 * and DeepSkyObject; for all other SkyObjects, this returns 0.0.
244 */
245 inline virtual double pa() const
246 {
247 return 0.0;
248 }
249
250 /**
251 * @return true if the object is a solar system body.
252 */
253 inline bool isSolarSystem() const
254 {
255 return (type() == 2 || type() == 9 || type() == 10 || type() == 12);
256 }
257
258 /**
259 * Initialize the popup menut. This function should call correct
260 * initialization function in KSPopupMenu. By overloading the
261 * function, we don't have to check the object type when we need
262 * the menu.
263 */
264 virtual void initPopupMenu(KSPopupMenu *pmenu);
265
266 /** Show Type-specific popup menu. Overloading is done in the function initPopupMenu */
267 void showPopupMenu(KSPopupMenu *pmenu, const QPoint &pos);
268
269 /**
270 * Determine the time at which the point will rise or set. Because solar system
271 * objects move across the sky, it is necessary to iterate on the solution.
272 * We compute the rise/set time for the object's current position, then
273 * compute the object's position at that time. Finally, we recompute then
274 * rise/set time for the new coordinates. Further iteration is not necessary,
275 * even for the most swiftly-moving object (the Moon).
276 * @return the local time that the object will rise
277 * @param dt current UT date/time
278 * @param geo current geographic location
279 * @param rst If true, compute rise time. If false, compute set time.
280 * @param exact If true, use a second iteration for more accurate time
281 */
282 QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact = true) const;
283
284 /**
285 * @return the UT time when the object will rise or set
286 * @param dt target date/time
287 * @param geo pointer to Geographic location
288 * @param rst Boolean. If true will compute rise time. If false
289 * will compute set time.
290 * @param exact If true, use a second iteration for more accurate time
291 */
292 QTime riseSetTimeUT(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact = true) const;
293
294 /**
295 * @return the Azimuth time when the object will rise or set. This function
296 * recomputes set or rise UT times.
297 * @param dt target date/time
298 * @param geo GeoLocation object
299 * @param rst Boolen. If true will compute rise time. If false
300 * will compute set time.
301 */
302 dms riseSetTimeAz(const KStarsDateTime &dt, const GeoLocation *geo, bool rst) const;
303
304 /**
305 * The same iteration technique described in riseSetTime() is used here.
306 * @return the local time that the object will transit the meridian.
307 * @param dt target date/time
308 * @param geo pointer to the geographic location
309 */
310 QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo) const;
311
312 /**
313 * @return the universal time that the object will transit the meridian.
314 * @param dt target date/time
315 * @param geo pointer to the geographic location
316 */
317 QTime transitTimeUT(const KStarsDateTime &dt, const GeoLocation *geo) const;
318
319 /**
320 * @return the altitude of the object at the moment it transits the meridian.
321 * @param dt target date/time
322 * @param geo pointer to the geographic location
323 */
324 dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo) const;
325
326 /**
327 * The equatorial coordinates for the object on date dt are computed and returned,
328 * but the object's internal coordinates are not modified.
329 * @return the coordinates of the selected object for the time given by jd
330 * @param dt date/time for which the coords will be computed.
331 * @param geo pointer to geographic location (used for solar system only)
332 * @note Does not update the horizontal coordinates. Call EquatorialToHorizontal for that.
333 */
334 SkyPoint recomputeCoords(const KStarsDateTime &dt, const GeoLocation *geo = nullptr) const;
335
336 /**
337 * @short Like recomputeCoords, but also calls EquatorialToHorizontal before returning
338 */
340
341 inline bool hasName() const
342 {
343 return !Name.isEmpty();
344 }
345
346 inline bool hasName2() const
347 {
348 return !Name2.isEmpty();
349 }
350
351 inline bool hasLongName() const
352 {
353 return !LongName.isEmpty();
354 }
355
356 /**
357 * @short Given the Image title from a URL file, try to convert it to an image credit string.
358 */
359 QString messageFromTitle(const QString &imageTitle) const;
360
361 /**
362 * @return the pixel distance for offseting the object's name label
363 * @note overridden in StarObject, DeepSkyObject, KSPlanetBase
364 */
365 virtual double labelOffset() const;
366
367 /**
368 * @short Return UID for object.
369 * This method should be reimplemented in all concrete
370 * subclasses. Implementation for SkyObject just returns
371 * invalidUID. It's required SkyObject is not an abstract class.
372 */
373 virtual UID getUID() const;
374
375 // TODO: (Valentin) have another think about onFocus handlers :)
376
377 /**
378 * @brief hashBeenUpdated
379 * @return whether the coordinates of the object have been updated
380 *
381 * This is used for faster filtering.
382 */
384 {
385 return has_been_updated;
386 }
387
388 /**
389 * Set the object's primary name.
390 * @param name the object's primary name
391 */
392 inline void setName(const QString &name)
393 {
394 Name = name;
395 }
396
397 /**
398 * Set the object's secondary name.
399 * @param name2 the object's secondary name.
400 */
401 inline void setName2(const QString &name2 = QString())
402 {
403 Name2 = name2;
404 }
405
406 private:
407 /**
408 * Compute the UT time when the object will rise or set. It is an auxiliary
409 * procedure because it does not use the RA and DEC of the object but values
410 * given as parameters. You may want to use riseSetTimeUT() which is
411 * public. riseSetTimeUT() calls this function iteratively.
412 * @param dt target date/time
413 * @param geo pointer to Geographic location
414 * @param righta pointer to Right ascention of the object
415 * @param decl pointer to Declination of the object
416 * @param rst Boolean. If true will compute rise time. If false
417 * will compute set time.
418 * @return the time at which the given position will rise or set.
419 */
420 QTime auxRiseSetTimeUT(const KStarsDateTime &dt, const GeoLocation *geo, const dms *righta, const dms *decl,
421 bool riseT) const;
422
423 /**
424 * Compute the LST time when the object will rise or set. It is an auxiliary
425 * procedure because it does not use the RA and DEC of the object but values
426 * given as parameters. You may want to use riseSetTimeLST() which is
427 * public. riseSetTimeLST() calls this function iteratively.
428 * @param gLt Geographic latitude
429 * @param rga Right ascention of the object
430 * @param decl Declination of the object
431 * @param rst Boolean. If true will compute rise time. If false
432 * will compute set time.
433 */
434 dms auxRiseSetTimeLST(const dms *gLt, const dms *rga, const dms *decl, bool rst) const;
435
436 /**
437 * Compute the approximate hour angle that an object with declination d will have
438 * when its altitude is h (as seen from geographic latitude gLat).
439 * This function is only used by auxRiseSetTimeLST().
440 * @param h pointer to the altitude of the object
441 * @param gLat pointer to the geographic latitude
442 * @param d pointer to the declination of the object.
443 * @return the Hour Angle, in degrees.
444 */
445 double approxHourAngle(const dms *h, const dms *gLat, const dms *d) const;
446
447 /**
448 * Correct for the geometric altitude of the center of the body at the
449 * time of rising or setting. This is due to refraction at the horizon
450 * and to the size of the body. The moon correction has also to take into
451 * account parallax. The value we use here is a rough approximation
452 * suggested by J. Meeus.
453 *
454 * Weather status (temperature and pressure basically) is not taken
455 * into account although change of conditions between summer and
456 * winter could shift the times of sunrise and sunset by 20 seconds.
457 *
458 * This function is only used by auxRiseSetTimeLST().
459 * @return dms object with the correction.
460 */
461 dms elevationCorrection(void) const;
462
463 unsigned char Type;
464 float
465 sortMagnitude; // This magnitude is used for sorting / making decisions about the visibility of an object. Should not be NaN.
466
467 protected:
468 /**
469 * Set the object's sorting magnitude.
470 * @param m the object's magnitude.
471 */
472 inline void setMag(float m)
473 {
474 sortMagnitude =
475 m < FAINTEST_MAGNITUDE ?
476 m :
477 NaN::
478 f;
479 }
480 // FIXME: We claim sortMagnitude should not be NaN, but we are setting it to NaN above!! ^
481
482 QString Name, Name2, LongName;
483
484 // Whether the coordinates of the object have been updated.
485 // The default value is chose for compatibility reasons.
486 // It primarily matters for objects which are filtered.
487 // See `KSAsteroid` for an example.
488 bool has_been_updated = true;
489};
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
The KStars Popup Menu.
Definition kspopupmenu.h:35
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
void setName2(const QString &name2=QString())
Set the object's secondary name.
Definition skyobject.h:401
virtual void initPopupMenu(KSPopupMenu *pmenu)
Initialize the popup menut.
Definition skyobject.cpp:67
void setLongName(const QString &longname=QString())
Set the object's long name.
Definition skyobject.cpp:76
static const UID invalidUID
Invalid UID.
Definition skyobject.h:66
SkyPoint recomputeHorizontalCoords(const KStarsDateTime &dt, const GeoLocation *geo) const
Like recomputeCoords, but also calls EquatorialToHorizontal before returning.
void setMag(float m)
Set the object's sorting magnitude.
Definition skyobject.h:472
virtual SkyObject * clone() const
Create copy of object.
Definition skyobject.cpp:50
SkyObject(int t=TYPE_UNKNOWN, dms r=dms(0.0), dms d=dms(0.0), float m=0.0, const QString &n=QString(), const QString &n2=QString(), const QString &lname=QString())
Constructor.
Definition skyobject.cpp:30
bool hashBeenUpdated()
hashBeenUpdated
Definition skyobject.h:383
QString translatedName() const
Definition skyobject.h:160
void showPopupMenu(KSPopupMenu *pmenu, const QPoint &pos)
Show Type-specific popup menu.
Definition skyobject.cpp:56
dms riseSetTimeAz(const KStarsDateTime &dt, const GeoLocation *geo, bool rst) const
qint64 UID
Type for Unique object IDenticator.
Definition skyobject.h:57
virtual ~SkyObject() override=default
Destructor (empty)
static const UID UID_STAR
Kind of UID.
Definition skyobject.h:60
virtual double pa() const
Definition skyobject.h:245
virtual QString labelString() const
QTime transitTimeUT(const KStarsDateTime &dt, const GeoLocation *geo) const
virtual QString name(void) const
Definition skyobject.h:154
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo) const
QString translatedName2() const
Definition skyobject.h:174
QString translatedLongName() const
Definition skyobject.h:190
QString messageFromTitle(const QString &imageTitle) const
Given the Image title from a URL file, try to convert it to an image credit string.
bool isSolarSystem() const
Definition skyobject.h:253
void setName(const QString &name)
Set the object's primary name.
Definition skyobject.h:392
virtual QString longname(void) const
Definition skyobject.h:182
QString name2(void) const
Definition skyobject.h:168
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo) const
The same iteration technique described in riseSetTime() is used here.
virtual UID getUID() const
Return UID for object.
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true) const
Determine the time at which the point will rise or set.
Definition skyobject.cpp:93
int type(void) const
Definition skyobject.h:212
QString typeName() const
float mag() const
Definition skyobject.h:236
void setType(int t)
Set the object's type identifier to the argument.
Definition skyobject.h:222
QTime riseSetTimeUT(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true) const
virtual double labelOffset() const
SkyPoint recomputeCoords(const KStarsDateTime &dt, const GeoLocation *geo=nullptr) const
The equatorial coordinates for the object on date dt are computed and returned, but the object's inte...
TYPE
The type classification of the SkyObject.
Definition skyobject.h:120
The sky coordinates of a point in the sky.
Definition skypoint.h:45
SkyPoint(const dms &r, const dms &d)
Default constructor: Sets RA, Dec and RA0, Dec0 according to arguments.
Definition skypoint.h:54
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:53:02 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.