• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

modcalcgalcoord.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcgal.cpp  -  description
00003                              -------------------
00004     begin                : Thu Jan 17 2002
00005     copyright            : (C) 2002 by Pablo de Vicente
00006     email                : vicente@oan.es
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "dms.h"
00019 #include "dmsbox.h"
00020 #include "skypoint.h"
00021 #include "modcalcgalcoord.h"
00022 #include "modcalcgalcoord.moc"
00023 #include "kstarsdatetime.h"
00024 
00025 #include <qradiobutton.h>
00026 #include <qstring.h>
00027 #include <qcheckbox.h>
00028 #include <qradiobutton.h>
00029 #include <qtextstream.h>
00030 #include <klocale.h>
00031 #include <klineedit.h>
00032 #include <kapplication.h>
00033 #include <kfiledialog.h>
00034 #include <kmessagebox.h>
00035 
00036 
00037 modCalcGalCoord::modCalcGalCoord(QWidget *parentSplit, const char *name) : modCalcGalCoordDlg(parentSplit,name) {
00038 
00039     equRadio->setChecked(TRUE);
00040     raBox->setDegType(FALSE);
00041     show();
00042 }
00043 
00044 modCalcGalCoord::~modCalcGalCoord() {
00045 }
00046 
00047 void modCalcGalCoord::getGalCoords (void) {
00048 
00049     galLong = lgBox->createDms();
00050     galLat = bgBox->createDms();
00051     epoch = getEpoch( epochName->text() );
00052 }
00053 
00054 void modCalcGalCoord::getEquCoords (void) {
00055 
00056     raCoord = raBox->createDms(FALSE);
00057     decCoord = decBox->createDms();
00058     epoch = getEpoch( epochName->text() );
00059 }
00060 
00061 double modCalcGalCoord::getEpoch (QString eName) {
00062 
00063     double epoch = eName.toDouble();
00064 
00065     return epoch;
00066 }
00067 
00068 void modCalcGalCoord::slotClearCoords (void) {
00069 
00070     raBox->clearFields();
00071     decBox->clearFields();
00072     lgBox->clearFields();
00073     bgBox->clearFields();
00074 
00075 }
00076 
00077 void modCalcGalCoord::slotComputeCoords (void) {
00078 
00079     if(galRadio->isChecked()) {
00080         getGalCoords();
00081 //      checkEpoch();
00082         GalToEqu();
00083         showEquCoords();
00084     } else {
00085         getEquCoords();
00086 //      checkEpoch();
00087         EquToGal();
00088         showGalCoords();
00089     }
00090 
00091 }
00092 
00093 void modCalcGalCoord::showEquCoords(void) {
00094     raBox->show( raCoord , FALSE);
00095     decBox->show( decCoord );
00096 }
00097 
00098 void modCalcGalCoord::showGalCoords(void) {
00099     lgBox->show( galLong );
00100     bgBox->show( galLat );
00101 }
00102 
00103 void modCalcGalCoord::GalToEqu(void) {
00104 
00105     SkyPoint sp = SkyPoint();
00106 
00107     sp.GalacticToEquatorial1950(&galLong, &galLat);
00108     sp.set(*sp.ra(), *sp.dec() );
00109 
00110     KStarsDateTime dt;
00111     dt.setFromEpoch( epoch );
00112     long double jdf = dt.djd();
00113     sp.precessFromAnyEpoch(B1950,jdf);
00114 
00115     raCoord.set( *sp.ra() );
00116     decCoord.set( *sp.dec() );
00117 }
00118 
00119 void modCalcGalCoord::EquToGal(void) {
00120 
00121     SkyPoint sp = SkyPoint (raCoord, decCoord);
00122 
00123     KStarsDateTime dt;
00124     dt.setFromEpoch( epoch );
00125     long double jd0 = dt.djd();
00126     sp.precessFromAnyEpoch(jd0,B1950);
00127 
00128     sp.Equatorial1950ToGalactic(galLong, galLat);
00129 
00130 }
00131 
00132 void modCalcGalCoord::galCheck() {
00133 
00134     galLatCheckBatch->setChecked(false);
00135     galLatBoxBatch->setEnabled(false);
00136     galLongCheckBatch->setChecked(false);
00137     galLongBoxBatch->setEnabled(false);
00138     galInputCoords = FALSE;
00139 
00140 }
00141 
00142 void modCalcGalCoord::equCheck() {
00143 
00144     raCheckBatch->setChecked(false);
00145     raBoxBatch->setEnabled(false);
00146     decCheckBatch->setChecked(false);
00147     decBoxBatch->setEnabled(false);
00148     epochCheckBatch->setChecked(false);
00149     galInputCoords = TRUE;
00150 
00151 }
00152 
00153 void modCalcGalCoord::slotRaCheckedBatch(){
00154 
00155     if ( raCheckBatch->isChecked() ) {
00156         raBoxBatch->setEnabled( false );
00157         galCheck();
00158     } else {
00159         raBoxBatch->setEnabled( true );
00160     }
00161 }
00162 
00163 void modCalcGalCoord::slotDecCheckedBatch(){
00164 
00165     if ( decCheckBatch->isChecked() ) {
00166         decBoxBatch->setEnabled( false );
00167         galCheck();
00168     } else {
00169         decBoxBatch->setEnabled( true );
00170     }
00171 }
00172 
00173 void modCalcGalCoord::slotEpochCheckedBatch(){
00174 
00175     epochCheckBatch->setChecked(false);
00176 
00177     if ( epochCheckBatch->isChecked() ) {
00178         epochBoxBatch->setEnabled( false );
00179         galCheck();
00180     } else {
00181         epochBoxBatch->setEnabled( true );
00182     }
00183 }
00184 
00185 void modCalcGalCoord::slotGalLatCheckedBatch(){
00186 
00187     if ( galLatCheckBatch->isChecked() ) {
00188         galLatBoxBatch->setEnabled( false );
00189         equCheck();
00190     } else {
00191         galLatBoxBatch->setEnabled( true );
00192     }
00193 }
00194 
00195 void modCalcGalCoord::slotGalLongCheckedBatch(){
00196 
00197     if ( galLongCheckBatch->isChecked() ) {
00198         galLongBoxBatch->setEnabled( false );
00199         equCheck();
00200     } else {
00201         galLongBoxBatch->setEnabled( true );
00202     }
00203 }
00204 
00205 void modCalcGalCoord::slotInputFile() {
00206     QString inputFileName;
00207     inputFileName = KFileDialog::getOpenFileName( );
00208     InputLineEditBatch->setText( inputFileName );
00209 }
00210 
00211 void modCalcGalCoord::slotOutputFile() {
00212     QString outputFileName;
00213     outputFileName = KFileDialog::getSaveFileName( );
00214     OutputLineEditBatch->setText( outputFileName );
00215 }
00216 
00217 void modCalcGalCoord::slotRunBatch() {
00218 
00219     QString inputFileName;
00220 
00221     inputFileName = InputLineEditBatch->text();
00222 
00223     // We open the input file and read its content
00224 
00225     if ( QFile::exists(inputFileName) ) {
00226         QFile f( inputFileName );
00227         if ( !f.open( IO_ReadOnly) ) {
00228             QString message = i18n( "Could not open file %1.").arg( f.name() );
00229             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00230             inputFileName = "";
00231             return;
00232         }
00233 
00234 //      processLines(&f);
00235         QTextStream istream(&f);
00236         processLines(istream);
00237 //      readFile( istream );
00238         f.close();
00239     } else  {
00240         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00241         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00242         inputFileName = "";
00243         InputLineEditBatch->setText( inputFileName );
00244         return;
00245     }
00246 }
00247 
00248 void modCalcGalCoord::processLines( QTextStream &istream ) {
00249 
00250     // we open the output file
00251 
00252 //  QTextStream istream(&fIn);
00253     QString outputFileName;
00254     outputFileName = OutputLineEditBatch->text();
00255     QFile fOut( outputFileName );
00256     fOut.open(IO_WriteOnly);
00257     QTextStream ostream(&fOut);
00258 
00259     QString line;
00260     QString space = " ";
00261     int i = 0;
00262     SkyPoint sp;
00263     dms raB, decB, galLatB, galLongB;
00264     double epoch0B(0.0);
00265     KStarsDateTime dt;
00266 
00267     while ( ! istream.eof() ) {
00268         line = istream.readLine();
00269         line.stripWhiteSpace();
00270 
00271         //Go through the line, looking for parameters
00272 
00273         QStringList fields = QStringList::split( " ", line );
00274 
00275         i = 0;
00276 
00277         // Input coords are galactic coordinates:
00278 
00279         if (galInputCoords) {
00280 
00281             // Read Galactic Longitude and write in ostream if corresponds
00282 
00283             if(galLongCheckBatch->isChecked() ) {
00284                 galLongB = dms::fromString( fields[i], TRUE);
00285                 i++;
00286             } else
00287                 galLongB = galLongBoxBatch->createDms(TRUE);
00288 
00289             if ( allRadioBatch->isChecked() )
00290                 ostream << galLongB.toDMSString() << space;
00291             else
00292                 if(galLongCheckBatch->isChecked() )
00293                     ostream << galLongB.toDMSString() << space;
00294 
00295             // Read Galactic Latitude and write in ostream if corresponds
00296 
00297             if(galLatCheckBatch->isChecked() ) {
00298                 galLatB = dms::fromString( fields[i], TRUE);
00299                 i++;
00300             } else
00301                 galLatB = galLatBoxBatch->createDms(TRUE);
00302 
00303             if ( allRadioBatch->isChecked() )
00304                 ostream << galLatB.toDMSString() << space;
00305             else
00306                 if(galLatCheckBatch->isChecked() )
00307                     ostream << galLatB.toDMSString() << space;
00308 
00309             sp = SkyPoint ();
00310             sp.GalacticToEquatorial1950(&galLongB, &galLatB);
00311             ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << epoch0B << endl;
00312         // Input coords. are equatorial coordinates:
00313 
00314         } else {
00315 
00316             // Read RA and write in ostream if corresponds
00317 
00318             if(raCheckBatch->isChecked() ) {
00319                 raB = dms::fromString( fields[i],FALSE);
00320                 i++;
00321             } else
00322                 raB = raBoxBatch->createDms(FALSE);
00323 
00324             if ( allRadioBatch->isChecked() )
00325                 ostream << raB.toHMSString() << space;
00326             else
00327                 if(raCheckBatch->isChecked() )
00328                     ostream << raB.toHMSString() << space;
00329 
00330             // Read DEC and write in ostream if corresponds
00331 
00332             if(decCheckBatch->isChecked() ) {
00333                 decB = dms::fromString( fields[i], TRUE);
00334                 i++;
00335             } else
00336                 decB = decBoxBatch->createDms();
00337 
00338             if ( allRadioBatch->isChecked() )
00339                 ostream << decB.toDMSString() << space;
00340             else
00341                 if(decCheckBatch->isChecked() )
00342                     ostream << decB.toDMSString() << space;
00343 
00344             // Read Epoch and write in ostream if corresponds
00345 
00346             if(epochCheckBatch->isChecked() ) {
00347                 epoch0B = fields[i].toDouble();
00348                 i++;
00349             } else
00350                 epoch0B = getEpoch( epochBoxBatch->text() );
00351 
00352             if ( allRadioBatch->isChecked() )
00353                 ostream << epoch0B << space;
00354             else
00355                 if(epochCheckBatch->isChecked() )
00356                     ostream << epoch0B << space;
00357 
00358             sp = SkyPoint (raB, decB);
00359             dt.setFromEpoch( epoch0B );
00360             long double jdf = dt.djd();
00361             sp.precessFromAnyEpoch(B1950,jdf);
00362             sp.Equatorial1950ToGalactic(galLongB, galLatB);
00363             ostream << galLongB.toDMSString() << space << galLatB.toDMSString() << endl;
00364 
00365         }
00366 
00367     }
00368 
00369 
00370     fOut.close();
00371 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal