-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathMeteorShowersMgr.hpp
More file actions
367 lines (310 loc) · 11.6 KB
/
MeteorShowersMgr.hpp
File metadata and controls
367 lines (310 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* Stellarium: Meteor Showers Plug-in
* Copyright (C) 2013-2015 Marcos Cardinot
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#ifndef METEORSHOWERSMGR_HPP
#define METEORSHOWERSMGR_HPP
#include <QDateTime>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include "StelGuiItems.hpp"
#include "StelModule.hpp"
#include "StelLocation.hpp"
#include "StelTextureTypes.hpp"
#include "VecMath.hpp"
#define MS_CATALOG_VERSION 2
#define MS_CONFIG_PREFIX QString("MeteorShowers")
class MeteorShowers;
class MSConfigDialog;
class MSSearchDialog;
/*! @defgroup meteorShowers Meteor Showers Plug-in
@{
The %Meteor Showers plugin displays meteor showers and a marker for each
active and inactive radiant, showing real information about its activity.
<b>Configuration</b>
The plug-ins' configuration data is stored in Stellarium's main configuration
file (section [MeteorShowers]).
@}
*/
//! @class MeteorShowersMgr
//! Main class of the %Meteor Showers plugin, inherits from StelModule.
//! @author Marcos Cardinot <mcardinot@gmail.com>
//! @ingroup meteorShowers
class MeteorShowersMgr : public StelModule
{
Q_OBJECT
Q_PROPERTY(bool enablePlugin READ getEnablePlugin WRITE actionEnablePlugin NOTIFY enablePluginChanged)
Q_PROPERTY(bool enableLabels READ getEnableLabels WRITE setEnableLabels NOTIFY enableLabelsChanged)
Q_PROPERTY(Vec3f colorARG READ getColorARG WRITE setColorARG NOTIFY colorARGChanged)
Q_PROPERTY(Vec3f colorARC READ getColorARC WRITE setColorARC NOTIFY colorARCChanged)
Q_PROPERTY(Vec3f colorIR READ getColorIR WRITE setColorIR NOTIFY colorIRChanged)
public:
//! @enum UpdateState
//! Used for keeping for track of the download/update status
enum UpdateState {
Updating, //!< Update in progress
CompleteNoUpdates, //!< Update completed, there we no updates
CompleteUpdates, //!< Update completed, there were updates
DownloadError, //!< Error during download phase
OtherError //!< Other error
};
//! Constructor.
MeteorShowersMgr();
//! Destructor.
virtual ~MeteorShowersMgr() Q_DECL_OVERRIDE;
//! Restore default catalog.
bool restoreDefaultCatalog(const QString& destination);
//! Gets the bolide texture.
//! @return texture
StelTextureSP getBolideTexture() { return m_bolideTexture; }
//! Gets the pointer texture.
//! @return texture
StelTextureSP getPointerTexture() { return m_pointerTexture; }
//! Gets the radiant texture
//! @return texture
StelTextureSP getRadiantTexture() { return m_radiantTexture; }
//! Gets the MeteorShowers instance
//! @return MeteorShowers instance
MeteorShowers* getMeteorShowers() { return m_meteorShowers; }
//! Enable/disable the meteor showers plugin.
void setEnablePlugin(const bool& b);
bool getEnablePlugin() { return m_enablePlugin; }
//! Get the font.
QFont getFont() { return m_font; }
//! Set the URL for downloading the meteor showers catalog.
void setUrl(const QString& url);
QString getUrl() { return m_url; }
//! Set the date and time of last update.
void setLastUpdate(const QDateTime& datetime);
QDateTime getLastUpdate() { return m_lastUpdate; }
//! Get the current updateState
UpdateState getUpdateState(void) const {return m_updateState;}
//! Gets the date of the next update.
QDateTime getNextUpdate();
//! It's useful to force the update() and draw().
void repaint();
//
// Methods defined in the StelModule class
//
virtual void init() Q_DECL_OVERRIDE;
virtual void deinit() Q_DECL_OVERRIDE;
virtual void update(double deltaTime) Q_DECL_OVERRIDE;
virtual void draw(StelCore* core) Q_DECL_OVERRIDE;
virtual double getCallOrder(StelModuleActionName actionName) const Q_DECL_OVERRIDE;
virtual bool configureGui(bool show=true) Q_DECL_OVERRIDE;
signals:
//! @param state the new update state.
void updateStateChanged(MeteorShowersMgr::UpdateState state);
//! Emitted after a JSON update has run.
void jsonUpdateComplete(void);
void enablePluginChanged(bool b);
void enableLabelsChanged(bool b);
void colorARGChanged(Vec3f c);
void colorARCChanged(Vec3f c);
void colorIRChanged(Vec3f c);
public slots:
//! Enable the meteor showers plugin at Stellarium startup.
//! @param b boolean flag
void setEnableAtStartup(const bool& b);
//! True if the plugin is enabled at Stellarium startup.
//! @return true if it's enabled at startup
bool getEnableAtStartup() { return m_enableAtStartup; }
//! Show/hide the button that enable/disable the meteor showers plugin.
//! @param b boolean flag
void setShowEnableButton(const bool& show);
//! Get the status of the enable button on the toolbar.
//! @return true if it's visible
bool getShowEnableButton() { return m_showEnableButton; }
//! Show/hide the button that opens the search dialog.
//! @param b boolean flag
void setShowSearchButton(const bool& show);
//! Get the status of the search button on the toolbar.
//! @return true if it's visible
bool getShowSearchButton() { return m_showSearchButton; }
//! Enable/disable radiant marker.
//! @param b boolean flag
//! @code
//! // example of usage in scripts
//! MeteorShowers.setEnableMarker(true);
//! @endcode
void setEnableMarker(const bool& b);
//! Enable/disable radiant marker.
//! @return true if radiant markers visible
//! @code
//! // example of usage in scripts
//! var flag = MeteorShowers.getEnableMarker();
//! @endcode
bool getEnableMarker() { return m_enableMarker; }
//! True if user wants to see the active radiants only.
//! @param b boolean flag
//! @code
//! // example of usage in scripts
//! MeteorShowers.setActiveRadiantOnly(true);
//! @endcode
void setActiveRadiantOnly(const bool& b);
//! True if user wants to see the active radiants only.
//! @return true if only active radiants are visible
//! @code
//! // example of usage in scripts
//! var flag = MeteorShowers.getActiveRadiantOnly();
//! @endcode
bool getActiveRadiantOnly() { return m_activeRadiantOnly; }
//! Enable/disable radiant labels
//! @param b boolean flag
//! @code
//! // example of usage in scripts
//! MeteorShowers.setEnableLabels(true);
//! @endcode
void setEnableLabels(const bool& b);
//! Enable/disable radiant labels
//! @return true if radiant labels visible
//! @code
//! // example of usage in scripts
//! var flag = MeteorShowers.getEnableLabels();
//! @endcode
bool getEnableLabels() { return m_enableLabels; }
//! Set the font size (used on radiant labels).
//! @param pixelSize size of font
//! @code
//! // example of usage in scripts
//! MeteorShowers.setFontSize(15);
//! @endcode
void setFontSize(int pixelSize);
//! Set the font size (used on radiant labels).
//! @return size of font
//! @code
//! // example of usage in scripts
//! var size = MeteorShowers.getFontSize();
//! @endcode
int getFontSize() { return m_font.pixelSize(); }
//! Set the update frequency in hours.
//! @param hours update frequency in hours
void setUpdateFrequencyHours(const int& hours);
//! Gets the update frequency in hours.
//! @return update frequency in hours
int getUpdateFrequencyHours() { return m_updateFrequencyHours; }
//! Enable/disable automatic catalog updates from the internet.
//! @param b boolean flag
void setEnableAutoUpdates(const bool& b);
//! Enable/disable catalog updates from the internet.
//! @return true if auto updates is enabled
bool getEnableAutoUpdates() { return m_enableAutoUpdates; }
//! Set the color of the active radiant based on generic data.
//! @code
//! // example of usage in scripts
//! MeteorShowers.setColorARG(Vec3f(1.0,0.0,0.0));
//! @endcode
void setColorARG(const Vec3f& rgb);
//! @return color of markers of the active radiants based on generic data.
//! @code
//! // example of usage in scripts
//! color = MeteorShowers.getColorARG();
//! @endcode
Vec3f getColorARG() { return m_colorARG; }
//! Set the color of the active radiant based on confirmed data.
//! @code
//! // example of usage in scripts
//! MeteorShowers.setColorARC(Vec3f(1.0,0.0,0.0));
//! @endcode
void setColorARC(const Vec3f& rgb);
//! @return color of markers of the active radiants based on confirmed data.
//! @code
//! // example of usage in scripts
//! color = MeteorShowers.getColorARC();
//! @endcode
Vec3f getColorARC() { return m_colorARC; }
//! Set the color of the inactive radiant.
//! @code
//! // example of usage in scripts
//! MeteorShowers.setColorIR(Vec3f(1.0,0.0,0.0));
//! @endcode
void setColorIR(const Vec3f& rgb);
//! @return color of markers of the inactive radiants.
//! @code
//! // example of usage in scripts
//! color = MeteorShowers.getColorIR();
//! @endcode
Vec3f getColorIR() { return m_colorIR; }
//! Download the Meteor Showers catalog from the Internet.
void updateCatalog();
//! Restore default settings.
void restoreDefaultSettings();
//! Display a message. This is used for plugin-specific warnings and such
void displayMessage(const QString& message, const QString hexColor="#999999");
private slots:
void checkForUpdates();
void updateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void downloadComplete(QNetworkReply * reply);
void locationChanged(const StelLocation &location);
//! Call when button "Save settings" in main GUI are pressed
void saveSettings();
private:
MeteorShowers* m_meteorShowers;
MSConfigDialog* m_configDialog;
MSSearchDialog* m_searchDialog;
QFont m_font;
QSettings* m_conf;
QString m_catalogPath;
bool m_onEarth;
bool m_enablePlugin;
bool m_activeRadiantOnly;
bool m_enableAtStartup;
bool m_enableLabels;
bool m_enableMarker;
bool m_showEnableButton;
bool m_showSearchButton;
Vec3f m_colorARG; //! color of active radiant based on generic data
Vec3f m_colorARC; //! color of active radiant based on confirmed data
Vec3f m_colorIR; //! color of inactive radiant
QList<int> m_messageIDs;
StelTextureSP m_bolideTexture; //! Meteor bolide texture
StelTextureSP m_pointerTexture; //! Pointer texture
StelTextureSP m_radiantTexture; //! Radiant texture
//bool m_isUpdating;
bool m_enableAutoUpdates;
int m_updateFrequencyHours;
QString m_url;
QDateTime m_lastUpdate;
UpdateState m_updateState;
QNetworkAccessManager * m_networkManager;
QNetworkReply * m_downloadReply;
class StelProgressController* m_progressBar;
QTimer* m_updateTimer;
void createActions();
void loadConfig();
void loadTextures();
bool loadCatalog(const QString& jsonPath);
void startDownload(QString url);
void deleteDownloadProgressBar();
//! Enable/disable the Meteor Showers plugin.
//! It'll be triggered by a StelAction! So, it should NOT be called directly!
void actionEnablePlugin(const bool& b);
};
#include <QObject>
#include "StelPluginInterface.hpp"
//! This class is used by Qt to manage a plug-in interface
class MeteorShowersStelPluginInterface : public QObject, public StelPluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
Q_INTERFACES(StelPluginInterface)
public:
virtual StelModule* getStelModule() const Q_DECL_OVERRIDE;
virtual StelPluginInfo getPluginInfo() const Q_DECL_OVERRIDE;
virtual QObjectList getExtensionList() const Q_DECL_OVERRIDE { return QObjectList(); }
};
#endif /*METEORSHOWERSMGR_HPP*/