Stellarium  0.16.1
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 
118  virtual StelObjectP searchByID(const QString &id) const;
119 
125  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=true) const;
126 
127  virtual QStringList listAllObjects(bool inEnglish) const;
128 
129  virtual QString getName() const { return "Exoplanets"; }
130  virtual QString getStelObjectType() const { return Exoplanet::EXOPLANET_TYPE; }
131 
133  ExoplanetP getByID(const QString& id);
134 
137  virtual bool configureGui(bool show=true);
138 
142  void restoreDefaults(void);
143 
146  void loadConfiguration(void);
147 
149  void saveConfiguration(void);
150 
153  bool getUpdatesEnabled(void) const {return updatesEnabled;}
156  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
157 
158  void setEnableAtStartup(bool b) { enableAtStartup=b; }
159  bool getEnableAtStartup(void) const { return enableAtStartup; }
160 
162  QDateTime getLastUpdate(void) const {return lastUpdate;}
163 
165  int getUpdateFrequencyHours(void) const {return updateFrequencyHours;}
166  void setUpdateFrequencyHours(int hours) {updateFrequencyHours = hours;}
167 
169  int getSecondsToUpdate(void);
170 
172  UpdateState getUpdateState(void) const {return updateState;}
173 
174  QList<double> getExoplanetsData(int mode) const
175  {
176  switch(mode)
177  {
178  case 1:
179  return EPSemiAxisAll;
180  break;
181  case 2:
182  return EPMassAll;
183  break;
184  case 3:
185  return EPRadiusAll;
186  break;
187  case 4:
188  return EPPeriodAll;
189  break;
190  case 5:
191  return EPAngleDistanceAll;
192  break;
193  case 6:
194  return EPEffectiveTempHostStarAll;
195  break;
196  case 7:
197  return EPYearDiscoveryAll;
198  break;
199  case 8:
200  return EPMetallicityHostStarAll;
201  break;
202  case 9:
203  return EPVMagHostStarAll;
204  break;
205  case 10:
206  return EPRAHostStarAll;
207  break;
208  case 11:
209  return EPDecHostStarAll;
210  break;
211  case 12:
212  return EPDistanceHostStarAll;
213  break;
214  case 13:
215  return EPMassHostStarAll;
216  break;
217  case 14:
218  return EPRadiusHostStarAll;
219  break;
220  default:
221  return EPEccentricityAll;
222  }
223  }
224 
225 signals:
228 
230  void jsonUpdateComplete(void);
231 
232  void flagExoplanetsVisibilityChanged(bool b);
233 
234 public slots:
237  void updateJSON(void);
238 
241  void setFlagShowExoplanets(bool b);
244  bool getFlagShowExoplanets(void) const { return flagShowExoplanets; }
245 
251  bool getFlagShowExoplanetsDesignations(void) const;
252 
254  void setFlagShowExoplanetsButton(bool b);
255  bool getFlagShowExoplanetsButton(void) { return flagShowExoplanetsButton; }
256 
259  bool getDisplayMode(void) const;
262  void setDisplayMode(bool b);
263 
266  bool getTimelineMode(void) const;
269  void setTimelineMode(bool b);
270 
273  bool getHabitableMode(void) const;
276  void setHabitableMode(bool b);
277 
281  Vec3f getMarkerColor(bool habitable) const;
289  void setMarkerColor(const Vec3f& c, bool h);
290 
293  int getCountPlanetarySystems(void) const
294  {
295  return PSCount;
296  }
297 
300  int getCountAllExoplanets(void) const
301  {
302  return EPCountAll;
303  }
304 
308  {
309  return EPCountPH;
310  }
311 
312 private:
313  // Font used for displaying our text
314  QFont font;
315 
316  // if existing, delete Satellites section in main config.ini, then create with default values
317  void resetConfiguration(void);
318 
319  // Upgrade config.ini: rename old key settings to new
320  void upgradeConfigIni(void);
321 
323  void restoreDefaultJsonFile(void);
324 
326  void readJsonFile(void);
327 
331  bool backupJsonFile(bool deleteOriginal=false) const;
332 
335  int getJsonFileFormatVersion(void) const;
336 
339  bool checkJsonFileFormat(void) const;
340 
342  QVariantMap loadEPMap(QString path=QString());
343 
345  void setEPMap(const QVariantMap& map);
346 
351  static void translations();
352 
353  QString jsonCatalogPath;
354 
355  int PSCount;
356  int EPCountAll;
357  int EPCountPH;
358 
359  QList<double> EPEccentricityAll, EPSemiAxisAll, EPMassAll, EPRadiusAll, EPPeriodAll, EPAngleDistanceAll,
360  EPEffectiveTempHostStarAll, EPYearDiscoveryAll, EPMetallicityHostStarAll, EPVMagHostStarAll,
361  EPRAHostStarAll, EPDecHostStarAll, EPDistanceHostStarAll, EPMassHostStarAll, EPRadiusHostStarAll;
362 
363  StelTextureSP texPointer;
364  QList<ExoplanetP> ep;
365 
366  // variables and functions for the updater
367  UpdateState updateState;
368  QNetworkAccessManager* downloadMgr;
369  QString updateUrl;
370  QTimer* updateTimer;
371  QTimer* messageTimer;
372  QList<int> messageIDs;
373  bool updatesEnabled;
374  QDateTime lastUpdate;
375  int updateFrequencyHours;
376  bool enableAtStartup;
377 
378  QSettings* conf;
379 
380  // GUI
381  ExoplanetsDialog* exoplanetsConfigDialog;
382  bool flagShowExoplanets;
383  bool flagShowExoplanetsButton;
384  StelButton* toolbarButton;
385  class StelProgressController* progressBar;
386 
387 private slots:
391  void checkForUpdate(void);
392  void updateDownloadComplete(QNetworkReply* reply);
393 
395  void displayMessage(const QString& message, const QString hexColor="#999999");
396  void messageTimeout(void);
397 
398  void reloadCatalog(void);
399 };
400 
401 
402 
403 #include <QObject>
404 #include "StelPluginInterface.hpp"
405 
408 {
409  Q_OBJECT
410  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
411  Q_INTERFACES(StelPluginInterface)
412 public:
413  virtual StelModule* getStelModule() const;
414  virtual StelPluginInfo getPluginInfo() const;
415  virtual QObjectList getExtensionList() const { return QObjectList(); }
416 };
417 
418 #endif /*_EXOPLANETS_HPP_*/
void jsonUpdateComplete(void)
emitted after a JSON update has run.
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Exoplanets.hpp:415
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.
void setFlagShowExoplanetsDesignations(bool b)
Enable/disable display of designations of exoplanetary systems.
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
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.
This class is used by Qt to manage a plug-in interface.
Definition: Exoplanets.hpp:407
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.
bool getDisplayMode(void) const
Get status to display of distribution of exoplanetary systems.
Define the StelTextureSP type.
Error during download phase.
Definition: Exoplanets.hpp:85
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...
virtual QString getName() const
Gets a user-displayable name of the object category.
Definition: Exoplanets.hpp:129
Specialization of StelModule which manages a collection of StelObject.
int getUpdateFrequencyHours(void) const
get the update frequency in hours
Definition: Exoplanets.hpp:165
int getCountAllExoplanets(void) const
Get count of exoplanets from catalog.
Definition: Exoplanets.hpp:300
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:156
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 Q_NULLPTR.
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.
Vec3f getMarkerColor(bool habitable) const
Get 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.
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
bool getHabitableMode(void) const
Get status to display of exoplanetary systems with the potentially habitable exoplanets.
Main window of the Exoplanets plugin.
UpdateState getUpdateState(void) const
Get the current updateState.
Definition: Exoplanets.hpp:172
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
QDateTime getLastUpdate(void) const
get the date and time the TLE elements were updated
Definition: Exoplanets.hpp:162
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 Q_NULLPTR.
bool getFlagShowExoplanetsDesignations(void) const
Get status to display of designations of exoplanetary systems.
virtual QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Exoplanets.hpp:130
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
bool getUpdatesEnabled(void) const
get whether or not the plugin will try to update TLE data from the internet
Definition: Exoplanets.hpp:153
bool getTimelineMode(void) const
Get status to display of systems with exoplanets after their discovery.
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:307
Update completed, there we no updates.
Definition: Exoplanets.hpp:83
bool getFlagShowExoplanets(void) const
Get status to display of markers of exoplanetary systems.
Definition: Exoplanets.hpp:244
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:293