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

kstars

modcalcazel.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcazel.cpp  -  description
00003                              -------------------
00004     begin                : s� oct 26 2002
00005     copyright            : (C) 2002 by Jason Harris
00006     email                : kstars@30doradus.org
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 "modcalcazel.h"
00019 
00020 #include "modcalcazel.moc"
00021 #include "dms.h"
00022 #include "dmsbox.h"
00023 #include "skypoint.h"
00024 #include "geolocation.h"
00025 #include "kstars.h"
00026 #include "kstarsdata.h"
00027 #include "kstarsdatetime.h"
00028 #include "libkdeedu/extdate/extdatetimeedit.h"
00029 
00030 #include <qdatetimeedit.h>  //need for QTimeEdit
00031 #include <qcheckbox.h>
00032 #include <qradiobutton.h>
00033 #include <qstring.h>
00034 #include <qtextstream.h>
00035 #include <kfiledialog.h>
00036 #include <kmessagebox.h>
00037 
00038 
00039 modCalcAzel::modCalcAzel(QWidget *parentSplit, const char *name) : modCalcAzelDlg (parentSplit,name) {
00040 
00041     showCurrentDateTime();
00042     initGeo();
00043     showLongLat();
00044     horInputCoords = FALSE;
00045     raBox->setDegType(FALSE);
00046     show();
00047 }
00048 
00049 modCalcAzel::~modCalcAzel(){
00050     delete geoPlace;
00051 }
00052 
00053 SkyPoint modCalcAzel::getEquCoords (void)
00054 {
00055     dms raCoord, decCoord;
00056 
00057     raCoord = raBox->createDms(FALSE);
00058     decCoord = decBox->createDms();
00059 
00060     SkyPoint sp = SkyPoint (raCoord, decCoord);
00061 
00062     return sp;
00063 }
00064 
00065 SkyPoint modCalcAzel::getHorCoords (void)
00066 {
00067     dms azCoord, elCoord;
00068 
00069     azCoord = azBox->createDms();
00070     elCoord = elBox->createDms();
00071 
00072     SkyPoint sp = SkyPoint();
00073 
00074     sp.setAz(azCoord);
00075     sp.setAlt(elCoord);
00076 
00077     return sp;
00078 }
00079 
00080 void modCalcAzel::showCurrentDateTime (void)
00081 {
00082     KStars *ks = (KStars*) parent()->parent()->parent();
00083 
00084     KStarsDateTime dt = ks->data()->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
00085 
00086     datBox->setDate( dt.date() );
00087     timBox->setTime( dt.time() );
00088     dateBoxBatch->setDate( dt.date() );
00089     utBoxBatch->setTime( dt.time() );
00090 }
00091 
00092 KStarsDateTime modCalcAzel::getDateTime (void)
00093 {
00094     return KStarsDateTime( datBox->date() , timBox->time() );
00095 }
00096 
00097 double modCalcAzel::getEpoch (QString eName)
00098 {
00099     bool ok = false;
00100     double epoch = eName.toDouble(&ok);
00101     if ( ok )
00102         return epoch;
00103     else {
00104         kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl;
00105         return 2000.0;
00106     }
00107 }
00108 
00109 dms modCalcAzel::getLongitude(void)
00110 {
00111     dms longitude;
00112     longitude = longBox->createDms();
00113     return longitude;
00114 }
00115 
00116 dms modCalcAzel::getLatitude(void)
00117 {
00118     dms latitude;
00119     latitude = latBox->createDms();
00120     return latitude;
00121 }
00122 
00123 void modCalcAzel::getGeoLocation (void)
00124 {
00125     geoPlace->setLong( longBox->createDms() );
00126     geoPlace->setLat(  latBox->createDms() );
00127     geoPlace->setHeight( 0.0);
00128 
00129 }
00130 
00131 void modCalcAzel::initGeo(void)
00132 {
00133     KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
00134     geoPlace = new GeoLocation( ks->geo() );
00135 }
00136 
00137 
00138 
00139 void modCalcAzel::showLongLat(void)
00140 {
00141 
00142     KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
00143     longBox->show( ks->geo()->lng() );
00144     latBox->show( ks->geo()->lat() );
00145     longBoxBatch->show( ks->geo()->lng() );
00146     latBoxBatch->show( ks->geo()->lat() );
00147 }
00148 
00149 void modCalcAzel::showHorCoords ( SkyPoint sp )
00150 {
00151 
00152     azBox->show( sp.az() );
00153     elBox->show( sp.alt() );
00154 
00155 }
00156 
00157 void modCalcAzel::showEquCoords ( SkyPoint sp )
00158 {
00159     raBox->show( sp.ra(), FALSE );
00160     decBox->show( sp.dec() );
00161     showEpoch( getDateTime() );
00162 }
00163 
00164 void modCalcAzel::showEpoch( const KStarsDateTime &dt )
00165 {
00166     double epochN = dt.epoch();
00167 //  Localization
00168 //  epochName->setText(KGlobal::locale()->formatNumber(epochN,3));
00169     epochName->setText( KGlobal::locale()->formatNumber( epochN ) );
00170     
00171 }
00172 
00173 void modCalcAzel::slotClearCoords()
00174 {
00175 
00176     raBox->clearFields();
00177     decBox->clearFields();
00178     azBox->clearFields();
00179     elBox->clearFields();
00180     epochName->setText("");
00181 
00182     datBox->setDate(ExtDate::currentDate());
00183     timBox->setTime(QTime(0,0,0));
00184 
00185 }
00186 
00187 void modCalcAzel::slotComputeCoords()
00188 {
00189     SkyPoint sp;
00190     double epoch0 = getEpoch( epochName->text() );
00191     KStarsDateTime dt;
00192     dt.setFromEpoch( epoch0 );
00193     long double jd = getDateTime().djd();
00194     long double jd0 = dt.djd();
00195 
00196     dms LST( getDateTime().gst().Degrees() + getLongitude().Degrees() );
00197 
00198     if(radioApCoords->isChecked()) {
00199         sp = getEquCoords();
00200         sp.apparentCoord(jd0, jd);
00201         dms lat(getLatitude());
00202         sp.EquatorialToHorizontal( &LST, &lat );
00203         showHorCoords( sp );
00204 
00205     } else {
00206         sp = getHorCoords();
00207         dms lat(getLatitude());
00208         sp.HorizontalToEquatorial( &LST, &lat );
00209         showEquCoords( sp );
00210     }
00211 
00212 }
00213 void modCalcAzel::slotUtChecked(){
00214     if ( utCheckBatch->isChecked() )
00215         utBoxBatch->setEnabled( false );
00216     else {
00217         utBoxBatch->setEnabled( true );
00218     }
00219 }
00220 
00221 void modCalcAzel::slotDateChecked(){
00222     if ( dateCheckBatch->isChecked() )
00223         dateBoxBatch->setEnabled( false );
00224     else {
00225         dateBoxBatch->setEnabled( true );
00226     }
00227 }
00228 
00229 void modCalcAzel::slotRaChecked(){
00230     if ( raCheckBatch->isChecked() ) {
00231         raBoxBatch->setEnabled( false );
00232         horNoCheck();
00233     }
00234     else {
00235         raBoxBatch->setEnabled( true );
00236     }
00237 }
00238 
00239 void modCalcAzel::slotDecChecked(){
00240     if ( decCheckBatch->isChecked() ) {
00241         decBoxBatch->setEnabled( false );
00242         horNoCheck();
00243     }
00244     else {
00245         decBoxBatch->setEnabled( true );
00246     }
00247 }
00248 
00249 void modCalcAzel::slotEpochChecked(){
00250     if ( epochCheckBatch->isChecked() )
00251         epochBoxBatch->setEnabled( false );
00252     else 
00253         epochBoxBatch->setEnabled( true );
00254 }
00255 
00256 void modCalcAzel::slotLongChecked(){
00257     if ( longCheckBatch->isChecked() )
00258         longBoxBatch->setEnabled( false );
00259     else 
00260         longBoxBatch->setEnabled( true );
00261 }
00262 
00263 void modCalcAzel::slotLatChecked(){
00264     if ( latCheckBatch->isChecked() )
00265         latBoxBatch->setEnabled( false );
00266     else {
00267         latBoxBatch->setEnabled( true );
00268     }
00269 }
00270 
00271 void modCalcAzel::slotAzChecked(){
00272     if ( azCheckBatch->isChecked() ) {
00273         azBoxBatch->setEnabled( false );
00274         equNoCheck();
00275     }
00276     else {
00277         azBoxBatch->setEnabled( true );
00278     }
00279 }
00280 
00281 void modCalcAzel::slotElChecked(){
00282     if ( elCheckBatch->isChecked() ) {
00283         elBoxBatch->setEnabled( false );
00284         equNoCheck();
00285     }
00286     else {
00287         elBoxBatch->setEnabled( true );
00288     }
00289 }
00290 
00291 void modCalcAzel::horNoCheck() {
00292     azCheckBatch->setChecked(false);
00293     azBoxBatch->setEnabled(false);
00294     elCheckBatch->setChecked(false);
00295     elBoxBatch->setEnabled(false);
00296     horInputCoords = FALSE;
00297 
00298 }
00299 
00300 void modCalcAzel::equNoCheck() {
00301     raCheckBatch->setChecked(false);
00302     raBoxBatch->setEnabled(false);
00303     decCheckBatch->setChecked(false);
00304     decBoxBatch->setEnabled(false);
00305     horInputCoords = TRUE;
00306 }
00307 
00308 
00309 void modCalcAzel::slotInputFile() {
00310     QString inputFileName;
00311     inputFileName = KFileDialog::getOpenFileName( );
00312     InputLineEditBatch->setText( inputFileName );
00313 }
00314 
00315 void modCalcAzel::slotOutputFile() {
00316     QString outputFileName;
00317     outputFileName = KFileDialog::getSaveFileName( );
00318     OutputLineEditBatch->setText( outputFileName );
00319 }
00320 
00321 void modCalcAzel::slotRunBatch() {
00322     QString inputFileName;
00323 
00324     inputFileName = InputLineEditBatch->text();
00325 
00326     // We open the input file and read its content
00327 
00328     if ( QFile::exists(inputFileName) ) {
00329         QFile f( inputFileName );
00330         if ( !f.open( IO_ReadOnly) ) {
00331             QString message = i18n( "Could not open file %1.").arg( f.name() );
00332             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00333             inputFileName = "";
00334             return;
00335         }
00336 
00337 //      processLines(&f);
00338         QTextStream istream(&f);
00339         processLines(istream);
00340 //      readFile( istream );
00341         f.close();
00342     } else  {
00343         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00344         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00345         inputFileName = "";
00346         InputLineEditBatch->setText( inputFileName );
00347         return;
00348     }
00349 }
00350 
00351 void modCalcAzel::processLines( QTextStream &istream ) {
00352 
00353     // we open the output file
00354 
00355 //  QTextStream istream(&fIn);
00356     QString outputFileName;
00357     outputFileName = OutputLineEditBatch->text();
00358     QFile fOut( outputFileName );
00359     fOut.open(IO_WriteOnly);
00360     QTextStream ostream(&fOut);
00361 
00362     QString line;
00363     QString space = " ";
00364     int i = 0;
00365     long double jd0, jdf;
00366     dms LST;
00367     SkyPoint sp;
00368     dms raB, decB, latB, longB, azB, elB;
00369     double epoch0B;
00370     QTime utB;
00371     ExtDate dtB;
00372 
00373     while ( ! istream.eof() ) {
00374         line = istream.readLine();
00375         line.stripWhiteSpace();
00376 
00377         //Go through the line, looking for parameters
00378 
00379         QStringList fields = QStringList::split( " ", line );
00380 
00381         i = 0;
00382 
00383         // Read Ut and write in ostream if corresponds
00384         
00385         if(utCheckBatch->isChecked() ) {
00386             utB = QTime::fromString( fields[i] );
00387             i++;
00388         } else
00389             utB = utBoxBatch->time();
00390         
00391         if ( allRadioBatch->isChecked() )
00392             ostream << utB.toString() << space;
00393         else
00394             if(utCheckBatch->isChecked() )
00395                 ostream << utB.toString() << space;
00396             
00397         // Read date and write in ostream if corresponds
00398         
00399         if(dateCheckBatch->isChecked() ) {
00400              dtB = ExtDate::fromString( fields[i] );
00401              i++;
00402         } else
00403             dtB = dateBoxBatch->date();
00404         if ( allRadioBatch->isChecked() )
00405             ostream << dtB.toString().append(space);
00406         else
00407             if(dateCheckBatch->isChecked() )
00408                 ostream << dtB.toString().append(space);
00409         
00410         // Read Longitude and write in ostream if corresponds
00411         
00412         if (longCheckBatch->isChecked() ) {
00413             longB = dms::fromString( fields[i],TRUE);
00414             i++;
00415         } else
00416             longB = longBoxBatch->createDms(TRUE);
00417         
00418         if ( allRadioBatch->isChecked() )
00419             ostream << longB.toDMSString() << space;
00420         else
00421             if (longCheckBatch->isChecked() )
00422                 ostream << longB.toDMSString() << space;
00423         
00424         // Read Latitude
00425 
00426 
00427         if (latCheckBatch->isChecked() ) {
00428             latB = dms::fromString( fields[i], TRUE);
00429             i++;
00430         } else
00431             latB = latBoxBatch->createDms(TRUE);
00432         if ( allRadioBatch->isChecked() )
00433             ostream << latB.toDMSString() << space;
00434         else
00435             if (latCheckBatch->isChecked() )
00436                 ostream << latB.toDMSString() << space;
00437         
00438         // Read Epoch and write in ostream if corresponds
00439     
00440         if(epochCheckBatch->isChecked() ) {
00441             epoch0B = fields[i].toDouble();
00442             i++;
00443         } else
00444             epoch0B = getEpoch( epochBoxBatch->text() );
00445 
00446         if ( allRadioBatch->isChecked() )
00447             ostream << epoch0B << space;
00448         else
00449             if(epochCheckBatch->isChecked() )
00450                 ostream << epoch0B << space;
00451 
00452         // We make the first calculations
00453         KStarsDateTime dt;
00454         dt.setFromEpoch( epoch0B );
00455         jdf = KStarsDateTime(dtB,utB).djd();
00456         jd0 = dt.djd();
00457 
00458         LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees();
00459         
00460         // Equatorial coordinates are the input coords.
00461         if (!horInputCoords) {
00462         // Read RA and write in ostream if corresponds
00463 
00464             if(raCheckBatch->isChecked() ) {
00465                 raB = dms::fromString( fields[i],FALSE);
00466                 i++;
00467             } else
00468                 raB = raBoxBatch->createDms(FALSE);
00469 
00470             if ( allRadioBatch->isChecked() )
00471                 ostream << raB.toHMSString() << space;
00472             else
00473                 if(raCheckBatch->isChecked() )
00474                     ostream << raB.toHMSString() << space;
00475 
00476             // Read DEC and write in ostream if corresponds
00477 
00478             if(decCheckBatch->isChecked() ) {
00479                 decB = dms::fromString( fields[i], TRUE);
00480                 i++;
00481             } else
00482                 decB = decBoxBatch->createDms();
00483 
00484             if ( allRadioBatch->isChecked() )
00485                 ostream << decB.toDMSString() << space;
00486             else
00487                 if(decCheckBatch->isChecked() )
00488                     ostream << decB.toDMSString() << space;
00489 
00490             sp = SkyPoint (raB, decB);
00491             sp.apparentCoord(jd0, jdf);
00492             sp.EquatorialToHorizontal( &LST, &latB );
00493             ostream << sp.az()->toDMSString() << space << sp.alt()->toDMSString() << endl;
00494 
00495         // Input coords are horizontal coordinates
00496         
00497         } else {
00498             if(azCheckBatch->isChecked() ) {
00499                 azB = dms::fromString( fields[i],FALSE);
00500                 i++;
00501             } else
00502                 azB = azBoxBatch->createDms();
00503 
00504             if ( allRadioBatch->isChecked() )
00505                 ostream << azB.toHMSString() << space;
00506             else
00507                 if(raCheckBatch->isChecked() )
00508                     ostream << azB.toHMSString() << space;
00509 
00510             // Read DEC and write in ostream if corresponds
00511 
00512             if(elCheckBatch->isChecked() ) {
00513                 elB = dms::fromString( fields[i], TRUE);
00514                 i++;
00515             } else
00516                 elB = decBoxBatch->createDms();
00517 
00518             if ( allRadioBatch->isChecked() )
00519                 ostream << elB.toDMSString() << space;
00520             else
00521                 if(elCheckBatch->isChecked() )
00522                     ostream << elB.toDMSString() << space;
00523 
00524             sp.setAz(azB);
00525             sp.setAlt(elB);
00526             sp.HorizontalToEquatorial( &LST, &latB );
00527             ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl;
00528         }
00529 
00530     }
00531 
00532 
00533     fOut.close();
00534 }

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