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

kstars

modcalcapcoord.cpp

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

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