moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / tools / modcalceclipticcoords.cpp
blob36a7e75b8a986be9cbe47d2732599d37fd3c5a58
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 ***************************************************************************/
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 ***************************************************************************/
18 #include "dms.h"
19 #include "dmsbox.h"
20 #include "modcalceclipticcoords.h"
21 #include "modcalceclipticcoords.moc"
22 #include "skypoint.h"
23 #include "ksutils.h"
24 #include "ksnumbers.h"
25 #include "kstarsdatetime.h"
26 #include <qradiobutton.h>
27 #include <qstring.h>
28 #include <qcheckbox.h>
29 #include <qradiobutton.h>
30 #include <qtextstream.h>
31 #include <klocale.h>
32 #include <klineedit.h>
33 #include <kapplication.h>
34 #include <kfiledialog.h>
35 #include <kmessagebox.h>
38 modCalcEclCoords::modCalcEclCoords(QWidget *parentSplit, const char *name) : modCalcEclCoordsDlg(parentSplit,name) {
40 equRadio->setChecked(TRUE);
41 raBox->setDegType(FALSE);
42 this->show();
45 modCalcEclCoords::~modCalcEclCoords() {
48 void modCalcEclCoords::getEclCoords (void) {
50 eclipLong = ecLongBox->createDms();
51 eclipLat = ecLatBox->createDms();
52 epoch = getEpoch( epochName->text() );
55 void modCalcEclCoords::getEquCoords (void) {
57 raCoord = raBox->createDms(FALSE);
58 decCoord = decBox->createDms();
59 epoch = getEpoch( epochName->text() );
62 double modCalcEclCoords::getEpoch (QString eName) {
64 double epoch = eName.toDouble();
66 return epoch;
69 void modCalcEclCoords::slotClearCoords (void) {
71 raBox->clearFields();
72 decBox->clearFields();
73 ecLongBox->clearFields();
74 ecLatBox->clearFields();
78 void modCalcEclCoords::slotComputeCoords (void) {
80 if(eclRadio->isChecked()) {
81 getEclCoords();
82 EclToEqu();
83 showEquCoords();
84 } else {
85 getEquCoords();
86 EquToEcl();
87 showEclCoords();
92 void modCalcEclCoords::showEquCoords(void) {
93 raBox->show( raCoord , FALSE);
94 decBox->show( decCoord );
97 void modCalcEclCoords::showEclCoords(void) {
98 ecLongBox->show( eclipLong );
99 ecLatBox->show( eclipLat );
102 void modCalcEclCoords::EclToEqu(void) {
104 SkyPoint sp = SkyPoint();
106 KStarsDateTime dt;
107 dt.setFromEpoch( epoch );
108 KSNumbers *num = new KSNumbers( dt.djd() );
110 // sp.setEclLong(eclipLong);
111 // sp.setEclLat(eclipLat);
112 sp.setFromEcliptic(num->obliquity(), &eclipLong, &eclipLat);
114 raCoord.set( *sp.ra() );
115 decCoord.set( *sp.dec() );
117 delete num;
120 void modCalcEclCoords::EquToEcl(void) {
122 SkyPoint sp = SkyPoint (raCoord, decCoord);
123 KStarsDateTime dt;
124 dt.setFromEpoch( epoch );
125 KSNumbers *num = new KSNumbers( dt.djd() );
127 sp.findEcliptic(num->obliquity(), eclipLong, eclipLat);
129 delete num;
132 void modCalcEclCoords::eclCheck() {
134 eclLatCheckBatch->setChecked(false);
135 eclLatBoxBatch->setEnabled(false);
136 eclLongCheckBatch->setChecked(false);
137 eclLongBoxBatch->setEnabled(false);
138 eclInputCoords = FALSE;
142 void modCalcEclCoords::equCheck() {
144 raCheckBatch->setChecked(false);
145 raBoxBatch->setEnabled(false);
146 decCheckBatch->setChecked(false);
147 decBoxBatch->setEnabled(false);
148 //epochCheckBatch->setChecked(false);
149 eclInputCoords = TRUE;
153 void modCalcEclCoords::slotRaCheckedBatch(){
155 if ( raCheckBatch->isChecked() ) {
156 raBoxBatch->setEnabled( false );
157 eclCheck();
158 } else {
159 raBoxBatch->setEnabled( true );
163 void modCalcEclCoords::slotDecCheckedBatch(){
165 if ( decCheckBatch->isChecked() ) {
166 decBoxBatch->setEnabled( false );
167 eclCheck();
168 } else {
169 decBoxBatch->setEnabled( true );
174 void modCalcEclCoords::slotEpochCheckedBatch(){
175 if ( epochCheckBatch->isChecked() ) {
176 epochBoxBatch->setEnabled( false );
177 } else {
178 epochBoxBatch->setEnabled( true );
183 void modCalcEclCoords::slotEclLatCheckedBatch(){
185 if ( eclLatCheckBatch->isChecked() ) {
186 eclLatBoxBatch->setEnabled( false );
187 equCheck();
188 } else {
189 eclLatBoxBatch->setEnabled( true );
193 void modCalcEclCoords::slotEclLongCheckedBatch(){
195 if ( eclLongCheckBatch->isChecked() ) {
196 eclLongBoxBatch->setEnabled( false );
197 equCheck();
198 } else {
199 eclLongBoxBatch->setEnabled( true );
203 void modCalcEclCoords::slotInputFile() {
204 QString inputFileName;
205 inputFileName = KFileDialog::getOpenFileName( );
206 InputLineEditBatch->setText( inputFileName );
209 void modCalcEclCoords::slotOutputFile() {
210 QString outputFileName;
211 outputFileName = KFileDialog::getSaveFileName( );
212 OutputLineEditBatch->setText( outputFileName );
215 void modCalcEclCoords::slotRunBatch() {
217 QString inputFileName;
219 inputFileName = InputLineEditBatch->text();
221 // We open the input file and read its content
223 if ( QFile::exists(inputFileName) ) {
224 QFile f( inputFileName );
225 if ( !f.open( IO_ReadOnly) ) {
226 QString message = i18n( "Could not open file %1.").arg( f.name() );
227 KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
228 inputFileName = "";
229 return;
232 // processLines(&f);
233 QTextStream istream(&f);
234 processLines(istream);
235 // readFile( istream );
236 f.close();
237 } else {
238 QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
239 KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
240 inputFileName = "";
241 InputLineEditBatch->setText( inputFileName );
242 return;
246 void modCalcEclCoords::processLines( QTextStream &istream ) {
248 // we open the output file
250 // QTextStream istream(&fIn);
251 QString outputFileName;
252 outputFileName = OutputLineEditBatch->text();
253 QFile fOut( outputFileName );
254 fOut.open(IO_WriteOnly);
255 QTextStream ostream(&fOut);
257 QString line;
258 QString space = " ";
259 int i = 0;
260 SkyPoint sp;
261 dms raB, decB, eclLatB, eclLongB;
262 double epoch0B;
264 while ( ! istream.eof() ) {
265 line = istream.readLine();
266 line.stripWhiteSpace();
268 //Go through the line, looking for parameters
270 QStringList fields = QStringList::split( " ", line );
272 i = 0;
274 // Input coords are ecliptic coordinates:
276 if (eclInputCoords) {
278 // Read Ecliptic Longitude and write in ostream if corresponds
280 if(eclLongCheckBatch->isChecked() ) {
281 eclLongB = dms::fromString( fields[i], TRUE);
282 i++;
283 } else
284 eclLongB = eclLongBoxBatch->createDms(TRUE);
286 if ( allRadioBatch->isChecked() )
287 ostream << eclLongB.toDMSString() << space;
288 else
289 if(eclLongCheckBatch->isChecked() )
290 ostream << eclLongB.toDMSString() << space;
292 // Read Ecliptic Latitude and write in ostream if corresponds
294 if(eclLatCheckBatch->isChecked() ) {
295 eclLatB = dms::fromString( fields[i], TRUE);
296 i++;
297 } else
298 if ( allRadioBatch->isChecked() )
299 ostream << eclLatB.toDMSString() << space;
300 else
301 if(eclLatCheckBatch->isChecked() )
302 ostream << eclLatB.toDMSString() << space;
304 // Read Epoch and write in ostream if corresponds
306 if(epochCheckBatch->isChecked() ) {
307 epoch0B = fields[i].toDouble();
308 i++;
309 } else
310 epoch0B = getEpoch( epochBoxBatch->text() );
312 if ( allRadioBatch->isChecked() )
313 ostream << epoch0B << space;
314 else
315 if(epochCheckBatch->isChecked() )
316 ostream << epoch0B << space;
318 sp = SkyPoint ();
320 KStarsDateTime dt;
321 dt.setFromEpoch( epoch0B );
322 KSNumbers *num = new KSNumbers( dt.djd() );
323 sp.setFromEcliptic(num->obliquity(), &eclLongB, &eclLatB);
324 ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
325 // Input coords. are equatorial coordinates:
327 } else {
329 // Read RA and write in ostream if corresponds
331 if(raCheckBatch->isChecked() ) {
332 raB = dms::fromString( fields[i],FALSE);
333 i++;
334 } else
335 raB = raBoxBatch->createDms(FALSE);
337 if ( allRadioBatch->isChecked() )
338 ostream << raB.toHMSString() << space;
339 else
340 if(raCheckBatch->isChecked() )
341 ostream << raB.toHMSString() << space;
343 // Read DEC and write in ostream if corresponds
345 if(decCheckBatch->isChecked() ) {
346 decB = dms::fromString( fields[i], TRUE);
347 i++;
348 } else
349 decB = decBoxBatch->createDms();
351 if ( allRadioBatch->isChecked() )
352 ostream << decB.toDMSString() << space;
353 else
354 if(decCheckBatch->isChecked() )
355 ostream << decB.toDMSString() << space;
357 // Read Epoch and write in ostream if corresponds
359 if(epochCheckBatch->isChecked() ) {
360 epoch0B = fields[i].toDouble();
361 i++;
362 } else
363 epoch0B = getEpoch( epochBoxBatch->text() );
365 if ( allRadioBatch->isChecked() )
366 ostream << epoch0B << space;
367 else
368 if(epochCheckBatch->isChecked() )
369 ostream << epoch0B << space;
371 sp = SkyPoint (raB, decB);
372 KStarsDateTime dt;
373 dt.setFromEpoch( epoch0B );
374 KSNumbers *num = new KSNumbers( dt.djd() );
375 sp.findEcliptic(num->obliquity(), eclLongB, eclLatB);
376 ostream << eclLongB.toDMSString() << space << eclLatB.toDMSString() << endl;
377 delete num;
384 fOut.close();