• 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
modcalceclipticcoords.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalceclipticcoords.cpp - description
3  -------------------
4  begin : Fri May 14 2004
5  copyright : (C) 2004 by Pablo de Vicente
6  email : vicente@oan.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 "modcalceclipticcoords.h"
19 
20 #include <QTextStream>
21 
22 #include <klocale.h>
23 #include <kfiledialog.h>
24 #include <kmessagebox.h>
25 #include <kurlrequester.h>
26 
27 #include "dms.h"
28 #include "kstars.h"
29 #include "kstarsdata.h"
30 #include "skyobjects/skypoint.h"
31 #include "ksnumbers.h"
32 #include "dialogs/finddialog.h"
33 #include "widgets/dmsbox.h"
34 
35 modCalcEclCoords::modCalcEclCoords(QWidget *parentSplit)
36  : QFrame(parentSplit) {
37 
38  setupUi(this);
39  RA->setDegType(false);
40 
41  //Initialize Date/Time and Location data
42  DateTime->setDateTime( KStarsData::Instance()->lt().dateTime() );
43  kdt = DateTime->dateTime();
44 
45  connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow()));
46  connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
47  connect(DateTime, SIGNAL(dateTimeChanged(const QDateTime&)), this, SLOT(slotDateTimeChanged(const QDateTime&)));
48 
49  connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
50  connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
51  connect(EcLong, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
52  connect(EcLat, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
53 
54  connect(ecLatCheckBatch, SIGNAL(clicked()), this, SLOT(slotEclLatCheckedBatch()));
55  connect(ecLongCheckBatch, SIGNAL(clicked()), this, SLOT(slotEclLongCheckedBatch()));
56  connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()));
57  connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()));
58  connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()));
59  connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
60 
61  this->show();
62 }
63 
64 modCalcEclCoords::~modCalcEclCoords() {
65 }
66 
67 void modCalcEclCoords::slotNow() {
68  DateTime->setDateTime( KStarsDateTime::currentDateTime().dateTime() );
69  slotCompute();
70 }
71 
72 void modCalcEclCoords::slotObject() {
73  QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
74  if ( fd->exec() == QDialog::Accepted ) {
75  SkyObject *o = fd->selectedObject();
76  RA->showInHours( o->ra() );
77  Dec->showInDegrees( o->dec() );
78  slotCompute();
79  }
80  delete fd;
81 }
82 
83 void modCalcEclCoords::slotDateTimeChanged(const QDateTime &edt) {
84  kdt = ((KStarsDateTime)edt);
85 }
86 
87 void modCalcEclCoords::slotCompute(void) {
88  KSNumbers num( kdt.djd() );
89 
90  //Determine whether we are calculating ecliptic coordinates from equatorial,
91  //or vice versa. We calculate ecliptic by default, unless the signal
92  //was sent by changing the EcLong or EcLat value.
93  if ( sender()->objectName() == "EcLong" || sender()->objectName() == "EcLat" ) {
94  //Validate ecliptic coordinates
95  bool ok( false );
96  dms elat;
97  dms elong = EcLong->createDms( true, &ok );
98  if ( ok ) elat = EcLat->createDms( true, &ok );
99  if ( ok ) {
100  SkyPoint sp;
101  sp.setFromEcliptic( num.obliquity(), elong, elat );
102  RA->showInHours( sp.ra() );
103  Dec->showInDegrees( sp.dec() );
104  }
105 
106  } else {
107  //Validate RA and Dec coordinates
108  bool ok( false );
109  dms ra;
110  dms dec = Dec->createDms( true, &ok );
111  if ( ok ) ra = RA->createDms( false, &ok );
112  if ( ok ) {
113  SkyPoint sp( ra, dec );
114  dms elong, elat;
115  sp.findEcliptic( num.obliquity(), elong, elat );
116  EcLong->showInDegrees( elong );
117  EcLat->showInDegrees( elat );
118  }
119  }
120 }
121 
122 void modCalcEclCoords::eclCheck() {
123 
124  ecLatCheckBatch->setChecked(false);
125  ecLatBoxBatch->setEnabled(false);
126  ecLongCheckBatch->setChecked(false);
127  ecLongBoxBatch->setEnabled(false);
128  // eclInputCoords = false;
129 
130 }
131 
132 void modCalcEclCoords::equCheck() {
133 
134  raCheckBatch->setChecked(false);
135  raBoxBatch->setEnabled(false);
136  decCheckBatch->setChecked(false);
137  decBoxBatch->setEnabled(false);
138  //epochCheckBatch->setChecked(false);
139  // eclInputCoords = true;
140 
141 }
142 
143 void modCalcEclCoords::slotRaCheckedBatch(){
144 
145  if ( raCheckBatch->isChecked() ) {
146  raBoxBatch->setEnabled( false );
147  eclCheck();
148  } else {
149  raBoxBatch->setEnabled( true );
150  }
151 }
152 
153 void modCalcEclCoords::slotDecCheckedBatch(){
154 
155  if ( decCheckBatch->isChecked() ) {
156  decBoxBatch->setEnabled( false );
157  eclCheck();
158  } else {
159  decBoxBatch->setEnabled( true );
160  }
161 }
162 
163 
164 void modCalcEclCoords::slotEpochCheckedBatch(){
165  if ( epochCheckBatch->isChecked() ) {
166  epochBoxBatch->setEnabled( false );
167  } else {
168  epochBoxBatch->setEnabled( true );
169  }
170 }
171 
172 
173 void modCalcEclCoords::slotEclLatCheckedBatch(){
174 
175  if ( ecLatCheckBatch->isChecked() ) {
176  ecLatBoxBatch->setEnabled( false );
177  equCheck();
178  } else {
179  ecLatBoxBatch->setEnabled( true );
180  }
181 }
182 
183 void modCalcEclCoords::slotEclLongCheckedBatch(){
184 
185  if ( ecLongCheckBatch->isChecked() ) {
186  ecLongBoxBatch->setEnabled( false );
187  equCheck();
188  } else {
189  ecLongBoxBatch->setEnabled( true );
190  }
191 }
192 
193 void modCalcEclCoords::slotRunBatch() {
194 
195  QString inputFileName = InputFileBoxBatch->url().toLocalFile();
196 
197  // We open the input file and read its content
198 
199  if ( QFile::exists(inputFileName) ) {
200  QFile f( inputFileName );
201  if ( !f.open( QIODevice::ReadOnly) ) {
202  QString message = i18n( "Could not open file %1.", f.fileName() );
203  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
204  inputFileName.clear();
205  return;
206  }
207 
208  // processLines(&f);
209  QTextStream istream(&f);
210  processLines(istream);
211  // readFile( istream );
212  f.close();
213  } else {
214  QString message = i18n( "Invalid file: %1", inputFileName );
215  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
216  inputFileName.clear();
217  InputFileBoxBatch->setUrl( inputFileName );
218  return;
219  }
220 }
221 
222 void modCalcEclCoords::processLines( QTextStream &istream ) {
223 
224  // we open the output file
225 
226  // QTextStream istream(&fIn);
227  QString outputFileName = OutputFileBoxBatch->url().toLocalFile();
228  QFile fOut( outputFileName );
229  fOut.open(QIODevice::WriteOnly); // TODO error checking
230  QTextStream ostream(&fOut);
231 
232  QString line;
233  QChar space = ' ';
234  int i = 0;
235  SkyPoint sp;
236  dms raB, decB, eclLatB, eclLongB;
237  QString epoch0B;
238 
239  while ( ! istream.atEnd() ) {
240  line = istream.readLine();
241  line.trimmed();
242 
243  //Go through the line, looking for parameters
244 
245  QStringList fields = line.split( ' ' );
246 
247  i = 0;
248 
249  // Input coords are ecliptic coordinates:
250 
251  // if (eclInputCoords) {
252  //
253  // // Read Ecliptic Longitude and write in ostream if corresponds
254  //
255  // if(ecLongCheckBatch->isChecked() ) {
256  // eclLongB = dms::fromString( fields[i], true);
257  // i++;
258  // } else
259  // eclLongB = ecLongBoxBatch->createDms(true);
260  //
261  // if ( allRadioBatch->isChecked() )
262  // ostream << eclLongB.toDMSString() << space;
263  // else
264  // if(ecLongCheckBatch->isChecked() )
265  // ostream << eclLongB.toDMSString() << space;
266  //
267  // // Read Ecliptic Latitude and write in ostream if corresponds
268  //
269  // if(ecLatCheckBatch->isChecked() ) {
270  // eclLatB = dms::fromString( fields[i], true);
271  // i++;
272  // } else
273  // if ( allRadioBatch->isChecked() )
274  // ostream << eclLatB.toDMSString() << space;
275  // else
276  // if(ecLatCheckBatch->isChecked() )
277  // ostream << eclLatB.toDMSString() << space;
278  //
279  // // Read Epoch and write in ostream if corresponds
280  //
281  // if(epochCheckBatch->isChecked() ) {
282  // epoch0B = fields[i];
283  // i++;
284  // } else
285  // epoch0B = epochBoxBatch->text();
286  //
287  // if ( allRadioBatch->isChecked() )
288  // ostream << epoch0B << space;
289  // else
290  // if(epochCheckBatch->isChecked() )
291  // ostream << epoch0B << space;
292  //
293  // sp = SkyPoint ();
294  //
295  // KStarsDateTime dt;
296  // dt.setFromEpoch( epoch0B );
297  // KSNumbers *num = new KSNumbers( dt.djd() );
298  // sp.setFromEcliptic(num->obliquity(), &eclLongB, &eclLatB);
299  // ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << endl;
300  // // Input coords. are equatorial coordinates:
301  //
302  // } else {
303 
304  // Read RA and write in ostream if corresponds
305 
306  if(raCheckBatch->isChecked() ) {
307  raB = dms::fromString( fields[i],false);
308  i++;
309  } else
310  raB = raBoxBatch->createDms(false);
311 
312  if ( allRadioBatch->isChecked() )
313  ostream << raB.toHMSString() << space;
314  else
315  if(raCheckBatch->isChecked() )
316  ostream << raB.toHMSString() << space;
317 
318  // Read DEC and write in ostream if corresponds
319 
320  if(decCheckBatch->isChecked() ) {
321  decB = dms::fromString( fields[i], true);
322  i++;
323  } else
324  decB = decBoxBatch->createDms();
325 
326  if ( allRadioBatch->isChecked() )
327  ostream << decB.toDMSString() << space;
328  else
329  if(decCheckBatch->isChecked() )
330  ostream << decB.toDMSString() << space;
331 
332  // Read Epoch and write in ostream if corresponds
333 
334  if(epochCheckBatch->isChecked() ) {
335  epoch0B = fields[i];
336  i++;
337  } else
338  epoch0B = epochBoxBatch->text();
339 
340  if ( allRadioBatch->isChecked() )
341  ostream << epoch0B << space;
342  else
343  if(epochCheckBatch->isChecked() )
344  ostream << epoch0B << space;
345 
346  sp = SkyPoint (raB, decB);
347  KStarsDateTime dt;
348  dt.setFromEpoch( epoch0B );
349  KSNumbers *num = new KSNumbers( dt.djd() );
350  sp.findEcliptic(num->obliquity(), eclLongB, eclLatB);
351  ostream << eclLongB.toDMSString() << space << eclLatB.toDMSString() << endl;
352  delete num;
353 
354  // }
355 
356  }
357 
358 
359  fOut.close();
360 }
361 
362 #include "modcalceclipticcoords.moc"
modCalcEclCoords::~modCalcEclCoords
~modCalcEclCoords()
Definition: modcalceclipticcoords.cpp:64
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
modCalcEclCoords::slotEclLatCheckedBatch
void slotEclLatCheckedBatch(void)
Definition: modcalceclipticcoords.cpp:173
modCalcEclCoords::slotNow
void slotNow(void)
Definition: modcalceclipticcoords.cpp:67
SkyPoint::findEcliptic
void findEcliptic(const dms *Obliquity, dms &EcLong, dms &EcLat)
Determine the Ecliptic coordinates of the SkyPoint, given the Julian Date.
Definition: skypoint.cpp:137
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
KStarsDateTime::setFromEpoch
bool setFromEpoch(double e)
Set the Date/Time from an epoch value, represented as a double.
Definition: kstarsdatetime.cpp:195
modCalcEclCoords::slotEpochCheckedBatch
void slotEpochCheckedBatch(void)
Definition: modcalceclipticcoords.cpp:164
dms.h
NaN::f
const float f
Definition: nan.h:36
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
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
modCalcEclCoords::slotCompute
void slotCompute(void)
Definition: modcalceclipticcoords.cpp:87
ksnumbers.h
KSNumbers::obliquity
const dms * obliquity() const
Definition: ksnumbers.h:58
SkyPoint::setFromEcliptic
void setFromEcliptic(const dms *Obliquity, const dms &EcLong, const dms &EcLat)
Set the current (RA, Dec) coordinates of the SkyPoint, given pointers to its Ecliptic (Long...
Definition: skypoint.cpp:151
modCalcEclCoords::slotDateTimeChanged
void slotDateTimeChanged(const QDateTime &edt)
Definition: modcalceclipticcoords.cpp:83
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
modCalcEclCoords::slotObject
void slotObject(void)
Definition: modcalceclipticcoords.cpp:72
QTextStream
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
modcalceclipticcoords.h
finddialog.h
kstarsdata.h
dmsbox.h
modCalcEclCoords::slotRunBatch
void slotRunBatch()
Definition: modcalceclipticcoords.cpp:193
modCalcEclCoords::slotDecCheckedBatch
void slotDecCheckedBatch(void)
Definition: modcalceclipticcoords.cpp:153
modCalcEclCoords::modCalcEclCoords
modCalcEclCoords(QWidget *p)
Definition: modcalceclipticcoords.cpp:35
modCalcEclCoords::slotRaCheckedBatch
void slotRaCheckedBatch(void)
Definition: modcalceclipticcoords.cpp:143
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
kstars.h
modCalcEclCoords::slotEclLongCheckedBatch
void slotEclLongCheckedBatch(void)
Definition: modcalceclipticcoords.cpp:183
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