• 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
  • tools
modcalcplanets.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcequinox.cpp - description
3  -------------------
4  begin : dom may 2 2004
5  copyright : (C) 2004-2005 by Pablo de Vicente
6  email : p.devicentea@wanadoo.es
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 "modcalcplanets.h"
19 
20 #include <KGlobal>
21 #include <KLocale>
22 #include <kfiledialog.h>
23 #include <kmessagebox.h>
24 
25 #include "geolocation.h"
26 #include "dialogs/locationdialog.h"
27 #include "dms.h"
28 #include "kstarsdata.h"
29 #include "ksnumbers.h"
30 #include "skyobjects/kssun.h"
31 #include "skyobjects/ksplanet.h"
32 #include "skyobjects/ksmoon.h"
33 #include "skyobjects/kspluto.h"
34 #include "widgets/dmsbox.h"
35 
36 modCalcPlanets::modCalcPlanets(QWidget *parentSplit) :
37  QFrame(parentSplit)
38 {
39  setupUi(this);
40 
41  KStarsDateTime dt( KStarsDateTime::currentDateTime() );
42 
43  DateTimeBox->setDateTime( dt.dateTime() );
44  DateBoxBatch->setDate( dt.date() );
45  UTBoxBatch->setTime( dt.time() );
46 
47  geoPlace = KStarsData::Instance()->geo();
48  LocationButton->setText( geoPlace->fullName() );
49 
50  RABox->setDegType(false);
51 
52  // signals and slots connections
53  connect(PlanetComboBox, SIGNAL(activated(int)), this, SLOT(slotComputePosition()));
54  connect(DateTimeBox, SIGNAL(dateTimeChanged( QDateTime )), this, SLOT(slotComputePosition()));
55  connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
56 
57  connect(UTCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch()));
58  connect(DateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch()));
59  connect(LatCheckBatch, SIGNAL(clicked()), this, SLOT(slotLatCheckedBatch()));
60  connect(LongCheckBatch, SIGNAL(clicked()), this, SLOT(slotLongCheckedBatch()));
61  connect(PlanetCheckBatch, SIGNAL(clicked()), this, SLOT(slotPlanetsCheckedBatch()));
62 
63  slotComputePosition();
64  show();
65 }
66 
67 modCalcPlanets::~modCalcPlanets(){
68 }
69 
70 void modCalcPlanets::slotLocation()
71 {
72  QPointer<LocationDialog> ld = new LocationDialog( this );
73 
74  if ( ld->exec() == QDialog::Accepted ) {
75  geoPlace = ld->selectedCity();
76  LocationButton->setText( geoPlace->fullName() );
77  slotComputePosition();
78  }
79  delete ld;
80 }
81 
82 void modCalcPlanets::slotComputePosition (void)
83 {
84  KStarsDateTime dt = DateTimeBox->dateTime();
85  long double julianDay = dt.djd();
86  KSNumbers num( julianDay );
87  dms LST( geoPlace->GSTtoLST( dt.gst() ) );
88 
89  // Earth
90  KSPlanet Earth( I18N_NOOP( "Earth" ));
91  Earth.findPosition( &num );
92 
93  // Earth is special case!
94  if( PlanetComboBox->currentIndex() == 2 ) {
95  showCoordinates( Earth );
96  return;
97  }
98 
99  // Pointer to hold planet data. Pointer is used since it has to
100  // hold objects of different type. It's safe to use new/delete
101  // because exceptions are disallowed.
102  KSPlanetBase* p = 0;
103 
104  switch( PlanetComboBox->currentIndex() ) {
105  case 0 :
106  p = new KSPlanet(KSPlanetBase::MERCURY); break;
107  case 1:
108  p = new KSPlanet(KSPlanetBase::VENUS); break;
109  case 3:
110  p = new KSPlanet(KSPlanetBase::MARS); break;
111  case 4:
112  p = new KSPlanet(KSPlanetBase::JUPITER); break;
113  case 5:
114  p = new KSPlanet(KSPlanetBase::SATURN); break;
115  case 6:
116  p = new KSPlanet(KSPlanetBase::URANUS); break;
117  case 7:
118  p = new KSPlanet(KSPlanetBase::NEPTUNE); break;
119  case 8:
120  p = new KSPluto(); break;
121  case 9:
122  p = new KSMoon(); break;
123  case 10:
124  p = new KSSun();
125  p->setRsun(0.0);
126  break;
127  }
128 
129  // Show data.
130  p->findPosition( &num, geoPlace->lat(), &LST, &Earth);
131  p->EquatorialToHorizontal( &LST, geoPlace->lat());
132  showCoordinates( *p );
133  // Cleanup.
134  delete p;
135 }
136 
137 void modCalcPlanets::showCoordinates( const KSPlanetBase &ksp)
138 {
139  showHeliocentricEclipticCoords(ksp.helEcLong(), ksp.helEcLat(), ksp.rsun() );
140  showGeocentricEclipticCoords(ksp.ecLong(), ksp.ecLat(), ksp.rearth() );
141  showEquatorialCoords(ksp.ra(), ksp.dec() );
142  showTopocentricCoords(ksp.az(), ksp.alt() );
143 }
144 
145 void modCalcPlanets::showHeliocentricEclipticCoords(const dms& hLong, const dms& hLat, double dist)
146 {
147  HelioLongBox->show( hLong );
148  HelioLatBox->show( hLat );
149  HelioDistBox->setText( KGlobal::locale()->formatNumber( dist,6));
150 }
151 
152 void modCalcPlanets::showGeocentricEclipticCoords(const dms& eLong, const dms& eLat, double dist)
153 {
154  GeoLongBox->show( eLong );
155  GeoLatBox->show( eLat );
156  GeoDistBox->setText( KGlobal::locale()->formatNumber( dist,6));
157 }
158 
159 void modCalcPlanets::showEquatorialCoords(const dms& ra, const dms& dec)
160 {
161  RABox->show( ra, false );
162  DecBox->show( dec );
163 }
164 
165 void modCalcPlanets::showTopocentricCoords(const dms& az, const dms& el)
166 {
167  AzBox->show( az );
168  AltBox->show( el );
169 }
170 
171 void modCalcPlanets::slotPlanetsCheckedBatch()
172 {
173  PlanetComboBoxBatch->setEnabled( ! PlanetCheckBatch->isChecked() );
174 }
175 
176 void modCalcPlanets::slotUtCheckedBatch()
177 {
178  UTBoxBatch->setEnabled( ! UTCheckBatch->isChecked() );
179 }
180 
181 void modCalcPlanets::slotDateCheckedBatch()
182 {
183  DateBoxBatch->setEnabled( ! DateCheckBatch->isChecked() );
184 }
185 
186 void modCalcPlanets::slotLongCheckedBatch()
187 {
188  LongBoxBatch->setEnabled( ! LongCheckBatch->isChecked() );
189 }
190 
191 void modCalcPlanets::slotLatCheckedBatch()
192 {
193  LatBoxBatch->setEnabled( ! LatCheckBatch->isChecked() );
194 }
195 
196 void modCalcPlanets::slotRunBatch() {
197 
198  QString inputFileName;
199 
200  inputFileName = InputFileBoxBatch->url().toLocalFile();
201 
202  // We open the input file and read its content
203 
204  if ( QFile::exists(inputFileName) ) {
205  QFile f( inputFileName );
206  if ( !f.open( QIODevice::ReadOnly) ) {
207  QString message = i18n( "Could not open file %1.", f.fileName() );
208  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
209  inputFileName.clear();
210  return;
211  }
212 
213  QTextStream istream(&f);
214  processLines(istream);
215  f.close();
216  } else {
217  QString message = i18n( "Invalid file: %1", inputFileName );
218  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
219  inputFileName.clear();
220  InputFileBoxBatch->setUrl( inputFileName );
221  return;
222  }
223 }
224 
225 unsigned int modCalcPlanets::requiredBatchFields() {
226  unsigned int i = 0;
227 
228  if(PlanetCheckBatch->isChecked() )
229  i++;
230  if(UTCheckBatch->isChecked() )
231  i++;
232  if(DateCheckBatch->isChecked() )
233  i++;
234  if (LongCheckBatch->isChecked() )
235  i++;
236  if (LatCheckBatch->isChecked() )
237  i++;
238 
239  return i;
240 }
241 
242 void modCalcPlanets::processLines( QTextStream &istream )
243 {
244  // we open the output file
245 
246  QString outputFileName;
247  outputFileName = OutputFileBoxBatch->url().toLocalFile();
248  QFile fOut( outputFileName );
249  fOut.open(QIODevice::WriteOnly);
250  QTextStream ostream(&fOut);
251  bool lineIsValid = true;
252  QString message;
253 
254  QChar space = ' ';
255  QString planetB;
256  unsigned int i = 0, nline = 0;
257  QTime utB;
258  QDate dtB;
259  dms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB;
260  double rSunB(0.0), rEarthB(0.0);
261 
262  //Initialize planet names
263  QString pn;
264  QStringList pNames, pNamesi18n;
265  pNames << "Mercury" << "Venus" << "Earth" << "Mars" << "Jupiter"
266  << "Saturn" << "Uranus" << "Neptune" << "Pluto"
267  << "Sun" << "Moon";
268  pNamesi18n << i18n("Mercury") << i18n("Venus") << i18n("Earth")
269  << i18n("Mars") << i18n("Jupiter") << i18n("Saturn")
270  << i18n("Uranus") << i18n("Neptune") << i18n("Pluto")
271  << i18n("Sun") << i18n("Moon");
272 
274  int numberOfRequiredFields = requiredBatchFields();
275  while ( ! istream.atEnd() ) {
276  QString lineToWrite;
277  QString line = istream.readLine();
278  line.trimmed();
279 
280  //Go through the line, looking for parameters
281 
282  QStringList fields = line.split( ' ' );
283 
284  if (fields.count() != numberOfRequiredFields ) {
285  lineIsValid = false;
286  kWarning() << i18n( "Incorrect number of fields in line %1: " , nline)
287  << i18n( "Present fields %1. " , fields.count())
288  << i18n( "Required fields %1. " , numberOfRequiredFields) << endl;
289  nline++;
290  continue;
291  }
292 
293  i = 0;
294  if(PlanetCheckBatch->isChecked() ) {
295  planetB = fields[i];
296  int j = pNamesi18n.indexOf( planetB );
297  if (j == -1) {
298  kWarning() << i18n("Unknown planet ")
299  << fields[i]
300  << i18n(" in line %1: ", nline) << endl;
301  continue;
302  }
303  pn = pNames.at(j); //untranslated planet name
304  i++;
305  } else {
306  planetB = PlanetComboBoxBatch->currentText( );
307  }
308  if ( AllRadioBatch->isChecked() || PlanetCheckBatch->isChecked() ) {
309  lineToWrite = planetB;
310  lineToWrite += space;
311  }
312 
313  // Read Ut and write in ostream if corresponds
314  if(UTCheckBatch->isChecked() ) {
315  utB = QTime::fromString( fields[i] );
316  if ( !utB.isValid() ) {
317  kWarning() << i18n( "Line %1 contains an invalid time" , nline) ;
318  lineIsValid=false;
319  nline++;
320  continue;
321  }
322  i++;
323  } else {
324  utB = UTBoxBatch->time();
325  }
326  if ( AllRadioBatch->isChecked() || UTCheckBatch->isChecked() )
327  lineToWrite += KGlobal::locale()->formatTime( utB, true ).append(space);
328 
329  // Read date and write in ostream if corresponds
330  if(DateCheckBatch->isChecked() ) {
331  dtB = QDate::fromString( fields[i], Qt::ISODate );
332  if ( !dtB.isValid() ) {
333  kWarning() << i18n( "Line %1 contains an invalid date: " , nline) <<
334  fields[i] << endl ;
335  lineIsValid=false;
336  nline++;
337  continue;
338  }
339  i++;
340  } else {
341  dtB = DateBoxBatch->date();
342  }
343  if ( AllRadioBatch->isChecked() || DateCheckBatch->isChecked() )
344  lineToWrite += KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
345 
346 
347  // Read Longitude and write in ostream if corresponds
348 
349  if (LongCheckBatch->isChecked() ) {
350  longB = dms::fromString( fields[i],true);
351  i++;
352  } else {
353  longB = LongBoxBatch->createDms(true);
354  }
355  if ( AllRadioBatch->isChecked() || LongCheckBatch->isChecked() )
356  lineToWrite += longB.toDMSString() + space;
357 
358  // Read Latitude
359  if (LatCheckBatch->isChecked() ) {
360  latB = dms::fromString( fields[i], true);
361  i++;
362  } else {
363  latB = LatBoxBatch->createDms(true);
364  }
365  if ( AllRadioBatch->isChecked() || LatCheckBatch->isChecked() )
366  lineToWrite += latB.toDMSString() + space;
367 
368 
369  KStarsDateTime edt( dtB, utB );
370  dms LST = edt.gst() + longB;
371 
372  KSNumbers num( edt.djd() );
373  KSPlanet Earth( I18N_NOOP( "Earth" ));
374  Earth.findPosition( &num );
375 
376  // FIXME: allocate new object for every iteration is probably not wisest idea.
377  KSPlanetBase *kspb = 0 ;
378  if ( pn == "Pluto" ) {
379  kspb = new KSPluto();
380  } else if ( pn == "Sun" ) {
381  kspb = new KSSun();
382  } else if ( pn == "Moon" ) {
383  kspb = new KSMoon();
384  } else {
385  kspb = new KSPlanet(i18n( pn.toLocal8Bit() ), QString(), Qt::white, 1.0 );
386  }
387  kspb->findPosition( &num, &latB, &LST, &Earth );
388  kspb->EquatorialToHorizontal( &LST, &latB );
389 
390  // Heliocentric Ecl. coords.
391  hlongB = kspb->helEcLong();
392  hlatB = kspb->helEcLat();
393  rSunB = kspb->rsun();
394  // Geocentric Ecl. coords.
395  glongB = kspb->ecLong();
396  glatB = kspb->ecLat();
397  rEarthB = kspb->rearth();
398  // Equatorial coords.
399  decB = kspb->dec();
400  raB = kspb->ra();
401  // Topocentric Coords.
402  azmB = kspb->az();
403  altB = kspb->alt();
404 
405  ostream << lineToWrite;
406 
407  if ( HelioEclCheckBatch->isChecked() )
408  ostream << hlongB.toDMSString() << space << hlatB.toDMSString() << space << rSunB << space ;
409  if ( GeoEclCheckBatch->isChecked() )
410  ostream << glongB.toDMSString() << space << glatB.toDMSString() << space << rEarthB << space ;
411  if ( EquatorialCheckBatch->isChecked() )
412  ostream << raB.toHMSString() << space << decB.toDMSString() << space ;
413  if ( HorizontalCheckBatch->isChecked() )
414  ostream << azmB.toDMSString() << space << altB.toDMSString() << space ;
415  ostream << endl;
416 
417  // Delete object
418  delete kspb;
419 
420  nline++;
421  }
422 
423  if (!lineIsValid) {
424  QString message = i18n("Errors found while parsing some lines in the input file");
425  KMessageBox::sorry( 0, message, i18n( "Errors in lines" ) );
426  }
427 
428  fOut.close();
429 }
430 
431 #include "modcalcplanets.moc"
modcalcplanets.h
KSPlanetBase::findPosition
void findPosition(const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth=0)
Find position, including correction for Figure-of-the-Earth.
Definition: ksplanetbase.cpp:122
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
modCalcPlanets::modCalcPlanets
modCalcPlanets(QWidget *p)
Definition: modcalcplanets.cpp:36
modCalcPlanets::slotDateCheckedBatch
void slotDateCheckedBatch()
Definition: modcalcplanets.cpp:181
modCalcPlanets::processLines
void processLines(QTextStream &istream)
Definition: modcalcplanets.cpp:242
KSPlanetBase::NEPTUNE
Definition: ksplanetbase.h:82
modCalcPlanets::slotLocation
void slotLocation()
Definition: modcalcplanets.cpp:70
KSPlanet
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Definition: ksplanet.h:40
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
KSSun
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition: kssun.h:31
modCalcPlanets::slotLatCheckedBatch
void slotLatCheckedBatch()
Definition: modcalcplanets.cpp:191
KSPlanetBase::JUPITER
Definition: ksplanetbase.h:82
QWidget
KSPlanetBase::helEcLat
const dms & helEcLat() const
Definition: ksplanetbase.h:110
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
KSPlanetBase::setRsun
void setRsun(double r)
Set the solar distance in AU.
Definition: ksplanetbase.h:131
modCalcPlanets::slotPlanetsCheckedBatch
void slotPlanetsCheckedBatch()
Definition: modcalcplanets.cpp:171
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
KSPlanetBase::MERCURY
Definition: ksplanetbase.h:82
geolocation.h
dms.h
ksplanet.h
NaN::f
const float f
Definition: nan.h:36
kspluto.h
locationdialog.h
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
GeoLocation::GSTtoLST
dms GSTtoLST(const dms &gst) const
Definition: geolocation.h:230
modCalcPlanets::slotRunBatch
void slotRunBatch()
Definition: modcalcplanets.cpp:196
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
KSPlanetBase::MARS
Definition: ksplanetbase.h:82
modCalcPlanets::slotComputePosition
void slotComputePosition()
Definition: modcalcplanets.cpp:82
KSPlanetBase::rsun
double rsun() const
Definition: ksplanetbase.h:126
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
ksnumbers.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
modCalcPlanets::slotLongCheckedBatch
void slotLongCheckedBatch()
Definition: modcalcplanets.cpp:186
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
KSPlanetBase::SATURN
Definition: ksplanetbase.h:82
modCalcPlanets::~modCalcPlanets
~modCalcPlanets()
Definition: modcalcplanets.cpp:67
KSPlanetBase::ecLat
const dms & ecLat() const
Definition: ksplanetbase.h:94
KSPlanetBase::helEcLong
const dms & helEcLong() const
Definition: ksplanetbase.h:107
QTextStream
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
KSPlanetBase::ecLong
const dms & ecLong() const
Definition: ksplanetbase.h:91
kssun.h
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
KSMoon
A subclass of SkyObject that provides information needed for the Moon.
Definition: ksmoon.h:36
KSPlanetBase::rearth
double rearth() const
Definition: ksplanetbase.h:134
modCalcPlanets::slotUtCheckedBatch
void slotUtCheckedBatch()
Definition: modcalcplanets.cpp:176
NaN::ld
const long double ld
Definition: nan.h:37
ksmoon.h
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
kstarsdata.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
dmsbox.h
KSPlanetBase::VENUS
Definition: ksplanetbase.h:82
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:138
QFrame
KSPlanetBase::URANUS
Definition: ksplanetbase.h:82
KSPluto
A subclass of KSAsteroid that represents the planet Pluto.
Definition: kspluto.h:43
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