Stellarium 0.15.2
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 #include <QCache>
32 
33 class Atmosphere;
34 class Cardinals;
35 class QSettings;
36 
52 class LandscapeMgr : public StelModule
53 {
54  Q_OBJECT
55  Q_PROPERTY(bool atmosphereDisplayed
57  WRITE setFlagAtmosphere
58  NOTIFY atmosphereDisplayedChanged)
59  Q_PROPERTY(bool cardinalsPointsDisplayed
62  NOTIFY cardinalsPointsDisplayedChanged)
63  Q_PROPERTY(Vec3f cardinalsPointsColor
66  NOTIFY cardinalsPointsColorChanged)
67  Q_PROPERTY(bool fogDisplayed
68  READ getFlagFog
69  WRITE setFlagFog
70  NOTIFY fogDisplayedChanged)
71  Q_PROPERTY(bool landscapeDisplayed
72  READ getFlagLandscape
73  WRITE setFlagLandscape
74  NOTIFY landscapeDisplayedChanged)
75  Q_PROPERTY(bool illuminationDisplayed
78  NOTIFY illuminationDisplayedChanged)
79  Q_PROPERTY(bool labelsDisplayed
80  READ getFlagLabels
81  WRITE setFlagLabels
82  NOTIFY labelsDisplayedChanged)
83  Q_PROPERTY(bool flagUseLightPollutionFromDatabase // was databaseUsage
86  NOTIFY flagUseLightPollutionFromDatabaseChanged)
87  Q_PROPERTY(bool flagLandscapeAutoSelection
90  NOTIFY flagLandscapeAutoSelectionChanged)
91  Q_PROPERTY(bool flagLandscapeSetsLocation
94  NOTIFY flagLandscapeSetsLocationChanged)
95  Q_PROPERTY(bool flagLandscapeUseMinimalBrightness
98  NOTIFY flagLandscapeUseMinimalBrightnessChanged)
102  NOTIFY flagLandscapeSetsMinimalBrightnessChanged)
103  Q_PROPERTY(double defaultMinimalBrightness
106  NOTIFY defaultMinimalBrightnessChanged)
107  Q_PROPERTY(bool flagAtmosphereAutoEnabling
110  NOTIFY setFlagAtmosphereAutoEnableChanged)
111  Q_PROPERTY(QString currentLandscapeID
115 public:
116  LandscapeMgr();
117  virtual ~LandscapeMgr();
118 
120  // Methods defined in the StelModule class
125  virtual void init();
126 
128  virtual void draw(StelCore* core);
129 
137  virtual void update(double deltaTime);
138 
140  virtual double getCallOrder(StelModuleActionName actionName) const;
141 
143  // Methods specific to the landscape manager
144 
145  // Load a landscape based on a hash of parameters mirroring the landscape.ini
146  // file and make it the current landscape.
147  // GZ: This was declared, but not implemented(?)
148  //bool loadLandscape(QMap<QString, QString>& param);
149 
158  Landscape* createFromFile(const QString& landscapeFile, const QString& landscapeId);
159 
160  // GZ: implement StelModule's method. For test purposes only, we implement a manual transparency sampler.
161  // TODO: comment this away for final builds. Please leave it in until this feature is finished.
162  // virtual void handleMouseClicks(class QMouseEvent*);
163 
164 public slots:
166  // Methods callable from scripts and GUI
170  float getLuminance() const;
172  float getAtmosphereAverageLuminance() const;
173 
180  void setAtmosphereAverageLuminance(const float overrideLuminance);
181 
183  QMap<QString,QString> getNameToDirMap() const;
184 
188  QStringList getAllLandscapeNames() const;
189 
193  QStringList getAllLandscapeIDs() const;
194 
198  QStringList getUserLandscapeIDs() const;
199 
201  const QString getCurrentLandscapeID() const {return currentLandscapeID;}
207  bool setCurrentLandscapeID(const QString& id, const double changeLocationDuration = 1.0);
208 
210  QString getCurrentLandscapeName() const;
215  bool setCurrentLandscapeName(const QString& name, const double changeLocationDuration = 1.0);
216 
219  float getCurrentLandscapeBrightness(const bool light=false) const {return (light? landscape->getLightscapeBrightness() : landscape->getBrightness());}
220 
225  bool precacheLandscape(const QString& id, const bool replace=true);
229  bool removeCachedLandscape(const QString& id);
238  void setCacheSize(int mb) { landscapeCache.setMaxCost(mb);}
240  int getCacheSize() const {return landscapeCache.maxCost();}
242  int getCacheFilledSize() const {return landscapeCache.totalCost();}
244  int getCacheCount() const {return landscapeCache.count();}
245 
247  Landscape* getCurrentLandscape() const { return landscape; }
248 
250  const QString getDefaultLandscapeID() const {return defaultLandscapeID;}
254  bool setDefaultLandscapeID(const QString& id);
255 
257  QString getCurrentLandscapeHtmlDescription() const;
258 
260  QString getDescription() const;
261 
263  bool getFlagLandscape() const;
265  void setFlagLandscape(const bool displayed);
266 
268  bool getIsLandscapeFullyVisible() const;
270  float getLandscapeSinMinAltitudeLimit() const;
271 
273  bool getFlagFog() const;
275  void setFlagFog(const bool displayed);
277  bool getFlagIllumination() const;
279  void setFlagIllumination(const bool on);
281  bool getFlagLabels() const;
283  void setFlagLabels(const bool on);
284 
286  bool getFlagLandscapeSetsLocation() const {return flagLandscapeSetsLocation;}
288  void setFlagLandscapeSetsLocation(bool b) {if(b!=flagLandscapeSetsLocation){ flagLandscapeSetsLocation=b; emit flagLandscapeSetsLocationChanged(b);}}
289 
293  void setFlagLandscapeUseMinimalBrightness(bool b) {if(b!=flagLandscapeUseMinimalBrightness){ flagLandscapeUseMinimalBrightness=b; emit flagLandscapeUseMinimalBrightnessChanged(b);}}
297  void setFlagLandscapeSetsMinimalBrightness(bool b) {if(b!=flagLandscapeSetsMinimalBrightness){ flagLandscapeSetsMinimalBrightness=b; emit flagLandscapeSetsMinimalBrightnessChanged(b);}}
301  void setDefaultMinimalBrightness(const double b) {if(b!=defaultMinimalBrightness){ defaultMinimalBrightness=b; emit defaultMinimalBrightnessChanged(b);}}
303  void setFlagUseLightPollutionFromDatabase(const bool usage);
306 
308  bool getFlagCardinalsPoints() const;
310  void setFlagCardinalsPoints(const bool displayed);
311 
315  void setColorCardinalPoints(const Vec3f& v);
316 
318  bool getFlagAtmosphere() const;
320  void setFlagAtmosphere(const bool displayed);
321 
323  float getAtmosphereFadeDuration() const;
325  void setAtmosphereFadeDuration(const float f);
326 
327  /*
328  //This method has been removed, use StelSkyDrawer::getBortleScaleIndex instead, or StelMainScriptAPI::getBortleScaleIndex in scripts
329  //Also, if required, please use StelSkyDrawer::setBortleScaleIndex or StelMainScriptAPI::setBortleScaleIndex instead of LandscapeMgr::setAtmosphereBortleLightPollution
330  int getAtmosphereBortleLightPollution() const;
331  */
332 
337  void setZRotation(const float d);
338 
369  QString installLandscapeFromArchive(QString pathToSourceArchive, const bool display = false, const bool forAllUsers = false);
370 
371  /* GZ: leaving doc without the method confuses Doxygen. Commenting out completely.
389  //QString installLandscapeFromDirectory(QString pathToSourceLandscapeIni, bool display = false, bool forAllUsers = false);
390  */
391 
401  bool removeLandscape(const QString landscapeID);
402 
407  QString loadLandscapeName(const QString landscapeID);
408 
413  quint64 loadLandscapeSize(const QString landscapeID) const;
414 
416  bool getFlagLandscapeAutoSelection() const;
418  void setFlagLandscapeAutoSelection(bool enableAutoSelect);
419 
421  bool getFlagAtmosphereAutoEnable() const;
423  void setFlagAtmosphereAutoEnable(bool b);
424 
427  float getLandscapeOpacity(Vec3d azalt) const {return landscape->getOpacity(azalt);}
428  // This variant is required for scripting!
429  float getLandscapeOpacity(Vec3f azalt) const {return landscape->getOpacity(Vec3d(azalt[0], azalt[1], azalt[2]));}
433  float getLandscapeOpacity(float azimuth, float altitude) const {
434  Vec3d azalt;
435  StelUtils::spheToRect((180.0f-azimuth)*M_PI/180.0, altitude*M_PI/180.0, azalt);
436  return landscape->getOpacity(azalt);
437  }
438 
439 signals:
440  void atmosphereDisplayedChanged(const bool displayed);
441  void cardinalsPointsDisplayedChanged(const bool displayed);
442  void cardinalsPointsColorChanged(const Vec3f & newColor) const;
443  void fogDisplayedChanged(const bool displayed);
444  void landscapeDisplayedChanged(const bool displayed);
445  void illuminationDisplayedChanged(const bool displayed);
446  void labelsDisplayedChanged(const bool displayed);
447  void flagUseLightPollutionFromDatabaseChanged(const bool usage);
448  void flagLandscapeAutoSelectionChanged(const bool value);
449  void flagLandscapeSetsLocationChanged(const bool value);
450  void flagLandscapeUseMinimalBrightnessChanged(const bool value);
451  void flagLandscapeSetsMinimalBrightnessChanged(const bool value);
452  void defaultMinimalBrightnessChanged(const double value);
453  void setFlagAtmosphereAutoEnableChanged(const bool enabled);
454 
457  void defaultLandscapeChanged(const QString& id);
458 
462  void landscapesChanged();
463 
468  void errorUnableToOpen(QString path);
472  void errorNotArchive();
477  void errorNotUnique(QString nameOrID);
482  void errorRemoveManually(QString path);
483 
487  void currentLandscapeChanged(QString currentLandscapeID,QString currentLandscapeName);
488 
489 private slots:
492  void setAtmosphereBortleLightPollution(const int bIndex);
493 
495  void updateLocationBasedPollution(StelLocation loc);
496 
498  void updateI18n();
499 
500 private:
502  float getAtmosphereLightPollutionLuminance() const;
504  void setAtmosphereLightPollutionLuminance(const float f);
505 
506 
510  QString nameToID(const QString& name) const;
511 
516  QString getLandscapePath(const QString landscapeID) const;
517 
518  Atmosphere* atmosphere; // Atmosphere
519  Cardinals* cardinalsPoints; // Cardinals points
520  Landscape* landscape; // The landscape i.e. the fog, the ground and "decor"
521  Landscape* oldLandscape; // Used only during transitions to newly loaded landscape.
522 
523  // Define whether the observer location is to be updated when the landscape is updated.
524  bool flagLandscapeSetsLocation;
525 
526  bool flagLandscapeAutoSelection;
527 
528  bool flagLightPollutionFromDatabase;
529 
538 
540  QString currentLandscapeID;
541 
543  QString defaultLandscapeID;
544 
547  QStringList packagedLandscapeIDs;
548 
556  QCache<QString,Landscape> landscapeCache;
557 };
558 
559 #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.
QString installLandscapeFromArchive(QString pathToSourceArchive, const bool display=false, const bool forAllUsers=false)
Install a landscape from a ZIP archive.
void currentLandscapeChanged(QString currentLandscapeID, QString currentLandscapeName)
Emitted when the current landscape was changed.
QStringList getUserLandscapeIDs() const
Retrieve a list of the identifiers of all user-installed landscapes.
Store the informations for a location on a planet.
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.
double defaultMinimalBrightness
A minimal brightness value to keep landscape visible.
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.
bool flagAtmosphereAutoEnabling
Indicate auto-enable atmosphere for planets with atmospheres in location window.
Compute and display the daylight sky color using openGL.
Definition: Atmosphere.hpp:39
void setCacheSize(int mb)
Set size of the landscape cache, in MB.
QMap< QString, QString > getNameToDirMap() const
Return a map of landscape names to landscape IDs (directory names).
float getLightscapeBrightness() const
Returns the lightscape brightness.
Definition: Landscape.hpp:101
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&#39;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.
QStringList getAllLandscapeNames() const
Retrieve a list of the names of all the available landscapes in the file search path sub-directories ...
void setDefaultMinimalBrightness(const double b)
Set the minimal brightness value of the landscape.
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.
bool removeCachedLandscape(const QString &id)
Remove a landscape from the cache of landscapes.
float getCurrentLandscapeBrightness(const bool light=false) const
Get the current landscape or lightscape brightness (0..1)
float getBrightness() const
Returns the current brightness level.
Definition: Landscape.hpp:99
QString getDescription() const
Return a pseudo HTML formatted string with information from description or ini file.
QString currentLandscapeID
The ID of the currently loaded landscape.
float getLandscapeSinMinAltitudeLimit() const
Get the sine of current landscape&#39;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&#39;s disc size in bytes.
void setAtmosphereAverageLuminance(const float overrideLuminance)
Override autocomputed value and set average luminance [cd/m^2] of atmosphere.
bool flagLandscapeUseMinimalBrightness
Indicate use of the default minimal brightness value specified in config.ini.
void setFlagLandscapeSetsLocation(bool b)
Set the value of the flag determining if a change of landscape will update the observer location...
double getDefaultMinimalBrightness() const
Return the minimal brightness value of the landscape.
bool flagLandscapeSetsMinimalBrightness
Indicate use of the minimal brightness value specified in the current landscape.ini, if present.
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...
int getCacheSize() const
Retrieve total size of cache (MB).
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:121
bool precacheLandscape(const QString &id, const bool replace=true)
Preload a landscape into cache.
void setFlagLabels(const bool on)
Set flag for displaying landscape labels.
QString loadLandscapeName(const QString landscapeID)
This function reads a landscape&#39;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...
const QString getCurrentLandscapeID() const
Get the current landscape ID.
void setColorCardinalPoints(const Vec3f &v)
Set Cardinals Points color.
virtual float getOpacity(Vec3d azalt) const
Find opacity in a certain direction.
Definition: Landscape.hpp:173
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 defaultLandscapeChanged(const QString &id)
Emitted whenever the default landscape is changed.
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&#39;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...
int getCacheFilledSize() const
Retrieve sum of currently used memory in cache (MB, approximate)
bool getIsLandscapeFullyVisible() const
Get whether the landscape is currently visible. If true, objects below landscape&#39;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.
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.
const QString getDefaultLandscapeID() const
Get the default landscape ID.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
int getCacheCount() const
Return number of landscapes already in the cache.
void setFlagLandscapeAutoSelection(bool enableAutoSelect)
Set flag for autoselect of landscapes for planets.