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

marble

  • sources
  • kde-4.12
  • 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_name(name),
44  m_showOrbit( false ),
45  m_satrec( satrec ),
46  m_track( new GeoDataTrack() ),
47  m_clock( clock )
48 {
49  double tumin, mu, xke, j2, j3, j4, j3oj2;
50  double radiusearthkm;
51  getgravconst( wgs84, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
52  m_earthSemiMajorAxis = radiusearthkm;
53 
54  setDescription();
55 
56  placemark()->setVisualCategory( GeoDataFeature::Satellite );
57  placemark()->setZoomLevel( 0 );
58  placemark()->setGeometry( m_track );
59 
60  GeoDataStyle *style = new GeoDataStyle( *placemark()->style() );
61  placemark()->setStyle( style );
62  placemark()->style()->lineStyle().setPenStyle( Qt::NoPen );
63  placemark()->style()->labelStyle().setGlow( true );
64 
65  update();
66 }
67 
68 void SatellitesTLEItem::setDescription()
69 {
70  QFile templateFile(":/marble/satellites/satellite.html");
71  if (!templateFile.open(QIODevice::ReadOnly)) {
72  placemark()->setDescription(tr("No info available."));
73  return;
74  }
75  QString html = templateFile.readAll();
76 
77  html.replace("%name%", name());
78  html.replace("%noradId%", QString::number(m_satrec.satnum));
79  html.replace("%perigee%", QString::number(perigee(), 'f', 2));
80  html.replace("%apogee%", QString::number(apogee(), 'f', 2));
81  html.replace("%inclination%", QString::number(inclination(), 'f', 2));
82  html.replace("%period%", QString::number(period(), 'f', 2));
83  html.replace("%semiMajorAxis%", QString::number(semiMajorAxis(), 'f', 2));
84 
85  placemark()->setDescription( html );
86 }
87 
88 void SatellitesTLEItem::update()
89 {
90  if( !isEnabled() ) {
91  return;
92  }
93 
94  QDateTime startTime = m_clock->dateTime().addSecs( - 2 * 60 );
95 
96  QDateTime endTime = startTime.addSecs( period() );
97 
98  m_track->removeBefore( startTime );
99  m_track->removeAfter( endTime );
100 
101  addPointAt( m_clock->dateTime() );
102 
103  // time interval between each point in the track, in seconds
104  double step = period() / 100.0;
105 
106  for ( double i = startTime.toTime_t(); i < endTime.toTime_t(); i += step ) {
107  // No need to add points in this interval
108  if ( i >= m_track->firstWhen().toTime_t() ) {
109  i = m_track->lastWhen().toTime_t() + step;
110  }
111 
112  addPointAt( QDateTime::fromTime_t( i ) );
113  }
114 }
115 
116 QString SatellitesTLEItem::name()
117 {
118  return m_name;
119 }
120 
121 void SatellitesTLEItem::setOrbitColor(const QColor &color)
122 {
123  placemark()->style()->lineStyle().setColor(color);
124 }
125 
126 void SatellitesTLEItem::addPointAt( const QDateTime &dateTime )
127 {
128  // in minutes
129  double timeSinceEpoch = (double)( dateTime.toTime_t() -
130  timeAtEpoch().toTime_t() ) / 60.0;
131 
132  double r[3], v[3];
133  sgp4( wgs84, m_satrec, timeSinceEpoch, r, v );
134 
135  GeoDataCoordinates coordinates = fromTEME(
136  r[0], r[1], r[2], gmst( timeSinceEpoch ) );
137  if ( m_satrec.error != 0 ) {
138  return;
139  }
140 
141  m_track->addPoint( dateTime, coordinates);
142 }
143 
144 QDateTime SatellitesTLEItem::timeAtEpoch()
145 {
146  int year = m_satrec.epochyr + ( m_satrec.epochyr < 57 ? 2000 : 1900 );
147 
148  int month, day, hours, minutes;
149  double seconds;
150  days2mdhms( year, m_satrec.epochdays, month, day, hours , minutes, seconds );
151 
152  int ms = fmod(seconds * 1000.0, 1000.0);
153 
154  return QDateTime( QDate( year, month, day ),
155  QTime( hours, minutes, (int)seconds, ms ),
156  Qt::UTC );
157 }
158 
159 double SatellitesTLEItem::period()
160 {
161  // no := mean motion (rad / min)
162  return 60 * (2 * M_PI / m_satrec.no);
163 }
164 
165 double SatellitesTLEItem::apogee()
166 {
167  return m_satrec.alta * m_earthSemiMajorAxis;
168 }
169 
170 double SatellitesTLEItem::perigee()
171 {
172  return m_satrec.altp * m_earthSemiMajorAxis;
173 }
174 
175 double SatellitesTLEItem::semiMajorAxis()
176 {
177 
178  return m_satrec.a * m_earthSemiMajorAxis;
179 }
180 
181 double SatellitesTLEItem::inclination()
182 {
183  return m_satrec.inclo / M_PI * 180;
184 }
185 
186 GeoDataCoordinates SatellitesTLEItem::fromTEME( double x,
187  double y,
188  double z,
189  double gmst )
190 {
191  double lon = atan2( y, x );
192  // Rotate the angle by gmst (the origin goes from the vernal equinox
193  // point to the Greenwich Meridian)
194  lon = GeoDataCoordinates::normalizeLon( fmod(lon - gmst, 2 * M_PI) );
195 
196  double lat = atan2( z, sqrt( x*x + y*y ) );
197 
198  //TODO: determine if this is worth the extra precision
199  // Algorithm from http://celestrak.com/columns/v02n03/
200  //TODO: demonstrate it.
201  double a = m_earthSemiMajorAxis;
202  double R = sqrt( x*x + y*y );
203  double latp = lat;
204  double C;
205  for ( int i = 0; i < 3; i++ ) {
206  C = 1 / sqrt( 1 - square( m_satrec.ecco * sin( latp ) ) );
207  lat = atan2( z + a * C * square( m_satrec.ecco ) * sin( latp ), R );
208  }
209 
210  double alt = R / cos( lat ) - a * C;
211 
212  lat = GeoDataCoordinates::normalizeLat( lat );
213 
214  return GeoDataCoordinates( lon, lat, alt * 1000 );
215 }
216 
217 double SatellitesTLEItem::gmst( double minutesP )
218 {
219  // Earth rotation rate in rad/min, from sgp4io.cpp
220  double rptim = 4.37526908801129966e-3;
221  return fmod( m_satrec.gsto + rptim * minutesP, 2 * M_PI );
222 }
223 
224 double SatellitesTLEItem::square( double x )
225 {
226  return x * x;
227 }
228 
229 } // namespace Marble
230 
231 #include "SatellitesTLEItem.moc"
232 
Marble::GeoDataTrack::removeAfter
void removeAfter(const QDateTime &when)
Remove all points from the track whose time value is greater than when.
Definition: GeoDataTrack.cpp:233
GeoDataCoordinates.h
Marble::TrackerPluginItem::isEnabled
virtual bool isEnabled() const
Returns whether the item is enabled or disabled.
Definition: TrackerPluginItem.cpp:45
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:680
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:518
Marble::GeoDataColorStyle::setColor
void setColor(const QColor &value)
Set a new color.
Definition: GeoDataColorStyle.cpp:73
elsetrec::alta
double alta
Definition: sgp4unit.h:88
elsetrec::epochyr
int epochyr
Definition: sgp4unit.h:66
GeoDataStyle.h
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark.
Definition: GeoDataFeature.cpp:624
sgp4
bool sgp4(gravconsttype whichconst, elsetrec &satrec, double tsince, double r[3], double v[3])
Definition: sgp4unit.cpp:1696
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:175
MarbleDebug.h
GeoDataTrack.h
Marble::MarbleClock::dateTime
QDateTime dateTime() const
Returns the internal date and time.
Definition: MarbleClock.cpp:110
Marble::GeoDataStyle::labelStyle
GeoDataLabelStyle & labelStyle() const
Return the label style of this style.
Definition: GeoDataStyle.cpp:128
Marble::GeoDataStyle
an addressable style group
Definition: GeoDataStyle.h:55
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:91
Marble::TrackerPluginItem::placemark
GeoDataPlacemark * placemark()
Returns the wrapped placemark which will be displayed if this item is in a TrackerPluginModel.
Definition: TrackerPluginItem.cpp:40
elsetrec::altp
double altp
Definition: sgp4unit.h:88
Marble::GeoDataLineStyle::setPenStyle
void setPenStyle(Qt::PenStyle style)
Set pen cap style.
Definition: GeoDataLineStyle.cpp:111
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
GeoPainter.h
MarbleGlobal.h
GeoDataPlacemark.h
Marble::GeoDataStyle::lineStyle
GeoDataLineStyle & lineStyle() const
Return the label style of this style.
Definition: GeoDataStyle.cpp:118
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
Marble::SatellitesTLEItem::name
QString name()
Definition: SatellitesTLEItem.cpp:116
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:82
Marble::SatellitesTLEItem::update
void update()
Reimplement this method to update the placemark, for example to change its coordinates.
Definition: SatellitesTLEItem.cpp:88
SatellitesTLEItem.h
GeoDataPoint.h
Marble::GeoDataFeature::Satellite
Definition: GeoDataFeature.h:265
elsetrec::satnum
long int satnum
Definition: sgp4unit.h:65
Marble::GeoDataLabelStyle::setGlow
void setGlow(bool on)
Enable or disable a glow effect around the text of the label.
Definition: GeoDataLabelStyle.cpp:130
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::GeoDataFeature::setZoomLevel
void setZoomLevel(int index)
Sets the popularity index of the placemark.
Definition: GeoDataFeature.cpp:712
days2mdhms
void days2mdhms(int year, double days, int &mon, int &day, int &hr, int &minute, double &sec)
Definition: sgp4ext.cpp:617
Marble::GeoDataFeature::setStyle
void setStyle(GeoDataStyle *style)
Sets the style of the placemark.
Definition: GeoDataFeature.cpp:645
getgravconst
void getgravconst(gravconsttype whichconst, double &tumin, double &mu, double &radiusearthkm, double &xke, double &j2, double &j3, double &j4, double &j3oj2)
Definition: sgp4unit.cpp:2059
elsetrec::ecco
double ecco
Definition: sgp4unit.h:88
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:219
Marble::SatellitesTLEItem::setOrbitColor
void setOrbitColor(const QColor &color)
Definition: SatellitesTLEItem.cpp:121
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:136
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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