Stellarium 0.15.2
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 StelMainView;
34 class StelSkyCultureMgr;
35 class StelViewportEffect;
36 class QOpenGLFramebufferObject;
37 class QOpenGLFunctions;
38 class QSettings;
39 class QNetworkAccessManager;
40 class QNetworkReply;
41 class QTimer;
42 class StelLocationMgr;
43 class StelSkyLayerMgr;
44 class StelAudioMgr;
45 class StelVideoMgr;
46 class StelGuiBase;
48 class StelScriptMgr;
49 class StelActionMgr;
50 class StelPropertyMgr;
52 
53 #ifdef ENABLE_SPOUT
54 class SpoutSender;
55 #endif
56 
68 class StelApp : public QObject
69 {
70  Q_OBJECT
71  Q_PROPERTY(bool nightMode READ getVisionModeNight WRITE setVisionModeNight NOTIFY visionNightModeChanged)
72 
73 public:
74  friend class StelAppGraphicsWidget;
75  friend class StelRootItem;
76 
82  StelApp(StelMainView* parent);
83 
85  virtual ~StelApp();
86 
88  void init(QSettings* conf);
90  void deinit();
91 
93  void initPlugIns();
94 
96  void initScriptMgr();
97 
100  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
101 
104  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
105 
108  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
109 
112  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
113 
116  StelTextureMgr& getTextureManager() {return *textureMgr;}
117 
120  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
121 
124  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
125 
126  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
127 
129  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
130 
132  StelActionMgr* getStelActionManager() {return actionMgr;}
133 
136 
138  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
139 
143  StelCore* getCore() {return core;}
144 
146  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
147 
149  void updateI18n();
150 
152  QSettings* getSettings() {return confSettings;}
153 
155  QString getCurrentStelStyle() {return "color";}
156 
158  void update(double deltaTime);
159 
161  // 2014-11: OLD COMMENT? What does a void return?
162  // @return the max squared distance in pixels that any object has travelled since the last update.
163  void draw();
164 
167  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
168  void setDevicePixelsPerPixel(float dppp);
169 
173  float getGlobalScalingRatio() const {return globalScalingRatio;}
174  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
175 
177  int getBaseFontSize() const { return baseFontSize; }
178  void setBaseFontSize(int s) { baseFontSize=s; }
179 
181  StelGuiBase* getGui() const {return stelGui;}
184  void setGui(StelGuiBase* b) {stelGui=b;}
185 
186 #ifndef DISABLE_SCRIPTING
187  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
190  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
191 #endif
192 
193  static void initStatic();
194  static void deinitStatic();
195 
200  void removeProgressBar(StelProgressController* p);
201 
204  void setViewportEffect(const QString& effectName);
206  QString getViewportEffect() const;
207 
210 
212  // Scriptable methods
213 public slots:
215  void glWindowHasBeenResized(const QRectF &rect);
216 
218  void setVisionModeNight(bool);
220  bool getVisionModeNight() const {return flagNightVision;}
221 
223  void setFlagShowDecimalDegrees(bool b);
225  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
226 
228  bool getFlagSouthAzimuthUsage() const { return flagUseAzimuthFromSouth; }
230  void setFlagSouthAzimuthUsage(bool use) { flagUseAzimuthFromSouth=use; }
231 
238 
239 
242  float getFps() const {return fps;}
243 
248  quint32 getDefaultFBO() const { return currentFbo; }
249 
253  void ensureGLContextCurrent();
254 
256  static double getTotalRunTime();
257 
259  static double getAnimationTime();
260 
263  void reportFileDownloadFinished(QNetworkReply* reply);
264 
266  void quit();
267 signals:
268  void visionNightModeChanged(bool);
269  void colorSchemeChanged(const QString&);
270  void languageChanged();
271 
277  void aboutToQuit();
278 private:
279 
281  void handleClick(class QMouseEvent* event);
283  void handleWheel(class QWheelEvent* event);
285  bool handleMove(float x, float y, Qt::MouseButtons b);
287  void handleKeys(class QKeyEvent* event);
289  void handlePinch(qreal scale, bool started);
290 
292  void prepareRenderBuffer();
295  void applyRenderBuffer(quint32 drawFbo=0);
296 
297  // The StelApp singleton
298  static StelApp* singleton;
299 
301  StelMainView* mainWin;
302 
303  // The associated StelCore instance
304  StelCore* core;
305 
306  // Module manager for the application
307  StelModuleMgr* moduleMgr;
308 
309  // Locale manager for the application
310  StelLocaleMgr* localeMgr;
311 
312  // Sky cultures manager for the application
313  StelSkyCultureMgr* skyCultureMgr;
314 
315  //Actions manager fot the application. Will replace shortcutMgr.
316  StelActionMgr* actionMgr;
317 
318  //Property manager for the application
319  StelPropertyMgr* propMgr;
320 
321  // Textures manager for the application
322  StelTextureMgr* textureMgr;
323 
324  // Manager for all the StelObjects of the program
325  StelObjectMgr* stelObjectMgr;
326 
327  // Manager for the list of observer locations on planets
328  StelLocationMgr* planetLocationMgr;
329 
330  // Main network manager used for the program
331  QNetworkAccessManager* networkAccessManager;
332 
334  void setupNetworkProxy();
335 
336  // The audio manager. Must execute in the main thread.
337  StelAudioMgr* audioMgr;
338 
339  // The video manager. Must execute in the main thread.
340  StelVideoMgr* videoMgr;
341 
342  StelSkyLayerMgr* skyImageMgr;
343 
344 #ifndef DISABLE_SCRIPTING
345  // The script API proxy object (for bridging threads)
346  StelMainScriptAPIProxy* scriptAPIProxy;
347 
348  // The script manager based on Qt script engine
349  StelScriptMgr* scriptMgr;
350 #endif
351 
352 
353 
354  StelGuiBase* stelGui;
355 
356  // Store the ratio between real device pixel in "Device Independent Pixel"
357  // Usually this value is 1, but for a mac with retina screen this will be value 2.
358  float devicePixelsPerPixel;
359 
360  // The scaling ratio to apply on all display elements, like GUI, text etc..
361  float globalScalingRatio;
362 
363  // Used to collect wheel events
364  QTimer * wheelEventTimer;
365 
366  // Accumulated horizontal and vertical wheel event deltas
367  int wheelEventDelta[2];
368 
369  float fps;
370  int frame;
371  double frameTimeAccum; // Used for fps counter
372 
374  bool flagNightVision;
375 
376  QSettings* confSettings;
377 
378  // Define whether the StelApp instance has completed initialization
379  bool initialized;
380 
381  static qint64 startMSecs;
382  static float animationScale;
383 
384  // Temporary variables used to store the last gl window resize
385  // if the core was not yet initialized
386  int saveProjW;
387  int saveProjH;
388 
390  int nbDownloadedFiles;
392  qint64 totalDownloadedSize;
393 
395  int nbUsedCache;
397  qint64 totalUsedCacheSize;
398 
399  QList<StelProgressController*> progressControllers;
400 
401  int baseFontSize;
402 
403  // Framebuffer object used for viewport effects.
404  QOpenGLFramebufferObject* renderBuffer;
405  StelViewportEffect* viewportEffect;
406  QOpenGLFunctions* gl;
407 
408  bool flagShowDecimalDegrees;
409  // flag to indicate we want calculate azimuth from south towards west (as in old astronomical literature)
410  bool flagUseAzimuthFromSouth;
411 #ifdef ENABLE_SPOUT
412  SpoutSender* spoutSender;
413 #endif
414 
415  // The current main FBO/render target handle, without requiring GL queries. Valid through a draw() call
416  quint32 currentFbo;
417 
418 };
419 
420 #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:230
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:190
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:120
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:138
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:225
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:228
bool getFlagOldAzimuthUsage() const
Set flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:234
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:177
void setFlagOldAzimuthUsage(bool use)
Get flag for using calculation of azimuth from south towards west (as in older astronomical literatur...
Definition: StelApp.hpp:237
void glWindowHasBeenResized(const QRectF &rect)
Call this when the size of the GL window has changed.
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:242
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:124
static double getAnimationTime()
Return the scaled time for animated objects.
StelPropertyMgr * getStelPropertyManager()
Return the property manager.
Definition: StelApp.hpp:135
void ensureGLContextCurrent()
Makes sure the correct GL context used for main drawing is made current.
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:104
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:116
void deinit()
Deinitialize core and all the modules.
Manage the list of available location.
StelApp(StelMainView *parent)
Create and initialize the main Stellarium application.
QNetworkAccessManager * getNetworkAccessManager()
Get the common instance of QNetworkAccessManager used in stellarium.
Definition: StelApp.hpp:146
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:155
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:188
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI is currently being used.
Definition: StelApp.hpp:184
void initPlugIns()
Load and initialize external modules (plugins)
Helper class to send rendered frames to Spout (http://spout.zeal.co/)
Definition: SpoutSender.hpp:28
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:132
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:173
void quit()
do some cleanup and call QCoreApplication::exit(0)
Reimplement a QGraphicsView for Stellarium.
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:129
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:167
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 ...
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:100
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:112
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:152
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:181
quint32 getDefaultFBO() const
Returns the default FBO handle, to be used when StelModule instances want to release their own FBOs...
Definition: StelApp.hpp:248
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:68
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:143
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:108
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:220