kstars
modcalceclipticcoords.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 "dms.h"
00019 #include "dmsbox.h"
00020 #include "modcalceclipticcoords.h"
00021 #include "modcalceclipticcoords.moc"
00022 #include "skypoint.h"
00023 #include "ksutils.h"
00024 #include "ksnumbers.h"
00025 #include "kstarsdatetime.h"
00026 #include <qradiobutton.h>
00027 #include <qstring.h>
00028 #include <qcheckbox.h>
00029 #include <qradiobutton.h>
00030 #include <qtextstream.h>
00031 #include <klocale.h>
00032 #include <klineedit.h>
00033 #include <kapplication.h>
00034 #include <kfiledialog.h>
00035 #include <kmessagebox.h>
00036
00037
00038 modCalcEclCoords::modCalcEclCoords(QWidget *parentSplit, const char *name) : modCalcEclCoordsDlg(parentSplit,name) {
00039
00040 equRadio->setChecked(TRUE);
00041 raBox->setDegType(FALSE);
00042 this->show();
00043 }
00044
00045 modCalcEclCoords::~modCalcEclCoords() {
00046 }
00047
00048 void modCalcEclCoords::getEclCoords (void) {
00049
00050 eclipLong = ecLongBox->createDms();
00051 eclipLat = ecLatBox->createDms();
00052 epoch = getEpoch( epochName->text() );
00053 }
00054
00055 void modCalcEclCoords::getEquCoords (void) {
00056
00057 raCoord = raBox->createDms(FALSE);
00058 decCoord = decBox->createDms();
00059 epoch = getEpoch( epochName->text() );
00060 }
00061
00062 double modCalcEclCoords::getEpoch (QString eName) {
00063
00064 double epoch = eName.toDouble();
00065
00066 return epoch;
00067 }
00068
00069 void modCalcEclCoords::slotClearCoords (void) {
00070
00071 raBox->clearFields();
00072 decBox->clearFields();
00073 ecLongBox->clearFields();
00074 ecLatBox->clearFields();
00075
00076 }
00077
00078 void modCalcEclCoords::slotComputeCoords (void) {
00079
00080 if(eclRadio->isChecked()) {
00081 getEclCoords();
00082 EclToEqu();
00083 showEquCoords();
00084 } else {
00085 getEquCoords();
00086 EquToEcl();
00087 showEclCoords();
00088 }
00089
00090 }
00091
00092 void modCalcEclCoords::showEquCoords(void) {
00093 raBox->show( raCoord , FALSE);
00094 decBox->show( decCoord );
00095 }
00096
00097 void modCalcEclCoords::showEclCoords(void) {
00098 ecLongBox->show( eclipLong );
00099 ecLatBox->show( eclipLat );
00100 }
00101
00102 void modCalcEclCoords::EclToEqu(void) {
00103
00104 SkyPoint sp = SkyPoint();
00105
00106 KStarsDateTime dt;
00107 dt.setFromEpoch( epoch );
00108 KSNumbers *num = new KSNumbers( dt.djd() );
00109
00110
00111
00112 sp.setFromEcliptic(num->obliquity(), &eclipLong, &eclipLat);
00113
00114 raCoord.set( *sp.ra() );
00115 decCoord.set( *sp.dec() );
00116
00117 delete num;
00118 }
00119
00120 void modCalcEclCoords::EquToEcl(void) {
00121
00122 SkyPoint sp = SkyPoint (raCoord, decCoord);
00123 KStarsDateTime dt;
00124 dt.setFromEpoch( epoch );
00125 KSNumbers *num = new KSNumbers( dt.djd() );
00126
00127 sp.findEcliptic(num->obliquity(), eclipLong, eclipLat);
00128
00129 delete num;
00130 }
00131
00132 void modCalcEclCoords::eclCheck() {
00133
00134 eclLatCheckBatch->setChecked(false);
00135 eclLatBoxBatch->setEnabled(false);
00136 eclLongCheckBatch->setChecked(false);
00137 eclLongBoxBatch->setEnabled(false);
00138 eclInputCoords = FALSE;
00139
00140 }
00141
00142 void modCalcEclCoords::equCheck() {
00143
00144 raCheckBatch->setChecked(false);
00145 raBoxBatch->setEnabled(false);
00146 decCheckBatch->setChecked(false);
00147 decBoxBatch->setEnabled(false);
00148
00149 eclInputCoords = TRUE;
00150
00151 }
00152
00153 void modCalcEclCoords::slotRaCheckedBatch(){
00154
00155 if ( raCheckBatch->isChecked() ) {
00156 raBoxBatch->setEnabled( false );
00157 eclCheck();
00158 } else {
00159 raBoxBatch->setEnabled( true );
00160 }
00161 }
00162
00163 void modCalcEclCoords::slotDecCheckedBatch(){
00164
00165 if ( decCheckBatch->isChecked() ) {
00166 decBoxBatch->setEnabled( false );
00167 eclCheck();
00168 } else {
00169 decBoxBatch->setEnabled( true );
00170 }
00171 }
00172
00173
00174 void modCalcEclCoords::slotEpochCheckedBatch(){
00175 if ( epochCheckBatch->isChecked() ) {
00176 epochBoxBatch->setEnabled( false );
00177 } else {
00178 epochBoxBatch->setEnabled( true );
00179 }
00180 }
00181
00182
00183 void modCalcEclCoords::slotEclLatCheckedBatch(){
00184
00185 if ( eclLatCheckBatch->isChecked() ) {
00186 eclLatBoxBatch->setEnabled( false );
00187 equCheck();
00188 } else {
00189 eclLatBoxBatch->setEnabled( true );
00190 }
00191 }
00192
00193 void modCalcEclCoords::slotEclLongCheckedBatch(){
00194
00195 if ( eclLongCheckBatch->isChecked() ) {
00196 eclLongBoxBatch->setEnabled( false );
00197 equCheck();
00198 } else {
00199 eclLongBoxBatch->setEnabled( true );
00200 }
00201 }
00202
00203 void modCalcEclCoords::slotInputFile() {
00204 QString inputFileName;
00205 inputFileName = KFileDialog::getOpenFileName( );
00206 InputLineEditBatch->setText( inputFileName );
00207 }
00208
00209 void modCalcEclCoords::slotOutputFile() {
00210 QString outputFileName;
00211 outputFileName = KFileDialog::getSaveFileName( );
00212 OutputLineEditBatch->setText( outputFileName );
00213 }
00214
00215 void modCalcEclCoords::slotRunBatch() {
00216
00217 QString inputFileName;
00218
00219 inputFileName = InputLineEditBatch->text();
00220
00221
00222
00223 if ( QFile::exists(inputFileName) ) {
00224 QFile f( inputFileName );
00225 if ( !f.open( IO_ReadOnly) ) {
00226 QString message = i18n( "Could not open file %1.").arg( f.name() );
00227 KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00228 inputFileName = "";
00229 return;
00230 }
00231
00232
00233 QTextStream istream(&f);
00234 processLines(istream);
00235
00236 f.close();
00237 } else {
00238 QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00239 KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00240 inputFileName = "";
00241 InputLineEditBatch->setText( inputFileName );
00242 return;
00243 }
00244 }
00245
00246 void modCalcEclCoords::processLines( QTextStream &istream ) {
00247
00248
00249
00250
00251 QString outputFileName;
00252 outputFileName = OutputLineEditBatch->text();
00253 QFile fOut( outputFileName );
00254 fOut.open(IO_WriteOnly);
00255 QTextStream ostream(&fOut);
00256
00257 QString line;
00258 QString space = " ";
00259 int i = 0;
00260 SkyPoint sp;
00261 dms raB, decB, eclLatB, eclLongB;
00262 double epoch0B;
00263
00264 while ( ! istream.eof() ) {
00265 line = istream.readLine();
00266 line.stripWhiteSpace();
00267
00268
00269
00270 QStringList fields = QStringList::split( " ", line );
00271
00272 i = 0;
00273
00274
00275
00276 if (eclInputCoords) {
00277
00278
00279
00280 if(eclLongCheckBatch->isChecked() ) {
00281 eclLongB = dms::fromString( fields[i], TRUE);
00282 i++;
00283 } else
00284 eclLongB = eclLongBoxBatch->createDms(TRUE);
00285
00286 if ( allRadioBatch->isChecked() )
00287 ostream << eclLongB.toDMSString() << space;
00288 else
00289 if(eclLongCheckBatch->isChecked() )
00290 ostream << eclLongB.toDMSString() << space;
00291
00292
00293
00294 if(eclLatCheckBatch->isChecked() ) {
00295 eclLatB = dms::fromString( fields[i], TRUE);
00296 i++;
00297 } else
00298 if ( allRadioBatch->isChecked() )
00299 ostream << eclLatB.toDMSString() << space;
00300 else
00301 if(eclLatCheckBatch->isChecked() )
00302 ostream << eclLatB.toDMSString() << space;
00303
00304
00305
00306 if(epochCheckBatch->isChecked() ) {
00307 epoch0B = fields[i].toDouble();
00308 i++;
00309 } else
00310 epoch0B = getEpoch( epochBoxBatch->text() );
00311
00312 if ( allRadioBatch->isChecked() )
00313 ostream << epoch0B << space;
00314 else
00315 if(epochCheckBatch->isChecked() )
00316 ostream << epoch0B << space;
00317
00318 sp = SkyPoint ();
00319
00320 KStarsDateTime dt;
00321 dt.setFromEpoch( epoch0B );
00322 KSNumbers *num = new KSNumbers( dt.djd() );
00323 sp.setFromEcliptic(num->obliquity(), &eclLongB, &eclLatB);
00324 ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
00325
00326
00327 } else {
00328
00329
00330
00331 if(raCheckBatch->isChecked() ) {
00332 raB = dms::fromString( fields[i],FALSE);
00333 i++;
00334 } else
00335 raB = raBoxBatch->createDms(FALSE);
00336
00337 if ( allRadioBatch->isChecked() )
00338 ostream << raB.toHMSString() << space;
00339 else
00340 if(raCheckBatch->isChecked() )
00341 ostream << raB.toHMSString() << space;
00342
00343
00344
00345 if(decCheckBatch->isChecked() ) {
00346 decB = dms::fromString( fields[i], TRUE);
00347 i++;
00348 } else
00349 decB = decBoxBatch->createDms();
00350
00351 if ( allRadioBatch->isChecked() )
00352 ostream << decB.toDMSString() << space;
00353 else
00354 if(decCheckBatch->isChecked() )
00355 ostream << decB.toDMSString() << space;
00356
00357
00358
00359 if(epochCheckBatch->isChecked() ) {
00360 epoch0B = fields[i].toDouble();
00361 i++;
00362 } else
00363 epoch0B = getEpoch( epochBoxBatch->text() );
00364
00365 if ( allRadioBatch->isChecked() )
00366 ostream << epoch0B << space;
00367 else
00368 if(epochCheckBatch->isChecked() )
00369 ostream << epoch0B << space;
00370
00371 sp = SkyPoint (raB, decB);
00372 KStarsDateTime dt;
00373 dt.setFromEpoch( epoch0B );
00374 KSNumbers *num = new KSNumbers( dt.djd() );
00375 sp.findEcliptic(num->obliquity(), eclLongB, eclLatB);
00376 ostream << eclLongB.toDMSString() << space << eclLatB.toDMSString() << endl;
00377 delete num;
00378
00379 }
00380
00381 }
00382
00383
00384 fOut.close();
00385 }