Stellarium 0.15.0
LandscapeMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 Fabien Chereau
4  * Copyright (C) 2010 Bogdan Marinov (add/remove landscapes feature)
5  * Copyright (C) 2012 Timothy Reaves
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
20  */
21 
22 #ifndef _LANDSCAPEMGR_HPP_
23 #define _LANDSCAPEMGR_HPP_
24 
25 #include "StelModule.hpp"
26 #include "StelUtils.hpp"
27 #include "Landscape.hpp"
28 
29 #include <QMap>
30 #include <QStringList>
31 
32 class Atmosphere;
33 class Cardinals;
34 class QSettings;
35 
41 class LandscapeMgr : public StelModule
42 {
43  Q_OBJECT
44  Q_PROPERTY(bool atmosphereDisplayed
46  WRITE setFlagAtmosphere
47  NOTIFY atmosphereDisplayedChanged)
48  Q_PROPERTY(bool cardinalsPointsDisplayed
51  NOTIFY cardinalsPointsDisplayedChanged)
52  Q_PROPERTY(bool fogDisplayed
53  READ getFlagFog
54  WRITE setFlagFog
55  NOTIFY fogDisplayedChanged)
56  Q_PROPERTY(bool landscapeDisplayed
57  READ getFlagLandscape
58  WRITE setFlagLandscape
59  NOTIFY landscapeDisplayedChanged)
60  Q_PROPERTY(bool illuminationDisplayed
63  NOTIFY illuminationDisplayedChanged)
64  Q_PROPERTY(bool labelsDisplayed
65  READ getFlagLabels
66  WRITE setFlagLabels
67  NOTIFY labelsDisplayedChanged)
68  Q_PROPERTY(bool databaseUsage
71  NOTIFY lightPollutionUsageChanged)
72 
73 public:
74  LandscapeMgr();
75  virtual ~LandscapeMgr();
76 
78  // Methods defined in the StelModule class
83  virtual void init();
84 
86  virtual void draw(StelCore* core);
87 
95  virtual void update(double deltaTime);
96 
98  virtual double getCallOrder(StelModuleActionName actionName) const;
99 
101  // Methods specific to the landscape manager
102 
105  bool loadLandscape(QMap<QString, QString>& param);
106 
115  Landscape* createFromFile(const QString& landscapeFile, const QString& landscapeId);
116 
117  // GZ: implement StelModule's method. For test purposes only, we implement a manual transparency sampler.
118  // TODO: comment this away for final builds. Please leave it in until this feature is finished.
119  // virtual void handleMouseClicks(class QMouseEvent*);
120 
121 public slots:
123  // Methods callable from scripts and GUI
127  float getLuminance() const;
129  float getAtmosphereAverageLuminance() const;
130 
137  void setAtmosphereAverageLuminance(const float overrideLuminance);
138 
142  QStringList getAllLandscapeNames() const;
143 
147  QStringList getAllLandscapeIDs() const;
148 
152  QStringList getUserLandscapeIDs() const;
153 
155  const QString& getCurrentLandscapeID() const {return currentLandscapeID;}
160  bool setCurrentLandscapeID(const QString& id, const double changeLocationDuration = 1.0);
161 
163  QString getCurrentLandscapeName() const;
167  bool setCurrentLandscapeName(const QString& name, const double changeLocationDuration = 1.0);
168 
170  Landscape* getCurrentLandscape() const { return landscape; }
171 
173  const QString& getDefaultLandscapeID() const {return defaultLandscapeID;}
177  bool setDefaultLandscapeID(const QString& id);
178 
180  QString getCurrentLandscapeHtmlDescription() const;
181 
183  QString getDescription() const;
184 
186  bool getFlagLandscape() const;
188  void setFlagLandscape(const bool displayed);
189 
191  bool getIsLandscapeFullyVisible() const;
193  float getLandscapeSinMinAltitudeLimit() const;
194 
196  bool getFlagFog() const;
198  void setFlagFog(const bool displayed);
200  bool getFlagIllumination() const;
202  void setFlagIllumination(const bool on);
204  bool getFlagLabels() const;
206  void setFlagLabels(const bool on);
207 
209  bool getFlagLandscapeSetsLocation() const {return flagLandscapeSetsLocation;}
211  void setFlagLandscapeSetsLocation(bool b) {flagLandscapeSetsLocation=b;}
212 
214  bool getFlagLandscapeUseMinimalBrightness() const {return flagLandscapeUseMinimalBrightness; }
216  void setFlagLandscapeUseMinimalBrightness(bool b) {flagLandscapeUseMinimalBrightness=b; }
218  bool getFlagLandscapeSetsMinimalBrightness() const {return flagLandscapeSetsMinimalBrightness;}
220  void setFlagLandscapeSetsMinimalBrightness(bool b) {flagLandscapeSetsMinimalBrightness=b;}
222  double getDefaultMinimalBrightness() const {return defaultMinimalBrightness;}
224  void setDefaultMinimalBrightness(const double b) {defaultMinimalBrightness=b;}
226  void setFlagUseLightPollutionFromDatabase(const bool usage);
229 
231  bool getFlagCardinalsPoints() const;
233  void setFlagCardinalsPoints(const bool displayed);
234 
238  void setColorCardinalPoints(const Vec3f& v);
239 
241  bool getFlagAtmosphere() const;
243  void setFlagAtmosphere(const bool displayed);
244 
246  float getAtmosphereFadeDuration() const;
248  void setAtmosphereFadeDuration(const float f);
249 
251  void setAtmosphereBortleLightPollution(const int bIndex);
254 
259  void setZRotation(const float d);
260 
291  QString installLandscapeFromArchive(QString pathToSourceArchive, const bool display = false, const bool forAllUsers = false);
292 
293  /* GZ: leaving doc without the method confuses Doxygen. Commenting out completely.
311  //QString installLandscapeFromDirectory(QString pathToSourceLandscapeIni, bool display = false, bool forAllUsers = false);
312  */
313 
323  bool removeLandscape(const QString landscapeID);
324 
329  QString loadLandscapeName(const QString landscapeID);
330 
335  quint64 loadLandscapeSize(const QString landscapeID) const;
336 
338  bool getFlagLandscapeAutoSelection() const;
340  void setFlagLandscapeAutoSelection(bool enableAutoSelect);
341 
343  bool getFlagAtmosphereAutoEnable() const;
345  void setFlagAtmosphereAutoEnable(bool b);
346 
349  float getLandscapeOpacity(Vec3d azalt) const {return landscape->getOpacity(azalt);}
350  // This variant is required for scripting!
351  float getLandscapeOpacity(Vec3f azalt) const {return landscape->getOpacity(Vec3d(azalt[0], azalt[1], azalt[2]));}
355  float getLandscapeOpacity(float azimuth, float altitude) const {
356  Vec3d azalt;
357  StelUtils::spheToRect((180.0f-azimuth)*M_PI/180.0, altitude*M_PI/180.0, azalt);
358  return landscape->getOpacity(azalt);
359  }
360 
361 signals:
362  void atmosphereDisplayedChanged(const bool displayed);
363  void cardinalsPointsDisplayedChanged(const bool displayed);
364  void fogDisplayedChanged(const bool displayed);
365  void landscapeDisplayedChanged(const bool displayed);
366  void illuminationDisplayedChanged(const bool displayed);
367  void labelsDisplayedChanged(const bool displayed);
368  void lightPollutionUsageChanged(const bool usage);
369 
373  void landscapesChanged();
374 
376  void lightPollutionChanged();
377 
382  void errorUnableToOpen(QString path);
386  void errorNotArchive();
391  void errorNotUnique(QString nameOrID);
396  void errorRemoveManually(QString path);
397 
398 private slots:
400  void setStelStyle(const QString& section);
401 
403  void updateI18n();
404 
405 private:
407  float getAtmosphereLightPollutionLuminance() const;
409  void setAtmosphereLightPollutionLuminance(const float f);
410 
411 
415  QString nameToID(const QString& name) const;
416 
418  QMap<QString,QString> getNameToDirMap() const;
419 
424  QString getLandscapePath(const QString landscapeID) const;
425 
426  Atmosphere* atmosphere; // Atmosphere
427  Cardinals* cardinalsPoints; // Cardinals points
428  Landscape* landscape; // The landscape i.e. the fog, the ground and "decor"
429  Landscape* oldLandscape; // Used only during transitions to newly loaded landscape.
430 
431  // Define whether the observer location is to be updated when the landscape is updated.
432  bool flagLandscapeSetsLocation;
433 
434  bool flagLandscapeAutoSelection;
435 
436  bool flagLightPollutionFromDatabase;
437 
439  bool flagLandscapeUseMinimalBrightness;
441  float defaultMinimalBrightness;
443  bool flagLandscapeSetsMinimalBrightness;
445  bool flagAtmosphereAutoEnabling;
446 
447  // The ID of the currently loaded landscape
448  QString currentLandscapeID;
449 
450  // The ID of the default landscape
451  QString defaultLandscapeID;
452 
455  QStringList packagedLandscapeIDs;
456 
457 };
458 
459 #endif // _LANDSCAPEMGR_HPP_
void setFlagUseLightPollutionFromDatabase(const bool usage)
Sets the value of the flag usage light pollution (and bortle index) from locations database...
void setZRotation(const float d)
Set the rotation of the landscape about the z-axis.
void setFlagLandscape(const bool displayed)
Set flag for displaying Landscape.
float getAtmosphereFadeDuration() const
Get atmosphere fade duration in s.
bool loadLandscape(QMap< QString, QString > &param)
Load a landscape based on a hash of parameters mirroring the landscape.ini file and make it the curre...
QString installLandscapeFromArchive(QString pathToSourceArchive, const bool display=false, const bool forAllUsers=false)
Install a landscape from a ZIP archive.
QStringList getUserLandscapeIDs() const
Retrieve a list of the identifiers of all user-installed landscapes.
bool removeLandscape(const QString landscapeID)
This function removes a landscape from the user data directory.
Store and manages the displaying of the Landscape.
Definition: Landscape.hpp:62
void spheToRect(const double lng, const double lat, Vec3d &v)
Convert from spherical coordinates to Rectangular direction.
void errorNotArchive()
Emitted when the file passed to installLandscapeFromArchive() is not a ZIP archive or does not contai...
virtual void update(double deltaTime)
Update time-dependent state.
QString getCurrentLandscapeName() const
Get the current landscape name.
Compute and display the daylight sky color using openGL.
Definition: Atmosphere.hpp:39
void setAtmosphereBortleLightPollution(const int bIndex)
Set the light pollution following the Bortle Scale. Emits lightPollutionChanged().
void landscapesChanged()
Emitted when a landscape has been installed or un-installed.
float getLandscapeOpacity(Vec3d azalt) const
Forward opacity query to current landscape.
bool getFlagIllumination() const
Get flag for displaying illumination layer.
Vec3f getColorCardinalPoints() const
Get Cardinals Points color.
bool setCurrentLandscapeName(const QString &name, const double changeLocationDuration=1.0)
Change the current landscape to the landscape with the name specified.
Manages all the rendering at the level of the observer's surroundings.
bool getFlagUseLightPollutionFromDatabase() const
Return the value of flag usage light pollution (and bortle index) from locations database.
void setFlagFog(const bool displayed)
Set flag for displaying Fog.
Landscape * getCurrentLandscape() const
Get the current landscape object.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void setFlagLandscapeUseMinimalBrightness(bool b)
Set the value of the flag determining if a minimal brightness should be used to keep landscape visibl...
bool getFlagAtmosphereAutoEnable() const
Get flag for auto-enable of atmospheres for planets.
bool getFlagFog() const
Get flag for displaying Fog.
void setDefaultMinimalBrightness(const double b)
Set the minimal brightness value of the landscape.
QStringList getAllLandscapeNames() const
Retrieve a list of the names of all the available landscapes in the file search path sub-directories ...
bool getFlagLandscapeUseMinimalBrightness() const
Return the value of the flag determining if a minimal brightness should be used to keep landscape vis...
QStringList getAllLandscapeIDs() const
Retrieve a list of the identifiers of all the available landscapes in the file search path sub-direct...
bool getFlagLandscape() const
Get flag for displaying Landscape.
bool getFlagLabels() const
Get flag for displaying landscape labels.
void setFlagCardinalsPoints(const bool displayed)
Set flag for displaying Cardinals Points.
QString getDescription() const
Return a pseudo HTML formatted string with information from description or ini file.
float getLandscapeSinMinAltitudeLimit() const
Get the sine of current landscape's minimal altitude. Useful to construct bounding caps...
float getAtmosphereAverageLuminance() const
return average luminance [cd/m^2] of atmosphere. Expect 10 at sunset, 6400 in daylight, >0 in dark night.
bool setCurrentLandscapeID(const QString &id, const double changeLocationDuration=1.0)
Change the current landscape to the landscape with the ID specified.
float getLandscapeOpacity(float azimuth, float altitude) const
Forward opacity query to current landscape.
bool getFlagLandscapeAutoSelection() const
Get flag for autoselect of landscapes for planets.
void setFlagLandscapeSetsMinimalBrightness(bool b)
Sets the value of the flag determining if the minimal brightness should be taken from landscape...
quint64 loadLandscapeSize(const QString landscapeID) const
This function calculates and returns a landscape's disc size in bytes.
void setAtmosphereAverageLuminance(const float overrideLuminance)
Override autocomputed value and set average luminance [cd/m^2] of atmosphere.
void setFlagLandscapeSetsLocation(bool b)
Set the value of the flag determining if a change of landscape will update the observer location...
const QString & getDefaultLandscapeID() const
Get the default landscape ID.
double getDefaultMinimalBrightness() const
Return the minimal brightness value of the landscape.
const QString & getCurrentLandscapeID() const
Get the current landscape ID.
Landscape * createFromFile(const QString &landscapeFile, const QString &landscapeId)
Create a new landscape from the files which describe it.
bool getFlagLandscapeSetsLocation() const
Return the value of the flag determining if a change of landscape will update the observer location...
virtual double getCallOrder(StelModuleActionName actionName) const
Get the order in which this module will draw its objects relative to other modules.
void setFlagIllumination(const bool on)
Set flag for displaying illumination layer.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:117
void setFlagLabels(const bool on)
Set flag for displaying landscape labels.
QString loadLandscapeName(const QString landscapeID)
This function reads a landscape's name from its configuration file.
bool getFlagCardinalsPoints() const
Get flag for displaying Cardinals Points.
virtual void init()
Initialize the LandscapeManager class.
void errorNotUnique(QString nameOrID)
Emitted when installLandscapeFromArchive() tries to install a landscape with the same name or identif...
void setColorCardinalPoints(const Vec3f &v)
Set Cardinals Points color.
virtual float getOpacity(Vec3d azalt) const
Find opacity in a certain direction.
Definition: Landscape.hpp:164
void lightPollutionChanged()
emitted by setAtmosphereBortleLightPollution().
bool getFlagAtmosphere() const
Get flag for displaying Atmosphere.
void setFlagAtmosphereAutoEnable(bool b)
Set flag for auto-enable atmosphere for planets with atmospheres in location window.
void setFlagAtmosphere(const bool displayed)
Set flag for displaying Atmosphere.
void errorRemoveManually(QString path)
Emitted when removeLandscape() is unable to remove all the files of a landscape.
void setAtmosphereFadeDuration(const float f)
Set atmosphere fade duration in s.
void errorUnableToOpen(QString path)
Emitted when installLandscapeFromArchive() can't read from, write to or create a file or a directory...
bool getFlagLandscapeSetsMinimalBrightness() const
Return the value of the flag determining if the minimal brightness should be taken from landscape...
bool getIsLandscapeFullyVisible() const
Get whether the landscape is currently visible. If true, objects below landscape's limiting altitude ...
float getLuminance() const
Return the global landscape luminance [0..1], for being used e.g for setting eye adaptation.
virtual void draw(StelCore *core)
Draw the landscape graphics, cardinal points and atmosphere.
int getAtmosphereBortleLightPollution() const
Get the light pollution following the Bortle Scale.
QString getCurrentLandscapeHtmlDescription() const
Return a pseudo HTML formatted string with all informations on the current landscape.
bool setDefaultLandscapeID(const QString &id)
Change the default landscape to the landscape with the ID specified.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
void setFlagLandscapeAutoSelection(bool enableAutoSelect)
Set flag for autoselect of landscapes for planets.