• 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
SatellitesModel.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 "SatellitesModel.h"
12 
13 #include "MarbleDebug.h"
14 #include "SatellitesMSCItem.h"
15 #include "SatellitesTLEItem.h"
16 
17 #include "MarbleClock.h"
18 #include "GeoDataPlacemark.h"
19 #include "GeoDataStyle.h"
20 
21 #include "sgp4/sgp4io.h"
22 #include <planetarySats.h>
23 
24 #include <locale.h>
25 
26 namespace Marble {
27 
28 SatellitesModel::SatellitesModel( GeoDataTreeModel *treeModel,
29  const MarbleClock *clock )
30  : TrackerPluginModel( treeModel ),
31  m_clock( clock ),
32  m_currentColorIndex( 0 )
33 {
34  setupColors();
35  connect(m_clock, SIGNAL(timeChanged()), this, SLOT(update()));
36 }
37 
38 void SatellitesModel::setupColors()
39 {
40  m_colorList.push_back( Oxygen::brickRed4 );
41  m_colorList.push_back( Oxygen::raspberryPink4 );
42  m_colorList.push_back( Oxygen::burgundyPurple4 );
43  m_colorList.push_back( Oxygen::grapeViolet4 );
44  m_colorList.push_back( Oxygen::skyBlue4 );
45  m_colorList.push_back( Oxygen::seaBlue4 );
46  m_colorList.push_back( Oxygen::emeraldGreen4 );
47  m_colorList.push_back( Oxygen::forestGreen4 );
48  m_colorList.push_back( Oxygen::sunYellow4 );
49  m_colorList.push_back( Oxygen::hotOrange4 );
50  m_colorList.push_back( Oxygen::aluminumGray4 );
51  m_colorList.push_back( Oxygen::woodBrown4 );
52 }
53 
54 QColor SatellitesModel::nextColor()
55 {
56  if (m_colorList.isEmpty()) {
57  return Oxygen::brickRed4;
58  }
59  if (m_currentColorIndex < m_colorList.size()) {
60  m_currentColorIndex++;
61  return m_colorList[m_currentColorIndex-1];
62  } else {
63  m_currentColorIndex = 1;
64  return m_colorList[0];
65  }
66  return Oxygen::brickRed4;
67 }
68 
69 void SatellitesModel::loadSettings( const QHash<QString, QVariant> &settings )
70 {
71  QStringList idList = settings["idList"].toStringList();
72  m_enabledIds = idList;
73 
74  updateVisibility();
75 }
76 
77 void SatellitesModel::setPlanet( const QString &planetId )
78 {
79  if( m_lcPlanet != planetId ) {
80 
81  mDebug() << "Planet changed from" << m_lcPlanet << "to" << planetId;
82  m_lcPlanet = planetId;
83 
84  updateVisibility();
85  }
86 }
87 
88 void SatellitesModel::updateVisibility()
89 {
90  beginUpdateItems();
91 
92  foreach( TrackerPluginItem *obj, items() ) {
93  SatellitesMSCItem *oItem = dynamic_cast<SatellitesMSCItem*>(obj);
94  if( oItem != NULL ) {
95  bool enabled = ( ( oItem->relatedBody().toLower() == m_lcPlanet ) &&
96  ( m_enabledIds.contains( oItem->id() ) ) );
97  oItem->setEnabled( enabled );
98 
99  if( enabled ) {
100  oItem->update();
101  }
102  }
103 
104  SatellitesTLEItem *eItem = dynamic_cast<SatellitesTLEItem*>(obj);
105  if( eItem != NULL ) {
106  // TLE satellites are always earth satellites
107  bool enabled = ( m_lcPlanet == "earth" );
108  eItem->setEnabled( enabled );
109 
110  if( enabled ) {
111  eItem->update();
112  }
113  }
114  }
115 
116  endUpdateItems();
117 }
118 
119 void SatellitesModel::parseFile( const QString &id,
120  const QByteArray &data )
121 {
122  // catalog files are comma serparated while tle files
123  // are not allowed to contain commas, so we use this
124  // to distinguish between those two
125  if( data.contains( ',' ) ) {
126  parseCatalog( id, data );
127  } else {
128  parseTLE( id, data );
129  }
130 
131  emit fileParsed( id );
132 }
133 
134 void SatellitesModel::parseCatalog( const QString &id,
135  const QByteArray &data )
136 {
137  // For details see:
138  // http://techbase.kde.org/Projects/Marble/SatelliteCatalogFormat
139 
140  mDebug() << "Reading satellite catalog from:" << id;
141 
142  QTextStream ts(data);
143  int index = 1;
144 
145  beginUpdateItems();
146 
147  QString line = ts.readLine();
148  for( ; !line.isNull(); line = ts.readLine() ) {
149 
150  if( line.trimmed().startsWith( QLatin1String( "#" ) ) ) {
151  continue;
152  }
153 
154  QStringList elms = line.split(", ");
155 
156  // check for '<' instead of '==' in order to allow fields to be added
157  // to catalogs later without breaking the code
158  if( elms.size() < 14 ) {
159  mDebug() << "Skipping line:" << elms << "(" << line << ")";
160  continue;
161  }
162 
163  QString name( elms[0] );
164  QString category( elms[1] );
165  QString body( elms[2] );
166  QByteArray body8Bit = body.toLocal8Bit();
167  char *cbody = const_cast<char*>( body8Bit.constData() );
168 
169  mDebug() << "Loading" << category << name;
170 
171  PlanetarySats *planSat = new PlanetarySats();
172  planSat->setPlanet( cbody );
173 
174  planSat->setStateVector(
175  elms[7].toFloat() - 2400000.5,
176  elms[8].toFloat(), elms[9].toFloat(), elms[10].toFloat(),
177  elms[11].toFloat(), elms[12].toFloat(), elms[13].toFloat() );
178 
179  planSat->stateToKepler();
180 
181  QDateTime missionStart, missionEnd;
182  if( elms[3].toUInt() > 0 ) {
183  missionStart = QDateTime::fromTime_t( elms[3].toUInt() );
184  }
185  if( elms[4].toUInt() > 0 ) {
186  missionEnd = QDateTime::fromTime_t( elms[4].toUInt() );
187  }
188 
189  SatellitesMSCItem *item = new SatellitesMSCItem( name, category, body, id,
190  missionStart, missionEnd,
191  index++, planSat, m_clock );
192  GeoDataStyle *style = new GeoDataStyle( *item->placemark()->style() );
193  style->lineStyle().setPenStyle( Qt::SolidLine );
194  style->lineStyle().setColor( nextColor() );
195  style->labelStyle().setGlow( true );
196 
197  // use special icon for moons
198  if( category == "Moons" ) {
199  style->iconStyle().setIcon( QImage( ":/icons/moon.png" ) );
200  }
201 
202  item->placemark()->setStyle( style );
203 
204  item->placemark()->setVisible( ( body.toLower() == m_lcPlanet ) );
205  addItem( item );
206  }
207 
208  endUpdateItems();
209 }
210 
211 void SatellitesModel::parseTLE( const QString &id,
212  const QByteArray &data )
213 {
214  mDebug() << "Reading satellite TLE data from:" << id;
215 
216  QList<QByteArray> tleLines = data.split( '\n' );
217  // File format: One line of description, two lines of TLE, last line is empty
218  if ( tleLines.size() % 3 != 1 ) {
219  mDebug() << "Malformated satellite data file";
220  }
221 
222  beginUpdateItems();
223 
224  //FIXME: terrible hack because twoline2rv uses sscanf
225  setlocale( LC_NUMERIC, "C" );
226 
227  double startmfe, stopmfe, deltamin;
228  elsetrec satrec;
229  int i = 0;
230  while ( i < tleLines.size() - 1 ) {
231  QString satelliteName = QString( tleLines.at( i++ ) ).trimmed();
232  char line1[130];
233  char line2[130];
234  if( tleLines.at( i ).size() >= 79 ||
235  tleLines.at( i+1 ).size() >= 79 ) {
236  mDebug() << "Invalid TLE data!";
237  return;
238  }
239  qstrcpy( line1, tleLines.at( i++ ).constData() );
240  qstrcpy( line2, tleLines.at( i++ ).constData() );
241  twoline2rv( line1, line2, 'c', 'd', 'i', wgs84,
242  startmfe, stopmfe, deltamin, satrec );
243  if ( satrec.error != 0 ) {
244  mDebug() << "Error: " << satrec.error;
245  return;
246  }
247 
248  SatellitesTLEItem *item = new SatellitesTLEItem( satelliteName, satrec, m_clock );
249  GeoDataStyle *style = new GeoDataStyle( *item->placemark()->style() );
250  style->lineStyle().setPenStyle( Qt::SolidLine );
251  style->lineStyle().setColor( nextColor() );
252  style->labelStyle().setGlow( true );
253  item->placemark()->setStyle( style );
254  addItem( item );
255  }
256 
257  //Reset to environment
258  setlocale( LC_NUMERIC, "" );
259 
260  endUpdateItems();
261 }
262 
263 } // namespace Marble
264 
265 #include "SatellitesModel.moc"
Marble::Oxygen::raspberryPink4
QColor const raspberryPink4
Definition: MarbleColors.h:38
Marble::SatellitesTLEItem
An instance SatellitesTLEItem represents an item of a two-line-elements set catalog.
Definition: SatellitesTLEItem.h:32
Marble::SatellitesModel::parseTLE
void parseTLE(const QString &id, const QByteArray &data)
Parse the two line elements set file id with content data.
Definition: SatellitesModel.cpp:211
elsetrec
Definition: sgp4unit.h:63
Marble::GeoDataTreeModel
The representation of GeoData in a model This class represents all available data given by kml-data f...
Definition: GeoDataTreeModel.h:32
Marble::GeoDataIconStyle::setIcon
void setIcon(const QImage &icon)
Definition: GeoDataIconStyle.cpp:102
QByteArray::split
QList< QByteArray > split(char sep) const
QTextStream::readLine
QString readLine(qint64 maxlen)
QByteArray
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Marble::Oxygen::sunYellow4
QColor const sunYellow4
Definition: MarbleColors.h:80
Marble::SatellitesMSCItem::id
QString id() const
Definition: SatellitesMSCItem.cpp:87
QList::at
const T & at(int i) const
Marble::GeoDataColorStyle::setColor
void setColor(const QColor &value)
Set a new color.
Definition: GeoDataColorStyle.cpp:84
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Marble::GeoDataStyle::iconStyle
GeoDataIconStyle & iconStyle()
Return the icon style of this style.
Definition: GeoDataStyle.cpp:133
GeoDataStyle.h
Marble::GeoDataFeature::style
const GeoDataStyle * style() const
Return the style assigned to the placemark, or a default style if none has been set.
Definition: GeoDataFeature.cpp:709
Marble::SatellitesModel::setPlanet
void setPlanet(const QString &lcPlanet)
Definition: SatellitesModel.cpp:77
Marble::SatellitesMSCItem::update
void update()
Reimplement this method to update the placemark, for example to change its coordinates.
Definition: SatellitesMSCItem.cpp:134
MarbleDebug.h
Marble::GeoDataStyle::lineStyle
GeoDataLineStyle & lineStyle()
Return the label style of this style.
Definition: GeoDataStyle.cpp:143
SatellitesMSCItem.h
QTextStream
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
QList::size
int size() const
QString::isNull
bool isNull() const
QObject::name
const char * name() const
QDateTime::fromTime_t
QDateTime fromTime_t(uint seconds)
Marble::GeoDataStyle
an addressable style group
Definition: GeoDataStyle.h:55
Marble::SatellitesModel::SatellitesModel
SatellitesModel(GeoDataTreeModel *treeModel, const MarbleClock *clock)
Definition: SatellitesModel.cpp:28
Marble::Oxygen::aluminumGray4
QColor const aluminumGray4
Definition: MarbleColors.h:92
QHash< QString, QVariant >
SatellitesModel.h
Marble::TrackerPluginItem::setEnabled
virtual void setEnabled(bool enabled)
Enable/Disable the item following the user checkbox action according to enabled.
Definition: TrackerPluginItem.cpp:59
twoline2rv
void twoline2rv(char longstr1[130], char longstr2[130], char typerun, char typeinput, char opsmode, gravconsttype whichconst, double &startmfe, double &stopmfe, double &deltamin, elsetrec &satrec)
Definition: sgp4io.cpp:71
QString::trimmed
QString trimmed() const
QByteArray::constData
const char * constData() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Marble::SatellitesModel::updateVisibility
void updateVisibility()
Definition: SatellitesModel.cpp:88
planetarySats.h
Marble::TrackerPluginItem::placemark
GeoDataPlacemark * placemark()
Returns the wrapped placemark which will be displayed if this item is in a TrackerPluginModel.
Definition: TrackerPluginItem.cpp:49
Marble::Oxygen::seaBlue4
QColor const seaBlue4
Definition: MarbleColors.h:62
Marble::TrackerPluginModel::fileParsed
void fileParsed(const QString &id)
Marble::GeoDataLineStyle::setPenStyle
void setPenStyle(Qt::PenStyle style)
Set pen cap style.
Definition: GeoDataLineStyle.cpp:130
Marble::TrackerPluginModel::items
QVector< TrackerPluginItem * > items() const
Return all available items.
Definition: TrackerPluginModel.cpp:127
Marble::TrackerPluginModel::endUpdateItems
void endUpdateItems()
End a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:151
Marble::Oxygen::skyBlue4
QColor const skyBlue4
Definition: MarbleColors.h:56
wgs84
Definition: sgp4unit.h:60
QString
QList
QColor
Marble::SatellitesModel::parseCatalog
void parseCatalog(const QString &id, const QByteArray &data)
Parse the Marble Satellite Catalog id with content data.
Definition: SatellitesModel.cpp:134
GeoDataPlacemark.h
QStringList
PlanetarySats::setStateVector
void setStateVector(double mjd, double x, double y, double z, double vx, double vy, double vz)
Definition: planetarySats.cpp:171
Marble::TrackerPluginItem
Subclass this to represent items in your TrackerPluginModel.
Definition: TrackerPluginItem.h:29
elsetrec::error
int error
Definition: sgp4unit.h:67
QString::toLower
QString toLower() const
QString::toLocal8Bit
QByteArray toLocal8Bit() const
MarbleClock.h
Marble::SatellitesModel::parseFile
void parseFile(const QString &id, const QByteArray &file)
This method is called whenever a file queued up for download by downloadFile() has finished downloadi...
Definition: SatellitesModel.cpp:119
QImage
Marble::GeoDataFeature::setVisible
void setVisible(bool value)
Set a new value for visibility.
Definition: GeoDataFeature.cpp:661
Marble::Oxygen::brickRed4
QColor const brickRed4
Definition: MarbleColors.h:32
Marble::SatellitesTLEItem::update
void update()
Reimplement this method to update the placemark, for example to change its coordinates.
Definition: SatellitesTLEItem.cpp:81
Marble::TrackerPluginModel::beginUpdateItems
void beginUpdateItems()
Begin a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:142
Marble::SatellitesModel::loadSettings
void loadSettings(const QHash< QString, QVariant > &settings)
Definition: SatellitesModel.cpp:69
SatellitesTLEItem.h
QLatin1String
Marble::Oxygen::burgundyPurple4
QColor const burgundyPurple4
Definition: MarbleColors.h:44
QVector::isEmpty
bool isEmpty() const
Marble::GeoDataLabelStyle::setGlow
void setGlow(bool on)
Enable or disable a glow effect around the text of the label.
Definition: GeoDataLabelStyle.cpp:143
PlanetarySats::setPlanet
void setPlanet(char *pname)
Definition: planetarySats.cpp:310
Marble::TrackerPluginModel
A model used to download, store and update items.
Definition: TrackerPluginModel.h:29
QByteArray::contains
bool contains(char ch) const
Marble::Oxygen::emeraldGreen4
QColor const emeraldGreen4
Definition: MarbleColors.h:68
Marble::Oxygen::forestGreen4
QColor const forestGreen4
Definition: MarbleColors.h:74
QVector::push_back
void push_back(const T &value)
Marble::SatellitesMSCItem
An instance of SatellitesMSCItem represents an item of a Marble satellites catalog.
Definition: SatellitesMSCItem.h:33
Marble::GeoDataFeature::setStyle
void setStyle(GeoDataStyle *style)
Sets the style of the placemark.
Definition: GeoDataFeature.cpp:735
Marble::SatellitesMSCItem::relatedBody
QString relatedBody() const
Definition: SatellitesMSCItem.cpp:72
Marble::TrackerPluginModel::addItem
void addItem(TrackerPluginItem *mark)
Add the item mark to the model.
Definition: TrackerPluginModel.cpp:121
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVector::size
int size() const
Marble::MarbleClock
Definition: MarbleClock.h:25
PlanetarySats::stateToKepler
void stateToKepler()
Definition: planetarySats.cpp:320
Marble::Oxygen::woodBrown4
QColor const woodBrown4
Definition: MarbleColors.h:26
Marble::GeoDataStyle::labelStyle
GeoDataLabelStyle & labelStyle()
Return the label style of this style.
Definition: GeoDataStyle.cpp:163
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::Oxygen::grapeViolet4
QColor const grapeViolet4
Definition: MarbleColors.h:50
QDateTime
sgp4io.h
PlanetarySats
Definition: planetarySats.h:17
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