Stellarium 0.15.2
Pulsars.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 _PULSARS_HPP_
20 #define _PULSARS_HPP_
21 
22 #include "StelObjectModule.hpp"
23 #include "StelObject.hpp"
24 #include "StelFader.hpp"
25 #include "StelTextureTypes.hpp"
26 #include "Pulsar.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 QPixmap;
38 class StelButton;
39 class PulsarsDialog;
40 
41 class StelPainter;
42 
66 typedef QSharedPointer<Pulsar> PulsarP;
68 
73 class Pulsars : public StelObjectModule
74 {
75  Q_OBJECT
76  Q_PROPERTY(bool pulsarsVisible
78  WRITE setFlagShowPulsars
79  NOTIFY flagPulsarsVisibilityChanged
80  )
81 public:
84  enum UpdateState {
90  };
91 
92  Pulsars();
93  virtual ~Pulsars();
94 
96  // Methods defined in the StelModule class
97  virtual void init();
98  virtual void deinit();
99  virtual void update(double) {;}
100  virtual void draw(StelCore* core);
101  virtual void drawPointer(StelCore* core, StelPainter& painter);
102  virtual double getCallOrder(StelModuleActionName actionName) const;
103 
105  // Methods defined in StelObjectManager class
111  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
112 
115  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
116 
119  virtual StelObjectP searchByName(const QString& name) const;
120 
126  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
127  virtual QStringList listAllObjects(bool inEnglish) const;
128  virtual QString getName() const { return "Pulsars"; }
129 
131  PulsarP getByID(const QString& id);
132 
135  virtual bool configureGui(bool show=true);
136 
140  void restoreDefaults(void);
141 
144  void readSettingsFromConfig(void);
145 
147  void saveSettingsToConfig(void);
148 
151  bool getUpdatesEnabled(void) {return updatesEnabled;}
154  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
155 
156  void setEnableAtStartup(bool b) { enableAtStartup=b; }
157  bool getEnableAtStartup(void) { return enableAtStartup; }
158 
160  QDateTime getLastUpdate(void) {return lastUpdate;}
161 
163  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
164  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
165 
167  int getSecondsToUpdate(void);
168 
170  UpdateState getUpdateState(void) {return updateState;}
171 
172 signals:
175 
177  void jsonUpdateComplete(void);
178 
179  void flagPulsarsVisibilityChanged(bool b);
180 
181 public slots:
183  void setFlagShowPulsarsButton(bool b);
184  bool getFlagShowPulsarsButton(void) { return flagShowPulsarsButton; }
185 
188  void setFlagShowPulsars(bool b);
191  bool getFlagShowPulsars(void) { return flagShowPulsars; }
192 
195  bool getDisplayMode(void);
198  void setDisplayMode(bool b);
199 
202  bool getGlitchFlag(void);
205  void setGlitchFlag(bool b);
206 
210  Vec3f getMarkerColor(bool mtype = true);
218  void setMarkerColor(const Vec3f& c, bool mtype = true);
219 
222  int getCountPulsars(void) {return PsrCount;}
223 
226  void updateJSON(void);
227 
228 private:
229  // Font used for displaying our text
230  QFont font;
231 
232  // if existing, delete Satellites section in main config.ini, then create with default values
233  void restoreDefaultConfigIni(void);
234 
235  // Upgrade config.ini: rename old key settings to new
236  void upgradeConfigIni(void);
237 
239  void restoreDefaultJsonFile(void);
240 
242  void readJsonFile(void);
243 
247  bool backupJsonFile(bool deleteOriginal=false);
248 
251  int getJsonFileFormatVersion(void);
252 
255  bool checkJsonFileFormat(void);
256 
258  QVariantMap loadPSRMap(QString path=QString());
259 
261  void setPSRMap(const QVariantMap& map);
262 
263  QString jsonCatalogPath;
264 
265  StelTextureSP texPointer;
266  QList<PulsarP> psr;
267 
268  int PsrCount;
269 
270  // variables and functions for the updater
271  UpdateState updateState;
272  QNetworkAccessManager* downloadMgr;
273  QString updateUrl;
274  QTimer* updateTimer;
275  QTimer* messageTimer;
276  QList<int> messageIDs;
277  bool updatesEnabled;
278  QDateTime lastUpdate;
279  int updateFrequencyDays;
280  bool enableAtStartup;
281 
282  QSettings* conf;
283 
284  // GUI
285  PulsarsDialog* configDialog;
286  bool flagShowPulsars;
287  bool flagShowPulsarsButton;
288  QPixmap* OnIcon;
289  QPixmap* OffIcon;
290  QPixmap* GlowIcon;
291  StelButton* toolbarButton;
292  class StelProgressController* progressBar;
293 
294 
295 private slots:
299  void checkForUpdate(void);
300  void updateDownloadComplete(QNetworkReply* reply);
301 
302  void reloadCatalog(void);
303 
305  void displayMessage(const QString& message, const QString hexColor="#999999");
306  void messageTimeout(void);
307 };
308 
309 
310 
311 #include <QObject>
312 #include "StelPluginInterface.hpp"
313 
315 class PulsarsStelPluginInterface : public QObject, public StelPluginInterface
316 {
317  Q_OBJECT
318  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
319  Q_INTERFACES(StelPluginInterface)
320 public:
321  virtual StelModule* getStelModule() const;
322  virtual StelPluginInfo getPluginInfo() const;
323 };
324 
325 #endif /*_PULSARS_HPP_*/
Define the interface to implement when creating a plugin.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
bool getGlitchFlag(void)
Get status for usage of separate color for pulsars with glitches.
void setFlagShowPulsarsButton(bool b)
Define whether the button toggling pulsars should be visible.
void jsonUpdateComplete(void)
emitted after a JSON update has run.
Error during download phase.
Definition: Pulsars.hpp:88
Define the StelTextureSP type.
void updateStateChanged(Pulsars::UpdateState state)
void restoreDefaults(void)
Set up the plugin with default values.
void setUpdatesEnabled(bool b)
set whether or not the plugin will try to update catalog data from the internet
Definition: Pulsars.hpp:154
Main class of the Pulsars plugin.
Definition: Pulsars.hpp:73
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual QStringList listAllObjects(bool inEnglish) const
List all StelObjects.
virtual void init()
Initialize itself.
virtual bool configureGui(bool show=true)
Implement this to tell the main Stellarium GUI that there is a GUI element to configure this plugin...
PulsarP getByID(const QString &id)
get a Pulsar object by identifier
virtual void update(double)
Update the module with respect to the time.
Definition: Pulsars.hpp:99
Vec3f getMarkerColor(bool mtype=true)
Get color for pulsars markers.
void saveSettingsToConfig(void)
Save the settings to the main configuration file.
Specialization of StelModule which manages a collection of StelObject.
UpdateState
Used for keeping for track of the download/update status.
Definition: Pulsars.hpp:84
void setDisplayMode(bool b)
Enable/disable display of distribution of pulsars.
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.
virtual QStringList listMatchingObjects(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object name...
void updateJSON(void)
Download JSON from web recources described in the module section of the module.ini file and update th...
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.
bool getDisplayMode(void)
Get status to display of distribution of pulsars.
int getCountPulsars(void)
Get count of pulsars from catalog.
Definition: Pulsars.hpp:222
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Other error.
Definition: Pulsars.hpp:89
virtual void draw(StelCore *core)
Execute all the drawing functions for this module.
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update catalog data from the internet
Definition: Pulsars.hpp:151
Update completed, there were updates.
Definition: Pulsars.hpp:87
int getSecondsToUpdate(void)
get the number of seconds till the next update
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object&#39;s pointer if exists or NULL.
bool getFlagShowPulsars(void)
Get status to display of markers of pulsars.
Definition: Pulsars.hpp:191
void readSettingsFromConfig(void)
Read (or re-read) settings from the main config file.
int getUpdateFrequencyDays(void)
get the update frequency in days
Definition: Pulsars.hpp:163
This class is used by Qt to manage a plug-in interface.
Definition: Pulsars.hpp:315
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
void setFlagShowPulsars(bool b)
Enable/disable display of markers of pulsars.
Update completed, there we no updates.
Definition: Pulsars.hpp:86
Maintain the state of a progress bar.
void setMarkerColor(const Vec3f &c, bool mtype=true)
Set color for pulsars markers.
QDateTime getLastUpdate(void)
get the date and time the pulsars were updated
Definition: Pulsars.hpp:160
virtual void deinit()
Called before the module will be delete, and before the openGL context is suppressed.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
UpdateState getUpdateState(void)
Get the current updateState.
Definition: Pulsars.hpp:170
void setGlitchFlag(bool b)
Enable/disable the use of a separate color for pulsars with glitches.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Update in progress.
Definition: Pulsars.hpp:85
Contains information about a Stellarium plugin.