Stellarium 0.12.3
Satellites.hpp
1 /*
2  * Copyright (C) 2009, 2012 Matthew Gates
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 _SATELLITES_HPP_
20 #define _SATELLITES_HPP_ 1
21 
22 #include "StelObjectModule.hpp"
23 #include "Satellite.hpp"
24 #include "StelFader.hpp"
25 #include "StelGui.hpp"
26 #include "StelDialog.hpp"
27 #include "StelLocation.hpp"
28 
29 #include <QDateTime>
30 #include <QFile>
31 #include <QDir>
32 #include <QUrl>
33 #include <QVariantMap>
34 
35 class StelButton;
36 class Planet;
37 class QNetworkAccessManager;
38 class QNetworkReply;
39 class QPixmap;
40 class QProgressBar;
41 class QSettings;
42 class QTimer;
43 
44 class SatellitesDialog;
46 
48 struct TleData
49 {
51  QString id;
53  QString name;
54  QString first;
55  QString second;
58  bool addThis;
59 };
60 
61 typedef QList<TleData> TleDataList;
62 typedef QHash<QString, TleData> TleDataHash ;
63 
65 struct TleSource
66 {
68  QUrl url;
71  QFile* file;
74  bool addNew;
75 };
76 
77 typedef QList<TleSource> TleSourceList;
78 
79 
120 
121 
122 
123 
125 {
126  Q_OBJECT
127  Q_PROPERTY(bool autoAddEnabled
128  READ isAutoAddEnabled
129  WRITE enableAutoAdd
131  Q_PROPERTY(bool autoRemoveEnabled
132  READ isAutoRemoveEnabled
133  WRITE enableAutoRemove
135 
136 public:
140  {
146  };
147 
149  enum Status
150  {
151  Visible,
152  NotVisible,
153  Both,
154  NewlyAdded,
155  OrbitError
156  };
157 
158  Satellites();
159  virtual ~Satellites();
160 
162  // Methods defined in the StelModule class
163  virtual void init();
164  virtual void deinit();
165  virtual void update(double deltaTime);
166  virtual void draw(StelCore* core, class StelRenderer* renderer);
167  virtual void drawPointer(StelCore* core, class StelRenderer* renderer);
168  virtual double getCallOrder(StelModuleActionName actionName) const;
169 
171  // Methods defined in StelObjectManager class
177  virtual QList<StelObjectP> searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
178 
181  virtual StelObjectP searchByNameI18n(const QString& nameI18n) const;
182 
185  virtual StelObjectP searchByName(const QString& name) const;
186 
192  StelObjectP searchByNoradNumber(const QString& noradNumber) const;
193 
198  virtual QStringList listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem=5) const;
199 
204  virtual QStringList listMatchingObjects(const QString& objPrefix, int maxNbItem=5) const;
205 
206  virtual QStringList listAllObjects(bool inEnglish) const;
207 
208  virtual QString getName() const { return "Satellites"; }
209 
212  virtual bool configureGui(bool show=true);
213 
217  void restoreDefaults(void);
218 
222  void loadSettings();
223 
225  void saveSettings();
226 
229  QSet<QString> getGroups() const;
232  QStringList getGroupIdList() const;
234  void addGroup(const QString& groupId);
235 
238  QHash<QString,QString> getSatellites(const QString& group=QString(), Status vis=Both);
241 
243  SatelliteP getById(const QString& id);
244 
246  QStringList listAllIds();
247 
251  void add(const TleDataList& newSatellites);
252 
255  void remove(const QStringList& idList);
256 
259  bool getUpdatesEnabled(void) {return updatesEnabled;}
260 
262  QDateTime getLastUpdate(void) {return lastUpdate;}
263 
265  int getUpdateFrequencyHours(void) {return updateFrequencyHours;}
266 
268  int getSecondsToUpdate(void);
269 
271  //void setUpdateFrequencyHours(int hours);
272 
274  UpdateState getUpdateState(void) {return updateState;}
275 
279  QStringList getTleSources(void) {return updateUrls;}
280 
288  void setTleSources(QStringList tleSources);
289 
291  void saveTleSources(const QStringList& urls);
292 
295  // TODO: Plugin-specific styles are no longer necessary?
296  const StelStyle getModuleStyleSheet(const StelStyle& style);
297 
306  void updateFromFiles(QStringList paths, bool deleteFiles=false);
307 
320  void updateSatellites(TleDataHash& newTleSets);
321 
330  static void parseTleFile(QFile& openFile,
331  TleDataHash& tleList,
332  bool addFlagValue = false);
333 
334  bool getFlagHints() {return hintFader;}
337  int getLabelFontSize() {return labelFont.pixelSize();}
338  bool getFlagLabels();
340  bool getOrbitLinesFlag();
341  bool isAutoAddEnabled() const { return autoAddEnabled; }
342  bool isAutoRemoveEnabled() const { return autoRemoveEnabled; }
343 
344 signals:
347  void settingsChanged();
348 
355 
362  void tleUpdateComplete(int updated, int total, int added, int missing);
363 
364 public slots:
365  // FIXME: Put back the getter functions - for scripts? --BM
366 
370  void enableInternetUpdates(bool enabled = true);
371 
373  void enableAutoAdd(bool enabled = true);
374 
376  void enableAutoRemove(bool enabled = true);
377 
381  void setFlagHints(bool b);
382 
386  void setFlagLabels(bool b);
387 
391  void setLabelFontSize(int size);
392 
395  void setUpdateFrequencyHours(int hours);
396 
411 
416  void setOrbitLinesFlag(bool b);
417 
418  void recalculateOrbitLines(void);
419 
422  void displayMessage(const QString& message, const QString hexColor="#999999");
424  void hideMessages();
425 
427  void saveCatalog(QString path=QString());
428 
429 private slots:
430  void setStelStyle(const QString& section);
431 
432 private:
438  bool add(const TleData& tleData);
439 
441  void restoreDefaultSettings();
443  void restoreDefaultCatalog();
447  void loadCatalog();
451  bool backupCatalog(bool deleteOriginal=false);
454  const QString readCatalogVersion();
455 
459  bool saveDataMap(const QVariantMap& map, QString path=QString());
462  QVariantMap loadDataMap(QString path=QString());
464  void setDataMap(const QVariantMap& map);
467  QVariantMap createDataMap();
468 
470  void markLastUpdate();
471 
476  static void translations();
477 
479  QString catalogPath;
484  QDir dataDir;
485 
486  QList<SatelliteP> satellites;
487  SatellitesListModel* satelliteListModel;
488 
493  QSet<QString> groups;
494 
495  LinearFader hintFader;
496  class StelTextureNew* hintTexture;
497  class StelTextureNew* texPointer;
498 
500 
501  QPixmap* pxmapGlow;
502  QPixmap* pxmapOnIcon;
503  QPixmap* pxmapOffIcon;
504  StelButton* toolbarButton;
506  // FIXME: Possible bug with the Solar System recreated by the SSEditor.
507  QSharedPointer<Planet> earth;
508  Vec3f defaultHintColor;
509  Vec3f defaultOrbitColor;
510  QFont labelFont;
511 
513 
514  UpdateState updateState;
515  QNetworkAccessManager* downloadMgr;
524  QStringList updateUrls;
530  TleSourceList updateSources;
531  QProgressBar* progressBar;
532  int numberDownloadsComplete;
533  QTimer* updateTimer;
535  bool updatesEnabled;
538  bool autoAddEnabled;
540  bool autoRemoveEnabled;
541  QDateTime lastUpdate;
542  int updateFrequencyHours;
544 
546 
547  QTimer* messageTimer;
548  QList<int> messageIDs;
550 
551  // GUI
552  SatellitesDialog* configDialog;
553  QByteArray normalStyleSheet;
554  QByteArray nightStyleSheet;
555 
556 private slots:
560  void checkForUpdate(void);
569  void saveDownloadedUpdate(QNetworkReply* reply);
570  void updateObserverLocation(StelLocation loc);
571 
572 };
573 
574 
575 #include "fixx11h.h"
576 #include <QObject>
577 #include "StelPluginInterface.hpp"
578 
581 {
582  Q_OBJECT
583  Q_INTERFACES(StelPluginInterface)
584 public:
585  virtual StelModule* getStelModule() const;
586  virtual StelPluginInfo getPluginInfo() const;
587 };
588 
589 #endif /*_SATELLITES_HPP_*/
590