Stellarium  0.16.1
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 
101  static QStringList getCommandlineArguments();
102 
105  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
106 
109  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
110 
113  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
114 
117  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
118 
121  StelTextureMgr& getTextureManager() {return *textureMgr;}
122 
125  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
126 
129  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
130 
131  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
132 
134  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
135 
137  StelActionMgr* getStelActionManager() {return actionMgr;}
138 
141 
143  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
144 
148  StelCore* getCore() {return core;}
149 
151  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
152 
154  void updateI18n();
155 
157  QSettings* getSettings() {return confSettings;}
158 
160  QString getCurrentStelStyle() {return "color";}
161 
163  void update(double deltaTime);
164 
166  // 2014-11: OLD COMMENT? What does a void return?
167  // @return the max squared distance in pixels that any object has travelled since the last update.
168  void draw();
169 
172  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
173  void setDevicePixelsPerPixel(float dppp);
174 
178  float getGlobalScalingRatio() const {return globalScalingRatio;}
179  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
180 
182  int getBaseFontSize() const { return baseFontSize; }
183  void setBaseFontSize(int s) { baseFontSize=s; }
184 
186  StelGuiBase* getGui() const {return stelGui;}
189  void setGui(StelGuiBase* b) {stelGui=b;}
190 
191 #ifndef DISABLE_SCRIPTING
192  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
195  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
196 #endif
197 
198  static void initStatic();
199  static void deinitStatic();
200 
205  void removeProgressBar(StelProgressController* p);
206 
209  void setViewportEffect(const QString& effectName);
211  QString getViewportEffect() const;
212 
215 
217  // Scriptable methods
218 public slots:
220  void glWindowHasBeenResized(const QRectF &rect);
221 
223  void setVisionModeNight(bool);
225  bool getVisionModeNight() const {return flagNightVision;}
226 
228  void setFlagShowDecimalDegrees(bool b);
230  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
231 
233  bool getFlagSouthAzimuthUsage() const { return flagUseAzimuthFromSouth; }
235  void setFlagSouthAzimuthUsage(bool use) { flagUseAzimuthFromSouth=use; }
236 
238  void setFlagUseFormattingOutput(bool b);
240  bool getFlagUseFormattingOutput() const {return flagUseFormattingOutput;}
241 
243  void setFlagUseCCSDesignation(bool b);
245  bool getFlagUseCCSDesignation() const {return flagUseCCSDesignation;}
246 
249  float getFps() const {return fps;}
250 
255  quint32 getDefaultFBO() const { return currentFbo; }
256 
260  void ensureGLContextCurrent();
261 
263  static double getTotalRunTime();
264 
266  static double getAnimationTime();
267 
270  void reportFileDownloadFinished(QNetworkReply* reply);
271 
273  void quit();
274 signals:
275  void visionNightModeChanged(bool);
276  void colorSchemeChanged(const QString&);
277  void languageChanged();
278 
284  void aboutToQuit();
285 private:
286 
288  void handleClick(class QMouseEvent* event);
290  void handleWheel(class QWheelEvent* event);
292  bool handleMove(float x, float y, Qt::MouseButtons b);
294  void handleKeys(class QKeyEvent* event);
296  void handlePinch(qreal scale, bool started);
297 
299  void prepareRenderBuffer();
302  void applyRenderBuffer(quint32 drawFbo=0);
303 
304  // The StelApp singleton
305  static StelApp* singleton;
306 
308  StelMainView* mainWin;
309 
310  // The associated StelCore instance
311  StelCore* core;
312 
313  // Module manager for the application
314  StelModuleMgr* moduleMgr;
315 
316  // Locale manager for the application
317  StelLocaleMgr* localeMgr;
318 
319  // Sky cultures manager for the application
320  StelSkyCultureMgr* skyCultureMgr;
321 
322  //Actions manager fot the application. Will replace shortcutMgr.
323  StelActionMgr* actionMgr;
324 
325  //Property manager for the application
326  StelPropertyMgr* propMgr;
327 
328  // Textures manager for the application
329  StelTextureMgr* textureMgr;
330 
331  // Manager for all the StelObjects of the program
332  StelObjectMgr* stelObjectMgr;
333 
334  // Manager for the list of observer locations on planets
335  StelLocationMgr* planetLocationMgr;
336 
337  // Main network manager used for the program
338  QNetworkAccessManager* networkAccessManager;
339 
341  void setupNetworkProxy();
342 
343  // The audio manager. Must execute in the main thread.
344  StelAudioMgr* audioMgr;
345 
346  // The video manager. Must execute in the main thread.
347  StelVideoMgr* videoMgr;
348 
349  StelSkyLayerMgr* skyImageMgr;
350 
351 #ifndef DISABLE_SCRIPTING
352  // The script API proxy object (for bridging threads)
353  StelMainScriptAPIProxy* scriptAPIProxy;
354 
355  // The script manager based on Qt script engine
356  StelScriptMgr* scriptMgr;
357 #endif
358 
359 
360 
361  StelGuiBase* stelGui;
362 
363  // Store the ratio between real device pixel in "Device Independent Pixel"
364  // Usually this value is 1, but for a mac with retina screen this will be value 2.
365  float devicePixelsPerPixel;
366 
367  // The scaling ratio to apply on all display elements, like GUI, text etc..
368  float globalScalingRatio;
369 
370  // Used to collect wheel events
371  QTimer * wheelEventTimer;
372 
373  // Accumulated horizontal and vertical wheel event deltas
374  int wheelEventDelta[2];
375 
376  float fps;
377  int frame;
378  double frameTimeAccum; // Used for fps counter
379 
381  bool flagNightVision;
382 
383  QSettings* confSettings;
384 
385  // Define whether the StelApp instance has completed initialization
386  bool initialized;
387 
388  static qint64 startMSecs;
389  static float animationScale;
390 
391  // Temporary variables used to store the last gl window resize
392  // if the core was not yet initialized
393  int saveProjW;
394  int saveProjH;
395 
397  int nbDownloadedFiles;
399  qint64 totalDownloadedSize;
400 
402  int nbUsedCache;
404  qint64 totalUsedCacheSize;
405 
406  QList<StelProgressController*> progressControllers;
407 
408  int baseFontSize;
409 
410  // Framebuffer object used for viewport effects.
411  QOpenGLFramebufferObject* renderBuffer;
412  StelViewportEffect* viewportEffect;
413  QOpenGLFunctions* gl;
414 
415  bool flagShowDecimalDegrees;
416  // flag to indicate we want calculate azimuth from south towards west (as in old astronomical literature)
417  bool flagUseAzimuthFromSouth;
418  bool flagUseFormattingOutput;
419  bool flagUseCCSDesignation;
420 #ifdef ENABLE_SPOUT
421  SpoutSender* spoutSender;
422 #endif
423 
424  // The current main FBO/render target handle, without requiring GL queries. Valid through a draw() call
425  quint32 currentFbo;
426 
427 };
428 
429 #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:235
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:195
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:125
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:143
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:230
A scriptable way to show videos embedded in the screen.
void setFlagUseFormattingOutput(bool b)
Set flag for using of formatting output for coordinates.
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:233
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:182
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:249
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:129
bool getFlagUseCCSDesignation() const
Get flag for using designations for celestial coordinate systems.
Definition: StelApp.hpp:245
static double getAnimationTime()
Return the scaled time for animated objects.
StelPropertyMgr * getStelPropertyManager()
Return the property manager.
Definition: StelApp.hpp:140
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:109
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:121
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:151
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:160
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:193
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI is currently being used.
Definition: StelApp.hpp:189
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:137
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:178
void quit()
do some cleanup and call QCoreApplication::exit(0)
Reimplement a QGraphicsView for Stellarium.
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:134
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:172
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.
bool getFlagUseFormattingOutput() const
Get flag for using of formatting output for coordinates.
Definition: StelApp.hpp:240
void setViewportEffect(const QString &effectName)
Define the type of viewport effect to use.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:105
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:117
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:157
void setFlagUseCCSDesignation(bool b)
Set flag for using designations for celestial coordinate systems.
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:186
quint32 getDefaultFBO() const
Returns the default FBO handle, to be used when StelModule instances want to release their own FBOs...
Definition: StelApp.hpp:255
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:68
static QStringList getCommandlineArguments()
Returns all arguments passed on the command line, together with the contents of the STEL_OPTS environ...
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:148
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:113
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:225