• 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
SatellitesMSCItem.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 2012 Rene Kuettner <rene@bitkanal.net>
9 //
10 
11 
12 #include "SatellitesMSCItem.h"
13 
14 #include <QDateTime>
15 #include <QFile>
16 #include <QString>
17 #include <QColor>
18 
19 #include "MarbleClock.h"
20 #include "MarbleDebug.h"
21 #include "MarbleGlobal.h"
22 #include "GeoPainter.h"
23 #include "GeoDataCoordinates.h"
24 #include "GeoDataPlacemark.h"
25 #include "GeoDataStyle.h"
26 #include "GeoDataTrack.h"
27 #include "GeoDataPoint.h"
28 
29 namespace Marble {
30 
31 SatellitesMSCItem::SatellitesMSCItem( const QString &name,
32  const QString &category,
33  const QString &relatedBody,
34  const QString &catalog,
35  const QDateTime &missionStart,
36  const QDateTime &missionEnd,
37  int catalogIndex,
38  PlanetarySats *planSat,
39  const MarbleClock *clock )
40  : TrackerPluginItem( name ),
41  m_showOrbit( false ),
42  m_track( new GeoDataTrack() ),
43  m_clock( clock ),
44  m_planSat( planSat ),
45  m_name( name ),
46  m_category( category ),
47  m_relatedBody( relatedBody ),
48  m_catalog( catalog ),
49  m_catalogIndex( catalogIndex ),
50  m_missionStart( missionStart ),
51  m_missionEnd( missionEnd )
52 {
53  placemark()->setVisualCategory( GeoDataFeature::Satellite );
54  placemark()->setZoomLevel( 0 );
55  placemark()->setGeometry( m_track );
56 
57  GeoDataStyle *style = new GeoDataStyle( *placemark()->style() );
58  placemark()->setStyle( style );
59  placemark()->style()->lineStyle().setPenStyle( Qt::NoPen );
60  placemark()->style()->labelStyle().setGlow( true );
61 
62  // use special icon for moons
63  if( m_category == "Moons" ) {
64  placemark()->style()->iconStyle().setIcon(
65  QImage( ":/icons/moon.png" ) );
66  }
67 
68 
69  m_planSat->getKeplerElements(
70  m_perc, m_apoc, m_inc, m_ecc, m_ra, m_tano, m_m0, m_a, m_n0 );
71 
72  setDescription();
73  update();
74 }
75 
76 SatellitesMSCItem::~SatellitesMSCItem()
77 {
78  delete m_planSat;
79 }
80 
81 QString SatellitesMSCItem::name() const
82 {
83  return m_name;
84 }
85 
86 QString SatellitesMSCItem::category() const
87 {
88  return m_category;
89 }
90 
91 QString SatellitesMSCItem::relatedBody() const
92 {
93  return m_relatedBody;
94 }
95 
96 QString SatellitesMSCItem::catalog() const
97 {
98  return m_catalog;
99 }
100 
101 int SatellitesMSCItem::catalogIndex() const
102 {
103  return m_catalogIndex;
104 }
105 
106 QString SatellitesMSCItem::id() const
107 {
108  return QString( "%1:%2" ).arg( catalog() ).arg( catalogIndex() );
109 }
110 
111 const QDateTime& SatellitesMSCItem::missionStart() const
112 {
113  return m_missionStart;
114 }
115 
116 const QDateTime& SatellitesMSCItem::missionEnd() const
117 {
118  return m_missionEnd;
119 }
120 
121 void SatellitesMSCItem::setDescription()
122 {
123  /*QString description =
124  QObject::tr( "Object name: %1 <br />"
125  "Category: %2 <br />"
126  "Pericentre: %3 km<br />"
127  "Apocentre: %4 km<br />"
128  "Inclination: %5 Degree<br />"
129  "Revolutions per day (24h): %6" )
130  .arg( name(), category(), QString::number( m_perc, 'f', 2 ),
131  QString::number( m_apoc, 'f', 2 ),
132  QString::number( m_inc, 'f', 2 ),
133  QString::number( m_n0, 'f', 2 ) );*/
134 
135  QFile templateFile(":/marble/satellites/satellite.html");
136  if (!templateFile.open(QIODevice::ReadOnly)) {
137  placemark()->setDescription(tr("No info available."));
138  return;
139  }
140  QString html = templateFile.readAll();
141 
142  html.replace("%name%", name());
143  html.replace("%noradId%", QString::number(catalogIndex()));
144  html.replace("%perigee%", QString::number(m_perc, 'f', 2));
145  html.replace("%apogee%", QString::number(m_apoc, 'f', 2));
146  html.replace("%inclination%", QString::number(m_inc, 'f', 2));
147  html.replace("%period%", "?");
148  html.replace("%semiMajorAxis%", "?");
149 
150  placemark()->setDescription( html );
151 }
152 
153 void SatellitesMSCItem::update()
154 {
155  if( m_missionStart.isValid() ) {
156  setVisible( ( m_clock->dateTime() > m_missionStart ) );
157  }
158 
159  if( m_missionEnd.isValid() ) {
160  setVisible( ( m_clock->dateTime() < m_missionEnd ) );
161  }
162 
163  if( !isEnabled() || !isVisible() ) {
164  return;
165  }
166 
167  double period = 24 * 3600 / m_n0;
168  QDateTime startTime = m_clock->dateTime().addSecs( - period / 2. );
169  QDateTime endTime = startTime.addSecs( period );
170 
171  m_track->removeBefore( startTime );
172  m_track->removeAfter( endTime );
173 
174  double step = period / 500.;
175 
176  // FIXME update track only if orbit is visible
177  for( double i = startTime.toTime_t(); i < endTime.toTime_t(); i += step ) {
178 
179  if ( i >= m_track->firstWhen().toTime_t() ) {
180  i = m_track->lastWhen().toTime_t() + step;
181  }
182 
183  addTrackPointAt( QDateTime::fromTime_t( i ) );
184  }
185 
186  addTrackPointAt( m_clock->dateTime() );
187 }
188 
189 void SatellitesMSCItem::setOrbitColor(const QColor &color)
190 {
191  placemark()->style()->lineStyle().setColor(color);
192 }
193 
194 void SatellitesMSCItem::addTrackPointAt( const QDateTime &dateTime )
195 {
196  double lng = 0.;
197  double lat = 0.;
198  double height = 0.;
199 
200  QDateTime dt = dateTime.toUTC();
201  QDate date = dt.date();
202  QTime time = dt.time();
203 
204  m_planSat->setMJD( date.year(), date.month(), date.day(),
205  time.hour(), time.minute(), time.second() );
206  m_planSat->currentPos();
207  m_planSat->getPlanetographic( lng, lat, height );
208 
209  m_track->addPoint( dateTime,
210  GeoDataCoordinates( lng, lat, height * 1000,
211  GeoDataCoordinates::Degree) );
212 }
213 
214 } // namespace Marble
215 
216 #include "SatellitesMSCItem.moc"
217 
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
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:54
Marble::GeoDataIconStyle::setIcon
void setIcon(const QImage &icon)
Definition: GeoDataIconStyle.cpp:84
Marble::GeoDataFeature::setVisualCategory
void setVisualCategory(GeoDataVisualCategory category)
Sets the symbol index of the placemark.
Definition: GeoDataFeature.cpp:680
PlanetarySats::setMJD
void setMJD(int year, int month, int day, int hour, int min, double sec)
Definition: planetarySats.cpp:128
Marble::GeoDataFeature::setDescription
void setDescription(const QString &value)
Set the description of this feature to value.
Definition: GeoDataFeature.cpp:518
Marble::SatellitesMSCItem::id
QString id() const
Definition: SatellitesMSCItem.cpp:106
Marble::SatellitesMSCItem::catalog
QString catalog() const
Definition: SatellitesMSCItem.cpp:96
Marble::GeoDataColorStyle::setColor
void setColor(const QColor &value)
Set a new color.
Definition: GeoDataColorStyle.cpp:73
GeoDataStyle.h
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark.
Definition: GeoDataFeature.cpp:624
Marble::SatellitesMSCItem::missionEnd
const QDateTime & missionEnd() const
Definition: SatellitesMSCItem.cpp:116
Marble::SatellitesMSCItem::update
void update()
Reimplement this method to update the placemark, for example to change its coordinates.
Definition: SatellitesMSCItem.cpp:153
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
PlanetarySats::getPlanetographic
void getPlanetographic(double &lng, double &lat, double &height)
Definition: planetarySats.cpp:475
GeoDataTrack.h
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
SatellitesMSCItem.h
Marble::MarbleClock::dateTime
QDateTime dateTime() const
Returns the internal date and time.
Definition: MarbleClock.cpp:110
Marble::SatellitesMSCItem::setOrbitColor
void setOrbitColor(const QColor &color)
Definition: SatellitesMSCItem.cpp:189
Marble::TrackerPluginItem::isVisible
virtual bool isVisible() const
Return whether the item is visible or invisible.
Definition: TrackerPluginItem.cpp:55
Marble::GeoDataStyle::labelStyle
GeoDataLabelStyle & labelStyle() const
Return the label style of this style.
Definition: GeoDataStyle.cpp:128
Marble::TrackerPluginItem::setVisible
virtual void setVisible(bool visible)
Set item visible/invisible according to visible.
Definition: TrackerPluginItem.cpp:60
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::SatellitesMSCItem::name
QString name() const
Definition: SatellitesMSCItem.cpp:81
Marble::TrackerPluginItem::placemark
GeoDataPlacemark * placemark()
Returns the wrapped placemark which will be displayed if this item is in a TrackerPluginModel.
Definition: TrackerPluginItem.cpp:40
Marble::SatellitesMSCItem::category
QString category() const
Definition: SatellitesMSCItem.cpp:86
Marble::SatellitesMSCItem::missionStart
const QDateTime & missionStart() const
Definition: SatellitesMSCItem.cpp:111
Marble::GeoDataLineStyle::setPenStyle
void setPenStyle(Qt::PenStyle style)
Set pen cap style.
Definition: GeoDataLineStyle.cpp:111
Marble::GeoDataStyle::iconStyle
GeoDataIconStyle & iconStyle() const
Return the icon style of this style.
Definition: GeoDataStyle.cpp:113
PlanetarySats::getKeplerElements
void getKeplerElements(double &perc, double &apoc, double &inc, double &ecc, double &ra, double &tano, double &m0, double &a, double &n0)
Definition: planetarySats.cpp:386
GeoPainter.h
MarbleGlobal.h
GeoDataPlacemark.h
Marble::GeoDataStyle::lineStyle
GeoDataLineStyle & lineStyle() const
Return the label style of this style.
Definition: GeoDataStyle.cpp:118
Marble::TrackerPluginItem
Subclass this to represent items in your TrackerPluginModel.
Definition: TrackerPluginItem.h:29
Marble::SatellitesMSCItem::~SatellitesMSCItem
~SatellitesMSCItem()
Definition: SatellitesMSCItem.cpp:76
MarbleClock.h
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
PlanetarySats::currentPos
void currentPos()
Definition: planetarySats.cpp:459
GeoDataPoint.h
Marble::GeoDataFeature::Satellite
Definition: GeoDataFeature.h:265
Marble::GeoDataLabelStyle::setGlow
void setGlow(bool on)
Enable or disable a glow effect around the text of the label.
Definition: GeoDataLabelStyle.cpp:130
Marble::SatellitesMSCItem::catalogIndex
int catalogIndex() const
Definition: SatellitesMSCItem.cpp:101
Marble::GeoDataFeature::setZoomLevel
void setZoomLevel(int index)
Sets the popularity index of the placemark.
Definition: GeoDataFeature.cpp:712
Marble::GeoDataFeature::setStyle
void setStyle(GeoDataStyle *style)
Sets the style of the placemark.
Definition: GeoDataFeature.cpp:645
Marble::SatellitesMSCItem::relatedBody
QString relatedBody() const
Definition: SatellitesMSCItem.cpp:91
Marble::MarbleClock
Definition: MarbleClock.h:25
Marble::SatellitesMSCItem::SatellitesMSCItem
SatellitesMSCItem(const QString &name, const QString &category, const QString &relatedBody, const QString &catalog, const QDateTime &missionStart, const QDateTime &missionEnd, int catalogIndex, PlanetarySats *planSat, const MarbleClock *clock)
Definition: SatellitesMSCItem.cpp:31
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
PlanetarySats
Definition: planetarySats.h:16
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