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 */
112 void setNextDSTChange(const KStarsDateTime &dt)
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 /** Sync the LST with the simulation clock. */
165 void syncLST();
166
167 /** @return pointer to SkyComposite */
169 {
170 return m_SkyComposite.get();
171 }
172
173 /** @return pointer to the ColorScheme object */
175 {
176 return &CScheme;
177 }
178
179 /** @return file name of current color scheme **/
181
182 /** @return file name of the color scheme with the name \p name **/
184 {
185 return m_color_schemes.count(name) > 0 ? m_color_schemes.at(name) : "";
186 }
187
188 /** @return file name of the current color scheme **/
190 {
191 return colorSchemeName(CScheme.fileName());
192 }
193
194 /** @return the name of the color scheme with the name \p name **/
196 {
197 return m_color_scheme_names.count(fileName) > 0 ? m_color_scheme_names.at(fileName) : "";
198 }
199
200 /** @return if the color scheme with the name or filename \p scheme is loaded **/
201 bool hasColorScheme(const QString &scheme)
202 {
203 return m_color_scheme_names.count(scheme) || m_color_schemes.count(scheme);
204 }
205
206 /** Register a color scheme with \p filename and \p name. */
207 void add_color_scheme(const QString &filename, const QString &name)
208 {
209 m_color_schemes[name] = filename;
210 m_color_scheme_names[filename] = name;
211 };
212
213 /** \return a map of color scheme names and filenames */
214 const std::map<QString, QString> color_schemes() { return m_color_schemes; };
215
216 /** @return pointer to the KSUserDB object */
217 KSUserDB *userdb() { return &m_ksuserdb; }
218
219 /** @return pointer to the simulation Clock object */
221 {
222 return &Clock;
223 }
224
225 /** @return pointer to the local sidereal time: a dms object */
226 CachingDms *lst()
227 {
228 return &LST;
229 }
230
231 /** @return pointer to the GeoLocation object*/
233 {
234 return &m_Geo;
235 }
236
237 /** @return list of all geographic locations */
239 {
240 return geoList;
241 }
242
243 GeoLocation *locationNamed(const QString &city, const QString &province = QString(),
244 const QString &country = QString());
245
246 /**
247 * @brief nearestLocation Return nearest location to the given longitude and latitude coordinates
248 * @param longitude Longitude (-180 to +180)
249 * @param latitude Latitude (-90 to +90)
250 * @return nearest geographical location to the parameters above.
251 */
252 GeoLocation *nearestLocation(double longitude, double latitude);
253
254 /**
255 * Set the GeoLocation according to the argument.
256 * @param l reference to the new GeoLocation
257 */
258 void setLocation(const GeoLocation &l);
259
260 /** Set the GeoLocation according to the values stored in the configuration file. */
262
263 /** Return map for daylight saving rules. */
265 {
266 return Rulebook;
267 }
268
269 /** @return whether the next Focus change will omit the slewing animation. */
270 bool snapNextFocus() const
271 {
272 return snapToFocus;
273 }
274
275 /**
276 * Disable or re-enable the slewing animation for the next Focus change.
277 * @note If the user has turned off all animated slewing, setSnapNextFocus(false)
278 * will *NOT* enable animation on the next slew. A false argument would only
279 * be used if you have previously called setSnapNextFocus(true), but then decided
280 * you didn't want that after all. In other words, it's extremely unlikely you'd
281 * ever want to use setSnapNextFocus(false).
282 * @param b when true (the default), the next Focus change will omit the slewing
283 * animation.
284 */
285 void setSnapNextFocus(bool b = true)
286 {
287 snapToFocus = b;
288 }
289
290 /**
291 * Execute a script. This function actually duplicates the DCOP functionality
292 * for those cases when invoking DCOP is not practical (i.e., when preparing
293 * a sky image in command-line dump mode).
294 * @param name the filename of the script to "execute".
295 * @param map pointer to the SkyMap object.
296 * @return true if the script was successfully parsed.
297 */
298 bool executeScript(const QString &name, SkyMap *map);
299
300 /** Synchronize list of visible FOVs and list of selected FOVs in Options */
301#ifndef KSTARS_LITE
302 void syncFOV();
303#endif
304
305 /**
306 * @return the list of visible FOVs
307 */
308 inline const QList<FOV *> getVisibleFOVs() const
309 {
310 return visibleFOVs;
311 }
312
313 /**
314 * @return the list of available FOVs
315 */
316 inline const QList<FOV *> getAvailableFOVs() const
317 {
318 return availFOVs;
319 }
320
321 /**
322 * @brief addTransientFOV Adds a new FOV to the list.
323 * @param newFOV pointer to FOV object.
324 */
325 inline void addTransientFOV(std::shared_ptr<FOV> newFOV)
326 {
327 transientFOVs.append(newFOV);
328 }
329 inline void clearTransientFOVs()
330 {
331 transientFOVs.clear();
332 }
333
334 /**
335 * @return the list of transient FOVs
336 */
338 {
339 return transientFOVs;
340 }
341#ifndef KSTARS_LITE
342 /** Return log object */
343 OAL::Log *logObject()
344 {
345 return m_LogObject.get();
346 }
347
348 /** Return ADV Tree */
350 {
351 return ADVtreeList;
352 }
353
354 inline ObservingList *observingList() const
355 {
356 return m_ObservingList;
357 }
358
359#ifdef HAVE_INDI
360 inline ImagingPlanner *imagingPlanner() const
361 {
362 return m_ImagingPlanner.get();
363 }
364#endif
365
366 ImageExporter *imageExporter();
367
368 Execute *executeSession();
369#endif
370 /*@short Increments the updateID, forcing a recomputation of star positions as well */
371 unsigned int incUpdateID();
372
373 unsigned int updateID() const
374 {
375 return m_updateID;
376 }
377 unsigned int updateNumID() const
378 {
379 return m_updateNumID;
380 }
381 KSNumbers *updateNum()
382 {
383 return &m_updateNum;
384 }
385 void syncUpdateIDs();
386
387 signals:
388 /** Signal that specifies the text that should be drawn in the KStarsSplash window. */
389 void progressText(const QString &text);
390
391 /** Should be used to refresh skymap. */
392 void skyUpdate(bool);
393
394 /** If data changed, emit clearCache signal. */
396
397 /** Emitted when geo location changed */
399
400 public slots:
401 /** @short send a message to the console*/
403 {
404 std::cout << (const char *)(s.toLocal8Bit()) << std::endl;
405 }
406
407 /**
408 * Update the Simulation Clock. Update positions of Planets. Update
409 * Alt/Az coordinates of objects. Update precession.
410 * emit the skyUpdate() signal so that SkyMap / whatever draws the sky can update itself
411 *
412 * This is ugly.
413 * It _will_ change!
414 * (JH:)hey, it's much less ugly now...can we lose the comment yet? :p
415 */
416 void updateTime(GeoLocation *geo, const bool automaticDSTchange = true);
417
418 /**
419 * Sets the direction of time and stores it in bool TimeRunForwards. If scale >= 0
420 * time is running forward else time runs backward. We need this to calculate just
421 * one daylight saving change time (previous or next DST change).
422 */
423 void setTimeDirection(float scale);
424
425 // What follows is mostly a port of Arkashs auxdata stuff to a
426 // more centralized approach that does not store the data in
427 // the skyobjects as they are ephemeral in the new DSO implementation
428 //
429 // I've tried to reuse as much code as possible and maintain
430 // compatibility with peoples data.
431 //
432 // -- Valentin Boettcher
433
434 /**
435 * Get a reference to the user data of an object with the name \p name.
436 */
437 const SkyObjectUserdata::Data &getUserData(const QString &name);
438
439 /**
440 * Adds a link \p data to the user data for the object with \p
441 * name, both in memory and on disk.
442 *
443 * @returns {success, error_message}
444 */
445 std::pair<bool, QString> addToUserData(const QString &name,
446 const SkyObjectUserdata::LinkData &data);
447
448 /**
449 * Replace \p data in the user data at \p index for the object with \p
450 * name, both in memory and on disk.
451 *
452 * @returns {success, error_message}
453 */
454 std::pair<bool, QString> editUserData(const QString &name,
455 const unsigned int index,
456 const SkyObjectUserdata::LinkData &data);
457
458 /**
459 * Remove data of \p type from the user data at \p index for
460 * the object with \p name, both in memory and on disk.
461 *
462 * @returns {success, error_message}
463 */
464 std::pair<bool, QString> deleteUserData(const QString &name,
465 const unsigned int index,
466 SkyObjectUserdata::Type type);
467 /**
468 * Update the user log of the object with the \p name to
469 * contain \p newLog (find and replace).
470 *
471 * @returns {success, error_message}
472 */
473 std::pair<bool, QString> updateUserLog(const QString &name,
474 const QString &newLog);
475
476 private:
477 /**
478 * Populate list of geographic locations from "citydb.sqlite" database. Also check for custom
479 * locations file "mycitydb.sqlite" database, but don't require it. Each line in the file
480 * provides the information required to create one GeoLocation object.
481 * @short Fill list of geographic locations from file(s)
482 * @return true if at least one city read successfully.
483 * @see KStarsData::processCity()
484 */
485 bool readCityData();
486
487 /** Read the data file that contains daylight savings time rules. */
488 bool readTimeZoneRulebook();
489
490 //TODO JM: ADV tree should use XML instead
491 /**
492 * Read Advanced interface structure to be used later to construct the list view in
493 * the advanced tab in the Detail Dialog.
494 * @li KSLABEL designates a top-level parent label
495 * @li KSINTERFACE designates a common URL interface for several objects
496 * @li END designates the end of a sub tree structure
497 * @short read online database lookup structure.
498 * @return true if data is successfully read.
499 */
500 bool readADVTreeData();
501
502 /** Read INDI hosts from an XML file */
503 bool readINDIHosts();
504
505 //TODO JM: Use XML instead; The logger should have more features
506 // that allow users to enter details about their observation logs
507 // objects observed, eye pieces, telescope, conditions, mag..etc
508 /**
509 * @short read user logs.
510 *
511 * Read user logs. The log file is formatted as following:
512 * @li KSLABEL designates the beginning of a log
513 * @li KSLogEnd designates the end of a log.
514 *
515 * @return true if data is successfully read.
516 */
517 bool readUserLog();
518
519 /**
520 * Read in URLs to be attached to a named object's right-click popup menu. At this
521 * point, there is no way to attach URLs to unnamed objects. There are two
522 * kinds of URLs, each with its own data file: image links and webpage links. In addition,
523 * there may be user-specific versions with custom URLs. Each line contains 3 fields
524 * separated by colons (":"). Note that the last field is the URL, and as such it will
525 * generally contain a colon itself. Only the first two colons encountered are treated
526 * as field separators. The fields are:
527 *
528 * @li Object name. This must be the "primary" name of the object (the name at the top of the popup menu).
529 * @li Menu text. The string that should appear in the popup menu to activate the link.
530 * @li URL.
531 * @short Read in image and information URLs.
532 * @return true if data files were successfully read.
533 */
534 bool readURLData(const QString &url,
535 SkyObjectUserdata::Type type = SkyObjectUserdata::Type::website);
536
537 /**
538 * @short open a file containing URL links.
539 * @param urlfile string representation of the filename to open
540 * @param file reference to the QFile object which will be opened to this file.
541 * @return true if file successfully opened.
542 */
543 bool openUrlFile(const QString &urlfile, QFile &file);
544
545 /**
546 * Reset local time to new daylight saving time. Use this function if DST has changed.
547 * Used by updateTime().
548 */
549 void resetToNewDST(GeoLocation *geo, const bool automaticDSTchange);
550
551 /**
552 * As KStarsData::getUserData just non-const.
553 * @warning This method is not thread safe :) so take care of that when you use it.
554 */
555 SkyObjectUserdata::Data &findUserData(const QString &name);
556
557 QList<ADVTreeData *> ADVtreeList;
558 std::unique_ptr<SkyMapComposite> m_SkyComposite;
559
560 GeoLocation m_Geo;
561 SimClock Clock;
562 KStarsDateTime LTime;
563 KSUserDB m_ksuserdb;
564 ColorScheme CScheme;
565 std::map<QString, QString> m_color_schemes; // name: filename
566 std::map<QString, QString> m_color_scheme_names; // filename: name
567
568#ifndef KSTARS_LITE
569#ifdef HAVE_INDI
570 std::unique_ptr<ImagingPlanner> m_ImagingPlanner;
571#endif
572 ObservingList* m_ObservingList { nullptr };
573 std::unique_ptr<OAL::Log> m_LogObject;
574 std::unique_ptr<Execute> m_Execute;
575 std::unique_ptr<ImageExporter> m_ImageExporter;
576#endif
577
578 //EquipmentWriter *m_equipmentWriter;
579
580 bool TimeRunsForward { false };
581 bool temporaryTrail { false };
582 // FIXME: Used in SkyMap only. Check!
583 bool snapToFocus { false };
584
585 //KLocale *locale;
586
587 CachingDms LST;
588
589 QKeySequence resumeKey;
590
591 QList<FOV *> availFOVs; // List of all available FOVs
592 QList<FOV *> visibleFOVs; // List of visible FOVs. Cached from Options::FOVNames
593 QList<std::shared_ptr<FOV>> transientFOVs; // List of non-permenant transient FOVs.
594
595 KStarsDateTime LastNumUpdate, LastSkyUpdate, LastPlanetUpdate, LastMoonUpdate;
596 KStarsDateTime NextDSTChange;
597 // FIXME: Used in kstarsdcop.cpp only
598 KStarsDateTime StoredDate;
599
600 QList<GeoLocation *> geoList;
602
603 quint32 m_preUpdateID, m_updateID;
604 quint32 m_preUpdateNumID, m_updateNumID;
605 KSNumbers m_preUpdateNum, m_updateNum;
606
607 static KStarsData *pinstance;
608
609 std::unordered_map<QString, SkyObjectUserdata::Data> m_user_data;
610 QMutex m_user_data_mutex; // for m_user_data
611};
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
QString fileName() const
Definition colorscheme.h:91
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.
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
Single class to delegate all User database I/O.
Definition ksuserdb.h:42
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
const KStarsDateTime & lt() const
Definition kstarsdata.h:153
CachingDms * lst()
Definition kstarsdata.h:226
void setNextDSTChange(const KStarsDateTime &dt)
Set the NextDSTChange member.
Definition kstarsdata.h:112
bool snapNextFocus() const
Definition kstarsdata.h:270
void setLocation(const GeoLocation &l)
Set the GeoLocation according to the argument.
KSUserDB * userdb()
Definition kstarsdata.h:217
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:238
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:337
void addTransientFOV(std::shared_ptr< FOV > newFOV)
addTransientFOV Adds a new FOV to the list.
Definition kstarsdata.h:325
SkyObject * objectNamed(const QString &name)
Find object by name.
QString colorSchemeFileName(const QString &name)
Definition kstarsdata.h:183
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:174
const QList< FOV * > getAvailableFOVs() const
Definition kstarsdata.h:316
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:402
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:343
bool executeScript(const QString &name, SkyMap *map)
Execute a script.
const std::map< QString, QString > color_schemes()
Definition kstarsdata.h:214
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:195
bool isTimeRunningForward() const
Returns true if time is running forward else false.
Definition kstarsdata.h:121
Q_INVOKABLE SimClock * clock()
Definition kstarsdata.h:220
GeoLocation * geo()
Definition kstarsdata.h:232
KStarsData()
Constructor.
void geoChanged()
Emitted when geo location changed.
const QMap< QString, TimeZoneRule > & getRulebook() const
Return map for daylight saving rules.
Definition kstarsdata.h:264
void add_color_scheme(const QString &filename, const QString &name)
Register a color scheme with filename and name.
Definition kstarsdata.h:207
bool hasColorScheme(const QString &scheme)
Definition kstarsdata.h:201
void setLocationFromOptions()
Set the GeoLocation according to the values stored in the configuration file.
SkyMapComposite * skyComposite()
Definition kstarsdata.h:168
void setSnapNextFocus(bool b=true)
Disable or re-enable the slewing animation for the next Focus change.
Definition kstarsdata.h:285
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:308
QList< ADVTreeData * > avdTree()
Return ADV Tree.
Definition kstarsdata.h:349
Q_INVOKABLE QString colorSchemeFileName()
Definition kstarsdata.h:180
Q_INVOKABLE QString colorSchemeName()
Definition kstarsdata.h:189
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
This is the main window for KStars.
Definition kstars.h:89
A backend of location dialog declared in QML.
Dialog for changing the geographic location of the observer.
Tool window for managing a custom list of objects.
kstars simulation clock
Definition simclock.h:23
const KStarsDateTime & utc() const
Definition simclock.h:35
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:42
This class provides the information needed to determine whether Daylight Savings Time (DST; a....
void append(QList< T > &&value)
void clear()
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.