Stellarium 0.12.4
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 
28 #include <QMap>
29 #include <QStringList>
30 
31 class Landscape;
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 
61 public:
62  LandscapeMgr();
63  virtual ~LandscapeMgr();
64 
66  // Methods defined in the StelModule class
71  virtual void init();
72 
74  virtual void draw(StelCore* core, class StelRenderer* renderer);
75 
82  virtual void update(double deltaTime);
83 
85  virtual double getCallOrder(StelModuleActionName actionName) const;
86 
87 
89  // Method specific to the landscape manager
91  float getLuminance();
92 
95  bool loadLandscape(QMap<QString, QString>& param);
96 
105  Landscape* createFromFile(const QString& landscapeFile, const QString& landscapeId);
106 
107 public slots:
109  // Methods callable from script and GUI
113  QStringList getAllLandscapeNames() const;
114 
118  QStringList getAllLandscapeIDs() const;
119 
123  QStringList getUserLandscapeIDs() const;
124 
126  const QString& getCurrentLandscapeID() const {return currentLandscapeID;}
130  bool setCurrentLandscapeID(const QString& id);
131 
133  QString getCurrentLandscapeName() const;
136  bool setCurrentLandscapeName(const QString& name);
137 
139  const QString& getDefaultLandscapeID() const {return defaultLandscapeID;}
143  bool setDefaultLandscapeID(const QString& id);
144 
146  QString getCurrentLandscapeHtmlDescription() const;
147 
149  QString getDescription() const;
150 
152  bool getFlagLandscape() const;
154  void setFlagLandscape(const bool displayed);
155 
157  bool getFlagFog() const;
159  void setFlagFog(const bool displayed);
160 
162  bool getFlagLandscapeSetsLocation() const {return flagLandscapeSetsLocation;}
164  void setFlagLandscapeSetsLocation(bool b) {flagLandscapeSetsLocation=b;}
165 
167  bool getFlagLandscapeNightBrightness() const {return flagLandscapeNightBrightness;}
169  void setFlagLandscapeNightBrightness(bool b) {flagLandscapeNightBrightness=b;}
170 
171 
173  bool getFlagCardinalsPoints() const;
175  void setFlagCardinalsPoints(const bool displayed);
176 
180  void setColorCardinalPoints(const Vec3f& v);
181 
183  bool getFlagAtmosphere() const;
185  void setFlagAtmosphere(const bool displayed);
186 
188  float getAtmosphereFadeDuration() const;
190  void setAtmosphereFadeDuration(float f);
191 
193  void setAtmosphereBortleLightPollution(int bIndex);
196 
201  void setZRotation(float d);
202 
233  QString installLandscapeFromArchive(QString pathToSourceArchive, bool display = false, bool forAllUsers = false);
234 
235  // //! Install a landscape from a directory.
236  // //! Expected directory structure: the name of the directory that contains
237  // //! a landscape.ini file is assumed to be the landscape ID and should be
238  // //! unique.
239  // //! This directory and all files in it will be installed, but its
240  // //! subdirectories will be skipped along with any other files or
241  // //! directories in the archive.
242  // //! @param pathToSourceLandscapeIni path to a landscape.ini file. Its parent
243  // //! directory is assumed to be the landscape source directory.
244  // //! @param display If true, the landscape will be set to be the current
245  // //! landscape after installation.
246  // //! @param forAllUsers If true, this function will try to install the
247  // //! landscape in a way that meakes it is available to all users of this
248  // //! computer. May require running Stellarium as an administrator (root)
249  // //! on some Windows or *nix systems. (NOT IMPLEMENTED!)
250  // //! @returns the installed landscape's identifier (the folder name), or
251  // //! an empty string on failure.
252  // QString installLandscapeFromDirectory(QString pathToSourceLandscapeIni, bool display = false, bool forAllUsers = false);
253 
263  bool removeLandscape(QString landscapeID);
264 
269  QString loadLandscapeName(QString landscapeID);
270 
275  quint64 loadLandscapeSize(QString landscapeID);
276 
278  bool getFlagLandscapeAutoSelection() const;
280  void setFlagLandscapeAutoSelection(bool enableAutoSelect);
281 
282 signals:
283  void atmosphereDisplayedChanged(const bool displayed);
284  void cardinalsPointsDisplayedChanged(const bool displayed);
285  void fogDisplayedChanged(const bool displayed);
286  void landscapeDisplayedChanged(const bool displayed);
287 
291  void landscapesChanged();
292 
297  void errorUnableToOpen(QString path);
301  void errorNotArchive();
306  void errorNotUnique(QString nameOrID);
311  void errorRemoveManually(QString path);
312 
313 private slots:
315  void setStelStyle(const QString& section);
316 
318  void updateI18n();
319 
321  float getInitialLandscapeBrightness() const {return initialLandscapeBrightness;}
323  void setInitialLandscapeBrightness(float b) {initialLandscapeBrightness=b;}
324 
325 private:
327  float getAtmosphereLightPollutionLuminance() const;
329  void setAtmosphereLightPollutionLuminance(float f);
330 
334  QString nameToID(const QString& name);
335 
337  QMap<QString,QString> getNameToDirMap() const;
338 
343  QString getLandscapePath(QString landscapeID);
344 
345  Atmosphere* atmosphere; // Atmosphere
346  Cardinals* cardinalsPoints; // Cardinals points
347  Landscape* landscape; // The landscape i.e. the fog, the ground and "decor"
348 
349  // Define whether the observer location is to be updated when the landscape is updated.
350  bool flagLandscapeSetsLocation;
351 
352  bool flagLandscapeAutoSelection;
353 
354  bool flagLandscapeNightBrightness;
355 
356  // The ID of the currently loaded landscape
357  QString currentLandscapeID;
358 
359  // The ID of the default landscape
360  QString defaultLandscapeID;
361 
367  QStringList packagedLandscapeIDs;
368 
369  float initialLandscapeBrightness;
370 };
371 
372 #endif // _LANDSCAPEMGR_HPP_