• 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
modcalcaltaz.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcaltaz.cpp - description
3  -------------------
4  begin : s� oct 26 2002
5  copyright : (C) 2002 by Jason Harris
6  email : kstars@30doradus.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 "modcalcaltaz.h"
19 
20 #include <QTextStream>
21 
22 #include <KGlobal>
23 #include <KLocale>
24 #include <kfiledialog.h>
25 #include <kmessagebox.h>
26 
27 #include "skyobjects/skypoint.h"
28 #include "geolocation.h"
29 #include "kstars.h"
30 #include "kstarsdata.h"
31 #include "kstarsdatetime.h"
32 #include "widgets/dmsbox.h"
33 #include "dialogs/finddialog.h"
34 #include "dialogs/locationdialog.h"
35 
36 modCalcAltAz::modCalcAltAz(QWidget *parentSplit)
37  : QFrame(parentSplit), horInputCoords(false)
38 {
39  setupUi(this);
40 
41  KStarsData *data = KStarsData::Instance();
42  RA->setDegType(false);
43 
44  //Initialize Date/Time and Location data
45  geoPlace = data->geo();
46  LocationButton->setText( geoPlace->fullName() );
47 
48  //Make sure slotDateTime() gets called, so that LST will be set
49  connect(DateTime, SIGNAL(dateTimeChanged(const QDateTime&)), this, SLOT(slotDateTimeChanged(const QDateTime&)));
50  DateTime->setDateTime( data->lt().dateTime() );
51 
52  connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow()));
53  connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
54  connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
55 
56  connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
57  connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
58  connect(Az, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
59  connect(Alt, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
60 
61  connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
62  connect(utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtChecked()));
63  connect(dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateChecked()));
64  connect(azCheckBatch, SIGNAL(clicked()), this, SLOT(slotAzChecked()));
65  connect(elCheckBatch, SIGNAL(clicked()), this, SLOT(slotElChecked()));
66  connect(latCheckBatch, SIGNAL(clicked()), this, SLOT(slotLatChecked()));
67  connect(longCheckBatch, SIGNAL(clicked()), this, SLOT(slotLongChecked()));
68  connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaChecked()));
69  connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecChecked()));
70 
71  show();
72 }
73 
74 modCalcAltAz::~modCalcAltAz(){
75 }
76 
77 void modCalcAltAz::slotNow()
78 {
79  DateTime->setDateTime( KStarsDateTime::currentDateTime().dateTime() );
80  slotCompute();
81 }
82 
83 void modCalcAltAz::slotLocation()
84 {
85  QPointer<LocationDialog> ld = new LocationDialog( this );
86  if ( ld->exec() == QDialog::Accepted ) {
87  GeoLocation *newGeo = ld->selectedCity();
88  if ( newGeo ) {
89  geoPlace = newGeo;
90  LocationButton->setText( geoPlace->fullName() );
91  slotCompute();
92  }
93  }
94  delete ld;
95 }
96 
97 void modCalcAltAz::slotObject()
98 {
99  QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
100  if ( fd->exec() == QDialog::Accepted ) {
101  SkyObject *o = fd->selectedObject();
102  RA->showInHours( o->ra() );
103  Dec->showInDegrees( o->dec() );
104  slotCompute();
105  }
106  delete fd;
107 }
108 
109 void modCalcAltAz::slotDateTimeChanged(const QDateTime &dt)
110 {
111  KStarsDateTime ut = geoPlace->LTtoUT( KStarsDateTime( dt ) );
112  LST = geoPlace->GSTtoLST( ut.gst() );
113 }
114 
115 void modCalcAltAz::slotCompute()
116 {
117  //Determine whether we are calculating Alt/Az coordinates from RA/Dec,
118  //or vice versa. We calculate Alt/Az by default, unless the signal
119  //was sent by changing the Az or Alt value.
120  if ( sender()->objectName() == "Az" || sender()->objectName() == "Alt" ) {
121  //Validate Az and Alt coordinates
122  bool ok( false );
123  dms alt;
124  dms az = Az->createDms( true, &ok );
125  if ( ok ) alt = Alt->createDms( true, &ok );
126  if ( ok ) {
127  SkyPoint sp;
128  sp.setAz( az );
129  sp.setAlt( alt );
130  sp.HorizontalToEquatorial( &LST, geoPlace->lat() );
131  RA->showInHours( sp.ra() );
132  Dec->showInDegrees( sp.dec() );
133  }
134 
135  } else {
136  //Validate RA and Dec coordinates
137  bool ok( false );
138  dms ra;
139  dms dec = Dec->createDms( true, &ok );
140  if ( ok ) ra = RA->createDms( false, &ok );
141  if ( ok ) {
142  SkyPoint sp( ra, dec );
143  sp.EquatorialToHorizontal( &LST, geoPlace->lat() );
144  Az->showInDegrees( sp.az() );
145  Alt->showInDegrees( sp.alt() );
146  }
147  }
148 }
149 
150 void modCalcAltAz::slotUtChecked(){
151  utBoxBatch->setEnabled( !utCheckBatch->isChecked() );
152 }
153 
154 void modCalcAltAz::slotDateChecked(){
155  dateBoxBatch->setEnabled( !dateCheckBatch->isChecked() );
156 }
157 
158 void modCalcAltAz::slotRaChecked(){
159  if ( raCheckBatch->isChecked() ) {
160  raBoxBatch->setEnabled( false );
161  horNoCheck();
162  }
163  else {
164  raBoxBatch->setEnabled( true );
165  }
166 }
167 
168 void modCalcAltAz::slotDecChecked(){
169  if ( decCheckBatch->isChecked() ) {
170  decBoxBatch->setEnabled( false );
171  horNoCheck();
172  }
173  else {
174  decBoxBatch->setEnabled( true );
175  }
176 }
177 
178 void modCalcAltAz::slotEpochChecked(){
179  epochBoxBatch->setEnabled( !epochCheckBatch->isChecked() );
180 }
181 
182 void modCalcAltAz::slotLongChecked(){
183  longBoxBatch->setEnabled( !longCheckBatch->isChecked());
184 }
185 
186 void modCalcAltAz::slotLatChecked(){
187  latBoxBatch->setEnabled( !latCheckBatch->isChecked() );
188 }
189 
190 void modCalcAltAz::slotAzChecked(){
191  if ( azCheckBatch->isChecked() ) {
192  azBoxBatch->setEnabled( false );
193  equNoCheck();
194  }
195  else {
196  azBoxBatch->setEnabled( true );
197  }
198 }
199 
200 void modCalcAltAz::slotElChecked(){
201  if ( elCheckBatch->isChecked() ) {
202  elBoxBatch->setEnabled( false );
203  equNoCheck();
204  }
205  else {
206  elBoxBatch->setEnabled( true );
207  }
208 }
209 
210 void modCalcAltAz::horNoCheck() {
211  azCheckBatch->setChecked(false);
212  azBoxBatch->setEnabled(false);
213  elCheckBatch->setChecked(false);
214  elBoxBatch->setEnabled(false);
215  horInputCoords = false;
216 
217 }
218 
219 void modCalcAltAz::equNoCheck() {
220  raCheckBatch->setChecked(false);
221  raBoxBatch->setEnabled(false);
222  decCheckBatch->setChecked(false);
223  decBoxBatch->setEnabled(false);
224  horInputCoords = true;
225 }
226 
227 
228 void modCalcAltAz::slotRunBatch() {
229 
230  QString inputFileName = InputLineEditBatch->url().toLocalFile();
231 
232  // We open the input file and read its content
233 
234  if ( QFile::exists(inputFileName) ) {
235  QFile f( inputFileName );
236  if ( !f.open( QIODevice::ReadOnly) ) {
237  QString message = i18n( "Could not open file %1.", f.fileName() );
238  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
239  inputFileName.clear();
240  return;
241  }
242 
243  // processLines(&f);
244  QTextStream istream(&f);
245  processLines(istream);
246  // readFile( istream );
247  f.close();
248  } else {
249  QString message = i18n( "Invalid file: %1", inputFileName );
250  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
251  inputFileName.clear();
252  InputLineEditBatch->setText( inputFileName );
253  return;
254  }
255 }
256 
257 void modCalcAltAz::processLines( QTextStream &istream ) {
258 
259  // we open the output file
260 
261  // QTextStream istream(&fIn);
262  QString outputFileName;
263  outputFileName = OutputLineEditBatch->text();
264  QFile fOut( outputFileName );
265  fOut.open(QIODevice::WriteOnly);
266  QTextStream ostream(&fOut);
267 
268  QString line;
269  QChar space = ' ';
270  int i = 0;
271  long double jd0, jdf;
272  dms LST;
273  SkyPoint sp;
274  dms raB, decB, latB, longB, azB, elB;
275  QString epoch0B;
276  QTime utB;
277  QDate dtB;
278 
279  while ( ! istream.atEnd() ) {
280  line = istream.readLine();
281  line.trimmed();
282 
283  //Go through the line, looking for parameters
284 
285  QStringList fields = line.split( ' ' );
286 
287  i = 0;
288 
289  // Read Ut and write in ostream if corresponds
290 
291  if(utCheckBatch->isChecked() ) {
292  utB = QTime::fromString( fields[i] );
293  i++;
294  } else
295  utB = utBoxBatch->time();
296 
297  if ( allRadioBatch->isChecked() )
298  ostream << KGlobal::locale()->formatTime( utB ) << space;
299  else
300  if(utCheckBatch->isChecked() )
301  ostream << KGlobal::locale()->formatTime( utB ) << space;
302 
303  // Read date and write in ostream if corresponds
304 
305  if(dateCheckBatch->isChecked() ) {
306  dtB = QDate::fromString( fields[i] );
307  i++;
308  } else
309  dtB = dateBoxBatch->date();
310  if ( allRadioBatch->isChecked() )
311  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
312  else
313  if(dateCheckBatch->isChecked() )
314  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
315 
316  // Read Longitude and write in ostream if corresponds
317 
318  if (longCheckBatch->isChecked() ) {
319  longB = dms::fromString( fields[i],true);
320  i++;
321  } else
322  longB = longBoxBatch->createDms(true);
323 
324  if ( allRadioBatch->isChecked() )
325  ostream << longB.toDMSString() << space;
326  else
327  if (longCheckBatch->isChecked() )
328  ostream << longB.toDMSString() << space;
329 
330  // Read Latitude
331 
332 
333  if (latCheckBatch->isChecked() ) {
334  latB = dms::fromString( fields[i], true);
335  i++;
336  } else
337  latB = latBoxBatch->createDms(true);
338  if ( allRadioBatch->isChecked() )
339  ostream << latB.toDMSString() << space;
340  else
341  if (latCheckBatch->isChecked() )
342  ostream << latB.toDMSString() << space;
343 
344  // Read Epoch and write in ostream if corresponds
345 
346  if(epochCheckBatch->isChecked() ) {
347  epoch0B = fields[i];
348  i++;
349  } else
350  epoch0B = epochBoxBatch->text();
351 
352  if ( allRadioBatch->isChecked() )
353  ostream << epoch0B << space;
354  else
355  if(epochCheckBatch->isChecked() )
356  ostream << epoch0B << space;
357 
358  // We make the first calculations
359  KStarsDateTime dt;
360  dt.setFromEpoch( epoch0B );
361  jdf = KStarsDateTime(dtB,utB).djd();
362  jd0 = dt.djd();
363 
364  LST = KStarsDateTime(dtB,utB).gst() + longB;
365 
366  // Equatorial coordinates are the input coords.
367  if (!horInputCoords) {
368  // Read RA and write in ostream if corresponds
369 
370  if(raCheckBatch->isChecked() ) {
371  raB = dms::fromString( fields[i],false);
372  i++;
373  } else
374  raB = raBoxBatch->createDms(false);
375 
376  if ( allRadioBatch->isChecked() )
377  ostream << raB.toHMSString() << space;
378  else
379  if(raCheckBatch->isChecked() )
380  ostream << raB.toHMSString() << space;
381 
382  // Read DEC and write in ostream if corresponds
383 
384  if(decCheckBatch->isChecked() ) {
385  decB = dms::fromString( fields[i], true);
386  i++;
387  } else
388  decB = decBoxBatch->createDms();
389 
390  if ( allRadioBatch->isChecked() )
391  ostream << decB.toDMSString() << space;
392  else
393  if(decCheckBatch->isChecked() )
394  ostream << decB.toDMSString() << space;
395 
396  sp = SkyPoint (raB, decB);
397  sp.apparentCoord(jd0, jdf);
398  sp.EquatorialToHorizontal( &LST, &latB );
399  ostream << sp.az().toDMSString() << space << sp.alt().toDMSString() << endl;
400 
401  // Input coords are horizontal coordinates
402 
403  } else {
404  if(azCheckBatch->isChecked() ) {
405  azB = dms::fromString( fields[i],false);
406  i++;
407  } else
408  azB = azBoxBatch->createDms();
409 
410  if ( allRadioBatch->isChecked() )
411  ostream << azB.toHMSString() << space;
412  else
413  if(raCheckBatch->isChecked() )
414  ostream << azB.toHMSString() << space;
415 
416  // Read DEC and write in ostream if corresponds
417 
418  if(elCheckBatch->isChecked() ) {
419  elB = dms::fromString( fields[i], true);
420  i++;
421  } else
422  elB = decBoxBatch->createDms();
423 
424  if ( allRadioBatch->isChecked() )
425  ostream << elB.toDMSString() << space;
426  else
427  if(elCheckBatch->isChecked() )
428  ostream << elB.toDMSString() << space;
429 
430  sp.setAz(azB);
431  sp.setAlt(elB);
432  sp.HorizontalToEquatorial( &LST, &latB );
433  ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << endl;
434  }
435 
436  }
437 
438 
439  fOut.close();
440 }
441 
442 #include "modcalcaltaz.moc"
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
modCalcAltAz::slotRunBatch
void slotRunBatch()
Definition: modcalcaltaz.cpp:228
SkyPoint::apparentCoord
void apparentCoord(long double jd0, long double jdf)
Computes the apparent coordinates for this SkyPoint for any epoch, accounting for the effects of prec...
Definition: skypoint.cpp:433
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
modCalcAltAz::slotObject
void slotObject()
Definition: modcalcaltaz.cpp:97
modCalcAltAz::slotDateChecked
void slotDateChecked()
Definition: modcalcaltaz.cpp:154
SkyPoint::setAz
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:152
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
modCalcAltAz::slotDateTimeChanged
void slotDateTimeChanged(const QDateTime &)
Definition: modcalcaltaz.cpp:109
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
modCalcAltAz::slotCompute
void slotCompute()
Definition: modcalcaltaz.cpp:115
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
modCalcAltAz::slotLocation
void slotLocation()
Definition: modcalcaltaz.cpp:83
modCalcAltAz::slotLongChecked
void slotLongChecked()
Definition: modcalcaltaz.cpp:182
geolocation.h
modCalcAltAz::slotLatChecked
void slotLatChecked()
Definition: modcalcaltaz.cpp:186
modCalcAltAz::modCalcAltAz
modCalcAltAz(QWidget *p)
Definition: modcalcaltaz.cpp:36
KStarsDateTime::setFromEpoch
bool setFromEpoch(double e)
Set the Date/Time from an epoch value, represented as a double.
Definition: kstarsdatetime.cpp:195
NaN::f
const float f
Definition: nan.h:36
modCalcAltAz::slotElChecked
void slotElChecked()
Definition: modcalcaltaz.cpp:200
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
modCalcAltAz::slotNow
void slotNow()
Definition: modcalcaltaz.cpp:77
modCalcAltAz::slotEpochChecked
void slotEpochChecked()
Definition: modcalcaltaz.cpp:178
KStarsData::lt
const KStarsDateTime & lt() const
Definition: kstarsdata.h:137
locationdialog.h
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
modCalcAltAz::slotUtChecked
void slotUtChecked()
Definition: modcalcaltaz.cpp:150
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
modcalcaltaz.h
SkyPoint::HorizontalToEquatorial
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:102
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
modCalcAltAz::slotDecChecked
void slotDecChecked()
Definition: modcalcaltaz.cpp:168
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
skypoint.h
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
QTextStream
finddialog.h
NaN::ld
const long double ld
Definition: nan.h:37
modCalcAltAz::~modCalcAltAz
~modCalcAltAz()
Definition: modcalcaltaz.cpp:74
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
kstarsdatetime.h
SkyPoint::setAlt
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:141
kstarsdata.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
dmsbox.h
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:138
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
QFrame
modCalcAltAz::slotAzChecked
void slotAzChecked()
Definition: modcalcaltaz.cpp:190
kstars.h
modCalcAltAz::slotRaChecked
void slotRaChecked()
Definition: modcalcaltaz.cpp:158
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