• 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
modcalcvlsr.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcvlsr.cpp - description
3  -------------------
4  begin : sun mar 13 2005
5  copyright : (C) 2005 by Pablo de Vicente
6  email : p.devicente@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 "modcalcvlsr.h"
19 
20 #include <QPointer>
21 
22 #include <KGlobal>
23 #include <KLocale>
24 #include <kfiledialog.h>
25 #include <kmessagebox.h>
26 
27 #include "ksnumbers.h"
28 #include "dms.h"
29 #include "skyobjects/skypoint.h"
30 #include "geolocation.h"
31 #include "kstarsdata.h"
32 #include "kstarsdatetime.h"
33 #include "widgets/dmsbox.h"
34 #include "dialogs/locationdialog.h"
35 #include "dialogs/finddialog.h"
36 
37 modCalcVlsr::modCalcVlsr(QWidget *parentSplit) :
38  QFrame(parentSplit), velocityFlag(0)
39 {
40  setupUi(this);
41  RA->setDegType(false);
42 
43  Date->setDateTime( KStarsDateTime::currentDateTime().dateTime() );
44  initGeo();
45 
46  VLSR->setValidator( new QDoubleValidator( VLSR ) );
47  VHelio->setValidator( new QDoubleValidator( VHelio ) );
48  VGeo->setValidator( new QDoubleValidator( VGeo ) );
49  VTopo->setValidator( new QDoubleValidator( VTopo ) );
50 
51  // signals and slots connections
52  connect(Date, SIGNAL( dateTimeChanged( const QDateTime & ) ),
53  this, SLOT( slotCompute() ) );
54  connect(NowButton, SIGNAL( clicked() ), this, SLOT( slotNow() ) );
55  connect(LocationButton, SIGNAL( clicked() ), this, SLOT( slotLocation() ) );
56  connect(ObjectButton, SIGNAL( clicked() ), this, SLOT( slotFindObject() ) );
57  connect(RA, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
58  connect(Dec, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
59  connect(VLSR, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
60  connect(VHelio, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
61  connect(VGeo, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
62  connect(VTopo, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
63 
64  connect(RunButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
65 
66  show();
67 }
68 
69 modCalcVlsr::~modCalcVlsr(){
70 }
71 
72 void modCalcVlsr::initGeo(void)
73 {
74  geoPlace = KStarsData::Instance()->geo();
75  LocationButton->setText( geoPlace->fullName() );
76 }
77 
78 void modCalcVlsr::slotNow()
79 {
80  Date->setDateTime( KStarsDateTime::currentDateTime().dateTime() );
81  slotCompute();
82 }
83 
84 void modCalcVlsr::slotFindObject() {
85  QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
86  if ( fd->exec() == QDialog::Accepted ) {
87  SkyObject *o = fd->selectedObject();
88  RA->showInHours( o->ra0() );
89  Dec->showInDegrees( o->dec0() );
90  }
91  delete fd;
92 }
93 
94 void modCalcVlsr::slotLocation() {
95  QPointer<LocationDialog> ld( new LocationDialog( this ) );
96 
97  if ( ld->exec() == QDialog::Accepted && ld ) {
98  GeoLocation *newGeo = ld->selectedCity();
99  if ( newGeo ) {
100  geoPlace = newGeo;
101  LocationButton->setText( geoPlace->fullName() );
102  }
103  }
104  delete ld;
105 
106  slotCompute();
107 }
108 
109 void modCalcVlsr::slotCompute()
110 {
111  bool ok1(false), ok2(false);
112  SkyPoint sp( RA->createDms(false, &ok1), Dec->createDms(true, &ok2) );
113  if ( !ok1 || !ok2 ) return;
114 
115  KStarsDateTime dt = Date->dateTime();
116  double vst[3];
117  geoPlace->TopocentricVelocity( vst, dt.gst() );
118 
119  if ( sender()->objectName() == "VLSR" ) velocityFlag = 0;
120  if ( sender()->objectName() == "VHelio" ) velocityFlag = 1;
121  if ( sender()->objectName() == "VGeo" ) velocityFlag = 2;
122  if ( sender()->objectName() == "VTopo" ) velocityFlag = 3;
123 
124  switch ( velocityFlag ) {
125  case 0: //Hold VLSR constant, compute the others
126  {
127  double vlsr = VLSR->text().toDouble();
128  double vhelio = sp.vHeliocentric( vlsr, dt.djd() );
129  double vgeo = sp.vGeocentric( vhelio, dt.djd() );
130 
131  VHelio->setText( QString::number( vhelio ) );
132  VGeo->setText( QString::number( vgeo ) );
133  VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
134  break;
135  }
136 
137  case 1: //Hold VHelio constant, compute the others
138  {
139  double vhelio = VHelio->text().toDouble();
140  double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );
141  double vgeo = sp.vGeocentric( vhelio, dt.djd() );
142 
143  VLSR->setText( QString::number( vlsr ) );
144  VGeo->setText( QString::number( vgeo ) );
145  VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
146  break;
147  }
148 
149  case 2: //Hold VGeo constant, compute the others
150  {
151  double vgeo = VGeo->text().toDouble();
152  double vhelio = sp.vGeoToVHelio( vgeo, dt.djd() );
153  double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );
154 
155  VLSR->setText( QString::number( vlsr ) );
156  VHelio->setText( QString::number( vhelio ) );
157  VTopo->setText( QString::number( sp.vTopocentric(vgeo, vst) ) );
158  break;
159  }
160 
161  case 3: //Hold VTopo constant, compute the others
162  {
163  double vtopo = VTopo->text().toDouble();
164  double vgeo = sp.vTopoToVGeo( vtopo, vst );
165  double vhelio = sp.vGeoToVHelio( vgeo, dt.djd() );
166  double vlsr = sp.vHelioToVlsr( vhelio, dt.djd() );
167 
168  VLSR->setText( QString::number( vlsr ) );
169  VHelio->setText( QString::number( vhelio ) );
170  VGeo->setText( QString::number( vgeo ) );
171  break;
172  }
173 
174  default: //oops
175  kDebug() << i18n("Error: do not know which velocity to use for input.");
176  break;
177  }
178 }
179 
180 void modCalcVlsr::slotUtChecked(){
181  if ( UTCheckBatch->isChecked() )
182  UTBoxBatch->setEnabled( false );
183  else {
184  UTBoxBatch->setEnabled( true );
185  }
186 }
187 
188 void modCalcVlsr::slotDateChecked(){
189  if ( DateCheckBatch->isChecked() )
190  DateBoxBatch->setEnabled( false );
191  else {
192  DateBoxBatch->setEnabled( true );
193  }
194 }
195 
196 void modCalcVlsr::slotRaChecked(){
197  if ( RACheckBatch->isChecked() ) {
198  RABoxBatch->setEnabled( false );
199  }
200  else {
201  RABoxBatch->setEnabled( true );
202  }
203 }
204 
205 void modCalcVlsr::slotDecChecked(){
206  if ( DecCheckBatch->isChecked() ) {
207  DecBoxBatch->setEnabled( false );
208  }
209  else {
210  DecBoxBatch->setEnabled( true );
211  }
212 }
213 
214 void modCalcVlsr::slotEpochChecked(){
215  if ( EpochCheckBatch->isChecked() )
216  EpochBoxBatch->setEnabled( false );
217  else
218  EpochBoxBatch->setEnabled( true );
219 }
220 
221 void modCalcVlsr::slotLongChecked(){
222  if ( LongCheckBatch->isChecked() )
223  LongitudeBoxBatch->setEnabled( false );
224  else
225  LongitudeBoxBatch->setEnabled( true );
226 }
227 
228 void modCalcVlsr::slotLatChecked(){
229  if ( LatCheckBatch->isChecked() )
230  LatitudeBoxBatch->setEnabled( false );
231  else {
232  LatitudeBoxBatch->setEnabled( true );
233  }
234 }
235 
236 void modCalcVlsr::slotHeightChecked(){
237  if ( ElevationCheckBatch->isChecked() )
238  ElevationBoxBatch->setEnabled( false );
239  else {
240  ElevationBoxBatch->setEnabled( true );
241  }
242 }
243 
244 void modCalcVlsr::slotVlsrChecked(){
245  if ( InputVelocityCheckBatch->isChecked() )
246  InputVelocityBoxBatch->setEnabled( false );
247  else {
248  InputVelocityBoxBatch->setEnabled( true );
249  }
250 }
251 
252 void modCalcVlsr::slotInputFile() {
253  QString inputFileName;
254  inputFileName = KFileDialog::getOpenFileName( );
255  InputFileBoxBatch->setUrl( inputFileName );
256 }
257 
258 void modCalcVlsr::slotOutputFile() {
259  QString outputFileName;
260  outputFileName = KFileDialog::getSaveFileName( );
261  OutputFileBoxBatch->setUrl( outputFileName );
262 }
263 
264 void modCalcVlsr::slotRunBatch() {
265  QString inputFileName;
266 
267  inputFileName = InputFileBoxBatch->url().toLocalFile();
268 
269  // We open the input file and read its content
270 
271  if ( QFile::exists(inputFileName) ) {
272  QFile f( inputFileName );
273  if ( !f.open( QIODevice::ReadOnly) ) {
274  QString message = i18n( "Could not open file %1.", f.fileName() );
275  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
276  inputFileName.clear();
277  return;
278  }
279 
280  // processLines(&f);
281  QTextStream istream(&f);
282  processLines(istream);
283  // readFile( istream );
284  f.close();
285  } else {
286  QString message = i18n( "Invalid file: %1", inputFileName );
287  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
288  inputFileName.clear();
289  InputFileBoxBatch->setUrl( inputFileName );
290  return;
291  }
292 }
293 
294 void modCalcVlsr::processLines( QTextStream &istream ) {
295 
296  // we open the output file
297 
298  // QTextStream istream(&fIn);
299  QString outputFileName;
300  outputFileName = OutputFileBoxBatch->url().toLocalFile();
301  QFile fOut( outputFileName );
302  fOut.open(QIODevice::WriteOnly);
303  QTextStream ostream(&fOut);
304 
305  QString line;
306  QChar space = ' ';
307  int i = 0;
308  long double jd0;
309  SkyPoint spB;
310  double sra, cra, sdc, cdc;
311  dms raB, decB, latB, longB;
312  QString epoch0B;
313  double vhB, vgB, vtB, vlsrB, heightB;
314  double vtopo[3];
315  QTime utB;
316  QDate dtB;
317  KStarsDateTime dt0B;
318 
319  while ( ! istream.atEnd() ) {
320  line = istream.readLine();
321  line.trimmed();
322 
323  //Go through the line, looking for parameters
324 
325  QStringList fields = line.split( ' ' );
326 
327  i = 0;
328 
329  // Read Ut and write in ostream if corresponds
330 
331  if(UTCheckBatch->isChecked() ) {
332  utB = QTime::fromString( fields[i] );
333  i++;
334  } else
335  utB = UTBoxBatch->time();
336 
337  if ( AllRadioBatch->isChecked() )
338  ostream << KGlobal::locale()->formatTime( utB ) << space;
339  else
340  if(UTCheckBatch->isChecked() )
341  ostream << KGlobal::locale()->formatTime( utB ) << space;
342 
343  // Read date and write in ostream if corresponds
344 
345  if(DateCheckBatch->isChecked() ) {
346  dtB = QDate::fromString( fields[i] );
347  i++;
348  } else
349  dtB = DateBoxBatch->date();
350  if ( AllRadioBatch->isChecked() )
351  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
352  else
353  if(DateCheckBatch->isChecked() )
354  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
355 
356  // Read RA and write in ostream if corresponds
357 
358  if(RACheckBatch->isChecked() ) {
359  raB = dms::fromString( fields[i],false);
360  i++;
361  } else
362  raB = RABoxBatch->createDms(false);
363 
364  if ( AllRadioBatch->isChecked() )
365  ostream << raB.toHMSString() << space;
366  else
367  if(RACheckBatch->isChecked() )
368  ostream << raB.toHMSString() << space;
369 
370  // Read DEC and write in ostream if corresponds
371 
372  if(DecCheckBatch->isChecked() ) {
373  decB = dms::fromString( fields[i], true);
374  i++;
375  } else
376  decB = DecBoxBatch->createDms();
377 
378  if ( AllRadioBatch->isChecked() )
379  ostream << decB.toDMSString() << space;
380  else
381  if(DecCheckBatch->isChecked() )
382  ostream << decB.toDMSString() << space;
383 
384  // Read Epoch and write in ostream if corresponds
385 
386  if(EpochCheckBatch->isChecked() ) {
387  epoch0B = fields[i];
388  i++;
389  } else
390  epoch0B = EpochBoxBatch->text();
391 
392  if ( AllRadioBatch->isChecked() )
393  ostream << epoch0B << space;
394  else
395  if(EpochCheckBatch->isChecked() )
396  ostream << epoch0B << space;
397 
398  // Read vlsr and write in ostream if corresponds
399 
400  if(InputVelocityCheckBatch->isChecked() ) {
401  vlsrB = fields[i].toDouble();
402  i++;
403  } else
404  vlsrB = InputVelocityComboBatch->currentText().toDouble();
405 
406  if ( AllRadioBatch->isChecked() )
407  ostream << vlsrB << space;
408  else
409  if(InputVelocityCheckBatch->isChecked() )
410  ostream << vlsrB << space;
411 
412  // Read Longitude and write in ostream if corresponds
413 
414  if (LongCheckBatch->isChecked() ) {
415  longB = dms::fromString( fields[i],true);
416  i++;
417  } else
418  longB = LongitudeBoxBatch->createDms(true);
419 
420  if ( AllRadioBatch->isChecked() )
421  ostream << longB.toDMSString() << space;
422  else
423  if (LongCheckBatch->isChecked() )
424  ostream << longB.toDMSString() << space;
425 
426  // Read Latitude
427 
428 
429  if (LatCheckBatch->isChecked() ) {
430  latB = dms::fromString( fields[i], true);
431  i++;
432  } else
433  latB = LatitudeBoxBatch->createDms(true);
434  if ( AllRadioBatch->isChecked() )
435  ostream << latB.toDMSString() << space;
436  else
437  if (LatCheckBatch->isChecked() )
438  ostream << latB.toDMSString() << space;
439 
440  // Read height and write in ostream if corresponds
441 
442  if(ElevationCheckBatch->isChecked() ) {
443  heightB = fields[i].toDouble();
444  i++;
445  } else
446  heightB = ElevationBoxBatch->text().toDouble();
447 
448  if ( AllRadioBatch->isChecked() )
449  ostream << heightB << space;
450  else
451  if(ElevationCheckBatch->isChecked() )
452  ostream << heightB << space;
453 
454  // We make the first calculations
455 
456  spB = SkyPoint (raB, decB);
457  dt0B.setFromEpoch(epoch0B);
458  vhB = spB.vHeliocentric(vlsrB, dt0B.djd());
459  jd0 = KStarsDateTime(dtB,utB).djd();
460  vgB = spB.vGeocentric(vlsrB, jd0);
461  geoPlace->setLong( longB );
462  geoPlace->setLat( latB );
463  geoPlace->setHeight( heightB );
464  dms gsidt = KStarsDateTime(dtB,utB).gst();
465  geoPlace->TopocentricVelocity(vtopo, gsidt);
466  spB.ra().SinCos(sra, cra);
467  spB.dec().SinCos(sdc, cdc);
468  vtB = vgB - (vtopo[0]*cdc*cra + vtopo[1]*cdc*sra + vtopo[2]*sdc);
469 
470  ostream << vhB << space << vgB << space << vtB << endl;
471 
472  }
473 
474 
475  fOut.close();
476 }
477 
478 #include "modcalcvlsr.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
modCalcVlsr::modCalcVlsr
modCalcVlsr(QWidget *p)
Definition: modcalcvlsr.cpp:37
modCalcVlsr::~modCalcVlsr
~modCalcVlsr()
Definition: modcalcvlsr.cpp:69
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
GeoLocation::TopocentricVelocity
void TopocentricVelocity(double vtopo[], dms gt)
Computes the velocity in km/s of an observer on the surface of the Earth referred to a system whose o...
Definition: geolocation.cpp:139
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
GeoLocation::setLat
void setLat(dms l)
Set latitude according to dms argument.
Definition: geolocation.h:136
geolocation.h
KStarsDateTime::setFromEpoch
bool setFromEpoch(double e)
Set the Date/Time from an epoch value, represented as a double.
Definition: kstarsdatetime.cpp:195
dms.h
GeoLocation::setLong
void setLong(dms l)
Set longitude according to dms argument.
Definition: geolocation.h:128
NaN::f
const float f
Definition: nan.h:36
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
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
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
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
skypoint.h
modcalcvlsr.h
GeoLocation::setHeight
void setHeight(double hg)
Set elevation above sea level.
Definition: geolocation.h:144
QTextStream
SkyPoint::vHeliocentric
double vHeliocentric(double vlsr, long double jd)
Computes the radial velocity of a source referred to the solar system barycenter from the radial velo...
Definition: skypoint.cpp:673
finddialog.h
SkyPoint::vGeocentric
double vGeocentric(double vhelio, long double jd)
Computes the radial velocity of a source referred to the center of the earth from the radial velocity...
Definition: skypoint.cpp:719
NaN::ld
const long double ld
Definition: nan.h:37
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
kstarsdatetime.h
kstarsdata.h
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
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