Stellarium  0.90.0
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 
121  virtual StelObjectP searchByID(const QString &id) const
122  {
123  return qSharedPointerCast<StelObject>(getByID(id));
124  }
125 
131  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
132  virtual QStringList listAllObjects(bool inEnglish) const;
133  virtual QString getName() const { return "Pulsars"; }
134  virtual QString getStelObjectType() const { return Pulsar::PULSAR_TYPE; }
135 
137  PulsarP getByID(const QString& id) const;
138 
141  virtual bool configureGui(bool show=true);
142 
146  void restoreDefaults(void);
147 
150  void readSettingsFromConfig(void);
151 
153  void saveSettingsToConfig(void);
154 
157  bool getUpdatesEnabled(void) {return updatesEnabled;}
160  void setUpdatesEnabled(bool b) {updatesEnabled=b;}
161 
162  void setEnableAtStartup(bool b) { enableAtStartup=b; }
163  bool getEnableAtStartup(void) { return enableAtStartup; }
164 
166  QDateTime getLastUpdate(void) {return lastUpdate;}
167 
169  int getUpdateFrequencyDays(void) {return updateFrequencyDays;}
170  void setUpdateFrequencyDays(int days) {updateFrequencyDays = days;}
171 
173  int getSecondsToUpdate(void);
174 
176  UpdateState getUpdateState(void) {return updateState;}
177 
178 signals:
181 
183  void jsonUpdateComplete(void);
184 
185  void flagPulsarsVisibilityChanged(bool b);
186 
187 public slots:
189  void setFlagShowPulsarsButton(bool b);
190  bool getFlagShowPulsarsButton(void) { return flagShowPulsarsButton; }
191 
194  void setFlagShowPulsars(bool b);
197  bool getFlagShowPulsars(void) { return flagShowPulsars; }
198 
201  bool getDisplayMode(void);
204  void setDisplayMode(bool b);
205 
208  bool getGlitchFlag(void);
211  void setGlitchFlag(bool b);
212 
216  Vec3f getMarkerColor(bool mtype = true);
224  void setMarkerColor(const Vec3f& c, bool mtype = true);
225 
228  int getCountPulsars(void) {return PsrCount;}
229 
232  void updateJSON(void);
233 
234 private:
235  // Font used for displaying our text
236  QFont font;
237 
238  // if existing, delete Satellites section in main config.ini, then create with default values
239  void restoreDefaultConfigIni(void);
240 
241  // Upgrade config.ini: rename old key settings to new
242  void upgradeConfigIni(void);
243 
245  void restoreDefaultJsonFile(void);
246 
248  void readJsonFile(void);
249 
253  bool backupJsonFile(bool deleteOriginal=false);
254 
257  int getJsonFileFormatVersion(void);
258 
261  bool checkJsonFileFormat(void);
262 
264  QVariantMap loadPSRMap(QString path=QString());
265 
267  void setPSRMap(const QVariantMap& map);
268 
269  QString jsonCatalogPath;
270 
271  StelTextureSP texPointer;
272  QList<PulsarP> psr;
273 
274  int PsrCount;
275 
276  // variables and functions for the updater
277  UpdateState updateState;
278  QNetworkAccessManager* downloadMgr;
279  QString updateUrl;
280  QTimer* updateTimer;
281  QTimer* messageTimer;
282  QList<int> messageIDs;
283  bool updatesEnabled;
284  QDateTime lastUpdate;
285  int updateFrequencyDays;
286  bool enableAtStartup;
287 
288  QSettings* conf;
289 
290  // GUI
291  PulsarsDialog* configDialog;
292  bool flagShowPulsars;
293  bool flagShowPulsarsButton;
294  QPixmap* OnIcon;
295  QPixmap* OffIcon;
296  QPixmap* GlowIcon;
297  StelButton* toolbarButton;
298  class StelProgressController* progressBar;
299 
300 
301 private slots:
305  void checkForUpdate(void);
306  void updateDownloadComplete(QNetworkReply* reply);
307 
308  void reloadCatalog(void);
309 
311  void displayMessage(const QString& message, const QString hexColor="#999999");
312  void messageTimeout(void);
313 };
314 
315 
316 
317 #include <QObject>
318 #include "StelPluginInterface.hpp"
319 
321 class PulsarsStelPluginInterface : public QObject, public StelPluginInterface
322 {
323  Q_OBJECT
324  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
325  Q_INTERFACES(StelPluginInterface)
326 public:
327  virtual StelModule* getStelModule() const;
328  virtual StelPluginInfo getPluginInfo() const;
329  virtual QObjectList getExtensionList() const { return QObjectList(); }
330 };
331 
332 #endif /*_PULSARS_HPP_*/
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Pulsars.hpp:329
Define the interface to implement when creating a plugin.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or Q_NULLPTR.
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:160
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...
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.
virtual QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Pulsars.hpp:134
bool getDisplayMode(void)
Get status to display of distribution of pulsars.
int getCountPulsars(void)
Get count of pulsars from catalog.
Definition: Pulsars.hpp:228
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:157
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 Q_NULLPTR.
bool getFlagShowPulsars(void)
Get status to display of markers of pulsars.
Definition: Pulsars.hpp:197
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:169
This class is used by Qt to manage a plug-in interface.
Definition: Pulsars.hpp:321
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.
virtual QString getName() const
Gets a user-displayable name of the object category.
Definition: Pulsars.hpp:133
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:166
PulsarP getByID(const QString &id) const
get a Pulsar object by identifier
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:176
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.
virtual StelObjectP searchByID(const QString &id) const
Return the StelObject with the given ID if exists or the empty StelObject if not found.
Definition: Pulsars.hpp:121