Stellarium 0.12.1
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 
52 public:
55  enum FrameType
56  {
57  FrameUninitialized,
58  FrameAltAz,
59  FrameHeliocentricEcliptic,
60  FrameObservercentricEcliptic,
61  FrameEquinoxEqu,
62 
63  FrameJ2000,
64 
65  FrameGalactic
66  };
67 
69  enum ProjectionType
70  {
71  ProjectionPerspective,
72  ProjectionEqualArea,
73  ProjectionStereographic,
74  ProjectionFisheye,
75  ProjectionHammer,
76  ProjectionCylinder,
77  ProjectionMercator,
78  ProjectionOrthographic
79  };
80 
82  enum RefractionMode
83  {
84  RefractionAuto,
85  RefractionOn,
86  RefractionOff
87  };
88 
91  enum DeltaTAlgorithm
92  {
93  WithoutCorrection,
94  Schoch,
95  Clemence,
96  IAU,
97  AstronomicalEphemeris,
98  TuckermanGoldstine,
99  MullerStephenson,
100  Stephenson1978,
101  SchmadelZech1979,
102  MorrisonStephenson1982,
103  StephensonMorrison1984,
104  StephensonHoulden,
105  Espenak,
106  Borkowski,
107  SchmadelZech1988,
108  ChaprontTouze,
109  StephensonMorrison1995,
110  Stephenson1997,
111  ChaprontMeeus,
112  JPLHorizons,
113  MeeusSimons,
114  MontenbruckPfleger,
115  ReingoldDershowitz,
116  MorrisonStephenson2004,
117  Reijs,
118  EspenakMeeus,
119  Custom
120  };
121 
122  StelCore();
123  virtual ~StelCore();
124 
126  void init(class StelRenderer* renderer);
127 
130  void update(double deltaTime);
131 
133  void windowHasBeenResized(float x, float y, float width, float height);
134 
136  void preDraw();
137 
139  void postDraw(StelRenderer* renderer);
140 
143  StelProjectorP getProjection2d() const;
144 
147  StelProjectorP getProjection(FrameType frameType, RefractionMode refractionMode=RefractionAuto) const;
148 
151  StelProjectorP getProjection(StelProjector::ModelViewTranformP modelViewTransform, ProjectionType projType=(ProjectionType)1000) const;
152 
154  StelToneReproducer* getToneReproducer();
156  const StelToneReproducer* getToneReproducer() const;
157 
159  StelSkyDrawer* getSkyDrawer();
161  const StelSkyDrawer* getSkyDrawer() const;
162 
164  const StelGeodesicGrid* getGeodesicGrid(int maxLevel) const;
165 
167  StelMovementMgr* getMovementMgr();
169  const StelMovementMgr* getMovementMgr() const;
170 
172  void setClippingPlanes(double znear, double zfar);
174  void getClippingPlanes(double* zn, double* zf) const;
175 
177  QString projectionTypeKeyToNameI18n(const QString& key) const;
178 
180  QString projectionNameI18nToTypeKey(const QString& nameI18n) const;
181 
183  StelProjector::StelProjectorParams getCurrentStelProjectorParams() const;
185  void setCurrentStelProjectorParams(const StelProjector::StelProjectorParams& newParams);
186 
188  void lookAtJ2000(const Vec3d& pos, const Vec3d& up);
189 
190  Vec3d altAzToEquinoxEqu(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
191  Vec3d equinoxEquToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
192  Vec3d altAzToJ2000(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
193  Vec3d j2000ToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
194  Vec3d galacticToJ2000(const Vec3d& v) const;
195  Vec3d equinoxEquToJ2000(const Vec3d& v) const;
196  Vec3d j2000ToEquinoxEqu(const Vec3d& v) const;
197  Vec3d j2000ToGalactic(const Vec3d& v) const;
198 
200  Vec3d heliocentricEclipticToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const;
201 
203  Vec3d heliocentricEclipticToEquinoxEqu(const Vec3d& v) const;
206  Vec3d heliocentricEclipticToEarthPosEquinoxEqu(const Vec3d& v) const;
207 
209  StelProjector::ModelViewTranformP getHeliocentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
210 
212  StelProjector::ModelViewTranformP getObservercentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
213 
215  StelProjector::ModelViewTranformP getEquinoxEquModelViewTransform(RefractionMode refMode=RefractionAuto) const;
216 
218  StelProjector::ModelViewTranformP getAltAzModelViewTransform(RefractionMode refMode=RefractionAuto) const;
219 
221  StelProjector::ModelViewTranformP getJ2000ModelViewTransform(RefractionMode refMode=RefractionAuto) const;
222 
224  StelProjector::ModelViewTranformP getGalacticModelViewTransform(RefractionMode refMode=RefractionAuto) const;
225 
227  static const Mat4d matJ2000ToVsop87;
229  static const Mat4d matVsop87ToJ2000;
231  static const Mat4d matJ2000ToGalactic;
233  static const Mat4d matGalacticToJ2000;
234 
236  Vec3d getObserverHeliocentricEclipticPos() const;
237 
239  const StelLocation& getCurrentLocation() const;
240 
241  const QSharedPointer<class Planet> getCurrentPlanet() const;
242 
248  void moveObserverTo(const StelLocation& target, double duration=1., double durationIfPlanetChange=1.);
249 
250  // Conversion in standar Julian time format
251  static const double JD_SECOND;
252  static const double JD_MINUTE;
253  static const double JD_HOUR;
254  static const double JD_DAY;
255 
258  double getLocalSideralTime() const;
259 
261  double getLocalSideralDayLength() const;
262 
264  QString getStartupTimeMode();
265  void setStartupTimeMode(const QString& s);
266 
271  double getDeltaT(double jDay) const;
272 
277  QString getCurrentDeltaTAlgorithmValidRange(double jDay, QString* marker) const;
278 
279 public slots:
281  void setCurrentProjectionType(ProjectionType type);
282  ProjectionType getCurrentProjectionType() const;
283 
285  QString getCurrentProjectionTypeKey(void) const;
287  void setCurrentProjectionTypeKey(QString type);
288 
290  QStringList getAllProjectionTypeKeys() const;
291 
293  void setCurrentDeltaTAlgorithm(DeltaTAlgorithm algorithm) { currentDeltaTAlgorithm=algorithm; }
295  DeltaTAlgorithm getCurrentDeltaTAlgorithm() const { return currentDeltaTAlgorithm; }
297  QString getCurrentDeltaTAlgorithmDescription(void) const;
299  QString getCurrentDeltaTAlgorithmKey(void) const;
301  void setCurrentDeltaTAlgorithmKey(QString type);
302 
305 
308  void setFlagGravityLabels(bool gravity);
310  void setDefautAngleForGravityText(float a);
313  void setFlipHorz(bool flip);
316  void setFlipVert(bool flip);
319  bool getFlipHorz(void) const;
322  bool getFlipVert(void) const;
323 
325  QString getDefaultLocationID() const;
327  void setDefaultLocationID(const QString& id);
331  void returnToHome();
332 
334  void setJDay(double JD);
336  double getJDay() const;
337 
339  void setMJDay(double MJD);
341  double getMJDay() const;
342 
344  double getPresetSkyTime() const;
346  void setPresetSkyTime(double d);
347 
349  void setTimeRate(double ts);
351  double getTimeRate() const;
352 
354  void increaseTimeSpeed();
356  void decreaseTimeSpeed();
358  void increaseTimeSpeedLess();
360  void decreaseTimeSpeedLess();
361 
363  void setZeroTimeSpeed();
365  void setRealTimeSpeed();
367  void toggleRealTimeSpeed();
369  bool getRealTimeSpeed() const;
370 
372  void setTimeNow();
374  void setTodayTime(const QTime& target);
376  bool getIsTimeNow() const;
377 
379  QTime getInitTodayTime(void);
381  void setInitTodayTime(const QTime& t);
383  void setPresetSkyTime(QDateTime dt);
384 
386  void addHour();
388  void addDay();
390  void addWeek();
391 
394  void addSiderealDay();
397  void addSiderealWeek();
401  void addSiderealMonth();
405  void addSiderealYear();
409  void addSiderealCentury();
410 
412  void subtractHour();
414  void subtractDay();
416  void subtractWeek();
417 
420  void subtractSiderealDay();
423  void subtractSiderealWeek();
427  void subtractSiderealMonth();
431  void subtractSiderealYear();
436 
438  void addSynodicMonth();
439 
441  void addDraconicYear();
443  void addDraconicMonth();
444 
446  void addAnomalisticMonth();
447 
449  void addTropicalMonth();
451  void addTropicalYear();
453  void addTropicalCentury();
454 
456  void subtractSynodicMonth();
457 
459  void subtractDraconicYear();
461  void subtractDraconicMonth();
462 
465 
467  void subtractTropicalMonth();
469  void subtractTropicalYear();
472 
475  void addSolarDays(double d);
479  void addSiderealDays(double d);
480 
483  void moveObserverToSelected();
484 
487  void setCustomYear(float y) { customYear=y; }
490  void setCustomNDot(float v) { customNDot=v; }
493  void setCustomEquationCoefficients(Vec3f c) { customEquationCoeff=c; }
494 
496  float getCustomYear() const { return customYear; }
498  float getCustomNDot() const { return customNDot; }
500  Vec3f getCustomEquationCoefficients() const { return customEquationCoeff; }
501 
502 signals:
506  void timeRateChanged(double rate);
507 
508 private:
509  StelToneReproducer* toneConverter; // Tones conversion between stellarium world and display device
510  StelSkyDrawer* skyDrawer;
511  StelMovementMgr* movementMgr; // Manage vision movements
512 
513  // Manage geodesic grid
514  mutable StelGeodesicGrid* geodesicGrid;
515 
516  // The currently used projection type
517  ProjectionType currentProjectionType;
518 
519  // The currentrly used time correction (DeltaT)
520  DeltaTAlgorithm currentDeltaTAlgorithm;
521 
522  // Parameters to use when creating new instances of StelProjector
523  StelProjector::StelProjectorParams currentProjectorParams;
524 
525  void updateTransformMatrices();
526  void updateTime(double deltaTime);
527 
528  // Matrices used for every coordinate transfo
529  Mat4d matHeliocentricEclipticToAltAz; // Transform from heliocentric ecliptic (Vsop87) to observer-centric altazimuthal coordinate
530  Mat4d matAltAzToHeliocentricEcliptic; // Transform from observer-centric altazimuthal coordinate to heliocentric ecliptic (Vsop87)
531  Mat4d matAltAzToEquinoxEqu; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
532  Mat4d matEquinoxEquToAltAz; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
533  Mat4d matHeliocentricEclipticToEquinoxEqu; // Transform from heliocentric ecliptic (Vsop87) to earth equatorial coordinate
534  Mat4d matEquinoxEquToJ2000;
535  Mat4d matJ2000ToEquinoxEqu;
536  Mat4d matJ2000ToAltAz;
537 
538  Mat4d matAltAzModelView; // Modelview matrix for observer-centric altazimuthal drawing
539  Mat4d invertMatAltAzModelView; // Inverted modelview matrix for observer-centric altazimuthal drawing
540 
541  // Position variables
542  StelObserver* position;
543  // The ID of the default startup location
544  QString defaultLocationID;
545 
546  // Time variables
547  double timeSpeed; // Positive : forward, Negative : Backward, 1 = 1sec/sec
548  double JDay; // Curent time in Julian day
549  double presetSkyTime;
550  QTime initTodayTime;
551  QString startupTimeMode;
552 
553  // Variables for custom equation of Delta-T
554  Vec3f customEquationCoeff;
555  float customNDot;
556  float customYear;
557 
558 };
559 
560 #endif // _STELCORE_HPP_