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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skycomponents
asteroidscomponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  asteroidscomponent.cpp - K Desktop Planetarium
3  -------------------
4  begin : 2005/30/08
5  copyright : (C) 2005 by Thomas Kabelmann
6  email : thomas.kabelmann@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "asteroidscomponent.h"
19 
20 #include "projections/projector.h"
21 #include "solarsystemcomposite.h"
22 #include "skycomponent.h"
23 #include "skylabeler.h"
24 #include "skymap.h"
25 #include "skypainter.h"
26 #include "Options.h"
27 #include "skyobjects/ksasteroid.h"
28 #include "kstarsdata.h"
29 #include "ksfilereader.h"
30 #include <kdebug.h>
31 #include <kglobal.h>
32 #include <kio/job.h>
33 #include <kio/netaccess.h>
34 #include <kio/jobuidelegate.h>
35 #include <kstandarddirs.h>
36 #include <QPen>
37 
38 
39 AsteroidsComponent::AsteroidsComponent(SolarSystemComposite *parent)
40  : SolarSystemListComponent(parent) {
41  loadData();
42 }
43 
44 AsteroidsComponent::~AsteroidsComponent()
45 {}
46 
47 bool AsteroidsComponent::selected() {
48  return Options::showAsteroids();
49 }
50 
51 /*
52  *@short Initialize the asteroids list.
53  *Reads in the asteroids data from the asteroids.dat file.
54  *
55  * The data file is a CSV file with the following columns :
56  * @li 1 full name [string]
57  * @li 2 Modified Julian Day of orbital elements [int]
58  * @li 3 perihelion distance in AU [double]
59  * @li 4 semi-major axis
60  * @li 5 eccentricity of orbit [double]
61  * @li 6 inclination angle of orbit in degrees [double]
62  * @li 7 argument of perihelion in degrees [double]
63  * @li 8 longitude of the ascending node in degrees [double]
64  * @li 9 mean anomaly
65  * @li 10 time of perihelion passage (YYYYMMDD.DDD) [double]
66  * @li 11 orbit solution ID [string]
67  * @li 12 absolute magnitude [float]
68  * @li 13 slope parameter [float]
69  * @li 14 Near-Earth Object (NEO) flag [bool]
70  * @li 15 comet total magnitude parameter [float] (we should remove this column)
71  * @li 16 comet nuclear magnitude parameter [float] (we should remove this column)
72  * @li 17 object diameter (from equivalent sphere) [float]
73  * @li 18 object bi/tri-axial ellipsoid dimensions [string]
74  * @li 19 geometric albedo [float]
75  * @li 20 rotation period [float]
76  * @li 21 orbital period [float]
77  * @li 22 earth minimum orbit intersection distance [double]
78  * @li 23 orbit classification [string]
79  */
80 void AsteroidsComponent::loadData() {
81  QString name, full_name, orbit_id, orbit_class, dimensions;
82  int mJD;
83  double q, a, e, dble_i, dble_w, dble_N, dble_M, H, G, earth_moid;
84  long double JD;
85  float diameter, albedo, rot_period, period;
86  bool neo;
87 
88  emitProgressText( i18n("Loading asteroids") );
89 
90  // Clear lists
91  m_ObjectList.clear();
92  objectNames( SkyObject::ASTEROID ).clear();
93 
94  QList< QPair<QString, KSParser::DataTypes> > sequence;
95  sequence.append(qMakePair(QString("full name"), KSParser::D_QSTRING));
96  sequence.append(qMakePair(QString("epoch_mjd"), KSParser::D_INT));
97  sequence.append(qMakePair(QString("q"), KSParser::D_DOUBLE));
98  sequence.append(qMakePair(QString("a"), KSParser::D_DOUBLE));
99  sequence.append(qMakePair(QString("e"), KSParser::D_DOUBLE));
100  sequence.append(qMakePair(QString("i"), KSParser::D_DOUBLE));
101  sequence.append(qMakePair(QString("w"), KSParser::D_DOUBLE));
102  sequence.append(qMakePair(QString("om"), KSParser::D_DOUBLE));
103  sequence.append(qMakePair(QString("ma"), KSParser::D_DOUBLE));
104  sequence.append(qMakePair(QString("tp_calc"), KSParser::D_SKIP));
105  sequence.append(qMakePair(QString("orbit_id"), KSParser::D_QSTRING));
106  sequence.append(qMakePair(QString("H"), KSParser::D_DOUBLE));
107  sequence.append(qMakePair(QString("G"), KSParser::D_DOUBLE));
108  sequence.append(qMakePair(QString("neo"), KSParser::D_QSTRING));
109  sequence.append(qMakePair(QString("tp_calc"), KSParser::D_SKIP));
110  sequence.append(qMakePair(QString("M2"), KSParser::D_SKIP));
111  sequence.append(qMakePair(QString("diameter"), KSParser::D_FLOAT));
112  sequence.append(qMakePair(QString("extent"), KSParser::D_QSTRING));
113  sequence.append(qMakePair(QString("albedo"), KSParser::D_FLOAT));
114  sequence.append(qMakePair(QString("rot_period"), KSParser::D_FLOAT));
115  sequence.append(qMakePair(QString("per_y"), KSParser::D_FLOAT));
116  sequence.append(qMakePair(QString("moid"), KSParser::D_DOUBLE));
117  sequence.append(qMakePair(QString("class"), KSParser::D_QSTRING));
118 
119  QString file_name = KStandardDirs::locate( "appdata",
120  QString("asteroids.dat") );
121  KSParser asteroid_parser(file_name, '#', sequence);
122 
123  QHash<QString, QVariant> row_content;
124  while (asteroid_parser.HasNextRow()){
125  row_content = asteroid_parser.ReadNextRow();
126  full_name = row_content["full name"].toString();
127  full_name = full_name.trimmed();
128  int catN = full_name.section(' ', 0, 0).toInt();
129  name = full_name.section(' ', 1, -1);
130  mJD = row_content["epoch_mjd"].toInt();
131  q = row_content["q"].toDouble();
132  a = row_content["a"].toDouble();
133  e = row_content["e"].toDouble();
134  dble_i = row_content["i"].toDouble();
135  dble_w = row_content["w"].toDouble();
136  dble_N = row_content["om"].toDouble();
137  dble_M = row_content["ma"].toDouble();
138  orbit_id = row_content["orbit_id"].toString();
139  H = row_content["H"].toDouble();
140  G = row_content["G"].toDouble();
141  neo = row_content["neo"].toString() == "Y";
142  diameter = row_content["diameter"].toFloat();
143  dimensions = row_content["extent"].toString();
144  albedo = row_content["albedo"].toFloat();
145  rot_period = row_content["rot_period"].toFloat();
146  period = row_content["per_y"].toFloat();
147  earth_moid = row_content["moid"].toDouble();
148  orbit_class = row_content["class"].toString();
149 
150  JD = static_cast<double>(mJD) + 2400000.5;
151 
152  KSAsteroid *new_asteroid = new KSAsteroid( catN, name, QString(), JD,
153  a, e,
154  dms(dble_i), dms(dble_w),
155  dms(dble_N), dms(dble_M),
156  H, G );
157  new_asteroid->setPerihelion(q);
158  new_asteroid->setOrbitID(orbit_id);
159  new_asteroid->setNEO(neo);
160  new_asteroid->setDiameter(diameter);
161  new_asteroid->setDimensions(dimensions);
162  new_asteroid->setAlbedo(albedo);
163  new_asteroid->setRotationPeriod(rot_period);
164  new_asteroid->setPeriod(period);
165  new_asteroid->setEarthMOID(earth_moid);
166  new_asteroid->setOrbitClass(orbit_class);
167  new_asteroid->setAngularSize(0.005);
168  m_ObjectList.append(new_asteroid);
169 
170  // Add name to the list of object names
171  objectNames(SkyObject::ASTEROID).append(name);
172  }
173 }
174 
175 
176 void AsteroidsComponent::draw( SkyPainter *skyp )
177 {
178  if ( ! selected() ) return;
179 
180  bool hideLabels = ! Options::showAsteroidNames() ||
181  ( SkyMap::Instance()->isSlewing() && Options::hideLabels() );
182 
183  double lgmin = log10(MINZOOM);
184  double lgmax = log10(MAXZOOM);
185  double lgz = log10(Options::zoomFactor());
186  double labelMagLimit = 2.5 + Options::asteroidLabelDensity() / 5.0;
187  labelMagLimit += ( 15.0 - labelMagLimit ) * ( lgz - lgmin) / (lgmax - lgmin );
188  if ( labelMagLimit > 10.0 ) labelMagLimit = 10.0;
189  //printf("labelMagLim = %.1f\n", labelMagLimit );
190 
191  skyp->setBrush( QBrush( QColor( "gray" ) ) );
192 
193  foreach ( SkyObject *so, m_ObjectList ) {
194  // FIXME: God help us!
195  KSAsteroid *ast = (KSAsteroid*) so;
196 
197  if ( ast->mag() > Options::magLimitAsteroid() ) continue;
198 
199  bool drawn = skyp->drawPointSource(ast,ast->mag());
200 
201  if ( drawn && !( hideLabels || ast->mag() >= labelMagLimit ) )
202  SkyLabeler::AddLabel( ast, SkyLabeler::ASTEROID_LABEL );
203  }
204 }
205 
206 SkyObject* AsteroidsComponent::objectNearest( SkyPoint *p, double &maxrad ) {
207  SkyObject *oBest = 0;
208 
209  if ( ! selected() ) return 0;
210 
211  foreach ( SkyObject *o, m_ObjectList ) {
212  if ( o->mag() > Options::magLimitAsteroid() ) continue;
213 
214  double r = o->angularDistanceTo( p ).Degrees();
215  if ( r < maxrad ) {
216  oBest = o;
217  maxrad = r;
218  }
219  }
220 
221  return oBest;
222 }
223 
224 void AsteroidsComponent::updateDataFile() {
225  KUrl url = KUrl( "http://ssd.jpl.nasa.gov/sbdb_query.cgi" );
226  QByteArray post_data = QByteArray( "obj_group=all&obj_kind=ast&obj_numbere"
227  "d=num&OBJ_field=0&ORB_field=0&c1_group=OBJ&c1_item=Ai&c1_op=%3C&c1_value="
228  "12&c_fields=AcBdBiBhBgBjBlBkBmBqBbAiAjAgAkAlApAqArAsBsBtCh&table_format=C"
229  "SV&max_rows=10&format_option=full&query=Generate%20Table&.cgifields=forma"
230  "t_option&.cgifields=field_list&.cgifields=obj_kind&.cgifields=obj_group&."
231  "cgifields=obj_numbered&.cgifields=combine_mode&.cgifields=ast_orbit_class"
232  "&.cgifields=table_format&.cgifields=ORB_field_set&.cgifields=OBJ_field_se"
233  "t&.cgifields=preset_field_set&.cgifields=com_orbit_class" );
234  QString content_type = "Content-Type: application/x-www-form-urlencoded";
235 
236  // Download file
237  KIO::StoredTransferJob* get_job = KIO::storedHttpPost( post_data, url );
238  get_job->addMetaData("content-type", content_type );
239 
240  if( KIO::NetAccess::synchronousRun( get_job, 0 ) ) {
241  // Comment the first line
242  QByteArray data = get_job->data();
243  data.insert( 0, '#' );
244 
245  // Write data to asteroids.dat
246  QFile file( KStandardDirs::locateLocal( "appdata", "asteroids.dat" ) );
247  file.open( QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text );
248  file.write( data );
249  file.close();
250 
251  // Reload asteroids
252  loadData();
253 
254  KStars::Instance()->data()->setFullTimeUpdate();
255  } else {
256  get_job->ui()->showErrorMessage();
257  }
258 }
SkyPainter::drawPointSource
virtual bool drawPointSource(SkyPoint *loc, float mag, char sp= 'A')=0
Draw a point source (e.g., a star).
SkyPainter::setBrush
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
Options::magLimitAsteroid
static double magLimitAsteroid()
Get Faint limit for asteroids.
Definition: Options.h:2550
AsteroidsComponent::draw
virtual void draw(SkyPainter *skyp)
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Definition: asteroidscomponent.cpp:176
KSAsteroid::setOrbitID
void setOrbitID(QString orbit_id)
Sets the asteroid's orbit solution ID.
Definition: ksasteroid.cpp:171
KSParser
Generic class for text file parsers used in KStars.
Definition: ksparser.h:49
KSAsteroid::setAlbedo
void setAlbedo(float albedo)
Sets the asteroid's albedo.
Definition: ksasteroid.cpp:146
AsteroidsComponent::updateDataFile
void updateDataFile()
Definition: asteroidscomponent.cpp:224
ListComponent::m_ObjectList
QList< SkyObject * > m_ObjectList
Definition: listcomponent.h:64
AsteroidsComponent::AsteroidsComponent
AsteroidsComponent(SolarSystemComposite *parent)
Default constructor.
Definition: asteroidscomponent.cpp:39
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
KSAsteroid::setPeriod
void setPeriod(float per)
Sets the asteroid's period.
Definition: ksasteroid.cpp:176
skypainter.h
KSParser::D_DOUBLE
Definition: ksparser.h:71
KSAsteroid::setEarthMOID
void setEarthMOID(double earth_moid)
Sets the asteroid's earth minimum orbit intersection distance.
Definition: ksasteroid.cpp:141
KStarsData::setFullTimeUpdate
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets...
Definition: kstarsdata.cpp:260
KSAsteroid::setDiameter
void setDiameter(float diam)
Sets the asteroid's diameter.
Definition: ksasteroid.cpp:151
Options::hideLabels
static bool hideLabels()
Get Hide object name labels while moving?
Definition: Options.h:1341
solarsystemcomposite.h
MAXZOOM
#define MAXZOOM
Definition: kstarsdata.h:39
SolarSystemListComponent
Definition: solarsystemlistcomponent.h:32
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
KSAsteroid::setNEO
void setNEO(bool neo)
Sets if the comet is a near earth object.
Definition: ksasteroid.cpp:161
AsteroidsComponent::~AsteroidsComponent
virtual ~AsteroidsComponent()
Definition: asteroidscomponent.cpp:44
KSAsteroid::setRotationPeriod
void setRotationPeriod(float rot_per)
Sets the asteroid's rotation period.
Definition: ksasteroid.cpp:181
KSParser::D_FLOAT
Definition: ksparser.h:70
MINZOOM
#define MINZOOM
Definition: kstarsdata.h:38
AsteroidsComponent::selected
virtual bool selected()
Definition: asteroidscomponent.cpp:47
Options::showAsteroidNames
static bool showAsteroidNames()
Get Label asteroid names in the sky map?
Definition: Options.h:1379
SkyMap::isSlewing
bool isSlewing() const
Definition: skymap.cpp:1133
skymap.h
KSAsteroid
A subclass of KSPlanetBase that implements asteroids.
Definition: ksasteroid.h:48
skycomponent.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
KSParser::D_INT
Definition: ksparser.h:69
Options.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
ksfilereader.h
asteroidscomponent.h
Options::asteroidLabelDensity
static double asteroidLabelDensity()
Get Label density for asteroid names.
Definition: Options.h:2569
Options::showAsteroids
static bool showAsteroids()
Get Draw asteroids in the sky map?
Definition: Options.h:1360
KSAsteroid::setOrbitClass
void setOrbitClass(QString orbit_class)
Sets the asteroid's orbit class.
Definition: ksasteroid.cpp:166
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
KSAsteroid::setPerihelion
void setPerihelion(double perihelion)
Sets the asteroid's perihelion distance.
Definition: ksasteroid.cpp:136
projector.h
SkyMap::Instance
static SkyMap * Instance()
Definition: skymap.cpp:141
KStars::data
KStarsData * data() const
Definition: kstars.h:131
SkyObject::ASTEROID
Definition: skyobject.h:110
KSAsteroid::setDimensions
void setDimensions(QString dim)
Sets the asteroid's dimensions.
Definition: ksasteroid.cpp:156
AsteroidsComponent::objectNearest
virtual SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Find the SkyObject nearest the given SkyPoint.
Definition: asteroidscomponent.cpp:206
ksasteroid.h
SkyComponent::emitProgressText
virtual void emitProgressText(const QString &message)
Emit signal about progress.
Definition: skycomponent.cpp:35
kstarsdata.h
skylabeler.h
KSPlanetBase::setAngularSize
void setAngularSize(double size)
set the planet's angular size, in km.
Definition: ksplanetbase.h:176
SkyLabeler::ASTEROID_LABEL
Definition: skylabeler.h:121
SkyComponent::objectNames
QHash< int, QStringList > & objectNames()
Definition: skycomponent.h:127
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
KSParser::D_SKIP
Definition: ksparser.h:72
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
KSParser::D_QSTRING
Definition: ksparser.h:68
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
SolarSystemComposite
The solar system composite manages all planets, asteroids and comets.
Definition: solarsystemcomposite.h:41
SkyLabeler::AddLabel
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:149
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • 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