Stellarium  0.90.0
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 
218  virtual StelObjectP searchByID(const QString &id) const;
219 
225  StelObjectP searchByNoradNumber(const QString& noradNumber) const;
226 
232  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5, bool useStartOfWords=false, bool inEnglish=false) const;
233 
234  virtual QStringList listAllObjects(bool inEnglish) const;
235 
236  virtual QString getName() const { return "Satellites"; }
237  virtual QString getStelObjectType() const { return Satellite::SATELLITE_TYPE; }
238 
241  virtual bool configureGui(bool show=true);
242 
246  void restoreDefaults(void);
247 
251  void loadSettings();
252 
254  void saveSettings();
255 
258  QSet<QString> getGroups() const;
261  QStringList getGroupIdList() const;
263  void addGroup(const QString& groupId);
264 
267  QHash<QString,QString> getSatellites(const QString& group=QString(), Status vis=Both) const;
269  SatellitesListModel* getSatellitesListModel();
270 
272  SatelliteP getById(const QString& id) const;
273 
275  QStringList listAllIds() const;
276 
280  void add(const TleDataList& newSatellites);
281 
284  void remove(const QStringList& idList);
285 
288  bool getUpdatesEnabled(void) const {return updatesEnabled;}
289 
291  QDateTime getLastUpdate(void) const {return lastUpdate;}
292 
294  int getUpdateFrequencyHours(void) const {return updateFrequencyHours;}
295 
297  int getSecondsToUpdate(void);
298 
300  //void setUpdateFrequencyHours(int hours);
301 
303  UpdateState getUpdateState(void) const {return updateState;}
304 
308  QStringList getTleSources(void) const {return updateUrls;}
309 
317  void setTleSources(QStringList tleSources);
318 
320  void saveTleSources(const QStringList& urls);
321 
330  void updateFromFiles(QStringList paths, bool deleteFiles=false);
331 
344  void updateSatellites(TleDataHash& newTleSets);
345 
354  static void parseTleFile(QFile& openFile,
355  TleDataHash& tleList,
356  bool addFlagValue = false);
357 
362  void parseQSMagFile(QString qsMagFile);
363 
364  bool getFlagHints() const {return hintFader;}
367  int getLabelFontSize() const {return labelFont.pixelSize();}
368  bool getFlagLabels() const;
369  bool getFlagRealisticMode() const;
371  bool getOrbitLinesFlag() const;
372  bool isAutoAddEnabled() const { return autoAddEnabled; }
373  bool isAutoRemoveEnabled() const { return autoRemoveEnabled; }
374 
376  int getIridiumFlaresPredictionDepth(void) const { return iridiumFlaresPredictionDepth; }
377 
378  IridiumFlaresPredictionList getIridiumFlaresPrediction();
379 
380 signals:
381  void hintsVisibleChanged(bool b);
382  void labelsVisibleChanged(bool b);
383 
386  void settingsChanged();
387 
393  void updateStateChanged(Satellites::UpdateState state);
394 
401  void tleUpdateComplete(int updated, int total, int added, int missing);
402 
403 public slots:
404  // FIXME: Put back the getter functions - for scripts? --BM
405 
409  void enableInternetUpdates(bool enabled = true);
410 
412  void enableAutoAdd(bool enabled = true);
413 
415  void enableAutoRemove(bool enabled = true);
416 
420  void setFlagHints(bool b);
421 
425  void setFlagLabels(bool b);
426 
428  void setFlagRelisticMode(bool b);
429 
433  void setLabelFontSize(int size);
434 
437  void setUpdateFrequencyHours(int hours);
438 
452  void updateFromOnlineSources();
453 
458  void setOrbitLinesFlag(bool b);
459 
460  void recalculateOrbitLines(void);
461 
464  void displayMessage(const QString& message, const QString hexColor="#999999");
466  void hideMessages();
467 
469  void saveCatalog(QString path=QString());
470 
473  void setIridiumFlaresPredictionDepth(int depth) { iridiumFlaresPredictionDepth=depth; }
474 
475 private slots:
476 
477 private:
483  bool add(const TleData& tleData);
484 
486  void restoreDefaultSettings();
488  void restoreDefaultCatalog();
492  void loadCatalog();
496  bool backupCatalog(bool deleteOriginal=false);
499  const QString readCatalogVersion();
501  void restoreDefaultQSMagFile();
502 
504  bool isValidRangeDates(const StelCore* core) const;
505 
509  bool saveDataMap(const QVariantMap& map, QString path=QString());
512  QVariantMap loadDataMap(QString path=QString());
514  void setDataMap(const QVariantMap& map);
517  QVariantMap createDataMap();
518 
520  void markLastUpdate();
521 
524  bool checkJsonFileFormat();
525 
530  static void translations();
531 
533  QString qsMagFilePath;
535  QString catalogPath;
540  QDir dataDir;
541 
542  QList<SatelliteP> satellites;
543  SatellitesListModel* satelliteListModel;
544 
545  QHash<QString, double> qsMagList;
546 
551  QSet<QString> groups;
552 
553  LinearFader hintFader;
554  StelTextureSP texPointer;
555 
557 
558  StelButton* toolbarButton;
560  // FIXME: Possible bug with the Solar System recreated by the SSEditor.
561  QSharedPointer<Planet> earth;
562  Vec3f defaultHintColor;
563  Vec3f defaultOrbitColor;
564  QFont labelFont;
565 
567 
568  UpdateState updateState;
569  QNetworkAccessManager* downloadMgr;
578  QStringList updateUrls;
584  TleSourceList updateSources;
585  class StelProgressController* progressBar;
586  int numberDownloadsComplete;
587  QTimer* updateTimer;
589  bool updatesEnabled;
592  bool autoAddEnabled;
594  bool autoRemoveEnabled;
595  QDateTime lastUpdate;
596  int updateFrequencyHours;
598 
600 
601  QTimer* messageTimer;
602  QList<int> messageIDs;
604 
605  int iridiumFlaresPredictionDepth;
606 
607  // GUI
608  SatellitesDialog* configDialog;
609 
610 private slots:
614  void checkForUpdate(void);
623  void saveDownloadedUpdate(QNetworkReply* reply);
624  void updateObserverLocation(StelLocation loc);
625 };
626 
627 
628 
629 #include <QObject>
630 #include "StelPluginInterface.hpp"
631 
634 {
635  Q_OBJECT
636  Q_PLUGIN_METADATA(IID StelPluginInterface_iid)
637  Q_INTERFACES(StelPluginInterface)
638 public:
639  virtual StelModule* getStelModule() const;
640  virtual StelPluginInfo getPluginInfo() const;
641  virtual QObjectList getExtensionList() const { return QObjectList(); }
642 };
643 
644 #endif /*_SATELLITES_HPP_*/
645 
UpdateState getUpdateState(void) const
get the update frequency in hours
Definition: Satellites.hpp:303
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
int getLabelFontSize() const
get the label font size.
Definition: Satellites.hpp:367
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
QFile * file
The downloaded file, location set after finishing download.
Definition: Satellites.hpp:119
int getUpdateFrequencyHours(void) const
get the update frequency in hours
Definition: Satellites.hpp:294
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
QDateTime getLastUpdate(void) const
get the date and time the TLE elements were updated
Definition: Satellites.hpp:291
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
Update completed, there we no updates.
Definition: Satellites.hpp:173
virtual QString getName() const
Gets a user-displayable name of the object category.
Definition: Satellites.hpp:236
QStringList getTleSources(void) const
Get a list of URLs which are sources of TLE data.
Definition: Satellites.hpp:308
Specialization of StelModule which manages a collection of StelObject.
void setIridiumFlaresPredictionDepth(int depth)
Set depth of prediction for Iridium flares.
Definition: Satellites.hpp:473
Update in progress.
Definition: Satellites.hpp:172
bool getUpdatesEnabled(void) const
get whether or not the plugin will try to update TLE data from the internet
Definition: Satellites.hpp:288
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
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
int getIridiumFlaresPredictionDepth(void) const
Get depth of prediction for Iridium flares.
Definition: Satellites.hpp:376
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
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:633
Maintain the state of a progress bar.
Update completed, there were updates.
Definition: Satellites.hpp:174
virtual QObjectList getExtensionList() const
A mechanism to provide abitrary QObjects to the StelModuleMgr.
Definition: Satellites.hpp:641
Main class of the Satellites plugin.
Definition: Satellites.hpp:144
A model encapsulating a satellite list.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
virtual QString getStelObjectType() const
Returns the name that will be returned by StelObject::getType() for the objects this module manages...
Definition: Satellites.hpp:237
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