• 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
satellitescomponent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  satellitescomponent.cpp - K Desktop Planetarium
3  -------------------
4  begin : Tue 02 Mar 2011
5  copyright : (C) 2009 by Jerome SONRIER
6  email : jsid@emor3j.fr.eu.org
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 "satellitescomponent.h"
19 
20 #include <QStringList>
21 #include <QObject>
22 #include <QProgressDialog>
23 
24 #include <kjob.h>
25 #include <kio/job.h>
26 #include <kio/copyjob.h>
27 #include <kio/netaccess.h>
28 #include <kio/jobuidelegate.h>
29 
30 #include "klocale.h"
31 
32 #include "satellitegroup.h"
33 #include "Options.h"
34 #include "ksfilereader.h"
35 #include "skylabeler.h"
36 #include "kstarsdata.h"
37 
38 SatellitesComponent::SatellitesComponent( SkyComposite *parent ) :
39  SkyComponent( parent )
40 {
41  KSFileReader fileReader;
42  QString line;
43  QStringList group_infos;
44 
45  if ( ! fileReader.open( "satellites.dat" ) ) return;
46 
47  emitProgressText( i18n("Loading satellites" ) );
48 
49 
50  while ( fileReader.hasMoreLines() ) {
51  line = fileReader.readLine();
52  if ( line.trimmed().isEmpty() || line.at( 0 ) == '#' )
53  continue;
54  group_infos = line.split( ';' );
55  m_groups.append( new SatelliteGroup( group_infos.at( 0 ), group_infos.at( 1 ), KUrl( group_infos.at( 2 ) ) ) );
56  }
57 }
58 
59 SatellitesComponent::~SatellitesComponent()
60 {
61 
62 }
63 
64 bool SatellitesComponent::selected() {
65  return Options::showSatellites();
66 }
67 
68 void SatellitesComponent::update( KSNumbers * )
69 {
70  // Return if satellites must not be draw
71  if( ! selected() )
72  return;
73 
74  foreach( SatelliteGroup *group, m_groups ) {
75  group->updateSatellitesPos();
76  }
77 }
78 
79 void SatellitesComponent::draw( SkyPainter *skyp )
80 {
81  // Return if satellites must not be draw
82  if( ! selected() )
83  return;
84 
85  foreach( SatelliteGroup *group, m_groups ) {
86  for ( int i=0; i<group->size(); i++ ) {
87  Satellite *sat = group->at( i );
88  if ( sat->selected() ) {
89  if ( Options::showVisibleSatellites() ) {
90  if ( sat->isVisible() )
91  skyp->drawSatellite( sat );
92  } else {
93  skyp->drawSatellite( sat );
94  }
95  }
96  }
97  }
98 }
99 
100 void SatellitesComponent::drawLabel( Satellite *sat, QPointF pos )
101 {
102  SkyLabeler *labeler = SkyLabeler::Instance();
103  labeler->setPen( KStarsData::Instance()->colorScheme()->colorNamed( "SatLabelColor" ) );
104  labeler->drawNameLabel( sat, pos );
105 }
106 
107 void SatellitesComponent::drawTrails( SkyPainter *skyp ) {
108  Q_UNUSED(skyp);
109 }
110 
111 void SatellitesComponent::updateTLEs()
112 {
113  int i = 0;
114 
115  QProgressDialog progressDlg( i18n( "Update TLEs..." ), i18n( "Abort" ), 0, m_groups.count() );
116  progressDlg.setWindowModality( Qt::WindowModal );
117  progressDlg.setValue( 0 );
118 
119  foreach ( SatelliteGroup *group, m_groups ) {
120  if ( progressDlg.wasCanceled() )
121  return;
122 
123  if( group->tleUrl().isEmpty() )
124  continue;
125 
126  progressDlg.setLabelText( i18n( "Update %1 satellites", group->name() ) );
127  KIO::Job* getJob = KIO::file_copy( group->tleUrl(), group->tleFilename(), -1, KIO::Overwrite | KIO::HideProgressInfo );
128  if( KIO::NetAccess::synchronousRun( getJob, 0 ) ) {
129  group->readTLE();
130  group->updateSatellitesPos();
131  progressDlg.setValue( ++i );
132  } else {
133  getJob->ui()->showErrorMessage();
134  }
135  }
136 }
137 
138 QList<SatelliteGroup*> SatellitesComponent::groups()
139 {
140  return m_groups;
141 }
142 
143 Satellite* SatellitesComponent::findSatellite( QString name )
144 {
145  foreach ( SatelliteGroup *group, m_groups ) {
146  for ( int i=0; i<group->size(); i++ ) {
147  Satellite *sat = group->at( i );
148  if ( sat->name() == name )
149  return sat;
150  }
151  }
152 
153  return 0;
154 }
155 
156 SkyObject* SatellitesComponent::objectNearest( SkyPoint* p, double& maxrad ) {
157  if ( ! selected() )
158  return 0;
159 
160  //KStarsData* data = KStarsData::Instance();
161 
162  SkyObject *oBest = 0;
163  double rBest = maxrad;
164  double r;
165 
166  foreach ( SatelliteGroup *group, m_groups ) {
167  for ( int i=0; i<group->size(); i++ ) {
168  Satellite *sat = group->at( i );
169  if ( ! sat->selected() )
170  continue;
171 
172  r = sat->angularDistanceTo( p ).Degrees();
173  //kDebug() << sat->name();
174  //kDebug() << "r = " << r << " - max = " << rBest;
175  //kDebug() << "ra2=" << sat->ra().Degrees() << " - dec2=" << sat->dec().Degrees();
176  if ( r < rBest ) {
177  rBest = r;
178  oBest = sat;
179  }
180  }
181  }
182 
183  maxrad = rBest;
184  return oBest;
185 }
KSFileReader::hasMoreLines
bool hasMoreLines()
Definition: ksfilereader.h:108
satellitescomponent.h
satellitegroup.h
SatelliteGroup
Represents a group of artificial satellites.
Definition: satellitegroup.h:35
SatelliteGroup::tleUrl
KUrl tleUrl()
Definition: satellitegroup.cpp:79
SatellitesComponent::SatellitesComponent
SatellitesComponent(SkyComposite *parent)
Constructor.
Definition: satellitescomponent.cpp:38
Options::showVisibleSatellites
static bool showVisibleSatellites()
Get Draw only visible satellites in the sky map.
Definition: Options.h:4331
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SatellitesComponent::draw
virtual void draw(SkyPainter *skyp)
Draw all satellites.
Definition: satellitescomponent.cpp:79
SatelliteGroup::name
QString name()
Definition: satellitegroup.cpp:84
SatellitesComponent::~SatellitesComponent
~SatellitesComponent()
Destructor.
Definition: satellitescomponent.cpp:59
SkyComponent
SkyComponent represents an object on the sky map.
Definition: skycomponent.h:44
SatellitesComponent::objectNearest
SkyObject * objectNearest(SkyPoint *p, double &maxrad)
Search the nearest satellite from point p.
Definition: satellitescomponent.cpp:156
SatellitesComponent::selected
virtual bool selected()
Definition: satellitescomponent.cpp:64
KSFileReader::open
bool open(const QString &fname)
Definition: ksfilereader.cpp:46
SkyLabeler::Instance
static SkyLabeler * Instance()
Definition: skylabeler.cpp:49
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SatelliteGroup::updateSatellitesPos
void updateSatellitesPos()
Compute current position of the each satellites in the group.
Definition: satellitegroup.cpp:64
SatellitesComponent::updateTLEs
void updateTLEs()
Download new TLE files.
Definition: satellitescomponent.cpp:111
SatellitesComponent::drawTrails
virtual void drawTrails(SkyPainter *skyp)
Draw trails for objects.
Definition: satellitescomponent.cpp:107
SkyComposite
SkyComposite is a kind of container class for SkyComponent objects.
Definition: skycomposite.h:43
SatellitesComponent::groups
QList< SatelliteGroup * > groups()
Definition: satellitescomponent.cpp:138
Satellite::selected
bool selected()
Definition: satellite.cpp:1201
Options.h
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
ksfilereader.h
SatellitesComponent::drawLabel
void drawLabel(Satellite *sat, QPointF pos)
Draw label of a satellite.
Definition: satellitescomponent.cpp:100
KSFileReader::readLine
QString readLine()
Definition: ksfilereader.h:113
KSFileReader
Definition: ksfilereader.h:65
Satellite::isVisible
bool isVisible()
Definition: satellite.cpp:1196
SatelliteGroup::readTLE
void readTLE()
Read TLE file of the group and create all satellites found in the file.
Definition: satellitegroup.cpp:40
SkyLabeler::setPen
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:173
Options::showSatellites
static bool showSatellites()
Get Draw satellites in the sky map?
Definition: Options.h:4312
Satellite
Represents an artificial satellites.
Definition: satellite.h:35
SatellitesComponent::update
virtual void update(KSNumbers *num)
Update satellites position.
Definition: satellitescomponent.cpp:68
SkyLabeler::drawNameLabel
bool drawNameLabel(SkyObject *obj, const QPointF &_p)
Tries to draw a label for an object.
Definition: skylabeler.cpp:151
SkyComponent::emitProgressText
virtual void emitProgressText(const QString &message)
Emit signal about progress.
Definition: skycomponent.cpp:35
kstarsdata.h
skylabeler.h
SkyLabeler
The purpose of this class is to prevent labels from overlapping.
Definition: skylabeler.h:112
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyPainter::drawSatellite
virtual void drawSatellite(Satellite *sat)=0
Draw a satellite.
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
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
SatellitesComponent::findSatellite
Satellite * findSatellite(QString name)
Search a satellite by name.
Definition: satellitescomponent.cpp:143
QList
SatelliteGroup::tleFilename
KUrl tleFilename()
Definition: satellitegroup.cpp:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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