Stellarium 0.14.3
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;
102  bool addThis;
103 };
104 
106 typedef QList<TleData> TleDataList;
108 typedef QHash<QString, TleData> TleDataHash ;
109 
112 struct TleSource
113 {
115  QUrl url;
118  QFile* file;
121  bool addNew;
122 };
123 
125 typedef QList<TleSource> TleSourceList;
126 
128 {
129  QString datetime;
130  QString satellite;
131  float azimuth; // radians
132  float altitude; // radians
133  float magnitude;
134 };
135 
136 typedef QList<IridiumFlaresPrediction> IridiumFlaresPredictionList;
137 
144 {
145  Q_OBJECT
146  Q_PROPERTY(bool hintsVisible
147  READ getFlagHints
148  WRITE setFlagHints)
149  Q_PROPERTY(bool labelsVisible
150  READ getFlagLabels
151  WRITE setFlagLabels)
152  Q_PROPERTY(bool autoAddEnabled
153  READ isAutoAddEnabled
154  WRITE enableAutoAdd
155  NOTIFY settingsChanged)
156  Q_PROPERTY(bool autoRemoveEnabled
157  READ isAutoRemoveEnabled
158  WRITE enableAutoRemove
159  NOTIFY settingsChanged)
160  Q_PROPERTY(bool realisticMode
161  READ getFlagRealisticMode
162  WRITE setFlagRelisticMode)
163 
164 public:
168  {
174  };
175 
177  enum Status
178  {
179  Visible,
180  NotVisible,
181  Both,
182  NewlyAdded,
183  OrbitError
184  };
185 
186  Satellites();
187  virtual ~Satellites();
188 
190  // Methods defined in the StelModule class
191  virtual void init();
192  virtual void deinit();
193  virtual void update(double deltaTime);
194  virtual void draw(StelCore* core);
195  virtual void drawPointer(StelCore* core, StelPainter& painter);
196  virtual double getCallOrder(StelModuleActionName actionName) const;
197 
199  // Methods defined in StelObjectManager class
205  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
206 
209  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
210 
213  virtual StelObjectP searchByName(const QString& name) const;
214 
220  StelObjectP searchByNoradNumber(const QString& noradNumber) const;
221 
227  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
228 
234  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false) const;
235 
236  virtual QStringList listAllObjects(bool inEnglish) const;
237  virtual QStringList listAllObjectsByType(const QString& objType, bool inEnglish) const { Q_UNUSED(objType) Q_UNUSED(inEnglish) return QStringList(); }
238 
239  virtual QString getName() const { return "Satellites"; }
240 
243  virtual bool configureGui(bool show=true);
244 
248  void restoreDefaults(void);
249 
253  void loadSettings();
254 
256  void saveSettings();
257 
260  QSet<QString> getGroups() const;
263  QStringList getGroupIdList() const;
265  void addGroup(const QString& groupId);
266 
269  QHash<QString,QString> getSatellites(const QString& group=QString(), Status vis=Both);
272 
274  SatelliteP getById(const QString& id);
275 
277  QStringList listAllIds();
278 
282  void add(const TleDataList& newSatellites);
283 
286  void remove(const QStringList& idList);
287 
290  bool getUpdatesEnabled(void) {return updatesEnabled;}
291 
293  QDateTime getLastUpdate(void) {return lastUpdate;}
294 
296  int getUpdateFrequencyHours(void) {return updateFrequencyHours;}
297 
299  int getSecondsToUpdate(void);
300 
302  //void setUpdateFrequencyHours(int hours);
303 
305  UpdateState getUpdateState(void) {return updateState;}
306 
310  QStringList getTleSources(void) {return updateUrls;}
311 
319  void setTleSources(QStringList tleSources);
320 
322  void saveTleSources(const QStringList& urls);
323 
332  void updateFromFiles(QStringList paths, bool deleteFiles=false);
333 
346  void updateSatellites(TleDataHash& newTleSets);
347 
356  static void parseTleFile(QFile& openFile,
357  TleDataHash& tleList,
358  bool addFlagValue = false);
359 
364  void parseQSMagFile(QString qsMagFile);
365 
366  bool getFlagHints() {return hintFader;}
369  int getLabelFontSize() {return labelFont.pixelSize();}
370  bool getFlagLabels();
371  bool getFlagRealisticMode();
373  bool getOrbitLinesFlag();
374  bool isAutoAddEnabled() const { return autoAddEnabled; }
375  bool isAutoRemoveEnabled() const { return autoRemoveEnabled; }
376 
377  IridiumFlaresPredictionList getIridiumFlaresPrediction();
378 
379 signals:
382  void settingsChanged();
383 
390 
397  void tleUpdateComplete(int updated, int total, int added, int missing);
398 
399 public slots:
400  // FIXME: Put back the getter functions - for scripts? --BM
401 
405  void enableInternetUpdates(bool enabled = true);
406 
408  void enableAutoAdd(bool enabled = true);
409 
411  void enableAutoRemove(bool enabled = true);
412 
416  void setFlagHints(bool b);
417 
421  void setFlagLabels(bool b);
422 
424  void setFlagRelisticMode(bool b);
425 
429  void setLabelFontSize(int size);
430 
433  void setUpdateFrequencyHours(int hours);
434 
449 
454  void setOrbitLinesFlag(bool b);
455 
456  void recalculateOrbitLines(void);
457 
460  void displayMessage(const QString& message, const QString hexColor="#999999");
462  void hideMessages();
463 
465  void saveCatalog(QString path=QString());
466 
467 private slots:
468 
469 private:
475  bool add(const TleData& tleData);
476 
478  void restoreDefaultSettings();
480  void restoreDefaultCatalog();
484  void loadCatalog();
488  bool backupCatalog(bool deleteOriginal=false);
491  const QString readCatalogVersion();
493  void restoreDefaultQSMagFile();
494 
496  bool isValidRangeDates() const;
497 
501  bool saveDataMap(const QVariantMap& map, QString path=QString());
504  QVariantMap loadDataMap(QString path=QString());
506  void setDataMap(const QVariantMap& map);
509  QVariantMap createDataMap();
510 
512  void markLastUpdate();
513 
516  bool checkJsonFileFormat();
517 
522  static void translations();
523 
525  QString qsMagFilePath;
527  QString catalogPath;
532  QDir dataDir;
533 
534  QList<SatelliteP> satellites;
535  SatellitesListModel* satelliteListModel;
536 
537  QHash<QString, double> qsMagList;
538 
543  QSet<QString> groups;
544 
545  LinearFader hintFader;
546  StelTextureSP texPointer;
547 
549 
550  StelButton* toolbarButton;
552  // FIXME: Possible bug with the Solar System recreated by the SSEditor.
553  QSharedPointer<Planet> earth;
554  Vec3f defaultHintColor;
555  Vec3f defaultOrbitColor;
556  QFont labelFont;
557 
559 
560  UpdateState updateState;
561  QNetworkAccessManager* downloadMgr;
570  QStringList updateUrls;
576  TleSourceList updateSources;
577  class StelProgressController* progressBar;
578  int numberDownloadsComplete;
579  QTimer* updateTimer;
581  bool updatesEnabled;
584  bool autoAddEnabled;
586  bool autoRemoveEnabled;
587  QDateTime lastUpdate;
588  int updateFrequencyHours;
590 
592 
593  QTimer* messageTimer;
594  QList<int> messageIDs;
596 
597  // GUI
598  SatellitesDialog* configDialog;
599 
600 private slots:
604  void checkForUpdate(void);
613  void saveDownloadedUpdate(QNetworkReply* reply);
614  void updateObserverLocation(StelLocation loc);
615 };
616 
617 
618 
619 #include <QObject>
620 #include "StelPluginInterface.hpp"
621 
624 {
625  Q_OBJECT
626  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
627  Q_INTERFACES(StelPluginInterface)
628 public:
629  virtual StelModule* getStelModule() const;
630  virtual StelPluginInfo getPluginInfo() const;
631 };
632 
633 #endif /*_SATELLITES_HPP_*/
634 
Main configuration window of the Satellites plugin.
void setUpdateFrequencyHours(int hours)
Set the Internet update frequency.
bool getOrbitLinesFlag()
Get the current status of the orbit line rendering flag.
Error during download phase.
Definition: Satellites.hpp:172
QString id
NORAD catalog number, as extracted from the TLE set.
Definition: Satellites.hpp:95
static void parseTleFile(QFile &openFile, TleDataHash &tleList, bool addFlagValue=false)
Reads a TLE list from a file to the supplied hash.
Status
Flags used to filter the satellites list according to their status.
Definition: Satellites.hpp:177
virtual bool configureGui(bool show=true)
Implment this to tell the main Stellarium GUi that there is a GUI element to configure this plugin...
QFile * file
The downloaded file, location set after finishing download.
Definition: Satellites.hpp:118
virtual QStringList listMatchingObjectsI18n(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object I18n name...
void restoreDefaults(void)
Set up the plugin with default values.
void saveCatalog(QString path=QString())
Save the current satellite catalog to disk.
QDateTime getLastUpdate(void)
get the date and time the TLE elements were updated
Definition: Satellites.hpp:293
QSet< QString > getGroups() const
Get the groups used in the currently loaded satellite collection.
UpdateState getUpdateState(void)
get the update frequency in hours
Definition: Satellites.hpp:305
void saveTleSources(const QStringList &urls)
Saves the current list of update URLs to the configuration file.
void setFlagLabels(bool b)
Set whether text labels should be displayed next to satellite hints.
void settingsChanged()
Emitted when some of the plugin settings have been changed.
Update completed, there we no updates.
Definition: Satellites.hpp:170
SatellitesListModel * getSatellitesListModel()
Get a model representing the list of satellites.
StelObjectP searchByNoradNumber(const QString &noradNumber) const
Return the satellite with the given catalog number.
void setTleSources(QStringList tleSources)
Set the list of URLs which are sources of TLE data.
void loadSettings()
Read (or re-read) the plugin's settings from the configuration file.
void setOrbitLinesFlag(bool b)
Choose whether or not to draw orbit lines.
void setFlagRelisticMode(bool b)
Emits settingsChanged() if the value changes.
void enableInternetUpdates(bool enabled=true)
Set whether the plugin will try to download updates from the Internet.
void parseQSMagFile(QString qsMagFile)
Reads qs.mag file and its parsing for getting id and standard magnitude for satellites.
int getSecondsToUpdate(void)
get the number of seconds till the next update
Update in progress.
Definition: Satellites.hpp:169
UpdateState
Used for keeping track of the download/update status.
Definition: Satellites.hpp:167
Data structure containing unvalidated TLE set as read from a TLE list file.
Definition: Satellites.hpp:92
void tleUpdateComplete(int updated, int total, int added, int missing)
Emitted after an update has run.
void setFlagHints(bool b)
Set whether satellite position hints (icons) should be displayed.
int getLabelFontSize()
get the label font size.
Definition: Satellites.hpp:369
QUrl url
URL from where the source list should be downloaded.
Definition: Satellites.hpp:115
bool addNew
Flag indicating whether new satellites in this list should be added.
Definition: Satellites.hpp:121
virtual QStringList listMatchingObjects(const QString &objPrefix, int maxNbItem=5, bool useStartOfWords=false) const
Find and return the list of at most maxNbItem objects auto-completing the passed object English name...
void updateFromFiles(QStringList paths, bool deleteFiles=false)
Reads update file(s) in celestrak's .txt format, and updates the TLE elements for exisiting satellite...
QString name
Human readable name, as extracted from the TLE title line.
Definition: Satellites.hpp:97
void saveSettings()
Save the plugin's settings to the main configuration file.
void displayMessage(const QString &message, const QString hexColor="#999999")
Display a message on the screen for a few seconds.
QHash< QString, QString > getSatellites(const QString &group=QString(), Status vis=Both)
get satellite objects filtered by group.
TLE update source, used only internally for now.
Definition: Satellites.hpp:112
QStringList getGroupIdList() const
Get a sorted list of group names.
QStringList getTleSources(void)
Get a list of URLs which are sources of TLE data.
Definition: Satellites.hpp:310
int getUpdateFrequencyHours(void)
get the update frequency in hours
Definition: Satellites.hpp:296
void addGroup(const QString &groupId)
Add this group to the global list.
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.
SatelliteP getById(const QString &id)
Get a satellite object by its identifier (i.e. NORAD number).
This class is used by Qt to manage a plug-in interface.
Definition: Satellites.hpp:623
Update completed, there were updates.
Definition: Satellites.hpp:171
void enableAutoRemove(bool enabled=true)
Emits settingsChanged() if the value changes.
void setLabelFontSize(int size)
set the label font size.
Main class of the Satellites plugin.
Definition: Satellites.hpp:143
void updateStateChanged(Satellites::UpdateState state)
emitted when the update status changes, e.g.
QStringList listAllIds()
Returns a list of all satellite IDs.
virtual StelObjectP searchByNameI18n(const QString &nameI18n) const
Return the matching satellite object's pointer if exists or NULL.
void enableAutoAdd(bool enabled=true)
Emits settingsChanged() if the value changes.
A model encapsulating a satellite list.
void add(const TleDataList &newSatellites)
Add to the current collection the satellites described by the data list.
bool getUpdatesEnabled(void)
get whether or not the plugin will try to update TLE data from the internet
Definition: Satellites.hpp:290
QSharedPointer< StelTexture > StelTextureSP
void updateSatellites(TleDataHash &newTleSets)
Updates the loaded satellite collection from the provided data.
virtual StelObjectP searchByName(const QString &name) const
Return the matching satellite if exists or NULL.
void updateFromOnlineSources()
Start an Internet update.
void hideMessages()
Hide all messages.
bool addThis
Flag indicating whether this satellite should be added.
Definition: Satellites.hpp:102