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

kstars

wutdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           wutdialog.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Die Feb 25 2003
00005     copyright            : (C) 2003 by Thomas Kabelmann
00006     email                : tk78@gmx.de
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 "wutdialog.h"
00019 #include "wutdialogui.h"
00020 
00021 #include "kstars.h"
00022 #include "kstarsdata.h"
00023 #include "skymap.h"
00024 #include "ksnumbers.h"
00025 #include "skyobjectname.h"
00026 #include "objectnamelist.h"
00027 #include "simclock.h"
00028 #include "detaildialog.h"
00029 #include "locationdialog.h"
00030 #include "timedialog.h"
00031 #include "kssun.h"
00032 #include "ksmoon.h"
00033 
00034 #include <kcombobox.h>
00035 #include <klocale.h>
00036 #include <klistbox.h>
00037 #include <kpushbutton.h>
00038 
00039 #include <qgroupbox.h>
00040 #include <qlabel.h>
00041 #include <qlayout.h>
00042 #include <qframe.h>
00043 #include <qtabbar.h>
00044 #include <qtimer.h>
00045 #include <qcursor.h>
00046 
00047 WUTDialog::WUTDialog(KStars *ks) :
00048     KDialogBase (KDialogBase::Plain, i18n("What's up Tonight"), Close, Close, (QWidget*)ks),
00049     kstars(ks), EveningFlag(0) {
00050 
00051     QFrame *page = plainPage();
00052     setMainWidget(page);
00053     QVBoxLayout *vlay = new QVBoxLayout( page, 0, spacingHint() );
00054     WUT = new WUTDialogUI( page );
00055     vlay->addWidget( WUT );
00056 
00057     objectList = &(ks->data()->ObjNames);
00058 //  objectList->setLanguage( Options::useLatinConstellNames() );
00059 
00060     //initialize location and date to current KStars settings:
00061     geo = kstars->geo();
00062     
00063     T0 = kstars->data()->lt();
00064     //If the Time is earlier than 6:00 am, assume the user wants the night of the previous date
00065     if ( T0.time().hour() < 6 ) 
00066         T0 = T0.addDays( -1 );
00067 
00068     //Now, set time T0 to midnight (of the following day)
00069     T0.setTime( QTime( 0, 0, 0 ) );
00070     T0 = T0.addDays( 1 );
00071     UT0 = geo->LTtoUT( T0 );
00072     
00073     //Set the Tomorrow date/time to Noon the following day
00074     Tomorrow = T0.addSecs( 12*3600 );
00075     TomorrowUT = geo->LTtoUT( Tomorrow );
00076     
00077     //Set the Evening date/time to 6:00 pm 
00078     Evening = T0.addSecs( -6*3600 );
00079     EveningUT = geo->LTtoUT( Evening );
00080     
00081     QString sGeo = geo->translatedName();
00082     if ( ! geo->translatedProvince().isEmpty() ) sGeo += ", " + geo->translatedProvince();
00083     sGeo += ", " + geo->translatedCountry();
00084     WUT->LocationLabel->setText( i18n( "at %1" ).arg( sGeo ) );
00085     WUT->DateLabel->setText( i18n( "The night of %1" ).arg( Evening.date().toString( Qt::LocalDate ) ) );
00086 
00087     initCategories();
00088 
00089     makeConnections();
00090 
00091     QTimer::singleShot(0, this, SLOT(init()));
00092 }
00093 
00094 WUTDialog::~WUTDialog(){
00095 }
00096 
00097 void WUTDialog::makeConnections() {
00098     connect( WUT->DateButton, SIGNAL( clicked() ), SLOT( slotChangeDate() ) );
00099     connect( WUT->LocationButton, SIGNAL( clicked() ), SLOT( slotChangeLocation() ) );
00100     connect( WUT->CenterButton, SIGNAL( clicked() ), SLOT( slotCenter() ) );
00101     connect( WUT->DetailButton, SIGNAL( clicked() ), SLOT( slotDetails() ) );
00102     connect( WUT->CategoryListBox, SIGNAL( highlighted(int) ), SLOT( slotLoadList(int) ) );
00103     connect( WUT->ObjectListBox, SIGNAL( selectionChanged(QListBoxItem*) ),
00104             SLOT( slotDisplayObject(QListBoxItem*) ) );
00105     connect( WUT->EveningMorningBox, SIGNAL( activated(int) ), SLOT( slotEveningMorning(int) ) );
00106 }
00107 
00108 void WUTDialog::initCategories() {
00109     WUT->CategoryListBox->insertItem( i18n( "Planets" ) );
00110     WUT->CategoryListBox->insertItem( i18n( "Comets" ) );
00111     WUT->CategoryListBox->insertItem( i18n( "Asteroids" ) );
00112     WUT->CategoryListBox->insertItem( i18n( "Stars" ) );
00113     WUT->CategoryListBox->insertItem( i18n( "Constellations" ) );
00114     WUT->CategoryListBox->insertItem( i18n( "Star Clusters" ) );
00115     WUT->CategoryListBox->insertItem( i18n( "Nebulae" ) );
00116     WUT->CategoryListBox->insertItem( i18n( "Galaxies" ) );
00117     WUT->CategoryListBox->setSelected(0, true);
00118 }
00119 
00120 void WUTDialog::init() {
00121     QString sRise, sSet, sDuration;
00122 
00123     // reset all lists
00124     for (int i=0; i<NCATEGORY; i++) {
00125         lists.visibleList[i].clear();
00126         lists.initialized[i] = false;
00127     }
00128 
00129     // sun almanac information
00130     KSSun *oSun = (KSSun*) kstars->data()->PCat->planetSun();
00131     sunRiseTomorrow = oSun->riseSetTime( TomorrowUT, geo, true );
00132     sunSetToday = oSun->riseSetTime( EveningUT, geo, false );
00133     sunRiseToday = oSun->riseSetTime( EveningUT, geo, true );
00134 
00135     //check to see if Sun is circumpolar
00136     KSNumbers *num = new KSNumbers( UT0.djd() );
00137     KSNumbers *oldNum = new KSNumbers( kstars->data()->ut().djd() );
00138     dms LST = geo->GSTtoLST( T0.gst() );
00139     
00140     oSun->updateCoords( num, true, geo->lat(), &LST );
00141     if ( oSun->checkCircumpolar( geo->lat() ) ) {
00142         if ( oSun->alt()->Degrees() > 0.0 ) {
00143             sRise = i18n( "circumpolar" );
00144             sSet = i18n( "circumpolar" );
00145             sDuration = "00:00";
00146         } else {
00147             sRise = i18n( "does not rise" );
00148             sSet = i18n( "does not rise" );
00149             sDuration = "24:00";
00150         }
00151     } else {
00152         //Round times to the nearest minute by adding 30 seconds to the time
00153         sRise = sunRiseTomorrow.addSecs(30).toString("hh:mm");
00154         sSet = sunSetToday.addSecs(30).toString("hh:mm");
00155 
00156         float Dur = 24.0 + (float)sunRiseTomorrow.hour() 
00157                 + (float)sunRiseTomorrow.minute()/60.0 
00158                 + (float)sunRiseTomorrow.second()/3600.0 
00159                 - (float)sunSetToday.hour() 
00160                 - (float)sunSetToday.minute()/60.0
00161                 - (float)sunSetToday.second()/3600.0;
00162         int hDur = int(Dur);
00163         int mDur = int(60.0*(Dur - (float)hDur));
00164         sDuration = QString().sprintf( "%02d:%02d", hDur, mDur );
00165     }
00166 
00167     WUT->SunSetLabel->setText( i18n( "Sunset: %1" ).arg(sSet) );
00168     WUT->SunRiseLabel->setText( i18n( "Sunrise: %1" ).arg(sRise) );
00169     WUT->NightDurationLabel->setText( i18n( "Night duration: %1 hours" ).arg( sDuration ) );
00170 
00171     // moon almanac information
00172     KSMoon *oMoon = (KSMoon*) kstars->data()->Moon;
00173     moonRise = oMoon->riseSetTime( UT0, geo, true );
00174     moonSet = oMoon->riseSetTime( UT0, geo, false );
00175 
00176     //check to see if Moon is circumpolar
00177     oMoon->updateCoords( num, true, geo->lat(), &LST );
00178     if ( oMoon->checkCircumpolar( geo->lat() ) ) {
00179         if ( oMoon->alt()->Degrees() > 0.0 ) {
00180             sRise = i18n( "circumpolar" );
00181             sSet = i18n( "circumpolar" );
00182         } else {
00183             sRise = i18n( "does not rise" );
00184             sSet = i18n( "does not rise" );
00185         }
00186     } else {
00187         //Round times to the nearest minute by adding 30 seconds to the time
00188         sRise = moonRise.addSecs(30).toString("hh:mm");
00189         sSet = moonSet.addSecs(30).toString("hh:mm");
00190     }
00191 
00192     WUT->MoonRiseLabel->setText( i18n( "Moon rises at: %1" ).arg( sRise ) );
00193     WUT->MoonSetLabel->setText( i18n( "Moon sets at: %1" ).arg( sSet ) );
00194     oMoon->findPhase( oSun ); 
00195     WUT->MoonIllumLabel->setText( oMoon->phaseName() + QString( " (%1%)" ).arg(
00196             int(100.0*oMoon->illum() ) ) );
00197 
00198     //Restore Sun's and Moon's coordinates, and recompute Moon's original Phase
00199     oMoon->updateCoords( oldNum, true, geo->lat(), kstars->LST() );
00200     oSun->updateCoords( oldNum, true, geo->lat(), kstars->LST() );
00201     oMoon->findPhase( oSun ); 
00202     
00203     splitObjectList();
00204     // load first list
00205     slotLoadList(0);
00206 
00207     delete num;
00208     delete oldNum;
00209 }
00210 
00211 void WUTDialog::splitObjectList() {
00212     // don't append objects which are never visible
00213     for (SkyObjectName *oname=objectList->first(); oname; oname=objectList->next()) {
00214         bool visible = true;
00215         SkyObject *o = oname->skyObject();
00216         // is object circumpolar or never visible
00217         if (o->checkCircumpolar(geo->lat()) == true) {
00218             // never visible
00219             if (o->alt()->Degrees() <= 0) visible = false;
00220         }
00221         if (visible == true) appendToList(oname);
00222     }
00223 }
00224 
00225 void WUTDialog::appendToList(SkyObjectName *o) {
00226     // split into several lists
00227     switch (o->skyObject()->type()) {
00228         //case SkyObject::CATALOG_STAR          : //Omitting CATALOG_STARs from list
00229         case SkyObject::PLANET            : lists.visibleList[0].append(o); break;
00230         case SkyObject::COMET             : lists.visibleList[1].append(o); break;
00231         case SkyObject::ASTEROID          : lists.visibleList[2].append(o); break;
00232         case SkyObject::STAR              : lists.visibleList[3].append(o); break;
00233         case SkyObject::CONSTELLATION     : lists.visibleList[4].append(o); break;
00234         case SkyObject::OPEN_CLUSTER      :
00235         case SkyObject::GLOBULAR_CLUSTER  : lists.visibleList[5].append(o); break;
00236         case SkyObject::GASEOUS_NEBULA    :
00237         case SkyObject::PLANETARY_NEBULA  :
00238         case SkyObject::SUPERNOVA_REMNANT : lists.visibleList[6].append(o); break;
00239         case SkyObject::GALAXY            : lists.visibleList[7].append(o); break;
00240     }
00241 }
00242 
00243 void WUTDialog::slotLoadList(int i) {
00244     WUT->ObjectListBox->clear();
00245     setCursor(QCursor(Qt::WaitCursor));
00246     QPtrList <SkyObjectName> invisibleList;
00247     for (SkyObjectName *oname=lists.visibleList[i].first(); oname; oname=lists.visibleList[i].next()) {
00248         bool visible = true;
00249         if (lists.initialized[i] == false) {
00250             if (i == 0) {  //planets, sun and moon
00251                 if (oname->skyObject()->name() == "Sun" ) visible = false;  // don't ever display the sun
00252                 else visible = checkVisibility(oname);
00253             }
00254             if (visible == false) {
00255                 // collect all invisible objects
00256                 invisibleList.append(oname);
00257             }
00258         }
00259         // append to listbox
00260         if (visible == true) new SkyObjectNameListItem(WUT->ObjectListBox, oname);
00261     }
00262     // remove all invisible objects from list
00263     if (invisibleList.isEmpty() == false) {
00264         for (SkyObjectName *o=invisibleList.first(); o; o=invisibleList.next()) {
00265             lists.visibleList[i].removeRef(o);
00266         }
00267     }
00268     setCursor(QCursor(Qt::ArrowCursor));
00269     lists.initialized[i] = true;
00270 
00271     // highlight first item
00272     if ( WUT->ObjectListBox->count() ) {
00273         WUT->ObjectListBox->setSelected(0, true);
00274         WUT->ObjectListBox->setFocus();
00275     }
00276 }
00277 
00278 bool WUTDialog::checkVisibility(SkyObjectName *oname) {
00279     bool visible( false );
00280     double minAlt = 6.0; //An object is considered 'visible' if it is above horizon during civil twilight.
00281 
00282     //Initial values for T1, T2 assume all night option of EveningMorningBox
00283     KStarsDateTime T1 = Evening;
00284     T1.setTime( sunSetToday );
00285     KStarsDateTime T2 = Tomorrow;
00286     T2.setTime( sunRiseTomorrow );
00287 
00288     //Check Evening/Morning only state:
00289     if ( EveningFlag==0 ) { //Evening only
00290         T2 = T0; //midnight
00291     } else if ( EveningFlag==1 ) { //Morning only
00292         T1 = T0; //midnight
00293     }
00294 
00295     for ( KStarsDateTime test = T1; test < T2; test = test.addSecs(3600) ) {
00296         //Need LST of the test time, expressed as a dms object.
00297         KStarsDateTime ut = geo->LTtoUT( test );
00298         dms LST = geo->GSTtoLST( ut.gst() );
00299         SkyPoint sp = oname->skyObject()->recomputeCoords( ut, geo );
00300         
00301         //check altitude of object at this time.
00302         sp.EquatorialToHorizontal( &LST, geo->lat() );
00303 
00304         if ( sp.alt()->Degrees() > minAlt ) {
00305             visible = true;
00306             break;
00307         }
00308     }
00309 
00310     return visible;
00311 }
00312 
00313 void WUTDialog::slotDisplayObject(QListBoxItem *item) {
00314     QTime tRise, tSet, tTransit;
00315     QString sRise, sTransit, sSet;
00316 
00317     if ( item==0 ) { //no object selected
00318         WUT->ObjectBox->setTitle( i18n( "No Object Selected" ) );
00319 
00320         sRise = "--:--";
00321         sTransit = "--:--";
00322         sSet = "--:--";
00323         WUT->DetailButton->setEnabled( false );
00324     } else {
00325         SkyObject *o = ((SkyObjectNameListItem*)item)->objName()->skyObject();
00326         WUT->ObjectBox->setTitle( o->name() );
00327 
00328         if ( o->checkCircumpolar( geo->lat() ) ) {
00329             if ( o->alt()->Degrees() > 0.0 ) {
00330                 sRise = i18n( "circumpolar" );
00331                 sSet = i18n( "circumpolar" );
00332             } else {
00333                 sRise = i18n( "does not rise" );
00334                 sSet = i18n( "does not rise" );
00335             }
00336         } else {
00337             tRise = o->riseSetTime( T0, geo, true );
00338             tSet = o->riseSetTime( T0, geo, false );
00339 //          if ( tSet < tRise ) 
00340 //              tSet = o->riseSetTime( JDTomorrow, geo, false );
00341             
00342             sRise = QString().sprintf( "%02d:%02d", tRise.hour(), tRise.minute() );
00343             sSet = QString().sprintf( "%02d:%02d", tSet.hour(), tSet.minute() );
00344         }
00345 
00346         tTransit = o->transitTime( T0, geo );
00347 //      if ( tTransit < tRise ) 
00348 //          tTransit = o->transitTime( JDTomorrow, geo );
00349         
00350         sTransit = QString().sprintf( "%02d:%02d", tTransit.hour(), tTransit.minute() );
00351 
00352         WUT->DetailButton->setEnabled( true );
00353     }
00354 
00355     WUT->ObjectRiseLabel->setText( i18n( "Rises at: %1" ).arg( sRise ) );
00356     WUT->ObjectTransitLabel->setText( i18n( "Transits at: %1" ).arg( sTransit ) );
00357     WUT->ObjectSetLabel->setText( i18n( "Sets at: %1" ).arg( sSet ) );
00358 }
00359 
00360 void WUTDialog::slotCenter() {
00361     SkyObject *o = 0;
00362     // get selected item
00363     if (WUT->ObjectListBox->selectedItem() != 0) {
00364         o = ((SkyObjectNameListItem*)WUT->ObjectListBox->selectedItem())->objName()->skyObject();
00365     }
00366     if (o != 0) {
00367         kstars->map()->setFocusPoint( o );
00368         kstars->map()->setFocusObject( o );
00369         kstars->map()->setDestination( kstars->map()->focusPoint() );
00370     }
00371 }
00372 
00373 void WUTDialog::slotDetails() {
00374     SkyObject *o = 0;
00375     // get selected item
00376     if (WUT->ObjectListBox->selectedItem() != 0) {
00377         o = ((SkyObjectNameListItem*)WUT->ObjectListBox->selectedItem())->objName()->skyObject();
00378     }
00379     if (o != 0) {
00380         DetailDialog detail(o, kstars->data()->LTime, geo, kstars);
00381         detail.exec();
00382     }
00383 }
00384 
00385 void WUTDialog::slotChangeDate() {
00386     TimeDialog td( T0, this );
00387     if ( td.exec() == QDialog::Accepted ) {
00388         T0 = td.selectedDateTime();
00389         //If the Time is earlier than 6:00 am, assume the user wants the night of the previous date
00390         if ( T0.time().hour() < 6 ) 
00391             T0 = T0.addDays( -1 );
00392         
00393         //Now, set time T0 to midnight (of the following day)
00394         T0.setTime( QTime( 0, 0, 0 ) );
00395         T0 = T0.addDays( 1 );
00396         UT0 = geo->LTtoUT( T0 );
00397         
00398         //Set the Tomorrow date/time to Noon the following day
00399         Tomorrow = T0.addSecs( 12*3600 );
00400         TomorrowUT = geo->LTtoUT( Tomorrow );
00401         
00402         //Set the Evening date/time to 6:00 pm 
00403         Evening = T0.addSecs( -6*3600 );
00404         EveningUT = geo->LTtoUT( Evening );
00405         
00406         WUT->DateLabel->setText( i18n( "The night of %1" ).arg( Evening.date().toString() ) );
00407 
00408         int i = WUT->CategoryListBox->currentItem();
00409         init();
00410         slotLoadList( i );
00411     }
00412 }
00413 
00414 void WUTDialog::slotChangeLocation() {
00415     LocationDialog ld( kstars );
00416     if ( ld.exec() == QDialog::Accepted ) {
00417         GeoLocation *newGeo = ld.selectedCity();
00418         if ( newGeo ) {
00419             geo = newGeo;
00420             UT0 = geo->LTtoUT( T0 );
00421             TomorrowUT = geo->LTtoUT( Tomorrow );
00422             EveningUT = geo->LTtoUT( Evening );
00423             
00424             WUT->LocationLabel->setText( i18n( "at %1" ).arg( geo->fullName() ) );
00425             
00426             int i = WUT->CategoryListBox->currentItem();
00427             init();
00428             slotLoadList( i );
00429         }
00430     }
00431 }
00432 
00433 void WUTDialog::slotEveningMorning( int index ) {
00434     if ( EveningFlag != index ) {
00435         EveningFlag = index;
00436 //      splitObjectList();
00437 //      slotLoadList( WUT->CategoryListBox->currentItem() );
00438         int i = WUT->CategoryListBox->currentItem();
00439         init();
00440         slotLoadList( i );
00441     }
00442 }
00443 
00444 #include "wutdialog.moc"

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