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

kstars

modcalcprec.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcprec.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jan 27 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 "modcalcprec.h"
00019 #include "modcalcprec.moc"
00020 #include "dmsbox.h"
00021 #include "skypoint.h"
00022 #include "dms.h"
00023 #include "kstarsdatetime.h"
00024 
00025 #include <qcheckbox.h>
00026 #include <qradiobutton.h>
00027 #include <qtextstream.h>
00028 #include <klocale.h>
00029 #include <klineedit.h>
00030 #include <kapplication.h>
00031 #include <kfiledialog.h>
00032 #include <kmessagebox.h>
00033 
00034 modCalcPrec::modCalcPrec(QWidget *parentSplit, const char *name) : modCalcPrecDlg(parentSplit,name) {
00035 
00036     ra0Box->setDegType(FALSE);
00037     rafBox->setDegType(FALSE);
00038     show();
00039 
00040 }
00041 
00042 modCalcPrec::~modCalcPrec(){
00043 
00044 }
00045 
00046 SkyPoint modCalcPrec::getEquCoords (void) {
00047     dms raCoord, decCoord;
00048 
00049     raCoord = ra0Box->createDms(FALSE);
00050     decCoord = dec0Box->createDms();
00051 
00052     SkyPoint sp = SkyPoint (raCoord, decCoord);
00053 
00054     return sp;
00055 }
00056 
00057 QString modCalcPrec:: showCurrentEpoch () {
00058 
00059     double epoch = setCurrentEpoch();
00060     QString eName = QString("%1").arg(epoch,7,'f',2);
00061 
00062     return eName;
00063 }
00064 
00065 double modCalcPrec::setCurrentEpoch () {
00066     return KStarsDateTime::currentDateTime().epoch();
00067 }
00068 
00069 double modCalcPrec::getEpoch (QString eName) {
00070     bool ok = false;
00071     double epoch = eName.toDouble(&ok);
00072 
00073     if ( ok )
00074         return epoch;
00075     else {
00076         kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl;
00077         return 2000.0;
00078     }
00079 }
00080 
00081 void modCalcPrec::slotClearCoords (void) {
00082 
00083     ra0Box->clearFields();
00084     dec0Box->clearFields();
00085     rafBox->clearFields();
00086     decfBox->clearFields();
00087     epoch0Name->setText("");
00088     epochfName->setText("");
00089 
00090 }
00091 
00092 void modCalcPrec::slotComputeCoords (void) {
00093 
00094     SkyPoint sp;
00095 
00096     sp = getEquCoords();
00097 
00098     double epoch0 = getEpoch( epoch0Name->text() );
00099     double epochf = getEpoch( epochfName->text() );
00100 
00101     KStarsDateTime dt;
00102     dt.setFromEpoch( epoch0 );
00103     long double jd0 = dt.djd();
00104     dt.setFromEpoch( epochf );
00105     long double jdf = dt.djd();
00106 
00107     sp.precessFromAnyEpoch(jd0, jdf);
00108 
00109     showEquCoords( sp );
00110 
00111 }
00112 
00113 void modCalcPrec::showEquCoords ( SkyPoint sp ) {
00114     rafBox->show( sp.ra(),FALSE );
00115     decfBox->show( sp.dec() );
00116 }
00117 
00118 void modCalcPrec::slotRaCheckedBatch(){
00119 
00120     if ( raCheckBatch->isChecked() )
00121         raBoxBatch->setEnabled( false );
00122     else {
00123         raBoxBatch->setEnabled( true );
00124     }
00125 }
00126 
00127 void modCalcPrec::slotDecCheckedBatch(){
00128 
00129     if ( decCheckBatch->isChecked() )
00130         decBoxBatch->setEnabled( false );
00131     else {
00132         decBoxBatch->setEnabled( true );
00133     }
00134 }
00135 
00136 void modCalcPrec::slotEpochCheckedBatch(){
00137 
00138     if ( epochCheckBatch->isChecked() )
00139         epochBoxBatch->setEnabled( false );
00140     else {
00141         epochBoxBatch->setEnabled( true );
00142     }
00143 }
00144 
00145 void modCalcPrec::slotTargetEpochCheckedBatch(){
00146 
00147     if ( targetEpochCheckBatch->isChecked() )
00148         targetEpochBoxBatch->setEnabled( false );
00149     else {
00150         targetEpochBoxBatch->setEnabled( true );
00151     }
00152 }
00153 
00154 void modCalcPrec::slotInputFile() {
00155     QString inputFileName;
00156     inputFileName = KFileDialog::getOpenFileName( );
00157     InputLineEditBatch->setText( inputFileName );
00158 }
00159 
00160 void modCalcPrec::slotOutputFile() {
00161     QString outputFileName;
00162     outputFileName = KFileDialog::getSaveFileName( );
00163     OutputLineEditBatch->setText( outputFileName );
00164 
00165 
00166 }
00167 
00168 void modCalcPrec::slotRunBatch() {
00169 
00170     QString inputFileName;
00171 
00172     inputFileName = InputLineEditBatch->text();
00173 
00174     // We open the input file and read its content
00175 
00176     if ( QFile::exists(inputFileName) ) {
00177         QFile f( inputFileName );
00178         if ( !f.open( IO_ReadOnly) ) {
00179             QString message = i18n( "Could not open file %1.").arg( f.name() );
00180             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00181             inputFileName = "";
00182             return;
00183         }
00184 
00185 //      processLines(&f);
00186         QTextStream istream(&f);
00187         processLines(istream);
00188 //      readFile( istream );
00189         f.close();
00190     } else  {
00191         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00192         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00193         inputFileName = "";
00194         InputLineEditBatch->setText( inputFileName );
00195         return;
00196     }
00197 }
00198 
00199 void modCalcPrec::processLines( QTextStream &istream ) {
00200 
00201     // we open the output file
00202 
00203 //  QTextStream istream(&fIn);
00204     QString outputFileName;
00205     outputFileName = OutputLineEditBatch->text();
00206     QFile fOut( outputFileName );
00207     fOut.open(IO_WriteOnly);
00208     QTextStream ostream(&fOut);
00209 
00210     QString line;
00211     QString space = " ";
00212     int i = 0;
00213     long double jd0, jdf;
00214     SkyPoint sp;
00215     dms raB, decB;
00216     double epoch0B, epochfB;
00217     KStarsDateTime dt0, dtf;
00218 
00219     while ( ! istream.eof() ) {
00220         line = istream.readLine();
00221         line.stripWhiteSpace();
00222 
00223         //Go through the line, looking for parameters
00224 
00225         QStringList fields = QStringList::split( " ", line );
00226 
00227         i = 0;
00228 
00229         // Read RA and write in ostream if corresponds
00230 
00231         if(raCheckBatch->isChecked() ) {
00232             raB = dms::fromString( fields[i],FALSE);
00233             i++;
00234         } else
00235             raB = raBoxBatch->createDms(FALSE);
00236 
00237         if ( allRadioBatch->isChecked() )
00238             ostream << raB.toHMSString() << space;
00239         else
00240             if(raCheckBatch->isChecked() )
00241                 ostream << raB.toHMSString() << space;
00242 
00243         // Read DEC and write in ostream if corresponds
00244 
00245         if(decCheckBatch->isChecked() ) {
00246             decB = dms::fromString( fields[i], TRUE);
00247             i++;
00248         } else
00249             decB = decBoxBatch->createDms();
00250 
00251         if ( allRadioBatch->isChecked() )
00252             ostream << decB.toDMSString() << space;
00253         else
00254             if(decCheckBatch->isChecked() )
00255                 ostream << decB.toDMSString() << space;
00256 
00257         // Read Epoch and write in ostream if corresponds
00258 
00259         if(epochCheckBatch->isChecked() ) {
00260             epoch0B = fields[i].toDouble();
00261             i++;
00262         } else
00263             epoch0B = getEpoch( epochBoxBatch->text() );
00264 
00265         if ( allRadioBatch->isChecked() )
00266             ostream << epoch0B;
00267         else
00268             if(epochCheckBatch->isChecked() )
00269                 ostream << epoch0B;
00270 
00271         // Read Target epoch and write in ostream if corresponds
00272 
00273         if(targetEpochCheckBatch->isChecked() ) {
00274             epochfB = fields[i].toDouble();
00275             i++;
00276         } else
00277             epochfB = getEpoch( targetEpochBoxBatch->text() );
00278 
00279         if ( allRadioBatch->isChecked() )
00280             ostream << epochfB << space;
00281         else
00282             if(targetEpochCheckBatch->isChecked() )
00283                 ostream << epochfB << space;
00284 
00285         dt0.setFromEpoch( epoch0B );
00286         dtf.setFromEpoch( epoch0B );
00287         jd0 = dt0.djd();
00288         jdf = dtf.djd();
00289         sp = SkyPoint (raB, decB);
00290         sp.precessFromAnyEpoch(jd0, jdf);
00291 
00292         ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
00293     }
00294 
00295 
00296     fOut.close();
00297 }

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