Kstars

kstarsdata.h
1/*
2 SPDX-FileCopyrightText: 2001 Heiko Evermann <heiko@evermann.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "config-kstars.h"
10#include "colorscheme.h"
11#include "geolocation.h"
12#include "ksnumbers.h"
13#include "kstarsdatetime.h"
14#include "ksuserdb.h"
15#include "simclock.h"
16#include "skyobjectuserdata.h"
17#include <qobject.h>
18#ifndef KSTARS_LITE
19#include "oal/oal.h"
20#include "oal/log.h"
21#include "polyfills/qstring_hash.h"
22#endif
23
24#include <QList>
25#include <QMap>
26#include <QKeySequence>
27#include <QMutex>
28
29#include <iostream>
30#include <memory>
31#include <unordered_map>
32
33#define MINZOOM 250.
34#define MAXZOOM 5000000.
35#define DEFAULTZOOM 2000.
36#define DZOOM 1.189207115 // 2^(1/4)
37#define AU_KM 1.49605e8 //km in one AU
38
39class QFile;
40
41class Execute;
42class FOV;
43class ImageExporter;
44class SkyMap;
45class SkyMapComposite;
46class SkyObject;
47class ObservingList;
48class ImagingPlanner;
49class TimeZoneRule;
50
51#ifdef KSTARS_LITE
52//Will go away when details window will be implemented in KStars Lite
53struct ADVTreeData
54{
55 QString Name;
56 QString Link;
57 int Type;
58};
59#else
60struct ADVTreeData;
61#endif
62
63/**
64 * @class KStarsData
65 * KStarsData is the backbone of KStars. It contains all the data used by KStars,
66 * including the SkyMapComposite that contains all items in the skymap
67 * (stars, deep-sky objects, planets, constellations, etc). Other kinds of data
68 * are stored here as well: the geographic locations, the timezone rules, etc.
69 *
70 * @author Heiko Evermann
71 * @version 1.0
72 */
73class KStarsData : public QObject
74{
76
77 protected:
78 /** Constructor. */
79 KStarsData();
80
81 public:
82 // FIXME: It uses temporary trail. There must be way to
83 // this better. And resumeKey in DBUS code
84 friend class KStars;
85 // FIXME: it uses temporary trail and resumeKey
86 friend class SkyMap;
87 // FIXME: uses geoList and changes it.
88 friend class LocationDialog;
89 friend class LocationDialogLite;
90
91 static KStarsData *Create();
92
93 static inline KStarsData *Instance()
94 {
95 return pinstance;
96 }
97
98 /**
99 * Initialize KStarsData while running splash screen.
100 * @return true on success.
101 */
102 bool initialize();
103
104 /** Destructor. Delete data objects. */
105 ~KStarsData() override;
106
107 /**
108 * Set the NextDSTChange member.
109 * Need this accessor because I could not make KStars::privatedata a friend
110 * class for some reason...:/
111 */
113 {
114 NextDSTChange = dt;
115 }
116
117 /**
118 * Returns true if time is running forward else false. Used by KStars to prevent
119 * double calculations of daylight saving change time.
120 */
122 {
123 return TimeRunsForward;
124 }
125
126 /** @return pointer to the localization (KLocale) object */
127 //KLocale *getLocale() { return locale; }
128
129 /**
130 * @short Find object by name.
131 * @param name Object name to find
132 * @return pointer to SkyObject matching this name
133 */
134 SkyObject *objectNamed(const QString &name);
135
136 /**
137 * The Sky is updated more frequently than the moon, which is updated more frequently
138 * than the planets. The date of the last update for each category is recorded so we
139 * know when we need to do it again (see KStars::updateTime()).
140 * Initializing these to -1000000.0 ensures they will be updated immediately
141 * on the first call to KStars::updateTime().
142 */
143 void setFullTimeUpdate();
144
145 /**
146 * Change the current simulation date/time to the KStarsDateTime argument.
147 * Specified DateTime is always universal time.
148 * @param newDate the DateTime to set.
149 */
150 void changeDateTime(const KStarsDateTime &newDate);
151
152 /** @return pointer to the current simulation local time */
153 const KStarsDateTime &lt() const
154 {
155 return LTime;
156 }
157
158 /** @return reference to the current simulation universal time */
159 const KStarsDateTime &ut() const
160 {
161 return Clock.utc();
162 }
163
164 /** @return inline method to return simulation JD */
165 inline long double djd() const
166 {
167 return ut().djd();
168 }
169
170 /** Sync the LST with the simulation clock. */
171 void syncLST();
172
173 /** @return pointer to SkyComposite */
175 {
176 return m_SkyComposite.get();
177 }
178
179 /** @return pointer to the ColorScheme object */
181 {
182 return &CScheme;
183 }
184
185 /** @return file name of current color scheme **/
186 Q_INVOKABLE QString colorSchemeFileName() { return CScheme.fileName(); }
187
188 /** @return file name of the color scheme with the name \p name **/
190 {
191 return m_color_schemes.count(name) > 0 ? m_color_schemes.at(name) : "";
192 }
193
194 /** @return file name of the current color scheme **/
196 {
197 return colorSchemeName(CScheme.fileName());
198 }
199
200 /** @return the name of the color scheme with the name \p name **/
202 {
203 return m_color_scheme_names.count(fileName) > 0 ? m_color_scheme_names.at(fileName) : "";
204 }
205
206 /** @return if the color scheme with the name or filename \p scheme is loaded **/
207 bool hasColorScheme(const QString &scheme)
208 {
209 return m_color_scheme_names.count(scheme) || m_color_schemes.count(scheme);
210 }
211
212 /** Register a color scheme with \p filename and \p name. */
213 void add_color_scheme(const QString &filename, const QString &name)
214 {
215 m_color_schemes[name] = filename;
216 m_color_scheme_names[filename] = name;
217 };
218
219 /** \return a map of color scheme names and filenames */
220 const std::map<QString, QString> color_schemes() { return m_color_schemes; };
221
222 /** @return pointer to the KSUserDB object */
223 KSUserDB *userdb() { return &m_ksuserdb; }
224
225 /** @return pointer to the simulation Clock object */
227 {
228 return &Clock;
229 }
230
231 /** @return pointer to the local sidereal time: a dms object */
233 {
234 return &LST;
235 }
236
237 /** @return pointer to the GeoLocation object*/
239 {
240 return &m_Geo;
241 }
242
243 /** @return list of all geographic locations */
245 {
246 return geoList;
247 }
248
249 GeoLocation *locationNamed(const QString &city, const QString &province = QString(),
250 const QString &country = QString());
251
252 /**
253 * @brief nearestLocation Return nearest location to the given longitude and latitude coordinates
254 * @param longitude Longitude (-180 to +180)
255 * @param latitude Latitude (-90 to +90)
256 * @return nearest geographical location to the parameters above.
257 */
258 GeoLocation *nearestLocation(double longitude, double latitude);
259
260 /**
261 * Set the GeoLocation according to the argument.
262 * @param l reference to the new GeoLocation
263 */
264 void setLocation(const GeoLocation &l);
265
266 /** Set the GeoLocation according to the values stored in the configuration file. */
268
269 /** Return map for daylight saving rules. */
271 {
272 return Rulebook;
273 }
274
275 /** @return whether the next Focus change will omit the slewing animation. */
276 bool snapNextFocus() const
277 {
278 return snapToFocus;
279 }
280
281 /**
282 * Disable or re-enable the slewing animation for the next Focus change.
283 * @note If the user has turned off all animated slewing, setSnapNextFocus(false)
284 * will *NOT* enable animation on the next slew. A false argument would only
285 * be used if you have previously called setSnapNextFocus(true), but then decided
286 * you didn't want that after all. In other words, it's extremely unlikely you'd
287 * ever want to use setSnapNextFocus(false).
288 * @param b when true (the default), the next Focus change will omit the slewing
289 * animation.
290 */
291 void setSnapNextFocus(bool b = true)
292 {
293 snapToFocus = b;
294 }
295
296 /**
297 * Execute a script. This function actually duplicates the DCOP functionality
298 * for those cases when invoking DCOP is not practical (i.e., when preparing
299 * a sky image in command-line dump mode).
300 * @param name the filename of the script to "execute".
301 * @param map pointer to the SkyMap object.
302 * @return true if the script was successfully parsed.
303 */
304 bool executeScript(const QString &name, SkyMap *map);
305
306 /** Synchronize list of visible FOVs and list of selected FOVs in Options */
307#ifndef KSTARS_LITE
308 void syncFOV();
309#endif
310
311 /**
312 * @return the list of visible FOVs
313 */
314 inline const QList<FOV *> getVisibleFOVs() const
315 {
316 return visibleFOVs;
317 }
318
319 /**
320 * @return the list of available FOVs
321 */
322 inline const QList<FOV *> getAvailableFOVs() const
323 {
324 return availFOVs;
325 }
326
327 /**
328 * @brief addTransientFOV Adds a new FOV to the list.
329 * @param newFOV pointer to FOV object.
330 */
331 inline void addTransientFOV(std::shared_ptr<FOV> newFOV)
332 {
333 transientFOVs.append(newFOV);
334 }
335 inline void clearTransientFOVs()
336 {
337 transientFOVs.clear();
338 }
339
340 /**
341 * @return the list of transient FOVs
342 */
344 {
345 return transientFOVs;
346 }
347#ifndef KSTARS_LITE
348 /** Return log object */
349 OAL::Log *logObject()
350 {
351 return m_LogObject.get();
352 }
353
354 /** Return ADV Tree */
356 {
357 return ADVtreeList;
358 }
359
360 inline ObservingList *observingList() const
361 {
362 return m_ObservingList;
363 }
364
365#ifdef HAVE_INDI
366 inline ImagingPlanner *imagingPlanner() const
367 {
368 return m_ImagingPlanner.get();
369 }
370#endif
371
372 ImageExporter *imageExporter();
373
374 Execute *executeSession();
375#endif
376 /*@short Increments the updateID, forcing a recomputation of star positions as well */
377 unsigned int incUpdateID();
378
379 unsigned int updateID() const
380 {
381 return m_updateID;
382 }
383 unsigned int updateNumID() const
384 {
385 return m_updateNumID;
386 }
387 KSNumbers *updateNum()
388 {
389 return &m_updateNum;
390 }
391 void syncUpdateIDs();
392
393 signals:
394 /** Signal that specifies the text that should be drawn in the KStarsSplash window. */
395 void progressText(const QString &text);
396
397 /** Should be used to refresh skymap. */
398 void skyUpdate(bool);
399
400 /** If data changed, emit clearCache signal. */
402
403 /** Emitted when geo location changed */
405
406 public slots:
407 /** @short send a message to the console*/
409 {
410 std::cout << (const char *)(s.toLocal8Bit()) << std::endl;
411 }
412
413 /**
414 * Update the Simulation Clock. Update positions of Planets. Update
415 * Alt/Az coordinates of objects. Update precession.
416 * emit the skyUpdate() signal so that SkyMap / whatever draws the sky can update itself
417 *
418 * This is ugly.
419 * It _will_ change!
420 * (JH:)hey, it's much less ugly now...can we lose the comment yet? :p
421 */
422 void updateTime(GeoLocation *geo, const bool automaticDSTchange = true);
423
424 /**
425 * Sets the direction of time and stores it in bool TimeRunForwards. If scale >= 0
426 * time is running forward else time runs backward. We need this to calculate just
427 * one daylight saving change time (previous or next DST change).
428 */
429 void setTimeDirection(float scale);
430
431 // What follows is mostly a port of Arkashs auxdata stuff to a
432 // more centralized approach that does not store the data in
433 // the skyobjects as they are ephemeral in the new DSO implementation
434 //
435 // I've tried to reuse as much code as possible and maintain
436 // compatibility with peoples data.
437 //
438 // -- Valentin Boettcher
439
440 /**
441 * Get a reference to the user data of an object with the name \p name.
442 */
443 const SkyObjectUserdata::Data &getUserData(const QString &name);
444
445 /**
446 * Adds a link \p data to the user data for the object with \p
447 * name, both in memory and on disk.
448 *
449 * @returns {success, error_message}
450 */
451 std::pair<bool, QString> addToUserData(const QString &name,
452 const SkyObjectUserdata::LinkData &data);
453
454 /**
455 * Replace \p data in the user data at \p index for the object with \p
456 * name, both in memory and on disk.
457 *
458 * @returns {success, error_message}
459 */
460 std::pair<bool, QString> editUserData(const QString &name,
461 const unsigned int index,
462 const SkyObjectUserdata::LinkData &data);
463
464 /**
465 * Remove data of \p type from the user data at \p index for
466 * the object with \p name, both in memory and on disk.
467 *
468 * @returns {success, error_message}
469 */
470 std::pair<bool, QString> deleteUserData(const QString &name,
471 const unsigned int index,
472 SkyObjectUserdata::Type type);
473 /**
474 * Update the user log of the object with the \p name to
475 * contain \p newLog (find and replace).
476 *
477 * @returns {success, error_message}
478 */
479 std::pair<bool, QString> updateUserLog(const QString &name,
480 const QString &newLog);
481
482 private:
483 /**
484 * Populate list of geographic locations from "citydb.sqlite" database. Also check for custom
485 * locations file "mycitydb.sqlite" database, but don't require it. Each line in the file
486 * provides the information required to create one GeoLocation object.
487 * @short Fill list of geographic locations from file(s)
488 * @return true if at least one city read successfully.
489 * @see KStarsData::processCity()
490 */
491 bool readCityData();
492
493 /** Read the data file that contains daylight savings time rules. */
494 bool readTimeZoneRulebook();
495
496 //TODO JM: ADV tree should use XML instead
497 /**
498 * Read Advanced interface structure to be used later to construct the list view in
499 * the advanced tab in the Detail Dialog.
500 * @li KSLABEL designates a top-level parent label
501 * @li KSINTERFACE designates a common URL interface for several objects
502 * @li END designates the end of a sub tree structure
503 * @short read online database lookup structure.
504 * @return true if data is successfully read.
505 */
506 bool readADVTreeData();
507
508 /** Read INDI hosts from an XML file */
509 bool readINDIHosts();
510
511 //TODO JM: Use XML instead; The logger should have more features
512 // that allow users to enter details about their observation logs
513 // objects observed, eye pieces, telescope, conditions, mag..etc
514 /**
515 * @short read user logs.
516 *
517 * Read user logs. The log file is formatted as following:
518 * @li KSLABEL designates the beginning of a log
519 * @li KSLogEnd designates the end of a log.
520 *
521 * @return true if data is successfully read.
522 */
523 bool readUserLog();
524
525 /**
526 * Read in URLs to be attached to a named object's right-click popup menu. At this
527 * point, there is no way to attach URLs to unnamed objects. There are two
528 * kinds of URLs, each with its own data file: image links and webpage links. In addition,
529 * there may be user-specific versions with custom URLs. Each line contains 3 fields
530 * separated by colons (":"). Note that the last field is the URL, and as such it will
531 * generally contain a colon itself. Only the first two colons encountered are treated
532 * as field separators. The fields are:
533 *
534 * @li Object name. This must be the "primary" name of the object (the name at the top of the popup menu).
535 * @li Menu text. The string that should appear in the popup menu to activate the link.
536 * @li URL.
537 * @short Read in image and information URLs.
538 * @return true if data files were successfully read.
539 */
540 bool readURLData(const QString &url,
541 SkyObjectUserdata::Type type = SkyObjectUserdata::Type::website);
542
543 /**
544 * @short open a file containing URL links.
545 * @param urlfile string representation of the filename to open
546 * @param file reference to the QFile object which will be opened to this file.
547 * @return true if file successfully opened.
548 */
549 bool openUrlFile(const QString &urlfile, QFile &file);
550
551 /**
552 * Reset local time to new daylight saving time. Use this function if DST has changed.
553 * Used by updateTime().
554 */
555 void resetToNewDST(GeoLocation *geo, const bool automaticDSTchange);
556
557 /**
558 * As KStarsData::getUserData just non-const.
559 * @warning This method is not thread safe :) so take care of that when you use it.
560 */
561 SkyObjectUserdata::Data &findUserData(const QString &name);
562
563 QList<ADVTreeData *> ADVtreeList;
564 std::unique_ptr<SkyMapComposite> m_SkyComposite;
565
566 GeoLocation m_Geo;
567 SimClock Clock;
568 KStarsDateTime LTime;
569 KSUserDB m_ksuserdb;
570 ColorScheme CScheme;
571 std::map<QString, QString> m_color_schemes; // name: filename
572 std::map<QString, QString> m_color_scheme_names; // filename: name
573
574#ifndef KSTARS_LITE
575#ifdef HAVE_INDI
576 std::unique_ptr<ImagingPlanner> m_ImagingPlanner;
577#endif
578 ObservingList* m_ObservingList { nullptr };
579 std::unique_ptr<OAL::Log> m_LogObject;
580 std::unique_ptr<Execute> m_Execute;
581 std::unique_ptr<ImageExporter> m_ImageExporter;
582#endif
583
584 //EquipmentWriter *m_equipmentWriter;
585
586 bool TimeRunsForward { false };
587 bool temporaryTrail { false };
588 // FIXME: Used in SkyMap only. Check!
589 bool snapToFocus { false };
590
591 //KLocale *locale;
592
593 CachingDms LST;
594
595 QKeySequence resumeKey;
596
597 QList<FOV *> availFOVs; // List of all available FOVs
598 QList<FOV *> visibleFOVs; // List of visible FOVs. Cached from Options::FOVNames
599 QList<std::shared_ptr<FOV>> transientFOVs; // List of non-permenant transient FOVs.
600
601 KStarsDateTime LastNumUpdate, LastSkyUpdate, LastPlanetUpdate, LastMoonUpdate;
602 KStarsDateTime NextDSTChange;
603 // FIXME: Used in kstarsdcop.cpp only
604 KStarsDateTime StoredDate;
605
606 QList<GeoLocation *> geoList;
607 QMap<QString, TimeZoneRule> Rulebook;
608
609 quint32 m_preUpdateID, m_updateID;
610 quint32 m_preUpdateNumID, m_updateNumID;
611 KSNumbers m_preUpdateNum, m_updateNum;
612
613 static KStarsData *pinstance;
614
615 std::unordered_map<QString, SkyObjectUserdata::Data> m_user_data;
616 QMutex m_user_data_mutex; // for m_user_data
617};
a dms subclass that caches its sine and cosine values every time the angle is changed.
Definition cachingdms.h:19
This class stores all of the adjustable colors in KStars, in a QMap object keyed by the names of the ...
Definition colorscheme.h:27
Executes an observation session.
Definition execute.h:25
A simple class encapsulating a Field-of-View symbol.
Definition fov.h:28
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
Backends for exporting a sky image, either raster or vector, with a legend.
Single class to delegate all User database I/O.
Definition ksuserdb.h:42
const KStarsDateTime & lt() const
Definition kstarsdata.h:153
CachingDms * lst()
Definition kstarsdata.h:232
void setNextDSTChange(const KStarsDateTime &dt)
Set the NextDSTChange member.
Definition kstarsdata.h:112
long double djd() const
Definition kstarsdata.h:165
bool snapNextFocus() const
Definition kstarsdata.h:276
void setLocation(const GeoLocation &l)
Set the GeoLocation according to the argument.
KSUserDB * userdb()
Definition kstarsdata.h:223
void clearCache()
If data changed, emit clearCache signal.
std::pair< bool, QString > deleteUserData(const QString &name, const unsigned int index, SkyObjectUserdata::Type type)
Remove data of type from the user data at index for the object with name, both in memory and on disk.
QList< GeoLocation * > & getGeoList()
Definition kstarsdata.h:244
void changeDateTime(const KStarsDateTime &newDate)
Change the current simulation date/time to the KStarsDateTime argument.
~KStarsData() override
Destructor.
std::pair< bool, QString > editUserData(const QString &name, const unsigned int index, const SkyObjectUserdata::LinkData &data)
Replace data in the user data at index for the object with name, both in memory and on disk.
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets.
void updateTime(GeoLocation *geo, const bool automaticDSTchange=true)
Update the Simulation Clock.
bool initialize()
Initialize KStarsData while running splash screen.
const QList< std::shared_ptr< FOV > > getTransientFOVs() const
Definition kstarsdata.h:343
void addTransientFOV(std::shared_ptr< FOV > newFOV)
addTransientFOV Adds a new FOV to the list.
Definition kstarsdata.h:331
SkyObject * objectNamed(const QString &name)
Find object by name.
QString colorSchemeFileName(const QString &name)
Definition kstarsdata.h:189
GeoLocation * nearestLocation(double longitude, double latitude)
nearestLocation Return nearest location to the given longitude and latitude coordinates
void setTimeDirection(float scale)
Sets the direction of time and stores it in bool TimeRunForwards.
std::pair< bool, QString > updateUserLog(const QString &name, const QString &newLog)
Update the user log of the object with the name to contain newLog (find and replace).
ColorScheme * colorScheme()
Definition kstarsdata.h:180
const QList< FOV * > getAvailableFOVs() const
Definition kstarsdata.h:322
const SkyObjectUserdata::Data & getUserData(const QString &name)
Get a reference to the user data of an object with the name name.
void skyUpdate(bool)
Should be used to refresh skymap.
void slotConsoleMessage(QString s)
send a message to the console
Definition kstarsdata.h:408
void syncLST()
Sync the LST with the simulation clock.
const KStarsDateTime & ut() const
Definition kstarsdata.h:159
void syncFOV()
Synchronize list of visible FOVs and list of selected FOVs in Options.
OAL::Log * logObject()
Return log object.
Definition kstarsdata.h:349
bool executeScript(const QString &name, SkyMap *map)
Execute a script.
const std::map< QString, QString > color_schemes()
Definition kstarsdata.h:220
void progressText(const QString &text)
Signal that specifies the text that should be drawn in the KStarsSplash window.
QString colorSchemeName(const QString &fileName)
Definition kstarsdata.h:201
bool isTimeRunningForward() const
Returns true if time is running forward else false.
Definition kstarsdata.h:121
Q_INVOKABLE SimClock * clock()
Definition kstarsdata.h:226
GeoLocation * geo()
Definition kstarsdata.h:238
KStarsData()
Constructor.
void geoChanged()
Emitted when geo location changed.
const QMap< QString, TimeZoneRule > & getRulebook() const
Return map for daylight saving rules.
Definition kstarsdata.h:270
void add_color_scheme(const QString &filename, const QString &name)
Register a color scheme with filename and name.
Definition kstarsdata.h:213
bool hasColorScheme(const QString &scheme)
Definition kstarsdata.h:207
void setLocationFromOptions()
Set the GeoLocation according to the values stored in the configuration file.
SkyMapComposite * skyComposite()
Definition kstarsdata.h:174
void setSnapNextFocus(bool b=true)
Disable or re-enable the slewing animation for the next Focus change.
Definition kstarsdata.h:291
std::pair< bool, QString > addToUserData(const QString &name, const SkyObjectUserdata::LinkData &data)
Adds a link data to the user data for the object with name, both in memory and on disk.
const QList< FOV * > getVisibleFOVs() const
Definition kstarsdata.h:314
QList< ADVTreeData * > avdTree()
Return ADV Tree.
Definition kstarsdata.h:355
Q_INVOKABLE QString colorSchemeFileName()
Definition kstarsdata.h:186
Q_INVOKABLE QString colorSchemeName()
Definition kstarsdata.h:195
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
long double djd() const
Tool window for managing a custom list of objects.
kstars simulation clock
Definition simclock.h:23
SkyMapComposite is the root object in the object hierarchy of the sky map.
This is the canvas on which the sky is painted.
Definition skymap.h:54
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:50
This class provides the information needed to determine whether Daylight Savings Time (DST; a....
void clear()
QObject(QObject *parent)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
qsizetype count() const const
QByteArray toLocal8Bit() const const
Stores Users' Logs, Pictures and Websites regarding an object in the sky.
Stores the tite and URL of a webpage.
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.