• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • satellites
SatellitesTLEItem.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Guillaume Martres <smarter@ubuntu.com>
9 //
10 
11 #include "SatellitesTLEItem.h"
12 
13 #include "MarbleClock.h"
14 #include "MarbleDebug.h"
15 #include "MarbleGlobal.h"
16 #include "GeoPainter.h"
17 #include "GeoDataCoordinates.h"
18 #include "GeoDataPlacemark.h"
19 #include "GeoDataStyle.h"
20 #include "GeoDataTrack.h"
21 
22 #include "sgp4/sgp4ext.h"
23 
24 #include <QFile>
25 #include <QDateTime>
26 #include <QAction>
27 #include <QLabel>
28 #include <QVBoxLayout>
29 #include <QColor>
30 
31 #include <cmath>
32 #include <QDialog>
33 #include <QCheckBox>
34 
35 namespace Marble {
36 
37 #include "GeoDataPoint.h"
38 
39 SatellitesTLEItem::SatellitesTLEItem( const QString &name,
40  elsetrec satrec,
41  const MarbleClock *clock )
42  : TrackerPluginItem( name ),
43  m_satrec( satrec ),
44  m_track( new GeoDataTrack() ),
45  m_clock( clock )
46 {
47  double tumin, mu, xke, j2, j3, j4, j3oj2;
48  double radiusearthkm;
49  getgravconst( wgs84, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
50  m_earthSemiMajorAxis = radiusearthkm;
51 
52  setDescription();
53 
54  placemark()->setVisualCategory( GeoDataFeature::Satellite );
55  placemark()->setZoomLevel( 0 );
56  placemark()->setGeometry( m_track );
57 
58  update();
59 }
60 
61 void SatellitesTLEItem::setDescription()
62 {
63  QFile templateFile(":/marble/satellites/satellite.html");
64  if (!templateFile.open(QIODevice::ReadOnly)) {
65  placemark()->setDescription(QObject::tr("No info available."));
66  return;
67  }
68  QString html = templateFile.readAll();
69 
70  html.replace("%name%", name());
71  html.replace("%noradId%", QString::number(m_satrec.satnum));
72  html.replace("%perigee%", QString::number(perigee(), 'f', 2));
73  html.replace("%apogee%", QString::number(apogee(), 'f', 2));
74  html.replace("%inclination%", QString::number(inclination(), 'f', 2));
75  html.replace("%period%", QString::number(period(), 'f', 2));
76  html.replace("%semiMajorAxis%", QString::number(semiMajorAxis(), 'f', 2));
77 
78  placemark()->setDescription( html );
79 }
80 
81 void SatellitesTLEItem::update()
82 {
83  if( !isEnabled() ) {
84  return;
85  }
86 
87  QDateTime startTime = m_clock->dateTime();
88  QDateTime endTime = startTime;
89  if( isTrackVisible() ) {
90  startTime = startTime.addSecs( -2 * 60 );
91  endTime = startTime.addSecs( period() );
92  }
93 
94  m_track->removeBefore( startTime );
95  m_track->removeAfter( endTime );
96 
97  addPointAt( m_clock->dateTime() );
98 
99  // time interval between each point in the track, in seconds
100  double step = period() / 100.0;
101 
102  for ( double i = startTime.toTime_t(); i < endTime.toTime_t(); i += step ) {
103  // No need to add points in this interval
104  if ( i >= m_track->firstWhen().toTime_t() ) {
105  i = m_track->lastWhen().toTime_t() + step;
106  }
107 
108  addPointAt( QDateTime::fromTime_t( i ) );
109  }
110 }
111 
112 void SatellitesTLEItem::addPointAt( const QDateTime &dateTime )
113 {
114  // in minutes
115  double timeSinceEpoch = (double)( dateTime.toTime_t() -
116  timeAtEpoch().toTime_t() ) / 60.0;
117 
118  double r[3], v[3];
119  sgp4( wgs84, m_satrec, timeSinceEpoch, r, v );
120 
121  GeoDataCoordinates coordinates = fromTEME(
122  r[0], r[1], r[2], gmst( timeSinceEpoch ) );
123  if ( m_satrec.error != 0 ) {
124  return;
125  }
126 
127  m_track->addPoint( dateTime, coordinates);
128 }
129 
130 QDateTime SatellitesTLEItem::timeAtEpoch() const
131 {
132  int year = m_satrec.epochyr + ( m_satrec.epochyr < 57 ? 2000 : 1900 );
133 
134  int month, day, hours, minutes;
135  double seconds;
136  days2mdhms( year, m_satrec.epochdays, month, day, hours , minutes, seconds );
137 
138  int ms = fmod(seconds * 1000.0, 1000.0);
139 
140  return QDateTime( QDate( year, month, day ),
141  QTime( hours, minutes, (int)seconds, ms ),
142  Qt::UTC );
143 }
144 
145 double SatellitesTLEItem::period() const
146 {
147  // no := mean motion (rad / min)
148  return 60 * (2 * M_PI / m_satrec.no);
149 }
150 
151 double SatellitesTLEItem::apogee() const
152 {
153  return m_satrec.alta * m_earthSemiMajorAxis;
154 }
155 
156 double SatellitesTLEItem::perigee() const
157 {
158  return m_satrec.altp * m_earthSemiMajorAxis;
159 }
160 
161 double SatellitesTLEItem::semiMajorAxis() const
162 {
163 
164  return m_satrec.a * m_earthSemiMajorAxis;
165 }
166 
167 double SatellitesTLEItem::inclination() const
168 {
169  return m_satrec.inclo / M_PI * 180;
170 }
171 
172 GeoDataCoordinates SatellitesTLEItem::fromTEME( double x,
173  double y,
174  double z,
175  double gmst ) const
176 {
177  double lon = atan2( y, x );
178  // Rotate the angle by gmst (the origin goes from the vernal equinox
179  // point to the Greenwich Meridian)
180  lon = GeoDataCoordinates::normalizeLon( fmod(lon - gmst, 2 * M_PI) );
181 
182  double lat = atan2( z, sqrt( x*x + y*y ) );
183 
184  //TODO: determine if this is worth the extra precision
185  // Algorithm from http://celestrak.com/columns/v02n03/
186  //TODO: demonstrate it.
187  double a = m_earthSemiMajorAxis;
188  double R = sqrt( x*x + y*y );
189  double latp = lat;
190  double C;
191  for ( int i = 0; i < 3; i++ ) {
192  C = 1 / sqrt( 1 - square( m_satrec.ecco * sin( latp ) ) );
193  lat = atan2( z + a * C * square( m_satrec.ecco ) * sin( latp ), R );
194  }
195 
196  double alt = R / cos( lat ) - a * C;
197 
198  lat = GeoDataCoordinates::normalizeLat( lat );
199 
200  return GeoDataCoordinates( lon, lat, alt * 1000 );
201 }
202 
203 double SatellitesTLEItem::gmst( double minutesP ) const
204 {
205  // Earth rotation rate in rad/min, from sgp4io.cpp
206  double rptim = 4.37526908801129966e-3;
207  return fmod( m_satrec.gsto + rptim * minutesP, 2 * M_PI );
208 }
209 
210 double SatellitesTLEItem::square( double x )
211 {
212  return x * x;
213 }
214 
215 } // namespace Marble
Marble::GeoDataTrack::removeAfter
void removeAfter(const QDateTime &when)
Remove all points from the track whose time value is greater than when.
Definition: GeoDataTrack.cpp:242
GeoDataCoordinates.h
Marble::TrackerPluginItem::isEnabled
virtual bool isEnabled() const
Returns whether the item is enabled or disabled.
Definition: TrackerPluginItem.cpp:54
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
elsetrec::a
double a
Definition: sgp4unit.h:88
elsetrec
Definition: sgp4unit.h:63
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:54
elsetrec::no
double no
Definition: sgp4unit.h:88
elsetrec::epochdays
double epochdays
Definition: sgp4unit.h:88
Marble::GeoDataFeature::setVisualCategory
void setVisualCategory(GeoDataVisualCategory category)
Sets the symbol index of the placemark.
Definition: GeoDataFeature.cpp:770
Marble::GeoDataCoordinates::normalizeLon
static qreal normalizeLon(qreal lon, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
Definition: GeoDataCoordinates.cpp:776
Marble::GeoDataFeature::setDescription
void setDescription(const QString &value)
Set the description of this feature to value.
Definition: GeoDataFeature.cpp:593
elsetrec::alta
double alta
Definition: sgp4unit.h:88
elsetrec::epochyr
int epochyr
Definition: sgp4unit.h:66
GeoDataStyle.h
Marble::TrackerPluginItem::name
QString name() const
Satellite's name.
Definition: TrackerPluginItem.cpp:44
sgp4
bool sgp4(gravconsttype whichconst, elsetrec &satrec, double tsince, double r[3], double v[3])
Definition: sgp4unit.cpp:1695
Marble::GeoDataTrack::addPoint
void addPoint(const QDateTime &when, const GeoDataCoordinates &coord)
Add a new point with coordinates coord associated with the time value when.
Definition: GeoDataTrack.cpp:184
QTime
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
GeoDataTrack.h
QFile
Marble::MarbleClock::dateTime
QDateTime dateTime() const
Returns the internal date and time.
Definition: MarbleClock.cpp:100
QDateTime::fromTime_t
QDateTime fromTime_t(uint seconds)
QString::number
QString number(int n, int base)
Marble::GeoDataTrack::lastWhen
QDateTime lastWhen() const
Return the time value of the last point in the track, or an invalid QDateTime if the track is empty...
Definition: GeoDataTrack.cpp:105
Marble::TrackerPluginItem::placemark
GeoDataPlacemark * placemark()
Returns the wrapped placemark which will be displayed if this item is in a TrackerPluginModel.
Definition: TrackerPluginItem.cpp:49
elsetrec::altp
double altp
Definition: sgp4unit.h:88
QDate
wgs84
Definition: sgp4unit.h:60
sgp4ext.h
Marble::GeoDataCoordinates::normalizeLat
static qreal normalizeLat(qreal lat, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize latitude to always be in -M_PI / 2.
Definition: GeoDataCoordinates.cpp:799
QString
GeoPainter.h
MarbleGlobal.h
GeoDataPlacemark.h
Marble::SatellitesTLEItem::SatellitesTLEItem
SatellitesTLEItem(const QString &name, elsetrec satrec, const MarbleClock *clock)
Definition: SatellitesTLEItem.cpp:39
Marble::TrackerPluginItem
Subclass this to represent items in your TrackerPluginModel.
Definition: TrackerPluginItem.h:29
elsetrec::gsto
double gsto
Definition: sgp4unit.h:80
elsetrec::error
int error
Definition: sgp4unit.h:67
MarbleClock.h
elsetrec::inclo
double inclo
Definition: sgp4unit.h:88
QDateTime::toTime_t
uint toTime_t() const
Marble::GeoDataTrack::firstWhen
QDateTime firstWhen() const
Return the time value of the first point in the track, or an invalid QDateTime if the track is empty...
Definition: GeoDataTrack.cpp:96
QString::replace
QString & replace(int position, int n, QChar after)
Marble::SatellitesTLEItem::update
void update()
Reimplement this method to update the placemark, for example to change its coordinates.
Definition: SatellitesTLEItem.cpp:81
SatellitesTLEItem.h
GeoDataPoint.h
Marble::GeoDataFeature::Satellite
Definition: GeoDataFeature.h:267
elsetrec::satnum
long int satnum
Definition: sgp4unit.h:65
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::TrackerPluginItem::isTrackVisible
virtual bool isTrackVisible() const
Return whether the track is visible or invisible.
Definition: TrackerPluginItem.cpp:74
Marble::GeoDataFeature::setZoomLevel
void setZoomLevel(int index)
Sets the popularity index of the placemark.
Definition: GeoDataFeature.cpp:802
days2mdhms
void days2mdhms(int year, double days, int &mon, int &day, int &hr, int &minute, double &sec)
Definition: sgp4ext.cpp:617
getgravconst
void getgravconst(gravconsttype whichconst, double &tumin, double &mu, double &radiusearthkm, double &xke, double &j2, double &j3, double &j4, double &j3oj2)
Definition: sgp4unit.cpp:2058
elsetrec::ecco
double ecco
Definition: sgp4unit.h:88
QDateTime::addSecs
QDateTime addSecs(int s) const
Marble::MarbleClock
Definition: MarbleClock.h:25
Marble::GeoDataTrack::removeBefore
void removeBefore(const QDateTime &when)
Remove all points from the track whose time value is less than when.
Definition: GeoDataTrack.cpp:228
QDateTime
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:230
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal