Stellarium 0.13.0
StelCore.hpp
1 /*
2  * Copyright (C) 2003 Fabien Chereau
3  * Copyright (C) 2012 Matthew Gates
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELCORE_HPP_
21 #define _STELCORE_HPP_
22 
23 #include "StelProjector.hpp"
24 #include "StelProjectorType.hpp"
25 #include "StelLocation.hpp"
26 #include "StelSkyDrawer.hpp"
27 #include <QString>
28 #include <QStringList>
29 #include <QTime>
30 
31 class StelToneReproducer;
32 class StelSkyDrawer;
33 class StelGeodesicGrid;
34 class StelMovementMgr;
35 class StelObserver;
36 
46 class StelCore : public QObject
47 {
48  Q_OBJECT
49  Q_ENUMS(ProjectionType)
50  Q_ENUMS(DeltaTAlgorithm)
51  Q_PROPERTY(bool flipHorz READ getFlipHorz WRITE setFlipHorz)
52  Q_PROPERTY(bool flipVert READ getFlipVert WRITE setFlipVert)
53 
54 public:
57  enum FrameType
58  {
59  FrameUninitialized,
60  FrameAltAz,
61  FrameHeliocentricEcliptic,
62  FrameObservercentricEcliptic,
63  FrameEquinoxEqu,
64  FrameJ2000,
66  FrameGalactic
68  };
69 
71  enum ProjectionType
72  {
73  ProjectionPerspective,
74  ProjectionEqualArea,
75  ProjectionStereographic,
76  ProjectionFisheye,
77  ProjectionHammer,
78  ProjectionCylinder,
79  ProjectionMercator,
80  ProjectionOrthographic
81  };
82 
84  enum RefractionMode
85  {
86  RefractionAuto,
87  RefractionOn,
88  RefractionOff
89  };
90 
93  enum DeltaTAlgorithm
94  {
95  WithoutCorrection,
96  Schoch,
97  Clemence,
98  IAU,
99  AstronomicalEphemeris,
100  TuckermanGoldstine,
101  MullerStephenson,
102  Stephenson1978,
103  SchmadelZech1979,
104  MorrisonStephenson1982,
105  StephensonMorrison1984,
106  StephensonHoulden,
107  Espenak,
108  Borkowski,
109  SchmadelZech1988,
110  ChaprontTouze,
111  StephensonMorrison1995,
112  Stephenson1997,
113  ChaprontMeeus,
114  JPLHorizons,
115  MeeusSimons,
116  MontenbruckPfleger,
117  ReingoldDershowitz,
118  MorrisonStephenson2004,
119  Reijs,
120  EspenakMeeus,
121  Banjevic,
122  IslamSadiqQureshi,
123  Custom
124  };
125 
126  StelCore();
127  virtual ~StelCore();
128 
130  void init();
131 
134  void update(double deltaTime);
135 
137  void windowHasBeenResized(float x, float y, float width, float height);
138 
140  void preDraw();
141 
143  void postDraw();
144 
147  StelProjectorP getProjection2d() const;
148 
151  StelProjectorP getProjection(FrameType frameType, RefractionMode refractionMode=RefractionAuto) const;
152 
155  StelProjectorP getProjection(StelProjector::ModelViewTranformP modelViewTransform, ProjectionType projType=(ProjectionType)1000) const;
156 
158  StelToneReproducer* getToneReproducer();
160  const StelToneReproducer* getToneReproducer() const;
161 
163  StelSkyDrawer* getSkyDrawer();
165  const StelSkyDrawer* getSkyDrawer() const;
166 
168  const StelGeodesicGrid* getGeodesicGrid(int maxLevel) const;
169 
171  StelMovementMgr* getMovementMgr();
173  const StelMovementMgr* getMovementMgr() const;
174 
176  void setClippingPlanes(double znear, double zfar);
178  void getClippingPlanes(double* zn, double* zf) const;
179 
181  QString projectionTypeKeyToNameI18n(const QString& key) const;
182 
184  QString projectionNameI18nToTypeKey(const QString& nameI18n) const;
185 
187  StelProjector::StelProjectorParams getCurrentStelProjectorParams() const;
189  void setCurrentStelProjectorParams(const StelProjector::StelProjectorParams& newParams);
190 
192  void lookAtJ2000(const Vec3d& pos, const Vec3d& up);
193 
194  Vec3d altAzToEquinoxEqu(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
195  Vec3d equinoxEquToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
196  Vec3d altAzToJ2000(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
197  Vec3d j2000ToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
198  void j2000ToAltAzInPlaceNoRefraction(Vec3f* v) const {v->transfo4d(matJ2000ToAltAz);}
199  Vec3d galacticToJ2000(const Vec3d& v) const;
200  Vec3d equinoxEquToJ2000(const Vec3d& v) const;
201  Vec3d j2000ToEquinoxEqu(const Vec3d& v) const;
202  Vec3d j2000ToGalactic(const Vec3d& v) const;
203 
205  Vec3d heliocentricEclipticToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
206 
208  Vec3d heliocentricEclipticToEquinoxEqu(const Vec3d& v) const;
211  Vec3d heliocentricEclipticToEarthPosEquinoxEqu(const Vec3d& v) const;
212 
214  StelProjector::ModelViewTranformP getHeliocentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
215 
217  StelProjector::ModelViewTranformP getObservercentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
218 
220  StelProjector::ModelViewTranformP getEquinoxEquModelViewTransform(RefractionMode refMode=RefractionAuto) const;
221 
223  StelProjector::ModelViewTranformP getAltAzModelViewTransform(RefractionMode refMode=RefractionAuto) const;
224 
226  StelProjector::ModelViewTranformP getJ2000ModelViewTransform(RefractionMode refMode=RefractionAuto) const;
227 
229  StelProjector::ModelViewTranformP getGalacticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
230 
232  static const Mat4d matJ2000ToVsop87;
234  static const Mat4d matVsop87ToJ2000;
236  static const Mat4d matJ2000ToGalactic;
238  static const Mat4d matGalacticToJ2000;
239 
241  Vec3d getObserverHeliocentricEclipticPos() const;
242 
244  const StelLocation& getCurrentLocation() const;
245 
246  const QSharedPointer<class Planet> getCurrentPlanet() const;
247 
248  SphericalCap getVisibleSkyArea() const;
249 
255  void moveObserverTo(const StelLocation& target, double duration=1., double durationIfPlanetChange=1.);
256 
257  // Conversion in standar Julian time format
258  static const double JD_SECOND;
259  static const double JD_MINUTE;
260  static const double JD_HOUR;
261  static const double JD_DAY;
262  static const double ONE_OVER_JD_SECOND;
263 
266  double getLocalSiderealTime() const;
267 
269  double getLocalSiderealDayLength() const;
270 
272  double getLocalSiderealYearLength() const;
273 
275  QString getStartupTimeMode();
276  void setStartupTimeMode(const QString& s);
277 
282  double getDeltaT(double jDay) const;
283 
288  QString getCurrentDeltaTAlgorithmValidRange(double jDay, QString* marker) const;
289 
290 public slots:
292  void setCurrentProjectionType(ProjectionType type);
293  ProjectionType getCurrentProjectionType() const;
294 
296  QString getCurrentProjectionTypeKey(void) const;
298  void setCurrentProjectionTypeKey(QString type);
299 
301  QStringList getAllProjectionTypeKeys() const;
302 
304  void setCurrentDeltaTAlgorithm(DeltaTAlgorithm algorithm) { currentDeltaTAlgorithm=algorithm; }
306  DeltaTAlgorithm getCurrentDeltaTAlgorithm() const { return currentDeltaTAlgorithm; }
308  QString getCurrentDeltaTAlgorithmDescription(void) const;
310  QString getCurrentDeltaTAlgorithmKey(void) const;
312  void setCurrentDeltaTAlgorithmKey(QString type);
313 
316 
319  void setFlagGravityLabels(bool gravity);
321  void setDefautAngleForGravityText(float a);
324  void setFlipHorz(bool flip);
327  void setFlipVert(bool flip);
330  bool getFlipHorz(void) const;
333  bool getFlipVert(void) const;
334 
336  QString getDefaultLocationID() const;
338  void setDefaultLocationID(const QString& id);
342  void returnToHome();
343 
345  void setJDay(double JD);
347  double getJDay() const;
348 
350  void setMJDay(double MJD);
352  double getMJDay() const;
353 
355  double getPresetSkyTime() const;
357  void setPresetSkyTime(double d);
358 
360  void setTimeRate(double ts);
362  double getTimeRate() const;
363 
365  void increaseTimeSpeed();
367  void decreaseTimeSpeed();
369  void increaseTimeSpeedLess();
371  void decreaseTimeSpeedLess();
372 
374  void setZeroTimeSpeed();
376  void setRealTimeSpeed();
378  void toggleRealTimeSpeed();
380  bool getRealTimeSpeed() const;
381 
383  void setTimeNow();
385  void setTodayTime(const QTime& target);
387  bool getIsTimeNow() const;
388 
390  QTime getInitTodayTime(void);
392  void setInitTodayTime(const QTime& t);
394  void setPresetSkyTime(QDateTime dt);
395 
397  void addHour();
399  void addDay();
401  void addWeek();
402 
405  void addSiderealDay();
408  void addSiderealWeek();
412  void addSiderealMonth();
416  void addSiderealYear();
420  void addSiderealCentury();
421 
423  void subtractHour();
425  void subtractDay();
427  void subtractWeek();
428 
431  void subtractSiderealDay();
434  void subtractSiderealWeek();
438  void subtractSiderealMonth();
442  void subtractSiderealYear();
447 
449  void addSynodicMonth();
450 
452  void addDraconicYear();
454  void addDraconicMonth();
455 
457  void addAnomalisticMonth();
458 
460  void addTropicalMonth();
462  void addTropicalYear();
464  void addTropicalCentury();
465 
467  void subtractSynodicMonth();
468 
470  void subtractDraconicYear();
472  void subtractDraconicMonth();
473 
476 
478  void subtractTropicalMonth();
480  void subtractTropicalYear();
483 
486  void addSolarDays(double d);
490  void addSiderealDays(double d);
491 
494  void moveObserverToSelected();
495 
498  void setDeltaTCustomYear(float y) { deltaTCustomYear=y; }
501  void setDeltaTCustomNDot(float v) { deltaTCustomNDot=v; }
504  void setDeltaTCustomEquationCoefficients(Vec3f c) { deltaTCustomEquationCoeff=c; }
505 
507  float getDeltaTCustomYear() const { return deltaTCustomYear; }
509  float getDeltaTCustomNDot() const { return deltaTCustomNDot; }
511  Vec3f getDeltaTCustomEquationCoefficients() const { return deltaTCustomEquationCoeff; }
512 
513 signals:
517  void timeRateChanged(double rate);
518 
519 private:
520  StelToneReproducer* toneConverter; // Tones conversion between stellarium world and display device
521  StelSkyDrawer* skyDrawer;
522  StelMovementMgr* movementMgr; // Manage vision movements
523 
524  // Manage geodesic grid
525  mutable StelGeodesicGrid* geodesicGrid;
526 
527  // The currently used projection type
528  ProjectionType currentProjectionType;
529 
530  // The currentrly used time correction (DeltaT)
531  DeltaTAlgorithm currentDeltaTAlgorithm;
532 
533  // Parameters to use when creating new instances of StelProjector
534  StelProjector::StelProjectorParams currentProjectorParams;
535 
536  void updateTransformMatrices();
537  void updateTime(double deltaTime);
538  void resetSync();
539 
540  // Matrices used for every coordinate transfo
541  Mat4d matHeliocentricEclipticToAltAz; // Transform from heliocentric ecliptic (Vsop87) to observer-centric altazimuthal coordinate
542  Mat4d matAltAzToHeliocentricEcliptic; // Transform from observer-centric altazimuthal coordinate to heliocentric ecliptic (Vsop87)
543  Mat4d matAltAzToEquinoxEqu; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
544  Mat4d matEquinoxEquToAltAz; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
545  Mat4d matHeliocentricEclipticToEquinoxEqu; // Transform from heliocentric ecliptic (Vsop87) to earth equatorial coordinate
546  Mat4d matEquinoxEquToJ2000;
547  Mat4d matJ2000ToEquinoxEqu;
548  Mat4d matJ2000ToAltAz;
549 
550  Mat4d matAltAzModelView; // Modelview matrix for observer-centric altazimuthal drawing
551  Mat4d invertMatAltAzModelView; // Inverted modelview matrix for observer-centric altazimuthal drawing
552 
553  // Position variables
554  StelObserver* position;
555  // The ID of the default startup location
556  QString defaultLocationID;
557 
558  // Time variables
559  double timeSpeed; // Positive : forward, Negative : Backward, 1 = 1sec/sec
560  double JDay; // Curent time in Julian day
561  double presetSkyTime;
562  QTime initTodayTime;
563  QString startupTimeMode;
564  double secondsOfLastJDayUpdate; // Time in seconds when the time rate or time last changed
565  double JDayOfLastJDayUpdate; // JDay when the time rate or time last changed
566 
567  // Variables for custom equation of Delta-T
568  Vec3f deltaTCustomEquationCoeff;
569  float deltaTCustomNDot;
570  float deltaTCustomYear;
571 
572 };
573 
574 #endif // _STELCORE_HPP_
void setTimeRate(double ts)
Set time speed in JDay/sec.
Store the informations for a location on a planet.
Definition: StelLocation.hpp:28
void setPresetSkyTime(double d)
Set the preset sky time from a JD.
void subtractSiderealYear()
Subtract one sidereal year to the simulation time.
void setCurrentProjectionType(ProjectionType type)
Set the current ProjectionType to use.
double getJDay() const
Get the current date in Julian Day.
void subtractTropicalYear()
Subtract one mean tropical year to the simulation time.
void timeRateChanged(double rate)
This signal is emitted when the time rate has changed.
void addWeek()
Add one [Earth, solar] week to the current simulation time.
DeltaTAlgorithm getCurrentDeltaTAlgorithm() const
Get the current algorithm for time correction (DeltaT)
Definition: StelCore.hpp:306
Provide a set of methods used to draw sky objects taking into account eyes adaptation, zoom level, instrument model and artificially set magnitude limits.
Definition: StelSkyDrawer.hpp:45
void addSiderealDay()
Add one sidereal day to the simulation time.
QStringList getAllProjectionTypeKeys() const
Get the list of all the available projections.
void returnToDefaultLocation()
Return to the default location.
StelProjectorMaskType
Define viewport mask types.
Definition: StelProjector.hpp:86
void setInitTodayTime(const QTime &t)
set the initial "today time" from the config file
bool getFlipHorz(void) const
Get the state of the horizontal flip.
Vec3f getDeltaTCustomEquationCoefficients() const
Get coefficients for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:511
void decreaseTimeSpeed()
Decrease the time speed.
void addSiderealWeek()
Add one sidereal week (7 sidereal days) to the simulation time.
void subtractDraconicMonth()
Subtract one draconic month to the simulation time.
void subtractDay()
Subtract one [Earth, solar] day to the current simulation time.
double getMJDay() const
Get the current date in Modified Julian Day.
void setFlipVert(bool flip)
Set the vertical flip status.
void subtractTropicalCentury()
Subtract one mean tropical century to the simulation time.
A SphericalCap is defined by a direction and an aperture.
Definition: StelSphereGeometry.hpp:273
void subtractSiderealMonth()
Subtract one sidereal month (1/12 of sidereal year) to the simulation time.
QString getCurrentDeltaTAlgorithmDescription(void) const
Get description of the current algorithm for time correction.
void addDay()
Add one [Earth, solar] day to the current simulation time.
void setCurrentDeltaTAlgorithmKey(QString type)
Set the current algorithm to use from its key.
void addTropicalCentury()
Add one mean tropical century to the simulation time.
void setCurrentDeltaTAlgorithm(DeltaTAlgorithm algorithm)
Set the current algorithm for time correction (DeltaT)
Definition: StelCore.hpp:304
void setRealTimeSpeed()
Set real time speed, i.e. 1 sec/sec.
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
void setDefautAngleForGravityText(float a)
Set the offset rotation angle in degree to apply to gravity text (only if gravityLabels is set to fal...
void addSynodicMonth()
Add one synodic month to the simulation time.
Grid of triangles (zones) on the sphere with radius 1, generated by subdividing the icosahedron...
Definition: StelGeodesicGrid.hpp:47
void addHour()
Add one [Earth, solar] hour to the current simulation time.
float getDeltaTCustomNDot() const
Get n-dot for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:509
void addTropicalYear()
Add one mean tropical year to the simulation time.
QSharedPointer< StelProjector > StelProjectorP
Shared pointer on a StelProjector instance (implement reference counting)
Definition: StelProjectorType.hpp:34
void setFlagGravityLabels(bool gravity)
Set the flag with decides whether to arrage labels so that they are aligned with the bottom of a 2d s...
void subtractSynodicMonth()
Subtract one synodic month to the simulation time.
QString getCurrentDeltaTAlgorithmKey(void) const
Get the current algorithm used by the DeltaT.
Manages the head movements and zoom operations.
Definition: StelMovementMgr.hpp:29
Converts tones in function of the eye adaptation to luminance.
Definition: StelToneReproducer.hpp:53
void addSiderealYear()
Add one sidereal year to the simulation time.
void decreaseTimeSpeedLess()
Decrease the time speed but not as much as with decreaseTimeSpeed()
float getDeltaTCustomYear() const
Get year for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:507
void addDraconicYear()
Add one draconic year to the simulation time.
void toggleRealTimeSpeed()
Set real time speed or pause simulation if we are already in realtime speed.
void setTodayTime(const QTime &target)
Set the time to some value, leaving the day the same.
Should be renamed as PlanetBasedObserver and derive from a more generical StelObserver class...
Definition: StelObserver.hpp:37
bool getFlipVert(void) const
Get the state of the vertical flip.
void returnToHome()
Return to the default location and set default landscape with atmosphere and fog effects.
void subtractWeek()
Subtract one [Earth, solar] week to the current simulation time.
void moveObserverToSelected()
Move the observer to the selected object.
double getPresetSkyTime() const
Return the preset sky time in JD.
void setFlipHorz(bool flip)
Set the horizontal flip status.
void setMaskType(StelProjector::StelProjectorMaskType m)
Set the mask type.
void setJDay(double JD)
Set the current date in Julian Day.
void addSiderealDays(double d)
Add a number of sidereal days to the current simulation time, based on the observer body's rotational...
void setZeroTimeSpeed()
Set time speed to 0, i.e. freeze the passage of simulation time.
bool getIsTimeNow() const
Get whether the current stellarium time is the real world time.
void setTimeNow()
Set stellarium time to current real world time.
void addAnomalisticMonth()
Add one anomalistic month to the simulation time.
void subtractSiderealWeek()
Subtract one sidereal week (7 sidereal days) to the simulation time.
void addTropicalMonth()
Add one mean tropical month to the simulation time.
void subtractAnomalisticMonth()
Subtract one anomalistic month to the simulation time.
void setDeltaTCustomEquationCoefficients(Vec3f c)
Set coefficients for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:504
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
Definition: StelProjector.hpp:46
QTime getInitTodayTime(void)
get the initial "today time" from the config file
void addDraconicMonth()
Add one draconic month to the simulation time.
void addSiderealCentury()
Add one sidereal century (100 sidereal years) to the simulation time.
void subtractTropicalMonth()
Subtract one mean tropical month to the simulation time.
void addSiderealMonth()
Add one sidereal month (1/12 of sidereal year) to the simulation time.
void subtractDraconicYear()
Subtract one draconic year to the simulation time.
void setDeltaTCustomYear(float y)
Set year for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:498
double getTimeRate() const
Get time speed in JDay/sec.
Define the StelProjectorP type.
Contains all the param needed to initialize a StelProjector.
Definition: StelProjector.hpp:94
QString getCurrentProjectionTypeKey(void) const
Get the current Mapping used by the Projection.
void subtractSiderealCentury()
Subtract one sidereal century (100 sidereal years) to the simulation time.
void increaseTimeSpeed()
Increase the time speed.
void addSolarDays(double d)
Add a number of Earth Solar days to the current simulation time.
void setCurrentProjectionTypeKey(QString type)
Set the current ProjectionType to use from its key.
void setDefaultLocationID(const QString &id)
Set the location to use by default at startup.
void setMJDay(double MJD)
Set the current date in Modified Julian Day.
void setDeltaTCustomNDot(float v)
Set n-dot for custom equation for calculation of Delta-T.
Definition: StelCore.hpp:501
void increaseTimeSpeedLess()
Increase the time speed, but not as much as with increaseTimeSpeed()
void subtractSiderealDay()
Subtract one sidereal day to the simulation time.
void locationChanged(StelLocation)
This signal is emitted when the observer location has changed.
void subtractHour()
Subtract one [Earth, solar] hour to the current simulation time.
bool getRealTimeSpeed() const
Get whether it is real time speed, i.e. 1 sec/sec.
QString getDefaultLocationID() const
Get the location used by default at startup.