1 /***************************************************************************
2 modcalcapcoord.cpp - description
4 begin : Wed Apr 10 2002
5 copyright : (C) 2002 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 ***************************************************************************/
18 #include "modcalcapcoord.h"
19 #include "modcalcapcoord.moc"
20 #include "modcalcprec.h"
24 #include "kstarsdatetime.h"
25 #include "libkdeedu/extdate/extdatetimeedit.h"
27 #include <qcheckbox.h>
28 #include <qradiobutton.h>
29 #include <qdatetimeedit.h> //needed for QTimeEdit
30 #include <klineedit.h>
31 #include <qtextstream.h>
33 #include <kfiledialog.h>
34 #include <kmessagebox.h>
36 //#include <kapplication.h> ..already included in modcalcapcoord.h
38 modCalcApCoord::modCalcApCoord(QWidget
*parentSplit
, const char *name
) : modCalcApCoordDlg(parentSplit
,name
) {
41 ra0Box
->setDegType(FALSE
);
42 rafBox
->setDegType(FALSE
);
47 modCalcApCoord::~modCalcApCoord(){
50 SkyPoint
modCalcApCoord::getEquCoords (void) {
51 dms raCoord
, decCoord
;
53 raCoord
= ra0Box
->createDms(FALSE
);
54 decCoord
= dec0Box
->createDms();
56 SkyPoint sp
= SkyPoint (raCoord
, decCoord
);
61 void modCalcApCoord::showCurrentTime (void)
63 KStarsDateTime
dt( KStarsDateTime::currentDateTime() );
64 datBox
->setDate( dt
.date() );
65 timBox
->setTime( dt
.time() );
68 KStarsDateTime
modCalcApCoord::getDateTime (void)
70 return KStarsDateTime( datBox
->date() , timBox
->time() );
73 double modCalcApCoord::getEpoch (QString eName
) {
75 double epoch
= eName
.toDouble(&ok
);
80 kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl
;
85 void modCalcApCoord::showEquCoords ( SkyPoint sp
) {
86 rafBox
->show( sp
.ra() , FALSE
);
87 decfBox
->show( sp
.dec() );
90 void modCalcApCoord::slotClearCoords(){
92 ra0Box
->clearFields();
93 dec0Box
->clearFields();
94 rafBox
->clearFields();
95 decfBox
->clearFields();
96 epoch0Name
->setText("");
97 datBox
->setDate(ExtDate::currentDate());
98 timBox
->setTime(QTime(0,0,0));
101 void modCalcApCoord::slotComputeCoords(){
102 long double jd
= getDateTime().djd();
104 dt
.setFromEpoch( getEpoch( epoch0Name
->text() ) );
105 long double jd0
= dt
.djd();
110 sp
.apparentCoord(jd0
, jd
);
114 void modCalcApCoord::slotUtCheckedBatch(){
115 if ( utCheckBatch
->isChecked() )
116 utBoxBatch
->setEnabled( false );
118 utBoxBatch
->setEnabled( true );
122 void modCalcApCoord::slotDateCheckedBatch(){
124 if ( dateCheckBatch
->isChecked() )
125 dateBoxBatch
->setEnabled( false );
127 dateBoxBatch
->setEnabled( true );
131 void modCalcApCoord::slotRaCheckedBatch(){
133 if ( raCheckBatch
->isChecked() )
134 raBoxBatch
->setEnabled( false );
136 raBoxBatch
->setEnabled( true );
140 void modCalcApCoord::slotDecCheckedBatch(){
142 if ( decCheckBatch
->isChecked() )
143 decBoxBatch
->setEnabled( false );
145 decBoxBatch
->setEnabled( true );
149 void modCalcApCoord::slotEpochCheckedBatch(){
151 if ( epochCheckBatch
->isChecked() )
152 epochBoxBatch
->setEnabled( false );
154 epochBoxBatch
->setEnabled( true );
158 void modCalcApCoord::slotInputFile() {
159 QString inputFileName
;
160 inputFileName
= KFileDialog::getOpenFileName( );
161 InputLineEditBatch
->setText( inputFileName
);
164 void modCalcApCoord::slotOutputFile() {
165 QString outputFileName
;
166 outputFileName
= KFileDialog::getSaveFileName( );
167 OutputLineEditBatch
->setText( outputFileName
);
170 void modCalcApCoord::slotRunBatch() {
172 QString inputFileName
;
174 inputFileName
= InputLineEditBatch
->text();
176 // We open the input file and read its content
178 if ( QFile::exists(inputFileName
) ) {
179 QFile
f( inputFileName
);
180 if ( !f
.open( IO_ReadOnly
) ) {
181 QString message
= i18n( "Could not open file %1.").arg( f
.name() );
182 KMessageBox::sorry( 0, message
, i18n( "Could Not Open File" ) );
188 QTextStream
istream(&f
);
189 processLines(istream
);
190 // readFile( istream );
193 QString message
= i18n( "Invalid file: %1" ).arg( inputFileName
);
194 KMessageBox::sorry( 0, message
, i18n( "Invalid file" ) );
196 InputLineEditBatch
->setText( inputFileName
);
201 //void modCalcApCoord::processLines( const QFile * fIn ) {
202 void modCalcApCoord::processLines( QTextStream
&istream
) {
204 // we open the output file
206 // QTextStream istream(&fIn);
207 QString outputFileName
;
208 outputFileName
= OutputLineEditBatch
->text();
209 QFile
fOut( outputFileName
);
210 fOut
.open(IO_WriteOnly
);
211 QTextStream
ostream(&fOut
);
223 while ( ! istream
.eof() ) {
224 line
= istream
.readLine();
225 line
.stripWhiteSpace();
227 //Go through the line, looking for parameters
229 QStringList fields
= QStringList::split( " ", line
);
233 // Read Ut and write in ostream if corresponds
235 if(utCheckBatch
->isChecked() ) {
236 utB
= QTime::fromString( fields
[i
] );
239 utB
= utBoxBatch
->time();
241 if ( allRadioBatch
->isChecked() )
242 ostream
<< utB
.toString() << space
;
244 if(utCheckBatch
->isChecked() )
245 ostream
<< utB
.toString() << space
;
247 // Read date and write in ostream if corresponds
249 if(dateCheckBatch
->isChecked() ) {
250 dtB
= ExtDate::fromString( fields
[i
] );
253 dtB
= dateBoxBatch
->date();
255 if ( allRadioBatch
->isChecked() )
256 ostream
<< dtB
.toString().append(space
);
258 if(dateCheckBatch
->isChecked() )
259 ostream
<< dtB
.toString().append(space
);
261 // Read RA and write in ostream if corresponds
263 if(raCheckBatch
->isChecked() ) {
264 raB
= dms::fromString( fields
[i
],FALSE
);
267 raB
= raBoxBatch
->createDms(FALSE
);
269 if ( allRadioBatch
->isChecked() )
270 ostream
<< raB
.toHMSString() << space
;
272 if(raCheckBatch
->isChecked() )
273 ostream
<< raB
.toHMSString() << space
;
275 // Read DEC and write in ostream if corresponds
277 if(decCheckBatch
->isChecked() ) {
278 decB
= dms::fromString( fields
[i
], TRUE
);
281 decB
= decBoxBatch
->createDms();
283 if ( allRadioBatch
->isChecked() )
284 ostream
<< decB
.toDMSString() << space
;
286 if(decCheckBatch
->isChecked() )
287 ostream
<< decB
.toHMSString() << space
;
289 // Read Epoch and write in ostream if corresponds
291 if(epochCheckBatch
->isChecked() ) {
292 epoch0B
= fields
[i
].toDouble();
295 epoch0B
= getEpoch( epochBoxBatch
->text() );
297 if ( allRadioBatch
->isChecked() )
300 if(decCheckBatch
->isChecked() )
304 dt
.setFromEpoch( epoch0B
);
305 jd
= KStarsDateTime(dtB
,utB
).djd();
307 sp
= SkyPoint (raB
, decB
);
308 sp
.apparentCoord(jd0
, jd
);
310 ostream
<< sp
.ra()->toHMSString() << sp
.dec()->toDMSString() << endl
;