1 /***************************************************************************
2 kstarsdata.h - K Desktop Planetarium
4 begin : Sun Jul 29 2001
5 copyright : (C) 2001 by Heiko Evermann
6 email : heiko@evermann.de
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
25 #include <kshortcut.h>
30 #include "geolocation.h"
31 #include "colorscheme.h"
32 #include "objectnamelist.h"
33 #include "planetcatalog.h"
34 #include "tools/lcgenerator.h"
35 #include "kstarsdatetime.h"
42 #define NCIRCLE 360 //number of points used to define equator, ecliptic and horizon
45 #define MAXZOOM 1000000.
46 #define DEFAULTZOOM 2000.
48 #define AU_KM 1.49605e8 //km in one AU
50 #define MINDRAWSTARMAG 6.5 // min. magnitude to load all stars which are needed for constellation lines
80 *KStarsData manages all the data objects used by KStars: Lists of stars, deep-sky objects,
81 *planets, geographic locations, and constellations. Also, the milky way, and URLs for
82 *images and information pages.
85 *@author Heiko Evermann
89 class KStarsData
: public QObject
93 //Friend classes can see the private data.
94 friend class FindDialog
;
96 friend class KSWizard
;
97 friend class LocationDialog
;
98 friend class FOVDialog
;
99 friend class MapCanvas
;
101 friend class FileSource
;
102 friend class StarDataSink
;
103 friend class LCGenerator
;
104 friend class DetailDialog
;
105 friend class AltVsTime
;
106 friend class KSPopupMenu
;
107 friend class WUTDialog
;
108 friend class ViewOpsDialog
;
109 friend class INDIDriver
;
111 friend class INDIStdProperty
;
112 friend class PlanetViewer
;
113 friend class JMoonTool
;
114 friend class telescopeWizardProcess
;
115 friend class KSNewStuff
;
120 /**Destructor. Delete data objects. */
121 virtual ~KStarsData();
123 /**Populate list of geographic locations from "Cities.dat". Also check for custom
124 *locations file "mycities.dat", but don't require it. Each line in the file
125 *provides the information required to create one GeoLocation object.
126 *@short Fill list of geographic locations from file(s)
127 *@return true if at least one city read successfully.
128 *@see KStarsData::processCity()
130 bool readCityData( void );
132 /**Read the data file that contains daylight savings time rules.
134 bool readTimeZoneRulebook( void );
136 /**Parse one line from a locations database file. The line contains 10 or 11 fields
137 *separated by colons (":"). The fields are:
138 *@li City Name [string]
139 *@li Province Name (optional) [string]
140 *@li Country Name [string]
141 *@li Longitude degrees [int]
142 *@li Latitude arcminutes [int]
143 *@li Latitude arcseconds [int]
144 *@li Latitude sign [char; 'E' or 'W' ]
145 *@li Latitude degrees [int]
146 *@li Latitude arcminutes [int]
147 *@li Latitude arcseconds [int]
148 *@li Latitude sign [char; 'N' or 'S' ]
149 *@li Timezone [float; -12 <= TZ <= 12, or 'x' if TZ unknown]
151 *@short Parse one line from a geographic database
152 *@param line The line from the geographic database to be parsed
153 *@return true if location successfully parsed; otherwise false.
154 *@see KStarsData::readCityData()
156 bool processCity( QString
& line
);
158 /**Populate list of star objects from the stars database file.
159 *Each line in the file provides the information required to construct a
160 *SkyObject of type 'star'.
161 *@short read the stars database, constructing the list of SkyObjects that represent the stars.
162 *@return true if the data file was successfully opened and read.
163 *@see KStarsData::processStar()
165 bool readStarData( void );
167 /**Parse a line from a stars data file, constructing a StarObject from the data.
168 *The StarObject is added to the list of stars.
170 *Each line is parsed according to the column
171 *position in the line:
172 *@li 0-1 RA hours [int]
173 *@li 2-3 RA minutes [int]
174 *@li 4-8 RA seconds [float]
175 *@li 10 Dec sign [char; '+' or '-']
176 *@li 11-12 Dec degrees [int]
177 *@li 13-14 Dec minutes [int]
178 *@li 15-18 Dec seconds [float]
179 *@li 20-28 dRA/dt (milli-arcsec/yr) [float]
180 *@li 29-37 dDec/dt (milli-arcsec/yr) [float]
181 *@li 38-44 Parallax (milli-arcsec) [float]
182 *@li 46-50 Magnitude [float]
183 *@li 51-55 B-V color index [float]
184 *@li 56-57 Spectral type [string]
185 *@li 59 Multiplicity flag (1=true, 0=false) [int]
186 *@li 61-64 Variability range of brightness (magnitudes; bank if not variable) [float]
187 *@li 66-71 Variability period (days; blank if not variable) [float]
188 *@li 72-END Name(s) [string]. This field may be blank. The string is the common
189 * name for the star (e.g., "Betelgeuse"). If there is a colon, then
190 * everything after the colon is the genetive name for the star (e.g.,
193 *@param line pointer to the line of data to be processed as a StarObject
194 *@param reloadMode makes additional calculations in reload mode, not needed at start up
195 *@see KStarsData::readStarData()
197 void processStar( QString
*line
, bool reloadMode
= false );
199 /**Populate the list of deep-sky objects from the database file.
200 *Each line in the file is parsed according to column position:
201 *@li 0 IC indicator [char] If 'I' then IC object; if ' ' then NGC object
202 *@li 1-4 Catalog number [int] The NGC/IC catalog ID number
203 *@li 6-8 Constellation code (IAU abbreviation)
204 *@li 10-11 RA hours [int]
205 *@li 13-14 RA minutes [int]
206 *@li 16-19 RA seconds [float]
207 *@li 21 Dec sign [char; '+' or '-']
208 *@li 22-23 Dec degrees [int]
209 *@li 25-26 Dec minutes [int]
210 *@li 28-29 Dec seconds [int]
211 *@li 31 Type ID [int] Indicates object type; see TypeName array in kstars.cpp
212 *@li 33-36 Type details [string] (not yet used)
213 *@li 38-41 Magnitude [float] can be blank
214 *@li 43-48 Major axis length, in arcmin [float] can be blank
215 *@li 50-54 Minor axis length, in arcmin [float] can be blank
216 *@li 56-58 Position angle, in degrees [int] can be blank
217 *@li 60-62 Messier catalog number [int] can be blank
218 *@li 64-69 PGC Catalog number [int] can be blank
219 *@li 71-75 UGC Catalog number [int] can be blank
220 *@li 77-END Common name [string] can be blank
221 *@short Read the ngcic.dat deep-sky database.
222 *@return true if data file is successfully read.
224 bool readDeepSkyData( void );
226 /**Populate the list of Asteroids from the data file.
227 *Each line in the data file is parsed as follows:
228 *@li 6-23 Name [string]
229 *@li 24-29 Modified Julian Day of orbital elements [int]
230 *@li 30-39 semi-major axis of orbit in AU [double]
231 *@li 41-51 eccentricity of orbit [double]
232 *@li 52-61 inclination angle of orbit in degrees [double]
233 *@li 62-71 argument of perihelion in degrees [double]
234 *@li 72-81 Longitude of the Ascending Node in degrees [double]
235 *@li 82-93 Mean Anomaly in degrees [double]
236 *@li 94-98 Magnitude [double]
238 bool readAsteroidData( void );
240 /**Populate the list of Comets from the data file.
241 *Each line in the data file is parsed as follows:
242 *@li 3-37 Name [string]
243 *@li 38-42 Modified Julian Day of orbital elements [double]
244 *@li 44-54 Perihelion distance in AU [double]
245 *@li 55-65 Eccentricity of orbit [double]
246 *@li 66-75 inclination of orbit in degrees [double]
247 *@li 76-85 argument of perihelion in degrees [double]
248 *@li 86-95 longitude of the ascending node in degrees[double]
249 *@li 96-110 Period of orbit in years [double]
251 bool readCometData( void );
253 /**Read in Constellation line data. The constellations are represented as a list of
254 *SkyPoints and an associated list of chars that indicates whether to draw a line
255 *between points (i) and (i+1) or to simply move to point (i+1). The lines are parsed
256 *according to column position:
257 *@li 0-1 RA hours [int]
258 *@li 2-3 RA minutes [int]
259 *@li 4-5 RA seconds [int]
260 *@li 6 Dec sign [char; '+' or '-']
261 *@li 7-9 Dec degrees [int]
262 *@li 10-11 Dec minutes [int]
263 *@li 12-13 Dec seconds [int]
264 *@li 14 draw indicator [char; 'D' or 'M'] 'D'==draw line; 'M'==just move
266 *@short Read in constellation line data.
267 *@return true if data file was successfully read
269 bool readCLineData( void );
271 /**Read constellation names. The coordinates are where the constellation name text
272 *will be centered. The positions are imprecise, but that's okay since
273 *constellations are so large. The lines are parsed according to column position:
274 *@li 0-1 RA hours [int]
275 *@li 2-3 RA minutes [int]
276 *@li 4-5 RA seconds [int]
277 *@li 6 Dec sign [char; '+' or '-']
278 *@li 7-8 Dec degrees [int]
279 *@li 9-10 Dec minutes [int]
280 *@li 11-12 Dec seconds [int]
281 *@li 13-15 IAU Abbreviation [string] e.g., 'Ori' == Orion
282 *@li 17- Constellation name [string]
283 *@short Read in constellation name data.
284 *@return TRUE if data file was successfully read.
286 bool readCNameData( void );
288 /**Read constellation boundary data. The boundary data is defined by a series of
289 *RA,Dec coordinate pairs defining the "nodes" of the boundaries. The nodes are
290 *organized into "segments", such that each segment represents a continuous series
291 *of boundary-line intervals that divide two particular constellations.
293 *The definition of a segment begins with an integer describing the number of Nodes
294 *in the segment. This is followed by that number of RA,Dec pairs (RA in hours,
295 *Dec in degrees). Finally, there is an integer indicating the number of
296 *constellations bordered by this segment (this number is always 2), followed by
297 *the IAU abbreviations of the two constellations.
299 *Since the definition of a segment can span multiple lines, we parse this file
300 *word-by-word, rather than line-by-line as we do in other files.
302 *@short Read in the constellation boundary data.
303 *@return TRUE if the boundary data is successfully parsed.
305 bool readCBoundData( void );
307 /**Read Milky Way data. Coordinates for the Milky Way contour are divided into 11
308 *files, each representing a simple closed curve that can be drawn with
309 *drawPolygon(). The lines in each file are parsed according to column position:
311 *@li 9-16 Dec [float]
312 *@short read Milky Way contour data.
313 *@return true if all MW files were successfully read
315 bool readMWData( void );
317 /**Read Variable Stars data and stores them in structure of type VariableStarsInfo.
318 *@li 0-8 AAVSO Star Designation
319 *@li 10-20 Common star name
320 *@short read Variable Stars data.
321 *@return true if data is successfully read.
323 bool readVARData(void);
325 //TODO JM: ADV tree should use XML instead
326 /**Read Advanced interface structure to be used later to construct the list view in
327 *the advanced tab in the Detail Dialog.
328 *@li KSLABEL designates a top-level parent label
329 *@li KSINTERFACE designates a common URL interface for several objects
330 *@li END designates the end of a sub tree structure
331 *@short read Advanted interface structure.
332 *@return true if data is successfully read.
334 bool readADVTreeData(void);
336 /**Read INDI hosts from an XML file*/
337 bool readINDIHosts(void);
339 //TODO JM: Use XML instead; The logger should have more features
340 // that allow users to enter details about their observation logs
341 // objects observed, eye pieces, telescope, conditions, mag..etc
342 /**Read user logs. The log file is formatted as following:
343 *@li KSLABEL designates the beginning of a log
344 *@li KSLogEnd designates the end of a log.
345 *@short read user logs.
346 *@return true if data is successfully read.
348 bool readUserLog(void);
350 /**Read in URLs to be attached to a named object's right-click popup menu. At this
351 *point, there is no way to attach URLs to unnamed objects. There are two
352 *kinds of URLs, each with its own data file: image links and webpage links. In addition,
353 *there may be user-specific versions with custom URLs. Each line contains 3 fields
354 *separated by colons (":"). Note that the last field is the URL, and as such it will
355 *generally contain a colon itself. Only the first two colons encountered are treated
356 *as field separators. The fields are:
357 *@li Object name. This must be the "primary" name of the object (the name at the top of the popup menu).
358 *@li Menu text. The string that should appear in the popup menu to activate the link.
360 *@short Read in image and information URLs.
361 *@return true if data files were successfully read.
363 bool readURLData( QString url
, int type
=0, bool deepOnly
=false );
365 /**@short open a file containing URL links.
366 *@param urlfile string representation of the filename to open
367 *@param file reference to the QFile object which will be opened to this file.
368 *@return TRUE if file successfully opened.
370 bool openURLFile(QString urlfile
, QFile
& file
);
372 /**Read in custom object catalog. Object data is read from a file, and parsed into a
373 *QPtrList of SkyObjects which is returned by reference through the 2nd argument.
374 *@param filename The custom catalog data file
375 *@param olist the list of skyobjects, returned as a reference through this variable
376 *@bool showerrs if true, notify user of unparsed lines.
378 bool readCustomData( QString filename
, QPtrList
<DeepSkyObject
> &olist
, bool showerrs
);
380 /**@short reset the faint limit for the stellar database
381 *@param newMagnitude the new faint limit.
382 *@param forceReload will force a reload also if newMagnitude <= maxSetMagnitude
383 *it's needed to set internal maxSetMagnitude and reload data later; is used in
384 *checkDataPumpAction() and should not used outside.
386 void setMagnitude( float newMagnitude
, bool forceReload
=false );
388 /**Add a custom object catalog. The QString name of the catalog and
389 *the QPtrList of SkyObjects comprising the data are given as arguments.
390 *This function simply appends the QPtrList as an entry in the
391 *CustomCatalogs QMap, with the name string used as the key.
393 void addCatalog( QString name
, QPtrList
<DeepSkyObject
> );
395 /**Set the NextDSTChange member.
396 *Need this accessor because I could not make KStars::privatedata a friend
397 *class for some reason...:/
399 void setNextDSTChange( const KStarsDateTime
&dt
) { NextDSTChange
= dt
; }
401 /**Returns true if time is running forward else false. Used by KStars to prevent
402 *2 calculations of daylight saving change time.
404 bool isTimeRunningForward() { return TimeRunsForward
; }
406 /**@return pointer to the localization (KLocale) object
408 KLocale
*getLocale() { return locale
; };
410 /**@return pointer to the Earth object
412 KSPlanet
*earth() { return PCat
->earth(); }
414 /**@short Find object by name.
415 *@param name Object name to find
416 *@return pointer to SkyObject matching this name
418 SkyObject
* objectNamed( const QString
&name
);
420 /**The Sky is updated more frequently than the moon, which is updated more frequently
421 *than the planets. The date of the last update for each category is recorded so we
422 *know when we need to do it again (see KStars::updateTime()).
423 *Initializing these to -1000000.0 ensures they will be updated immediately
424 *on the first call to KStars::updateTime().
426 void setFullTimeUpdate();
428 /**change the current simulation date/time to the KStarsDateTime argument.
429 *Specified DateTime is always universal time.
430 *@param newDate the DateTime to set.
431 *@param newTIme the time to set.
433 void changeDateTime( const KStarsDateTime
&newDate
);
435 /**@return pointer to the current simulation local time
437 const KStarsDateTime
& lt() const { return LTime
; }
439 /**@return reference to the current simulation universal time
441 const KStarsDateTime
& ut() const { return Clock
.utc(); }
443 /**Sync the LST with the simulation clock.
447 /**Set the HourAngle member variable according to the argument.
448 *@param ha The new HourAngle
450 void setHourAngle( double ha
) { HourAngle
->setH( ha
); }
452 //Some members need to be accessed outside of the friend classes (i.e., in the main fcn).
454 /**@return pointer to the ColorScheme object
456 ColorScheme
*colorScheme() { return &CScheme
; }
458 /**@return pointer to the simulation Clock object
460 SimClock
*clock() { return &Clock
; }
462 /**@return pointer to the local sidereal time: a dms object
464 dms
*lst() { return LST
; }
466 /**@return pointer to the GeoLocation object*/
467 GeoLocation
*geo() { return &Geo
; }
469 /**Set the GeoLocation according to the argument.
470 *@param l reference to the new GeoLocation
472 void setLocation( const GeoLocation
&l
);
474 /**Set the GeoLocation according to the values stored in the configuration file.
476 void setLocationFromOptions();
478 /**@return whether the next Focus change will omit the slewing animation.
480 bool snapNextFocus() const { return snapToFocus
; }
482 /**Disable or re-enable the slewing animation for the next Focus change.
483 *@note If the user has turned off all animated slewing, setSnapNextFocus(false)
484 *will *NOT* enable animation on the next slew. A false argument would only
485 *be used if you have previously called setSnapNextFocus(true), but then decided
486 *you didn't want that after all. In other words, it's extremely unlikely you'd
487 *ever want to use setSnapNextFocus(false).
488 *@param b when TRUE (the default), the next Focus chnage will omit the slewing
491 void setSnapNextFocus(bool b
=true) { snapToFocus
= b
; }
493 /**Execute a script. This function actually duplicates the DCOP functionality
494 *for those cases when invoking DCOP is not practical (i.e., when preparing
495 *a sky image in command-line dump mode).
496 *@param name the filename of the script to "execute".
497 *@param map pointer to the SkyMap object.
498 *@return TRUE if the script was successfully parsed.
500 bool executeScript( const QString
&name
, SkyMap
*map
);
502 /**@short Initialize celestial equator, horizon and ecliptic.
503 *@param num pointer to a KSNumbers object to use.
505 void initGuides( KSNumbers
*num
);
507 bool useDefaultOptions
, startupComplete
;
510 /**Signal that specifies the text that should be drawn in the KStarsSplash window.
512 void progressText(QString
);
514 /**Signal that the Data initialization has finished.
516 void initFinished(bool);
519 *Should be used to refresh skymap.
524 *If data changed, emit clearCache signal.
530 /**Create a timer and connect its timeout() signal to slotInitialize(). */
533 /**@short send a message to the console*/
534 void slotConsoleMessage( QString s
) { std::cout
<< s
.utf8() << std::endl
; }
536 /**Update the Simulation Clock. Update positions of Planets. Update
537 *Alt/Az coordinates of objects. Update precession. Update Focus position.
542 *(JH:)hey, it's much less ugly now...can we lose the comment yet? :p
544 void updateTime(GeoLocation
*geo
, SkyMap
* skymap
, const bool automaticDSTchange
= true);
546 /**Sets the direction of time and stores it in bool TimeRunForwards. If scale >= 0
547 *time is running forward else time runs backward. We need this to calculate just
548 *one daylight saving change time (previous or next DST change).
550 void setTimeDirection( float scale
);
552 /**@short Save the shaded state of the Time infobox.
553 *@param b TRUE if the box is shaded
555 void saveTimeBoxShaded( bool b
);
557 /**@short Save the shaded state of the Geo infobox.
558 *@param b TRUE if the box is shaded
560 void saveGeoBoxShaded( bool b
);
562 /**@short Save the shaded state of the Focus infobox.
563 *@param b TRUE if the box is shaded
565 void saveFocusBoxShaded( bool b
);
567 /**@short Save the screen position of the Time infobox.
568 *@param p the position of the box
570 void saveTimeBoxPos( QPoint p
);
572 /**@short Save the screen position of the Time infobox.
573 *@param p the position of the box
575 void saveGeoBoxPos( QPoint p
);
577 /**@short Save the screen position of the Time infobox.
578 *@param p the position of the box
580 void saveFocusBoxPos( QPoint p
);
583 /**This function runs while the splash screen is displayed as KStars is
584 *starting up. It is connected to the timeout() signal of a timer
585 *created in the initialize() slot. It consists of a large switch
586 *statement, in which each case causes the next data object to be
587 *initialized (which usually consists of reading data from a file on disk,
588 *and storing it in the appropriate object in memory).
589 *At the end of this function, the integer which the switch statement is
590 *checking is incremented, so that the next case label will be executed when
591 *the next timeout() signal is fired.
593 void slotInitialize();
595 /**Checks if data transmission is already running or not.
597 void checkDataPumpAction();
599 /**Send update signal to refresh skymap.
603 /**Send clearCache signal.
605 void sendClearCache();
609 /**Display an Error messagebox if a data file could not be opened. If the file
610 *was marked as "required", then abort the program when the messagebox is closed.
611 *Otherwise, continue loading the program.
612 *@param fn the name of the file which could not be opened.
613 *@param required if TRUE, then the error message is more severe, and the program
614 *exits when the messagebox is closed.
616 void initError(QString fn
, bool required
);
618 /**Reset local time to new daylight saving time. Use this function if DST has changed.
619 *Used by updateTime().
621 void resetToNewDST(const GeoLocation
*geo
, const bool automaticDSTchange
);
624 * Store the highest magnitude level at the current session and compare with current used
625 * magnitude. If current magnitude is equal to maxSetMagnitude reload data on next increment
626 * of magnitude level.
628 float maxSetMagnitude
;
630 * Store the last position in star data file. Needed by reloading star data.
634 bool reloadingData(); // is currently reloading of data in progress
636 /* bool openSAOFile(int i);*/
637 bool openStarFile(int i
);
639 static QPtrList
<GeoLocation
> geoList
;
640 QPtrList
<SkyObject
> objList
;
642 QPtrList
<StarObject
> starList
;
644 unsigned int StarCount
;
646 /** List of all deep sky objects */
647 QPtrList
<DeepSkyObject
> deepSkyList
;
648 /** List of all deep sky objects per type, to speed up drawing the sky map */
649 QPtrList
<DeepSkyObject
> deepSkyListMessier
;
650 /** List of all deep sky objects per type, to speed up drawing the sky map */
651 QPtrList
<DeepSkyObject
> deepSkyListNGC
;
652 /** List of all deep sky objects per type, to speed up drawing the sky map */
653 QPtrList
<DeepSkyObject
> deepSkyListIC
;
654 /** List of all deep sky objects per type, to speed up drawing the sky map */
655 QPtrList
<DeepSkyObject
> deepSkyListOther
;
657 QPtrList
<KSAsteroid
> asteroidList
;
658 QPtrList
<KSComet
> cometList
;
660 QPtrList
<SkyPoint
> MilkyWay
[NMWFILES
];
662 QPtrList
<SkyPoint
> clineList
;
663 QPtrList
<CSegment
> csegmentList
;
664 QPtrList
<QChar
> clineModeList
;
665 QPtrList
<SkyObject
> cnameList
;
666 QPtrList
<SkyObject
> ObjLabelList
;
668 QPtrList
<SkyPoint
> Equator
;
669 QPtrList
<SkyPoint
> Ecliptic
;
670 QPtrList
<SkyPoint
> Horizon
;
671 QPtrList
<VariableStarInfo
> VariableStarsList
;
672 QPtrList
<ADVTreeData
> ADVtreeList
;
673 QPtrList
<INDIHostsInfo
> INDIHostsList
;
675 ObjectNameList ObjNames
;
677 QMap
<QString
, QPtrList
<DeepSkyObject
> > CustomCatalogs
;
678 static QMap
<QString
, TimeZoneRule
> Rulebook
;
684 KStarsDateTime LTime
;
686 bool TimeRunsForward
, temporaryTrail
, snapToFocus
;
689 KStandardDirs
*stdDirs
;
692 dms
*LST
, *HourAngle
;
694 QString TypeName
[NTYPENAME
];
699 JupiterMoons
*jmoons
;
701 KSFileReader
*starFileReader
;
705 double Obliquity
, dObliq
, dEcLong
;
706 KStarsDateTime LastNumUpdate
, LastSkyUpdate
, LastPlanetUpdate
, LastMoonUpdate
;
707 KStarsDateTime NextDSTChange
;
713 *Reloading of star data asynchronous:
714 *QDataPump connects FileSource and StarDataSink and starts data transmission.
717 StarDataSink
*loader
;
721 *Count the number of KStarsData objects.
727 #endif // KSTARSDATA_H