Stellarium 0.90.0
StelApp.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 Fabien Chereau
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 _STELAPP_HPP_
21 #define _STELAPP_HPP_
22 
23 #include <QString>
24 #include <QObject>
25 #include "StelModule.hpp"
26 
27 // Predeclaration of some classes
28 class StelCore;
29 class StelTextureMgr;
30 class StelObjectMgr;
31 class StelLocaleMgr;
32 class StelModuleMgr;
33 class StelSkyCultureMgr;
34 class StelViewportEffect;
35 class QOpenGLFramebufferObject;
36 class QSettings;
37 class QNetworkAccessManager;
38 class QNetworkReply;
39 class QTimer;
40 class StelLocationMgr;
41 class StelSkyLayerMgr;
42 class StelAudioMgr;
43 class StelVideoMgr;
44 class StelGuiBase;
46 class StelScriptMgr;
47 class StelActionMgr;
48 class StelPropertyMgr;
50 
62 class StelApp : public QObject
63 {
64  Q_OBJECT
65  Q_PROPERTY(bool nightMode READ getVisionModeNight WRITE setVisionModeNight NOTIFY visionNightModeChanged)
66 
67 public:
68  friend class StelAppGraphicsWidget;
69  friend class StelSkyItem;
70 
76  StelApp(QObject* parent=NULL);
77 
79  virtual ~StelApp();
80 
82  void init(QSettings* conf);
84  void deinit();
85 
87  void initPlugIns();
88 
90  void initScriptMgr();
91 
94  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
95 
98  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
99 
102  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
103 
106  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
107 
110  StelTextureMgr& getTextureManager() {return *textureMgr;}
111 
114  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
115 
118  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
119 
120  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
121 
123  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
124 
126  StelActionMgr* getStelActionManager() {return actionMgr;}
127 
130 
132  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
133 
137  StelCore* getCore() {return core;}
138 
140  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
141 
143  void updateI18n();
144 
146  QSettings* getSettings() {return confSettings;}
147 
149  QString getCurrentStelStyle() {return "color";}
150 
152  void update(double deltaTime);
153 
155  // 2014-11: OLD COMMENT? What does a void return?
156  // @return the max squared distance in pixels that any object has travelled since the last update.
157  void draw();
158 
160  void glWindowHasBeenResized(float x, float y, float w, float h);
161 
164  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
165  void setDevicePixelsPerPixel(float dppp);
166 
170  float getGlobalScalingRatio() const {return globalScalingRatio;}
171  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
172 
174  int getBaseFontSize() const { return baseFontSize; }
175  void setBaseFontSize(int s) { baseFontSize=s; }
176 
178  StelGuiBase* getGui() const {return stelGui;}
181  void setGui(StelGuiBase* b) {stelGui=b;}
182 
183 #ifndef DISABLE_SCRIPTING
184  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
187  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
188 #endif
189 
190  static void initStatic();
191  static void deinitStatic();
192 
197  void removeProgressBar(StelProgressController* p);
198 
201  void setViewportEffect(const QString& effectName);
203  QString getViewportEffect() const;
204 
207 
209  // Scriptable methods
210 public slots:
211 
213  void setVisionModeNight(bool);
215  bool getVisionModeNight() const {return flagNightVision;}
216 
218  void setFlagShowDecimalDegrees(bool b);
220  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
221 
223  bool getFlagSouthAzimuthUsage() const { return flagUseAzimuthFromSouth; }
225  void setFlagSouthAzimuthUsage(bool use) { flagUseAzimuthFromSouth=use; }
226 
233 
234 
237  float getFps() const {return fps;}
238 
240  static double getTotalRunTime();
241 
243  static double getAnimationTime();
244 
247  void reportFileDownloadFinished(QNetworkReply* reply);
248 
250  void quit();
251 signals:
252  void visionNightModeChanged(bool);
253  void colorSchemeChanged(const QString&);
254  void languageChanged();
255 
261  void aboutToQuit();
262 
263 private:
264 
266  void handleClick(class QMouseEvent* event);
268  void handleWheel(class QWheelEvent* event);
270  void handleMove(float x, float y, Qt::MouseButtons b);
272  void handleKeys(class QKeyEvent* event);
274  void handlePinch(qreal scale, bool started);
275 
277  void prepareRenderBuffer();
280  void applyRenderBuffer(int drawFbo=0);
281 
282  // The StelApp singleton
283  static StelApp* singleton;
284 
285  // The associated StelCore instance
286  StelCore* core;
287 
288  // Module manager for the application
289  StelModuleMgr* moduleMgr;
290 
291  // Locale manager for the application
292  StelLocaleMgr* localeMgr;
293 
294  // Sky cultures manager for the application
295  StelSkyCultureMgr* skyCultureMgr;
296 
297  //Actions manager fot the application. Will replace shortcutMgr.
298  StelActionMgr* actionMgr;
299 
300  //Property manager for the application
301  StelPropertyMgr* propMgr;
302 
303  // Textures manager for the application
304  StelTextureMgr* textureMgr;
305 
306  // Manager for all the StelObjects of the program
307  StelObjectMgr* stelObjectMgr;
308 
309  // Manager for the list of observer locations on planets
310  StelLocationMgr* planetLocationMgr;
311 
312  // Main network manager used for the program
313  QNetworkAccessManager* networkAccessManager;
314 
316  void setupNetworkProxy();
317 
318  // The audio manager. Must execute in the main thread.
319  StelAudioMgr* audioMgr;
320 
321  // The video manager. Must execute in the main thread.
322  StelVideoMgr* videoMgr;
323 
324  StelSkyLayerMgr* skyImageMgr;
325 
326 #ifndef DISABLE_SCRIPTING
327  // The script API proxy object (for bridging threads)
328  StelMainScriptAPIProxy* scriptAPIProxy;
329 
330  // The script manager based on Qt script engine
331  StelScriptMgr* scriptMgr;
332 #endif
333 
334 
335 
336  StelGuiBase* stelGui;
337 
338  // Store the ratio between real device pixel in "Device Independent Pixel"
339  // Usually this value is 1, but for a mac with retina screen this will be value 2.
340  float devicePixelsPerPixel;
341 
342  // The scaling ratio to apply on all display elements, like GUI, text etc..
343  float globalScalingRatio;
344 
345  // Used to collect wheel events
346  QTimer * wheelEventTimer;
347 
348  // Accumulated horizontal and vertical wheel event deltas
349  int wheelEventDelta[2];
350 
351  float fps;
352  int frame;
353  double timefr, timeBase; // Used for fps counter
354 
356  bool flagNightVision;
357 
358  QSettings* confSettings;
359 
360  // Define whether the StelApp instance has completed initialization
361  bool initialized;
362 
363  static qint64 startMSecs;
364  static float animationScale;
365 
366  // Temporary variables used to store the last gl window resize
367  // if the core was not yet initialized
368  int saveProjW;
369  int saveProjH;
370 
372  int nbDownloadedFiles;
374  qint64 totalDownloadedSize;
375 
377  int nbUsedCache;
379  qint64 totalUsedCacheSize;
380 
381  QList<StelProgressController*> progressControllers;
382 
383  int baseFontSize;
384 
385  // Framebuffer object used for viewport effects.
386  QOpenGLFramebufferObject* renderBuffer;
387 
388  StelViewportEffect* viewportEffect;
389 
390  bool flagShowDecimalDegrees;
391  // flag to indicate we want calculate azimuth from south towards west (as in old astronomical literature)
392  bool flagUseAzimuthFromSouth;
393 
394 };
395 
396 #endif // _STELAPP_HPP_
Manage the sky background images, including DSS and deep sky objects images.
void setFlagSouthAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (instead north towards east) ...
Definition: StelApp.hpp:225
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:187
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:114
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:132
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:220
A scriptable way to show videos embedded in the screen.
void reportFileDownloadFinished(QNetworkReply *reply)
Report that a download occured.
bool getFlagSouthAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (instead north towards east) ...
Definition: StelApp.hpp:223
bool getFlagOldAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:229
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:174
void setFlagOldAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:232
void dumpModuleActionPriorities(StelModule::StelModuleActionName actionName)
Dump diagnostics about action call priorities.
float getFps() const
Get the current number of frame per second.
Definition: StelApp.hpp:237
void progressBarRemoved(const StelProgressController *)
Called just before a progress bar is removed.
void initScriptMgr()
Registers all loaded StelModules with the ScriptMgr, and queues starting of the startup script...
StelObjectMgr & getStelObjectMgr()
Get the StelObject manager to use for querying from all stellarium objects.
Definition: StelApp.hpp:118
static double getAnimationTime()
Return the scaled time for animated objects.
StelPropertyMgr * getStelPropertyManager()
Return the property manager.
Definition: StelApp.hpp:129
Manage i18n operations such as message translation and date/time localization.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Because the core API runs in a different thread to the main program, direct function calls to some cl...
StelModuleMgr & getModuleMgr()
Get the module manager to use for accessing any module loaded in the application. ...
Definition: StelApp.hpp:98
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:110
void deinit()
Deinitialize core and all the modules.
Manage the list of available location.
QNetworkAccessManager * getNetworkAccessManager()
Get the common instance of QNetworkAccessManager used in stellarium.
Definition: StelApp.hpp:140
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:149
void progressBarAdded(const StelProgressController *)
Called just after a progress bar is added.
Abstract class defining the base interface for all GUIs.
Definition: StelGuiBase.hpp:30
StelMainScriptAPIProxy * getMainScriptAPIProxy()
Get the script API proxy (for signal handling)
Definition: StelApp.hpp:185
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI si currently being used.
Definition: StelApp.hpp:181
void initPlugIns()
Load and initialize external modules (plugins)
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:126
void draw()
Draw all registered StelModule in the order defined by the order lists.
void update(double deltaTime)
Update all object according to the deltaTime in seconds.
Allow to apply visual effects on the whole Stellarium viewport.
Manage a collection of StelModules including both core and plugin modules.
QString getViewportEffect() const
Get the type of viewport effect currently used.
void updateI18n()
Update translations, font for GUI and sky everywhere in the program.
Manages the registration of specific object properties with the StelProperty system.
float getGlobalScalingRatio() const
Get the scaling ratio to apply on all display elements, like GUI, text etc.
Definition: StelApp.hpp:170
StelApp(QObject *parent=NULL)
Create and initialize the main Stellarium application.
void quit()
do some cleanup and call QCoreApplication::exit(0)
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:123
Manage the selection and queries on one or more StelObjects.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
Manage scripting in Stellarium.
float getDevicePixelsPerPixel() const
Get the ratio between real device pixel and "Device Independent Pixel".
Definition: StelApp.hpp:164
Manage textures loading.
Maintain the state of a progress bar.
Manage sky cultures for stellarium.
void setVisionModeNight(bool)
Set flag for activating night vision mode.
Manager for StelAction instances. Allows registration of new actions, and finding an existing one by ...
void glWindowHasBeenResized(float x, float y, float w, float h)
Call this when the size of the GL window has changed.
static double getTotalRunTime()
Return the time since when stellarium is running in second.
void setViewportEffect(const QString &effectName)
Define the type of viewport effect to use.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:94
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:106
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:146
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:178
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:62
StelProgressController * addProgressBar()
Add a progression indicator to the GUI (if applicable).
void aboutToQuit()
Called just before we exit Qt mainloop.
StelCore * getCore()
Get the core of the program.
Definition: StelApp.hpp:137
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:102
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:215