Stellarium 0.15.2
Satellites.hpp
1 /*
2  * Copyright (C) 2009, 2012 Matthew Gates
3  * Copyright (C) 2015 Nick Fedoseev (Iridium flares)
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _SATELLITES_HPP_
21 #define _SATELLITES_HPP_ 1
22 
23 #include "StelObjectModule.hpp"
24 #include "Satellite.hpp"
25 #include "StelFader.hpp"
26 #include "StelGui.hpp"
27 #include "StelDialog.hpp"
28 #include "StelLocation.hpp"
29 
30 #include <QDateTime>
31 #include <QFile>
32 #include <QDir>
33 #include <QUrl>
34 #include <QVariantMap>
35 
36 class StelButton;
37 class Planet;
38 class QNetworkAccessManager;
39 class QNetworkReply;
40 class QSettings;
41 class QTimer;
42 
43 class SatellitesDialog;
45 
90 struct TleData
93 {
95  QString id;
97  QString name;
98  QString first;
99  QString second;
100  int status;
103  bool addThis;
104 };
105 
107 typedef QList<TleData> TleDataList;
109 typedef QHash<QString, TleData> TleDataHash ;
110 
113 struct TleSource
114 {
116  QUrl url;
119  QFile* file;
122  bool addNew;
123 };
124 
126 typedef QList<TleSource> TleSourceList;
127 
129 {
130  QString datetime;
131  QString satellite;
132  float azimuth; // radians
133  float altitude; // radians
134  float magnitude;
135 };
136 
137 typedef QList<IridiumFlaresPrediction> IridiumFlaresPredictionList;
138 
145 {
146  Q_OBJECT
147  Q_PROPERTY(bool hintsVisible
148  READ getFlagHints
149  WRITE setFlagHints
150  NOTIFY hintsVisibleChanged)
151  Q_PROPERTY(bool labelsVisible
152  READ getFlagLabels
153  WRITE setFlagLabels
154  NOTIFY labelsVisibleChanged)
155  Q_PROPERTY(bool autoAddEnabled
156  READ isAutoAddEnabled
157  WRITE enableAutoAdd
158  NOTIFY settingsChanged)
159  Q_PROPERTY(bool autoRemoveEnabled
160  READ isAutoRemoveEnabled
161  WRITE enableAutoRemove
162  NOTIFY settingsChanged)
163  Q_PROPERTY(bool realisticMode
164  READ getFlagRealisticMode
165  WRITE setFlagRelisticMode)
166 
167 public:
171  {
176  OtherError
177  };
178 
180  enum Status
181  {
182  Visible,
183  NotVisible,
184  Both,
185  NewlyAdded,
186  OrbitError
187  };
188 
189  Satellites();
190  virtual ~Satellites();
191 
193  // Methods defined in the StelModule class
194  virtual void init();
195  virtual void deinit();
196  virtual void update(double deltaTime);
197  virtual void draw(StelCore* core);
198  virtual void drawPointer(StelCore* core, StelPainter& painter);
199  virtual double getCallOrder(StelModuleActionName actionName) const;
200 
202  // Methods defined in StelObjectManager class
208  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
209 
212  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
213 
216  virtual StelObjectP searchByName(const QString& name) const;
217 
223  StelObjectP searchByNoradNumber(const QString& noradNumber) const;
224 
230  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
231 
232  virtual QStringList listAllObjects(bool inEnglish) const;
233 
234  virtual QString getName() const { return "Satellites"; }
235 
238  virtual bool configureGui(bool show=true);
239 
243  void restoreDefaults(void);
244 
248  void loadSettings();
249 
251  void saveSettings();
252 
255  QSet<QString> getGroups() const;
258  QStringList getGroupIdList() const;
260  void addGroup(const QString& groupId);
261 
264  QHash<QString,QString> getSatellites(const QString& group=QString(), Status vis=Both);
266  SatellitesListModel* getSatellitesListModel();
267 
269  SatelliteP getById(const QString& id);
270 
272  QStringList listAllIds();
273 
277  void add(const TleDataList& newSatellites);
278 
281  void remove(const QStringList& idList);
282 
285  bool getUpdatesEnabled(void) {return updatesEnabled;}
286 
288  QDateTime getLastUpdate(void) {return lastUpdate;}
289 
291  int getUpdateFrequencyHours(void) {return updateFrequencyHours;}
292 
294  int getSecondsToUpdate(void);
295 
297  //void setUpdateFrequencyHours(int hours);
298 
300  UpdateState getUpdateState(void) {return updateState;}
301 
305  QStringList getTleSources(void) {return updateUrls;}
306 
314  void setTleSources(QStringList tleSources);
315 
317  void saveTleSources(const QStringList& urls);
318 
327  void updateFromFiles(QStringList paths, bool deleteFiles=false);
328 
341  void updateSatellites(TleDataHash& newTleSets);
342 
351  static void parseTleFile(QFile& openFile,
352  TleDataHash& tleList,
353  bool addFlagValue = false);
354 
359  void parseQSMagFile(QString qsMagFile);
360 
361  bool getFlagHints() {return hintFader;}
364  int getLabelFontSize() {return labelFont.pixelSize();}
365  bool getFlagLabels();
366  bool getFlagRealisticMode();
368  bool getOrbitLinesFlag();
369  bool isAutoAddEnabled() const { return autoAddEnabled; }
370  bool isAutoRemoveEnabled() const { return autoRemoveEnabled; }
371 
373  int getIridiumFlaresPredictionDepth(void) { return iridiumFlaresPredictionDepth; }
374 
375  IridiumFlaresPredictionList getIridiumFlaresPrediction();
376 
377 signals:
378  void hintsVisibleChanged(bool b);
379  void labelsVisibleChanged(bool b);
380 
383  void settingsChanged();
384 
390  void updateStateChanged(Satellites::UpdateState state);
391 
398  void tleUpdateComplete(int updated, int total, int added, int missing);
399 
400 public slots:
401  // FIXME: Put back the getter functions - for scripts? --BM
402 
406  void enableInternetUpdates(bool enabled = true);
407 
409  void enableAutoAdd(bool enabled = true);
410 
412  void enableAutoRemove(bool enabled = true);
413 
417  void setFlagHints(bool b);
418 
422  void setFlagLabels(bool b);
423 
425  void setFlagRelisticMode(bool b);
426 
430  void setLabelFontSize(int size);
431 
434  void setUpdateFrequencyHours(int hours);
435 
449  void updateFromOnlineSources();
450 
455  void setOrbitLinesFlag(bool b);
456 
457  void recalculateOrbitLines(void);
458 
461  void displayMessage(const QString& message, const QString hexColor="#999999");
463  void hideMessages();
464 
466  void saveCatalog(QString path=QString());
467 
470  void setIridiumFlaresPredictionDepth(int depth) { iridiumFlaresPredictionDepth=depth; }
471 
472 private slots:
473 
474 private:
480  bool add(const TleData& tleData);
481 
483  void restoreDefaultSettings();
485  void restoreDefaultCatalog();
489  void loadCatalog();
493  bool backupCatalog(bool deleteOriginal=false);
496  const QString readCatalogVersion();
498  void restoreDefaultQSMagFile();
499 
501  bool isValidRangeDates() const;
502 
506  bool saveDataMap(const QVariantMap& map, QString path=QString());
509  QVariantMap loadDataMap(QString path=QString());
511  void setDataMap(const QVariantMap& map);
514  QVariantMap createDataMap();
515 
517  void markLastUpdate();
518 
521  bool checkJsonFileFormat();
522 
527  static void translations();
528 
530  QString qsMagFilePath;
532  QString catalogPath;
537  QDir dataDir;
538 
539  QList<SatelliteP> satellites;
540  SatellitesListModel* satelliteListModel;
541 
542  QHash<QString, double> qsMagList;
543 
548  QSet<QString> groups;
549 
550  LinearFader hintFader;
551  StelTextureSP texPointer;
552 
554 
555  StelButton* toolbarButton;
557  // FIXME: Possible bug with the Solar System recreated by the SSEditor.
558  QSharedPointer<Planet> earth;
559  Vec3f defaultHintColor;
560  Vec3f defaultOrbitColor;
561  QFont labelFont;
562 
564 
565  UpdateState updateState;
566  QNetworkAccessManager* downloadMgr;
575  QStringList updateUrls;
581  TleSourceList updateSources;
582  class StelProgressController* progressBar;
583  int numberDownloadsComplete;
584  QTimer* updateTimer;
586  bool updatesEnabled;
589  bool autoAddEnabled;
591  bool autoRemoveEnabled;
592  QDateTime lastUpdate;
593  int updateFrequencyHours;
595 
597 
598  QTimer* messageTimer;
599  QList<int> messageIDs;
601 
602  int iridiumFlaresPredictionDepth;
603 
604  // GUI
605  SatellitesDialog* configDialog;
606 
607 private slots:
611  void checkForUpdate(void);
620  void saveDownloadedUpdate(QNetworkReply* reply);
621  void updateObserverLocation(StelLocation loc);
622 };
623 
624 
625 
626 #include <QObject>
627 #include "StelPluginInterface.hpp"
628 
631 {
632  Q_OBJECT
633  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
634  Q_INTERFACES(StelPluginInterface)
635 public:
636  virtual StelModule* getStelModule() const;
637  virtual StelPluginInfo getPluginInfo() const;
638 };
639 
640 #endif /*_SATELLITES_HPP_*/
641 
Main configuration window of the Satellites plugin.
Store the informations for a location on a planet.
Error during download phase.
Definition: Satellites.hpp:175
QString id
NORAD catalog number, as extracted from the TLE set.
Definition: Satellites.hpp:95
Define the interface to implement when creating a plugin.
Status
Flags used to filter the satellites list according to their status.
Definition: Satellites.hpp:180
int getIridiumFlaresPredictionDepth(void)
Get depth of prediction for Iridium flares.
Definition: Satellites.hpp:373
QFile * file
The downloaded file, location set after finishing download.
Definition: Satellites.hpp:119
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Satellites.hpp:288
UpdateState getUpdateState(void)
get the update frequency in hours
Definition: Satellites.hpp:300
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Update completed, there we no updates.
Definition: Satellites.hpp:173
Specialization of StelModule which manages a collection of StelObject.
void setIridiumFlaresPredictionDepth(int depth)
Set depth of prediction for Iridium flares.
Definition: Satellites.hpp:470
Update in progress.
Definition: Satellites.hpp:172
UpdateState
Used for keeping track of the download/update status.
Definition: Satellites.hpp:170
Data structure containing unvalidated TLE set as read from a TLE list file.
Definition: Satellites.hpp:92
int getLabelFontSize()
get the label font size.
Definition: Satellites.hpp:364
QUrl url
URL from where the source list should be downloaded.
Definition: Satellites.hpp:116
bool addNew
Flag indicating whether new satellites in this list should be added.
Definition: Satellites.hpp:122
QString name
Human readable name, as extracted from the TLE title line.
Definition: Satellites.hpp:97
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
A Button Graphicsitem for use in Stellarium&#39;s graphic widgets.
TLE update source, used only internally for now.
Definition: Satellites.hpp:113
QStringList getTleSources(void)
Get a list of URLs which are sources of TLE data.
Definition: Satellites.hpp:305
int getUpdateFrequencyHours(void)
get the update frequency in hours
Definition: Satellites.hpp:291
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
This class is used by Qt to manage a plug-in interface.
Definition: Satellites.hpp:630
Maintain the state of a progress bar.
Update completed, there were updates.
Definition: Satellites.hpp:174
Main class of the Satellites plugin.
Definition: Satellites.hpp:144
A model encapsulating a satellite list.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update TLE data from the internet
Definition: Satellites.hpp:285
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
Contains information about a Stellarium plugin.
bool addThis
Flag indicating whether this satellite should be added.
Definition: Satellites.hpp:103