kstars
modcalcapcoord.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "modcalcapcoord.h"
00019 #include "modcalcapcoord.moc"
00020 #include "modcalcprec.h"
00021 #include "dms.h"
00022 #include "dmsbox.h"
00023 #include "skypoint.h"
00024 #include "kstars.h"
00025 #include "kstarsdata.h"
00026 #include "kstarsdatetime.h"
00027 #include "libkdeedu/extdate/extdatetimeedit.h"
00028
00029 #include <qcheckbox.h>
00030 #include <qradiobutton.h>
00031 #include <qdatetimeedit.h>
00032 #include <klineedit.h>
00033 #include <qtextstream.h>
00034 #include <klocale.h>
00035 #include <kfiledialog.h>
00036 #include <kmessagebox.h>
00037
00038
00039
00040 modCalcApCoord::modCalcApCoord(QWidget *parentSplit, const char *name) : modCalcApCoordDlg(parentSplit,name) {
00041
00042 showCurrentTime();
00043 ra0Box->setDegType(FALSE);
00044 rafBox->setDegType(FALSE);
00045 show();
00046
00047 }
00048
00049 modCalcApCoord::~modCalcApCoord(){
00050 }
00051
00052 SkyPoint modCalcApCoord::getEquCoords (void) {
00053 dms raCoord, decCoord;
00054
00055 raCoord = ra0Box->createDms(FALSE);
00056 decCoord = dec0Box->createDms();
00057
00058 SkyPoint sp = SkyPoint (raCoord, decCoord);
00059
00060 return sp;
00061 }
00062
00063 void modCalcApCoord::showCurrentTime (void)
00064 {
00065 KStars *ks = (KStars*) parent()->parent()->parent();
00066
00067 KStarsDateTime dt = ks->data()->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
00068 datBox->setDate( dt.date() );
00069 timBox->setTime( dt.time() );
00070 }
00071
00072 KStarsDateTime modCalcApCoord::getDateTime (void)
00073 {
00074 return KStarsDateTime( datBox->date() , timBox->time() );
00075 }
00076
00077 double modCalcApCoord::getEpoch (QString eName) {
00078 bool ok = false;
00079 double epoch = eName.toDouble(&ok);
00080
00081 if ( ok )
00082 return epoch;
00083 else {
00084 kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl;
00085 return 2000.0;
00086 }
00087 }
00088
00089 void modCalcApCoord::showEquCoords ( SkyPoint sp ) {
00090 rafBox->show( sp.ra() , FALSE);
00091 decfBox->show( sp.dec() );
00092 }
00093
00094 void modCalcApCoord::slotClearCoords(){
00095
00096 ra0Box->clearFields();
00097 dec0Box->clearFields();
00098 rafBox->clearFields();
00099 decfBox->clearFields();
00100 epoch0Name->setText("");
00101 datBox->setDate(ExtDate::currentDate());
00102 timBox->setTime(QTime(0,0,0));
00103 }
00104
00105 void modCalcApCoord::slotComputeCoords(){
00106 long double jd = getDateTime().djd();
00107 KStarsDateTime dt;
00108 dt.setFromEpoch( getEpoch( epoch0Name->text() ) );
00109 long double jd0 = dt.djd();
00110
00111 SkyPoint sp;
00112 sp = getEquCoords();
00113
00114 sp.apparentCoord(jd0, jd);
00115 showEquCoords( sp );
00116 }
00117
00118 void modCalcApCoord::slotUtCheckedBatch(){
00119 if ( utCheckBatch->isChecked() )
00120 utBoxBatch->setEnabled( false );
00121 else {
00122 utBoxBatch->setEnabled( true );
00123 }
00124 }
00125
00126 void modCalcApCoord::slotDateCheckedBatch(){
00127
00128 if ( dateCheckBatch->isChecked() )
00129 dateBoxBatch->setEnabled( false );
00130 else {
00131 dateBoxBatch->setEnabled( true );
00132 }
00133 }
00134
00135 void modCalcApCoord::slotRaCheckedBatch(){
00136
00137 if ( raCheckBatch->isChecked() )
00138 raBoxBatch->setEnabled( false );
00139 else {
00140 raBoxBatch->setEnabled( true );
00141 }
00142 }
00143
00144 void modCalcApCoord::slotDecCheckedBatch(){
00145
00146 if ( decCheckBatch->isChecked() )
00147 decBoxBatch->setEnabled( false );
00148 else {
00149 decBoxBatch->setEnabled( true );
00150 }
00151 }
00152
00153 void modCalcApCoord::slotEpochCheckedBatch(){
00154
00155 if ( epochCheckBatch->isChecked() )
00156 epochBoxBatch->setEnabled( false );
00157 else {
00158 epochBoxBatch->setEnabled( true );
00159 }
00160 }
00161
00162 void modCalcApCoord::slotInputFile() {
00163 QString inputFileName;
00164 inputFileName = KFileDialog::getOpenFileName( );
00165 InputLineEditBatch->setText( inputFileName );
00166 }
00167
00168 void modCalcApCoord::slotOutputFile() {
00169 QString outputFileName;
00170 outputFileName = KFileDialog::getSaveFileName( );
00171 OutputLineEditBatch->setText( outputFileName );
00172 }
00173
00174 void modCalcApCoord::slotRunBatch() {
00175
00176 QString inputFileName;
00177
00178 inputFileName = InputLineEditBatch->text();
00179
00180
00181
00182 if ( QFile::exists(inputFileName) ) {
00183 QFile f( inputFileName );
00184 if ( !f.open( IO_ReadOnly) ) {
00185 QString message = i18n( "Could not open file %1.").arg( f.name() );
00186 KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00187 inputFileName = "";
00188 return;
00189 }
00190
00191
00192 QTextStream istream(&f);
00193 processLines(istream);
00194
00195 f.close();
00196 } else {
00197 QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00198 KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00199 inputFileName = "";
00200 InputLineEditBatch->setText( inputFileName );
00201 return;
00202 }
00203 }
00204
00205
00206 void modCalcApCoord::processLines( QTextStream &istream ) {
00207
00208
00209
00210
00211 QString outputFileName;
00212 outputFileName = OutputLineEditBatch->text();
00213 QFile fOut( outputFileName );
00214 fOut.open(IO_WriteOnly);
00215 QTextStream ostream(&fOut);
00216
00217 QString line;
00218 QString space = " ";
00219 int i = 0;
00220 long double jd, jd0;
00221 SkyPoint sp;
00222 QTime utB;
00223 ExtDate dtB;
00224 dms raB, decB;
00225 double epoch0B;
00226
00227 while ( ! istream.eof() ) {
00228 line = istream.readLine();
00229 line.stripWhiteSpace();
00230
00231
00232
00233 QStringList fields = QStringList::split( " ", line );
00234
00235 i = 0;
00236
00237
00238
00239 if(utCheckBatch->isChecked() ) {
00240 utB = QTime::fromString( fields[i] );
00241 i++;
00242 } else
00243 utB = utBoxBatch->time();
00244
00245 if ( allRadioBatch->isChecked() )
00246 ostream << utB.toString() << space;
00247 else
00248 if(utCheckBatch->isChecked() )
00249 ostream << utB.toString() << space;
00250
00251
00252
00253 if(dateCheckBatch->isChecked() ) {
00254 dtB = ExtDate::fromString( fields[i] );
00255 i++;
00256 } else
00257 dtB = dateBoxBatch->date();
00258
00259 if ( allRadioBatch->isChecked() )
00260 ostream << dtB.toString().append(space);
00261 else
00262 if(dateCheckBatch->isChecked() )
00263 ostream << dtB.toString().append(space);
00264
00265
00266
00267 if(raCheckBatch->isChecked() ) {
00268 raB = dms::fromString( fields[i],FALSE);
00269 i++;
00270 } else
00271 raB = raBoxBatch->createDms(FALSE);
00272
00273 if ( allRadioBatch->isChecked() )
00274 ostream << raB.toHMSString() << space;
00275 else
00276 if(raCheckBatch->isChecked() )
00277 ostream << raB.toHMSString() << space;
00278
00279
00280
00281 if(decCheckBatch->isChecked() ) {
00282 decB = dms::fromString( fields[i], TRUE);
00283 i++;
00284 } else
00285 decB = decBoxBatch->createDms();
00286
00287 if ( allRadioBatch->isChecked() )
00288 ostream << decB.toDMSString() << space;
00289 else
00290 if(decCheckBatch->isChecked() )
00291 ostream << decB.toHMSString() << space;
00292
00293
00294
00295 if(epochCheckBatch->isChecked() ) {
00296 epoch0B = fields[i].toDouble();
00297 i++;
00298 } else
00299 epoch0B = getEpoch( epochBoxBatch->text() );
00300
00301 if ( allRadioBatch->isChecked() )
00302 ostream << epoch0B;
00303 else
00304 if(decCheckBatch->isChecked() )
00305 ostream << epoch0B;
00306
00307 KStarsDateTime dt;
00308 dt.setFromEpoch( epoch0B );
00309 jd = KStarsDateTime(dtB,utB).djd();
00310 jd0 = dt.djd();
00311 sp = SkyPoint (raB, decB);
00312 sp.apparentCoord(jd0, jd);
00313
00314 ostream << sp.ra()->toHMSString() << sp.dec()->toDMSString() << endl;
00315 }
00316
00317 fOut.close();
00318 }