Stellarium 0.12.3
Satellite.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2009, 2012 Matthew Gates
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 _SATELLITE_HPP_
21 #define _SATELLITE_HPP_ 1
22 
23 #include <QDateTime>
24 #include <QFont>
25 #include <QList>
26 #include <QSharedPointer>
27 #include <QString>
28 #include <QStringList>
29 #include <QVariant>
30 
31 #include "StelObject.hpp"
32 #include "StelSphereGeometry.hpp"
33 #include "StelProjectorType.hpp"
34 
35 #include "gSatWrapper.hpp"
36 
37 
38 class StelLocation;
39 
41 typedef struct
42 {
43  double frequency;
44  QString modulation;
45  QString description;
46 } CommLink;
47 
49 enum SatelliteDataRole {
50  SatIdRole = Qt::UserRole,
51  SatDescriptionRole,
52  SatFlagsRole,
53  SatGroupsRole,
54  FirstLineRole,
55  SecondLineRole
56 };
57 
59 typedef QSet<QString> GroupSet;
60 
62 enum SatFlag
63 {
64  SatNoFlags = 0x0,
65  SatDisplayed = 0x1,
66  SatNotDisplayed = 0x2,
67  SatUser = 0x4,
68  SatOrbit = 0x8,
69  SatNew = 0x10,
70  SatError = 0x20
71 };
72 typedef QFlags<SatFlag> SatFlags;
73 Q_DECLARE_OPERATORS_FOR_FLAGS(SatFlags)
74 
75 // Allows the type to be used by QVariant
76 Q_DECLARE_METATYPE(GroupSet)
77 Q_DECLARE_METATYPE(SatFlags)
78 
86 class Satellite : public StelObject
87 {
88  friend class Satellites;
89  friend class SatellitesDialog;
90  friend class SatellitesListModel;
91 
92 public:
96  Satellite(const QString& identifier, const QVariantMap& data);
97  ~Satellite();
98 
101  QVariantMap getMap(void);
102 
103  virtual QString getType(void) const
104  {
105  return "Satellite";
106  }
107  virtual float getSelectPriority(const StelCore* core) const;
108 
117  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
118  virtual Vec3f getInfoColor(void) const;
119  virtual Vec3d getJ2000EquatorialPos(const StelCore*) const;
120  virtual float getVMagnitude(const StelCore* core=NULL, bool withExtinction=false) const;
121  virtual double getAngularSize(const StelCore* core) const;
122  virtual QString getNameI18n(void) const
123  {
124  return name;
125  }
126  virtual QString getEnglishName(void) const
127  {
128  return name;
129  }
131  QString getCatalogNumberString() const {return id;}
132 
135  void setNewTleElements(const QString& tle1, const QString& tle2);
136 
137  // calculate faders, new position
138  void update(double deltaTime);
139 
140  double getDoppler(double freq) const;
141  static float showLabels;
142  static double roundToDp(float n, int dp);
143 
144  // when the observer location changes we need to
145  void recalculateOrbitLines(void);
146 
147  void setNew() {newlyAdded = true;}
148  bool isNew() const {return newlyAdded;}
149 
151  SatFlags getFlags();
153  void setFlags(const SatFlags& flags);
154 
157  void parseInternationalDesignator(const QString& tle1);
158 
161  bool operator<(const Satellite& another) const;
162 
163 private:
164  //draw orbits methods
165  void computeOrbitPoints();
166  void drawOrbit(class StelRenderer* renderer, StelProjectorP projector);
169  float calculateOrbitSegmentIntensity(int segNum);
170  void setNightColors(bool night);
171 
172 private:
173  bool initialized;
177  bool displayed;
179  bool orbitDisplayed; // draw orbit enabled/disabled
183  bool userDefined;
185  bool newlyAdded;
186  bool orbitValid;
187 
191  QString id;
194  QString name;
196  QString description;
198  QString internationalDesignator;
203  double jdLaunchYearJan1;
205  Vec3d XYZ;
206  QPair< QByteArray, QByteArray > tleElements;
207  double height, range, rangeRate;
208  QList<CommLink> comms;
209  Vec3f hintColor;
212  GroupSet groups;
213  QDateTime lastUpdated;
214 
215  static SphericalCap viewportHalfspace;
216  static float hintBrightness;
217  static float hintScale;
218  static int orbitLineSegments;
219  static int orbitLineFadeSegments;
220  static int orbitLineSegmentDuration; //measured in seconds
221  static bool orbitLinesFlag;
223  static StelObject::InfoStringGroupFlags flagsMask;
224 
225  void draw(const StelCore* core, class StelRenderer* renderer,
226  StelProjectorP projector, class StelTextureNew* hintTexture);
227 
228  //Satellite Orbit Position calculation
229  gSatWrapper *pSatWrapper;
230  Vec3d position;
231  Vec3d velocity;
232  Vec3d latLongSubPointPosition;
233  Vec3d elAzPosition;
234  int visibility;
235 
236  //Satellite Orbit Draw
237  QFont font;
238  Vec3f orbitColorNormal;
239  Vec3f orbitColorNight;
240  Vec3f* orbitColor;
241  double lastEpochCompForOrbit; //measured in Julian Days
242  double epochTime; //measured in Julian Days
243  QList<Vec3d> orbitPoints; //orbit points represented by ElAzPos vectors
244 };
245 
246 typedef QSharedPointer<Satellite> SatelliteP;
247 bool operator<(const SatelliteP& left, const SatelliteP& right);
248 
249 #endif // _SATELLITE_HPP_
250