• 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
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 "mex/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( QObject *obj, items() ) {
93  SatellitesMSCItem *oItem = qobject_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 = qobject_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;
190  item = new SatellitesMSCItem( name, category, body, id,
191  missionStart, missionEnd,
192  index++, planSat, m_clock );
193  item->setOrbitColor( nextColor() );
194  item->placemark()->setVisible( ( body.toLower() == m_lcPlanet ) );
195  addItem( item );
196  }
197 
198  endUpdateItems();
199 }
200 
201 void SatellitesModel::parseTLE( const QString &id,
202  const QByteArray &data )
203 {
204  mDebug() << "Reading satellite TLE data from:" << id;
205 
206  QList<QByteArray> tleLines = data.split( '\n' );
207  // File format: One line of description, two lines of TLE, last line is empty
208  if ( tleLines.size() % 3 != 1 ) {
209  mDebug() << "Malformated satellite data file";
210  }
211 
212  beginUpdateItems();
213 
214  //FIXME: terrible hack because twoline2rv uses sscanf
215  setlocale( LC_NUMERIC, "C" );
216 
217  double startmfe, stopmfe, deltamin;
218  elsetrec satrec;
219  int i = 0;
220  while ( i < tleLines.size() - 1 ) {
221  QString satelliteName = QString( tleLines.at( i++ ) ).trimmed();
222  char line1[80];
223  char line2[80];
224  if( tleLines.at( i ).size() >= 79 ||
225  tleLines.at( i+1 ).size() >= 79 ) {
226  mDebug() << "Invalid TLE data!";
227  return;
228  }
229  qstrcpy( line1, tleLines.at( i++ ).constData() );
230  qstrcpy( line2, tleLines.at( i++ ).constData() );
231  twoline2rv( line1, line2, 'c', 'd', 'i', wgs84,
232  startmfe, stopmfe, deltamin, satrec );
233  if ( satrec.error != 0 ) {
234  mDebug() << "Error: " << satrec.error;
235  return;
236  }
237 
238  SatellitesTLEItem *item = new SatellitesTLEItem( satelliteName,
239  satrec, m_clock );
240  item->setOrbitColor( nextColor() );
241  addItem( item );
242  }
243 
244  //Reset to environment
245  setlocale( LC_NUMERIC, "" );
246 
247  endUpdateItems();
248 }
249 
250 } // namespace Marble
251 
252 #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:201
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::Oxygen::sunYellow4
QColor const sunYellow4
Definition: MarbleColors.h:80
Marble::SatellitesMSCItem::id
QString id() const
Definition: SatellitesMSCItem.cpp:106
GeoDataStyle.h
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:153
QObject
MarbleDebug.h
SatellitesMSCItem.h
Marble::SatellitesMSCItem::setOrbitColor
void setOrbitColor(const QColor &color)
Definition: SatellitesMSCItem.cpp:189
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
Marble::SatellitesModel::SatellitesModel
SatellitesModel(GeoDataTreeModel *treeModel, const MarbleClock *clock)
Definition: SatellitesModel.cpp:28
Marble::Oxygen::aluminumGray4
QColor const aluminumGray4
Definition: MarbleColors.h:92
SatellitesModel.h
Marble::TrackerPluginItem::setEnabled
virtual void setEnabled(bool enabled)
Enable/Disable the item according to enabled.
Definition: TrackerPluginItem.cpp:50
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
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:40
Marble::Oxygen::seaBlue4
QColor const seaBlue4
Definition: MarbleColors.h:62
Marble::TrackerPluginModel::fileParsed
void fileParsed(const QString &id)
Marble::TrackerPluginModel::items
QVector< TrackerPluginItem * > items() const
Return all available items.
Definition: TrackerPluginModel.cpp:126
Marble::TrackerPluginModel::endUpdateItems
void endUpdateItems()
End a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:150
Marble::Oxygen::skyBlue4
QColor const skyBlue4
Definition: MarbleColors.h:56
wgs84
Definition: sgp4unit.h:60
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
PlanetarySats::setStateVector
void setStateVector(double mjd, double x, double y, double z, double vx, double vy, double vz)
Definition: planetarySats.cpp:171
elsetrec::error
int error
Definition: sgp4unit.h:67
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
Marble::GeoDataFeature::setVisible
void setVisible(bool value)
Set a new value for visibility.
Definition: GeoDataFeature.cpp:586
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:88
Marble::TrackerPluginModel::beginUpdateItems
void beginUpdateItems()
Begin a series of add or remove items operations on the model.
Definition: TrackerPluginModel.cpp:141
Marble::SatellitesModel::loadSettings
void loadSettings(const QHash< QString, QVariant > &settings)
Definition: SatellitesModel.cpp:69
SatellitesTLEItem.h
Marble::Oxygen::burgundyPurple4
QColor const burgundyPurple4
Definition: MarbleColors.h:44
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
Marble::Oxygen::emeraldGreen4
QColor const emeraldGreen4
Definition: MarbleColors.h:68
Marble::Oxygen::forestGreen4
QColor const forestGreen4
Definition: MarbleColors.h:74
Marble::SatellitesMSCItem
An instance of SatellitesMSCItem represents an item of a Marble satellites catalog.
Definition: SatellitesMSCItem.h:33
Marble::SatellitesMSCItem::relatedBody
QString relatedBody() const
Definition: SatellitesMSCItem.cpp:91
Marble::TrackerPluginModel::addItem
void addItem(TrackerPluginItem *mark)
Add the item mark to the model.
Definition: TrackerPluginModel.cpp:120
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::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::Oxygen::grapeViolet4
QColor const grapeViolet4
Definition: MarbleColors.h:50
Marble::SatellitesTLEItem::setOrbitColor
void setOrbitColor(const QColor &color)
Definition: SatellitesTLEItem.cpp:121
sgp4io.h
PlanetarySats
Definition: planetarySats.h:16
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