1 /***************************************************************************
2 modcalceclipticcoords.cpp - description
4 begin : Fri May 14 2004
5 copyright : (C) 2004 by Pablo de Vicente
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
20 #include "modcalceclipticcoords.h"
21 #include "modcalceclipticcoords.moc"
24 #include "ksnumbers.h"
25 #include "kstarsdatetime.h"
26 #include <qradiobutton.h>
28 #include <qcheckbox.h>
29 #include <qradiobutton.h>
30 #include <qtextstream.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
);
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();
69 void modCalcEclCoords::slotClearCoords (void) {
72 decBox
->clearFields();
73 ecLongBox
->clearFields();
74 ecLatBox
->clearFields();
78 void modCalcEclCoords::slotComputeCoords (void) {
80 if(eclRadio
->isChecked()) {
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();
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() );
120 void modCalcEclCoords::EquToEcl(void) {
122 SkyPoint sp
= SkyPoint (raCoord
, decCoord
);
124 dt
.setFromEpoch( epoch
);
125 KSNumbers
*num
= new KSNumbers( dt
.djd() );
127 sp
.findEcliptic(num
->obliquity(), eclipLong
, eclipLat
);
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 );
159 raBoxBatch
->setEnabled( true );
163 void modCalcEclCoords::slotDecCheckedBatch(){
165 if ( decCheckBatch
->isChecked() ) {
166 decBoxBatch
->setEnabled( false );
169 decBoxBatch
->setEnabled( true );
174 void modCalcEclCoords::slotEpochCheckedBatch(){
175 if ( epochCheckBatch
->isChecked() ) {
176 epochBoxBatch
->setEnabled( false );
178 epochBoxBatch
->setEnabled( true );
183 void modCalcEclCoords::slotEclLatCheckedBatch(){
185 if ( eclLatCheckBatch
->isChecked() ) {
186 eclLatBoxBatch
->setEnabled( false );
189 eclLatBoxBatch
->setEnabled( true );
193 void modCalcEclCoords::slotEclLongCheckedBatch(){
195 if ( eclLongCheckBatch
->isChecked() ) {
196 eclLongBoxBatch
->setEnabled( false );
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" ) );
233 QTextStream
istream(&f
);
234 processLines(istream
);
235 // readFile( istream );
238 QString message
= i18n( "Invalid file: %1" ).arg( inputFileName
);
239 KMessageBox::sorry( 0, message
, i18n( "Invalid file" ) );
241 InputLineEditBatch
->setText( inputFileName
);
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
);
261 dms raB
, decB
, eclLatB
, eclLongB
;
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
);
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
);
284 eclLongB
= eclLongBoxBatch
->createDms(TRUE
);
286 if ( allRadioBatch
->isChecked() )
287 ostream
<< eclLongB
.toDMSString() << space
;
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
);
298 if ( allRadioBatch
->isChecked() )
299 ostream
<< eclLatB
.toDMSString() << space
;
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();
310 epoch0B
= getEpoch( epochBoxBatch
->text() );
312 if ( allRadioBatch
->isChecked() )
313 ostream
<< epoch0B
<< space
;
315 if(epochCheckBatch
->isChecked() )
316 ostream
<< epoch0B
<< space
;
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:
329 // Read RA and write in ostream if corresponds
331 if(raCheckBatch
->isChecked() ) {
332 raB
= dms::fromString( fields
[i
],FALSE
);
335 raB
= raBoxBatch
->createDms(FALSE
);
337 if ( allRadioBatch
->isChecked() )
338 ostream
<< raB
.toHMSString() << space
;
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
);
349 decB
= decBoxBatch
->createDms();
351 if ( allRadioBatch
->isChecked() )
352 ostream
<< decB
.toDMSString() << space
;
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();
363 epoch0B
= getEpoch( epochBoxBatch
->text() );
365 if ( allRadioBatch
->isChecked() )
366 ostream
<< epoch0B
<< space
;
368 if(epochCheckBatch
->isChecked() )
369 ostream
<< epoch0B
<< space
;
371 sp
= SkyPoint (raB
, decB
);
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
;