Stellarium 0.15.2
Exoplanets.hpp
1 /*
2  * Copyright (C) 2012 Alexander Wolf
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _EXOPLANETS_HPP_
20 #define _EXOPLANETS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "StelTextureTypes.hpp"
26 #include "Exoplanet.hpp"
27 #include <QFont>
28 #include <QVariantMap>
29 #include <QDateTime>
30 #include <QList>
31 #include <QSharedPointer>
32 
33 class QNetworkAccessManager;
34 class QNetworkReply;
35 class QSettings;
36 class QTimer;
37 class ExoplanetsDialog;
38 class StelPainter;
39 class StelButton;
40 
63 typedef QSharedPointer<Exoplanet> ExoplanetP;
65 
71 {
72  Q_OBJECT
73  Q_PROPERTY(bool showExoplanets
76  NOTIFY flagExoplanetsVisibilityChanged
77  )
78 public:
81  enum UpdateState {
87  };
88 
89  Exoplanets();
90  virtual ~Exoplanets();
91 
93  // Methods defined in the StelModule class
94  virtual void init();
95  virtual void deinit();
96  virtual void update(double deltaTime);
97  virtual void draw(StelCore* core);
98  virtual void drawPointer(StelCore* core, StelPainter& painter);
99  virtual double getCallOrder(StelModuleActionName actionName) const;
100 
102  // Methods defined in StelObjectManager class
108  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
109 
112  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
113 
116  virtual StelObjectP searchByName(const QString& name) const;
117 
123  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=true) const;
124 
125  virtual QStringList listAllObjects(bool inEnglish) const;
126 
127  virtual QString getName() const { return "Exoplanets"; }
128 
130  ExoplanetP getByID(const QString& id);
131 
134  virtual bool configureGui(bool show=true);
135 
139  void restoreDefaults(void);
140 
143  void loadConfiguration(void);
144 
146  void saveConfiguration(void);
147 
150  bool getUpdatesEnabled(void) {return updatesEnabled;}
153  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
154 
155  void setEnableAtStartup(bool b) { enableAtStartup=b; }
156  bool getEnableAtStartup(void) { return enableAtStartup; }
157 
159  QDateTime getLastUpdate(void) {return lastUpdate;}
160 
162  int getUpdateFrequencyHours(void) {return updateFrequencyHours;}
163  void setUpdateFrequencyHours(int hours) {updateFrequencyHours = hours;}
164 
166  int getSecondsToUpdate(void);
167 
169  UpdateState getUpdateState(void) {return updateState;}
170 
171  QList<double> getExoplanetsData(int mode)
172  {
173  switch(mode)
174  {
175  case 1:
176  return EPSemiAxisAll;
177  break;
178  case 2:
179  return EPMassAll;
180  break;
181  case 3:
182  return EPRadiusAll;
183  break;
184  case 4:
185  return EPPeriodAll;
186  break;
187  case 5:
188  return EPAngleDistanceAll;
189  break;
190  default:
191  return EPEccentricityAll;
192  }
193  }
194 
195 signals:
198 
200  void jsonUpdateComplete(void);
201 
202  void flagExoplanetsVisibilityChanged(bool b);
203 
204 public slots:
207  void updateJSON(void);
208 
211  void setFlagShowExoplanets(bool b);
214  bool getFlagShowExoplanets(void) { return flagShowExoplanets; }
215 
222 
224  void setFlagShowExoplanetsButton(bool b);
225  bool getFlagShowExoplanetsButton(void) { return flagShowExoplanetsButton; }
226 
229  bool getDisplayMode(void);
232  void setDisplayMode(bool b);
233 
236  bool getTimelineMode(void);
239  void setTimelineMode(bool b);
240 
243  bool getHabitableMode(void);
246  void setHabitableMode(bool b);
247 
251  Vec3f getMarkerColor(bool habitable);
259  void setMarkerColor(const Vec3f& c, bool h);
260 
263  int getCountPlanetarySystems(void) const
264  {
265  return PSCount;
266  }
267 
270  int getCountAllExoplanets(void) const
271  {
272  return EPCountAll;
273  }
274 
278  {
279  return EPCountPH;
280  }
281 
282 private:
283  // Font used for displaying our text
284  QFont font;
285 
286  // if existing, delete Satellites section in main config.ini, then create with default values
287  void resetConfiguration(void);
288 
289  // Upgrade config.ini: rename old key settings to new
290  void upgradeConfigIni(void);
291 
293  void restoreDefaultJsonFile(void);
294 
296  void readJsonFile(void);
297 
301  bool backupJsonFile(bool deleteOriginal=false);
302 
305  int getJsonFileFormatVersion(void);
306 
309  bool checkJsonFileFormat(void);
310 
312  QVariantMap loadEPMap(QString path=QString());
313 
315  void setEPMap(const QVariantMap& map);
316 
321  static void translations();
322 
323  QString jsonCatalogPath;
324 
325  int PSCount;
326  int EPCountAll;
327  int EPCountPH;
328 
329  QList<double> EPEccentricityAll, EPSemiAxisAll, EPMassAll, EPRadiusAll, EPPeriodAll, EPAngleDistanceAll;
330 
331  StelTextureSP texPointer;
332  QList<ExoplanetP> ep;
333 
334  // variables and functions for the updater
335  UpdateState updateState;
336  QNetworkAccessManager* downloadMgr;
337  QString updateUrl;
338  QTimer* updateTimer;
339  QTimer* messageTimer;
340  QList<int> messageIDs;
341  bool updatesEnabled;
342  QDateTime lastUpdate;
343  int updateFrequencyHours;
344  bool enableAtStartup;
345 
346  QSettings* conf;
347 
348  // GUI
349  ExoplanetsDialog* exoplanetsConfigDialog;
350  bool flagShowExoplanets;
351  bool flagShowExoplanetsButton;
352  StelButton* toolbarButton;
353  class StelProgressController* progressBar;
354 
355 private slots:
359  void checkForUpdate(void);
360  void updateDownloadComplete(QNetworkReply* reply);
361 
363  void displayMessage(const QString& message, const QString hexColor="#999999");
364  void messageTimeout(void);
365 
366  void reloadCatalog(void);
367 };
368 
369 
370 
371 #include <QObject>
372 #include "StelPluginInterface.hpp"
373 
376 {
377  Q_OBJECT
378  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
379  Q_INTERFACES(StelPluginInterface)
380 public:
381  virtual StelModule* getStelModule() const;
382  virtual StelPluginInfo getPluginInfo() const;
383 };
384 
385 #endif /*_EXOPLANETS_HPP_*/
void jsonUpdateComplete(void)
emitted after a JSON update has run.
virtual QList< StelObjectP > searchAround(const Vec3d &v, double limitFov, const StelCore *core) const
Used to get a list of objects which are near to some position.
bool getFlagShowExoplanetsDesignations(void)
Get status to display of designations of exoplanetary systems.
void setFlagShowExoplanetsDesignations(bool b)
Enable/disable display of designations of exoplanetary systems.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:150
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
bool getDisplayMode(void)
Get status to display of distribution of exoplanetary systems.
void setHabitableMode(bool b)
Enable/disable display of exoplanetary systems with the potentially habitable exoplanets only...
Define the interface to implement when creating a plugin.
void setFlagShowExoplanetsButton(bool b)
Define whether the button toggling exoplanets should be visible.
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Exoplanets.hpp:159
This class is used by Qt to manage a plug-in interface.
Definition: Exoplanets.hpp:375
UpdateState
Used for keeping for track of the download/update status.
Definition: Exoplanets.hpp:81
void setFlagShowExoplanets(bool b)
Enable/disable display of markers of exoplanetary systems.
Define the StelTextureSP type.
bool getHabitableMode(void)
Get status to display of exoplanetary systems with the potentially habitable exoplanets.
Error during download phase.
Definition: Exoplanets.hpp:85
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Exoplanets.hpp:169
void saveConfiguration(void)
Save the settings to the main configuration file.
Update in progress.
Definition: Exoplanets.hpp:82
void updateStateChanged(Exoplanets::UpdateState state)
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual double getCallOrder(StelModuleActionName actionName) const
Return the value defining the order of call for the given action For example if stars.callOrder[ActionDraw] == 10 and constellation.callOrder[ActionDraw] == 11, the stars module will be drawn before the constellations.
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
Vec3f getMarkerColor(bool habitable)
Get color for markers of exoplanetary systems.
Specialization of StelModule which manages a collection of StelObject.
bool getFlagShowExoplanets(void)
Get status to display of markers of exoplanetary systems.
Definition: Exoplanets.hpp:214
int getCountAllExoplanets(void) const
Get count of exoplanets from catalog.
Definition: Exoplanets.hpp:270
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:153
Main class of the Exoplanets plugin.
Definition: Exoplanets.hpp:70
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
void loadConfiguration(void)
Read (or re-read) settings from the main config file.
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
virtual void update(double deltaTime)
Update the module with respect to the time.
void setMarkerColor(const Vec3f &c, bool h)
Set color for markers of exoplanetary systems.
Update completed, there were updates.
Definition: Exoplanets.hpp:84
void setTimelineMode(bool b)
Enable/disable display of systems with exoplanets after their discovery only.
virtual QStringList listAllObjects(bool inEnglish) const
List all StelObjects.
Main window of the Exoplanets plugin.
int getSecondsToUpdate(void)
get the number of seconds till the next update
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
Maintain the state of a progress bar.
void restoreDefaults(void)
Set up the plugin with default values.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object&#39;s pointer if exists or NULL.
bool getTimelineMode(void)
Get status to display of systems with exoplanets after their discovery.
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
virtual void init()
Initialize itself.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
virtual QStringList listMatchingObjects(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=true) const
Find and return the list of at most maxNbItem objects auto-completing the passed object name...
int getCountHabitableExoplanets(void) const
Get count of potentially habitable exoplanets from catalog.
Definition: Exoplanets.hpp:277
Update completed, there we no updates.
Definition: Exoplanets.hpp:83
int getUpdateFrequencyHours(void)
get the update frequency in hours
Definition: Exoplanets.hpp:162
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Contains information about a Stellarium plugin.
void setDisplayMode(bool b)
Enable/disable display of distribution of exoplanetary systems.
ExoplanetP getByID(const QString &id)
get a exoplanet object by identifier
int getCountPlanetarySystems(void) const
Get count of planetary systems from catalog.
Definition: Exoplanets.hpp:263