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

kstars

modcalcsidtime.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcsidtime.cpp  -  description
00003                              -------------------
00004     begin                : Wed Jan 23 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 <qdatetimeedit.h>  //need for QTimeEdit
00019 #include <qradiobutton.h>
00020 #include <qcheckbox.h>
00021 #include <qstring.h>
00022 #include <qtextstream.h>
00023 #include <kfiledialog.h>
00024 #include <kmessagebox.h>
00025 
00026 #include "dmsbox.h"
00027 #include "modcalcsidtime.h"
00028 #include "modcalcsidtime.moc"
00029 #include "kstars.h"
00030 #include "kstarsdata.h"
00031 #include "kstarsdatetime.h"
00032 #include "simclock.h"
00033 #include "libkdeedu/extdate/extdatetimeedit.h"
00034 
00035 modCalcSidTime::modCalcSidTime(QWidget *parentSplit, const char *name) : modCalcSidTimeDlg (parentSplit,name) {
00036 
00037     showCurrentTimeAndLong();
00038     show();     
00039 }
00040 
00041 modCalcSidTime::~modCalcSidTime(void) {
00042 
00043 }
00044 
00045 void modCalcSidTime::showCurrentTimeAndLong (void)
00046 {
00047     KStars *ks = (KStars*) parent()->parent()->parent();
00048      // modCalcSidTimeDlg -> QSplitter->AstroCalc->KStars
00049 
00050     showUT( ks->data()->ut().time() );
00051     datBox->setDate( ks->data()->ut().date() );
00052 
00053     longBox->show( ks->geo()->lng() );
00054 }
00055 
00056 QTime modCalcSidTime::computeUTtoST (QTime ut, ExtDate dt, dms longitude)
00057 {
00058     KStarsDateTime utdt = KStarsDateTime( dt, ut);
00059     dms st = longitude.Degrees() + utdt.gst().Degrees();
00060     return QTime( st.hour(), st.minute(), st.second() );
00061 }
00062 
00063 QTime modCalcSidTime::computeSTtoUT (QTime st, ExtDate dt, dms longitude)
00064 {
00065     KStarsDateTime dtt = KStarsDateTime( dt, QTime());
00066     dms lst(st.hour(), st.minute(), st.second());
00067     dms gst( lst.Degrees() - longitude.Degrees() );
00068     return dtt.GSTtoUT( gst );
00069 }
00070 
00071 void modCalcSidTime::showUT( QTime dt )
00072 {
00073     UtBox->setTime( dt );
00074 }
00075 
00076 void modCalcSidTime::showST( QTime st )
00077 {
00078     StBox->setTime( st );
00079 }
00080 
00081 QTime modCalcSidTime::getUT( void ) 
00082 {
00083     return UtBox->time();
00084 }
00085 
00086 QTime modCalcSidTime::getST( void ) 
00087 {
00088     return StBox->time();
00089 }
00090 
00091 ExtDate modCalcSidTime::getDate( void ) 
00092 {
00093     return datBox->date();
00094 }
00095 
00096 dms modCalcSidTime::getLongitude( void )
00097 {
00098     return longBox->createDms();
00099 }
00100 
00101 void modCalcSidTime::slotClearFields(){
00102     datBox->setDate(ExtDate::currentDate());
00103     QTime time(0,0,0);
00104     UtBox->setTime(time);
00105     StBox->setTime(time);
00106 }
00107 
00108 void modCalcSidTime::slotComputeTime(){
00109     QTime ut, st;
00110 
00111     ExtDate dt = getDate();
00112     dms longitude = getLongitude();
00113 
00114     if(UtRadio->isChecked()) {
00115         ut = getUT();
00116         st = computeUTtoST( ut, dt, longitude );
00117         showST( st );
00118     } else {
00119         st = getST();
00120         ut = computeSTtoUT( st, dt, longitude );
00121         showUT( ut );
00122     }
00123 
00124 }
00125 
00126 void modCalcSidTime::slotUtChecked(){
00127 
00128     if ( utCheckBatch->isChecked() )
00129         utBoxBatch->setEnabled( false );
00130     else 
00131         utBoxBatch->setEnabled( true );
00132 }
00133 
00134 void modCalcSidTime::slotDateChecked(){
00135 
00136     if ( dateCheckBatch->isChecked() )
00137         dateBoxBatch->setEnabled( false );
00138     else 
00139         dateBoxBatch->setEnabled( true );
00140 }
00141 
00142 void modCalcSidTime::slotStChecked(){
00143 
00144     if ( stCheckBatch->isChecked() )
00145         stBoxBatch->setEnabled( false );
00146     else 
00147         stBoxBatch->setEnabled( true );
00148 }
00149 
00150 void modCalcSidTime::slotLongChecked(){
00151 
00152     if ( longCheckBatch->isChecked() )
00153         longBoxBatch->setEnabled( false );
00154     else
00155         longBoxBatch->setEnabled( true );
00156 }
00157 
00158 void modCalcSidTime::sidNoCheck() {
00159 
00160     stBoxBatch->setEnabled(false);
00161     stInputTime = FALSE;
00162 
00163 }
00164 
00165 void modCalcSidTime::utNoCheck() {
00166 
00167     utBoxBatch->setEnabled(false);
00168     stInputTime = TRUE;
00169 }
00170 
00171 void modCalcSidTime::slotInputFile() {
00172     QString inputFileName;
00173     inputFileName = KFileDialog::getOpenFileName( );
00174     InputLineEditBatch->setText( inputFileName );
00175 }
00176 
00177 void modCalcSidTime::slotOutputFile() {
00178     QString outputFileName;
00179     outputFileName = KFileDialog::getSaveFileName( );
00180     OutputLineEditBatch->setText( outputFileName );
00181 }
00182 
00183 
00184 void modCalcSidTime::slotRunBatch() {
00185 
00186     QString inputFileName;
00187 
00188     inputFileName = InputLineEditBatch->text();
00189 
00190     // We open the input file and read its content
00191 
00192     if ( QFile::exists(inputFileName) ) {
00193         QFile f( inputFileName );
00194         if ( !f.open( IO_ReadOnly) ) {
00195             QString message = i18n( "Could not open file %1.").arg( f.name() );
00196             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00197             inputFileName = "";
00198             return;
00199         }
00200 
00201 //      processLines(&f);
00202         QTextStream istream(&f);
00203         processLines(istream);
00204 //      readFile( istream );
00205         f.close();
00206     } else  {
00207         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00208         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00209         inputFileName = "";
00210         InputLineEditBatch->setText( inputFileName );
00211         return;
00212     }
00213 }
00214 
00215 void modCalcSidTime::processLines( QTextStream &istream ) {
00216 
00217     // we open the output file
00218 
00219 //  QTextStream istream(&fIn);
00220     QString outputFileName;
00221     outputFileName = OutputLineEditBatch->text();
00222     QFile fOut( outputFileName );
00223     fOut.open(IO_WriteOnly);
00224     QTextStream ostream(&fOut);
00225 
00226     QString line;
00227     QString space = " ";
00228     int i = 0;
00229     long double jd0, jdf;
00230     dms longB, LST;
00231     double epoch0B(0.0);
00232     QTime utB, stB;
00233     ExtDate dtB;
00234 
00235     while ( ! istream.eof() ) {
00236         line = istream.readLine();
00237         line.stripWhiteSpace();
00238 
00239         //Go through the line, looking for parameters
00240 
00241         QStringList fields = QStringList::split( " ", line );
00242 
00243         i = 0;
00244         
00245         // Read Longitude and write in ostream if corresponds
00246         
00247         if (longCheckBatch->isChecked() ) {
00248             longB = dms::fromString( fields[i],TRUE);
00249             i++;
00250         } else
00251             longB = longBoxBatch->createDms(TRUE);
00252         
00253         if ( allRadioBatch->isChecked() )
00254             ostream << longB.toDMSString() << space;
00255         else
00256             if (longCheckBatch->isChecked() )
00257                 ostream << longB.toDMSString() << space;
00258         
00259         // Read date and write in ostream if corresponds
00260         
00261         if(dateCheckBatch->isChecked() ) {
00262              dtB = ExtDate::fromString( fields[i] );
00263              i++;
00264         } else
00265             dtB = dateBoxBatch->date();
00266         if ( allRadioBatch->isChecked() )
00267             ostream << dtB.toString().append(space);
00268         else
00269             if(dateCheckBatch->isChecked() )
00270                 ostream << dtB.toString().append(space);
00271 
00272         
00273         // We make the first calculations
00274         KStarsDateTime dt;
00275         dt.setFromEpoch( epoch0B );
00276         jdf = KStarsDateTime(dtB,utB).djd();
00277         jd0 = dt.djd();
00278 
00279         LST = dms( longB.Degrees() + KStarsDateTime(dtB,utB).gst().Degrees() );
00280         
00281         // Universal Time is the input time.
00282         if (!stInputTime) {
00283 
00284         // Read Ut and write in ostream if corresponds
00285         
00286             if(utCheckBatch->isChecked() ) {
00287                 utB = QTime::fromString( fields[i] );
00288                 i++;
00289             } else
00290                 utB = utBoxBatch->time();
00291         
00292             if ( allRadioBatch->isChecked() )
00293                 ostream << utB.toString() << space;
00294             else
00295                 if(utCheckBatch->isChecked() )
00296                     ostream << utB.toString() << space;
00297             
00298 
00299             stB = computeUTtoST( utB, dtB, longB );
00300             ostream << stB.toString()  << endl;
00301 
00302         // Input coords are horizontal coordinates
00303         
00304         } else {
00305 
00306             if(stCheckBatch->isChecked() ) {
00307                 stB = QTime::fromString( fields[i] );
00308                 i++;
00309             } else
00310                 stB = stBoxBatch->time();
00311         
00312             if ( allRadioBatch->isChecked() )
00313                 ostream << stB.toString() << space;
00314             else
00315                 if(stCheckBatch->isChecked() )
00316                     ostream << stB.toString() << space;
00317             
00318 
00319             utB = computeSTtoUT( stB, dtB, longB );
00320             ostream << utB.toString()  << endl;
00321 
00322         }
00323 
00324     }
00325 
00326 
00327     fOut.close();
00328 }

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