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

kstars

modcalcequinox.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcequinox.cpp  -  description
00003                              -------------------
00004     begin                : dom apr 18 2002
00005     copyright            : (C) 2004 by Pablo de Vicente
00006     email                : p.devicentea@wanadoo.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 #include "modcalcequinox.h"
00018 
00019 #include "modcalcequinox.moc"
00020 #include "dms.h"
00021 #include "dmsbox.h"
00022 #include "kstars.h"
00023 #include "kstarsdata.h"
00024 #include "kstarsdatetime.h"
00025 #include "kssun.h"
00026 #include "libkdeedu/extdate/extdatetimeedit.h"
00027 
00028 #include <qcombobox.h>
00029 #include <qstring.h>
00030 #include <qtextstream.h>
00031 #include <kfiledialog.h>
00032 #include <kmessagebox.h>
00033 #include <qcheckbox.h>
00034 #include <qradiobutton.h>
00035 
00036 modCalcEquinox::modCalcEquinox(QWidget *parentSplit, const char *name) 
00037         : modCalcEquinoxDlg (parentSplit,name) {
00038     showCurrentYear();
00039     show();
00040 }
00041 
00042 modCalcEquinox::~modCalcEquinox(){
00043 }
00044 
00045 int modCalcEquinox::getYear (QString eName)
00046 {
00047     bool ok = FALSE;
00048     int equinoxYear = eName.toInt(&ok);
00049     if ( ok ) 
00050         return equinoxYear;
00051     else {
00052         kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl;
00053         return 2000;
00054     }
00055 }
00056 
00057 void modCalcEquinox::showCurrentYear (void)
00058 {
00059     KStarsDateTime dt( KStarsDateTime::currentDateTime() );
00060     yearEdit->setText( QString( "%1").arg( dt.date().year() ) );
00061 }
00062 
00063 void modCalcEquinox::slotComputeEquinoxesAndSolstices (void)
00064 {
00065     long double julianDay = 0., jdf = 0.;
00066     float deltaJd;
00067     KStarsData *kd = (KStarsData*) parent()->parent()->parent();
00068     KSSun *Sun = new KSSun(kd);
00069     int year0 = getYear( yearEdit->text() );
00070     
00071     if (equinoxSolsticesComboBox->currentItem() == 0 ) {
00072         julianDay = Sun->springEquinox(year0);
00073         jdf = Sun->summerSolstice(year0);
00074     }
00075     else if(equinoxSolsticesComboBox->currentItem() == 1) {
00076         julianDay = Sun->summerSolstice(year0);
00077         jdf = Sun->autumnEquinox(year0);
00078     }
00079     else if (equinoxSolsticesComboBox->currentItem() == 2 ) {
00080         julianDay = Sun->autumnEquinox(year0);
00081         jdf = Sun->winterSolstice(year0);
00082     }
00083     else if(equinoxSolsticesComboBox->currentItem() == 3) {
00084         julianDay = Sun->winterSolstice(year0);
00085         jdf = Sun->springEquinox(year0+1);
00086     }
00087     
00088     deltaJd = (float) (jdf - julianDay);
00089     showStartDateTime(julianDay);
00090     showSeasonDuration(deltaJd);
00091     
00092 }
00093 
00094 void modCalcEquinox::slotClear(void){
00095     yearEdit->setText("");
00096     seasonDuration->setText("");
00097 }
00098 
00099 void modCalcEquinox::showStartDateTime(long double jd)
00100 {
00101     KStarsDateTime dt( jd );
00102     startDateTimeEquinox->setDateTime( dt );
00103 }
00104 
00105 void modCalcEquinox::showSeasonDuration(float deltaJd)
00106 {
00107     seasonDuration->setText( QString( "%1").arg( deltaJd ) );
00108 }
00109 
00110 void modCalcEquinox::slotYearCheckedBatch(){
00111     if ( yearCheckBatch->isChecked() )
00112         yearCheckBatch->setEnabled( false );
00113     else {
00114         yearCheckBatch->setEnabled( true );
00115     }
00116 }
00117 
00118 void modCalcEquinox::slotInputFile() {
00119     QString inputFileName;
00120     inputFileName = KFileDialog::getOpenFileName( );
00121     InputLineEditBatch->setText( inputFileName );
00122 }
00123 
00124 void modCalcEquinox::slotOutputFile() {
00125     QString outputFileName;
00126     outputFileName = KFileDialog::getSaveFileName( );
00127     OutputLineEditBatch->setText( outputFileName );
00128 }
00129 
00130 void modCalcEquinox::slotRunBatch() {
00131 
00132     QString inputFileName;
00133 
00134     inputFileName = InputLineEditBatch->text();
00135 
00136     // We open the input file and read its content
00137 
00138     if ( QFile::exists(inputFileName) ) {
00139         QFile f( inputFileName );
00140         if ( !f.open( IO_ReadOnly) ) {
00141             QString message = i18n( "Could not open file %1.").arg( f.name() );
00142             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00143             inputFileName = "";
00144             return;
00145         }
00146 
00147 //      processLines(&f);
00148         QTextStream istream(&f);
00149         processLines(istream);
00150 //      readFile( istream );
00151         f.close();
00152     } else  {
00153         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00154         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00155         inputFileName = "";
00156         InputLineEditBatch->setText( inputFileName );
00157         return;
00158     }
00159 }
00160 
00161 void modCalcEquinox::processLines( QTextStream &istream ) {
00162 
00163     // we open the output file
00164 
00165 //  QTextStream istream(&fIn);
00166     QString outputFileName;
00167     outputFileName = OutputLineEditBatch->text();
00168     QFile fOut( outputFileName );
00169     fOut.open(IO_WriteOnly);
00170     QTextStream ostream(&fOut);
00171 
00172     QString line;
00173     QString space = " ";
00174     int yearB;
00175     int i = 0;
00176     long double jdsp = 0., jdsu = 0., jdau = 0., jdwin = 0., jdsp1 = 0.;
00177     KStarsData *kd = (KStarsData*) parent()->parent()->parent();
00178     KSSun *Sun = new KSSun(kd);
00179 
00180     while ( ! istream.eof() ) {
00181         line = istream.readLine();
00182         line.stripWhiteSpace();
00183 
00184         //Go through the line, looking for parameters
00185 
00186         QStringList fields = QStringList::split( " ", line );
00187 
00188         i = 0;
00189 
00190         // Read year and write in ostream if corresponds
00191 
00192         if(yearCheckBatch->isChecked() ) {
00193             yearB = fields[i].toInt();
00194             i++;
00195         } else
00196             yearB = yearEditBatch->text().toInt();
00197 
00198         if ( allRadioBatch->isChecked() )
00199             ostream << yearB << space;
00200         else
00201             if(yearCheckBatch->isChecked() )
00202                 ostream << yearB << space;
00203 
00204         jdsp = Sun->springEquinox(yearB);
00205         jdsu = Sun->summerSolstice(yearB);
00206         jdau = Sun->autumnEquinox(yearB);
00207         jdwin = Sun->winterSolstice(yearB);
00208         jdsp1 = Sun->springEquinox(yearB+1);
00209 
00210         KStarsDateTime dts( jdsp );
00211         KStarsDateTime dtu( jdsu );
00212         KStarsDateTime dta( jdau );
00213         KStarsDateTime dtw( jdwin );
00214 
00215         ostream << dts.toString(Qt::ISODate) << space << (float)(jdsu - jdsp) << space 
00216                         << dtu.toString(Qt::ISODate) << space << (float)(jdau - jdsu) << space 
00217                         << dta.toString(Qt::ISODate) << space << (float)(jdwin - jdau) << space 
00218                         << dtw.toString(Qt::ISODate) << space << (float)(jdsp1 - jdwin) << endl;
00219     }
00220 
00221 
00222     fOut.close();
00223 }

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