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

kstars

kstarsdcop.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kstarsdcop.cpp  -  description
00003                              -------------------
00004     begin                : Son Apr 7 2002
00005     copyright            : (C) 2002 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 //KStars DCOP functions
00019 
00020 #include <qdir.h>
00021 #include <qlistview.h>
00022 #include <qradiobutton.h>
00023 
00024 #include <kio/netaccess.h>
00025 #include <kmessagebox.h>
00026 #include <kprinter.h>
00027 #include <kshortcut.h>
00028 #include <ktempfile.h>
00029 #include <kurl.h>
00030 #include <klistview.h>
00031 #include <kpushbutton.h>
00032 #include <klineedit.h>
00033 #include <knuminput.h> 
00034 
00035 #include "kstars.h"
00036 #include "kstarsdata.h"
00037 #include "skymap.h"
00038 #include "skyobject.h"
00039 #include "infoboxes.h"
00040 #include "simclock.h"
00041 #include "Options.h"
00042 
00043 // INDI includes
00044 #include "indidriver.h"
00045 #include "indimenu.h"
00046 #include "indielement.h"
00047 #include "indidevice.h"
00048 #include "indiproperty.h"
00049 #include "devicemanager.h"
00050 
00051 void KStars::setRaDec( double ra, double dec ) {
00052     map()->setDestination( new SkyPoint( ra, dec ) );
00053 }
00054 
00055 void KStars::setAltAz( double alt, double az ) {
00056     map()->setDestinationAltAz(alt,az);
00057 }
00058 
00059 void KStars::lookTowards ( const QString direction ) {
00060   QString dir = direction.lower();
00061     if (dir == "zenith" || dir=="z") map()->invokeKey( KKey( "Z" ).keyCodeQt() );
00062     else if (dir == "north" || dir=="n") map()->invokeKey( KKey( "N" ).keyCodeQt() );
00063     else if (dir == "east"  || dir=="e") map()->invokeKey( KKey( "E" ).keyCodeQt() );
00064     else if (dir == "south" || dir=="s") map()->invokeKey( KKey( "S" ).keyCodeQt() );
00065     else if (dir == "west"  || dir=="w") map()->invokeKey( KKey( "W" ).keyCodeQt() );
00066     else if (dir == "northeast" || dir=="ne") {
00067         map()->stopTracking();
00068         map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 45.0 );
00069         map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
00070         map()->slotCenter();
00071     } else if (dir == "southeast" || dir=="se") {
00072         map()->stopTracking();
00073         map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 135.0 );
00074         map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
00075         map()->slotCenter();
00076     } else if (dir == "southwest" || dir=="sw") {
00077         map()->stopTracking();
00078         map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 225.0 );
00079         map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
00080         map()->slotCenter();
00081     } else if (dir == "northwest" || dir=="nw") {
00082         map()->stopTracking();
00083         map()->clickedPoint()->setAlt( 15.0 ); map()->clickedPoint()->setAz( 315.0 );
00084         map()->clickedPoint()->HorizontalToEquatorial( LST(), geo()->lat() );
00085         map()->slotCenter();
00086     } else {
00087         SkyObject *target = data()->objectNamed( direction );
00088         if ( target != NULL ) {
00089             map()->setClickedObject( target );
00090             map()->setClickedPoint( target );
00091             map()->slotCenter();
00092         }
00093     }
00094 }
00095 
00096 void KStars::zoom( double z ) {
00097     if ( z > MAXZOOM ) z = MAXZOOM;
00098     if ( z < MINZOOM ) z = MINZOOM;
00099     Options::setZoomFactor( z );
00100     map()->forceUpdate();
00101 }
00102 
00103 void KStars::setLocalTime(int yr, int mth, int day, int hr, int min, int sec) {
00104     data()->changeDateTime( geo()->LTtoUT( KStarsDateTime( ExtDate(yr, mth, day), QTime(hr,min,sec) ) ) );
00105 }
00106 
00107 void KStars::waitFor( double t ) {
00108     kapp->dcopClient()->suspend();
00109     QTimer::singleShot( int( 1000.*t ), this, SLOT( resumeDCOP() ) );
00110 }
00111 
00112 void KStars::waitForKey( const QString k ) {
00113     data()->resumeKey = KKey( k );
00114     if ( ! data()->resumeKey.isNull() ) {
00115         kapp->dcopClient()->suspend();
00116     } else {
00117         kdDebug() << i18n( "Error [DCOP waitForKey()]: Invalid key requested." ) << endl;
00118     }
00119 }
00120 
00121 void KStars::setTracking( bool track ) {
00122     if ( track != Options::isTracking() ) slotTrack();
00123 }
00124 
00125 void KStars::popupMessage( int /*x*/, int /*y*/, QString /*message*/ ){
00126     //Show a small popup window at (x,y) with a text message
00127 }
00128 
00129 void KStars::drawLine( int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/, int /*speed*/ ) {
00130     //Draw a line on the skymap display
00131 }
00132 
00133 void KStars::setGeoLocation( QString city, QString province, QString country ) {
00134     //Set the geographic location
00135     bool cityFound( false );
00136 
00137     for (GeoLocation *loc = data()->geoList.first(); loc; loc = data()->geoList.next()) {
00138         if ( loc->translatedName() == city &&
00139                     ( province.isEmpty() || loc->translatedProvince() == province ) &&
00140                     loc->translatedCountry() == country ) {
00141 
00142             cityFound = true;
00143 
00144             data()->setLocation( *loc );
00145 
00146             //notify on-screen GeoBox
00147             infoBoxes()->geoChanged( loc );
00148 
00149             //configure time zone rule
00150             KStarsDateTime ltime = loc->UTtoLT( data()->ut() );
00151             loc->tzrule()->reset_with_ltime( ltime, loc->TZ0(), data()->isTimeRunningForward() );
00152             data()->setNextDSTChange( loc->tzrule()->nextDSTChange() );
00153 
00154             //reset LST
00155             data()->syncLST();
00156 
00157             //make sure planets, etc. are updated immediately
00158             data()->setFullTimeUpdate();
00159 
00160             // If the sky is in Horizontal mode and not tracking, reset focus such that
00161             // Alt/Az remain constant.
00162             if ( ! Options::isTracking() && Options::useAltAz() ) {
00163                 map()->focus()->HorizontalToEquatorial( LST(), geo()->lat() );
00164             }
00165 
00166             // recalculate new times and objects
00167             data()->setSnapNextFocus();
00168             updateTime();
00169 
00170             //no need to keep looking, we're done.
00171             break;
00172         }
00173     }
00174 
00175     if ( !cityFound ) {
00176         if ( province.isEmpty() )
00177             kdDebug() << i18n( "Error [DCOP setGeoLocation]: city " ) << city << ", "
00178                     << country << i18n( " not found in database." ) << endl;
00179         else
00180             kdDebug() << i18n( "Error [DCOP setGeoLocation]: city " ) << city << ", "
00181                     << province << ", " << country << i18n( " not found in database." ) << endl;
00182     }
00183 }
00184 
00185 void KStars::readConfig() {
00186     //Load config file values into Options object
00187     Options::self()->readConfig();
00188 
00189     applyConfig();
00190 
00191     //Reset date, if one was stored
00192     if ( data()->StoredDate.isValid() ) {
00193         data()->changeDateTime( geo()->LTtoUT( data()->StoredDate ) );
00194         data()->StoredDate.setDJD( (long double)INVALID_DAY ); //invalidate StoredDate
00195     }
00196 
00197     map()->forceUpdate();
00198 }
00199 
00200 void KStars::writeConfig() {
00201     Options::writeConfig();
00202 
00203     //Store current simulation time
00204     data()->StoredDate.setDJD( data()->lt().djd() );
00205 }
00206 
00207 QString KStars::getOption( const QString &name ) {
00208     //Some config items are not stored in the Options object while 
00209     //the program is running; catch these here and returntheir current value.
00210     if ( name == "FocusRA" ) { return QString::number( map()->focus()->ra()->Hours(), 'f', 6 ); }
00211     if ( name == "FocusDec" ) { return QString::number( map()->focus()->dec()->Degrees(), 'f', 6 ); }
00212 
00213     KConfigSkeletonItem *it = Options::self()->findItem( name );
00214     if ( it ) return it->property().toString();
00215     else return QString::null;
00216 }
00217 
00218 void KStars::changeViewOption( const QString op, const QString val ) {
00219     bool bOk(false), nOk(false), dOk(false);
00220 
00221     //parse bool value
00222     bool bVal(false);
00223     if ( val.lower() == "true" ) { bOk = true; bVal = true; }
00224     if ( val.lower() == "false" ) { bOk = true; bVal = false; }
00225     if ( val == "1" ) { bOk = true; bVal = true; }
00226     if ( val == "0" ) { bOk = true; bVal = false; }
00227 
00228     //parse int value
00229     int nVal = val.toInt( &nOk );
00230 
00231     //parse double value
00232     double dVal = val.toDouble( &dOk );
00233 
00234     //[GUI]
00235     if ( op == "ShowInfoBoxes"   && bOk ) Options::setShowInfoBoxes(   bVal );
00236     if ( op == "ShowTimeBox"     && bOk ) Options::setShowTimeBox(     bVal );
00237     if ( op == "ShowGeoBox"      && bOk ) Options::setShowGeoBox(      bVal );
00238     if ( op == "ShowFocusBox"    && bOk ) Options::setShowFocusBox(    bVal );
00239     if ( op == "ShadeTimeBox"    && bOk ) Options::setShadeTimeBox(    bVal );
00240     if ( op == "ShadeGeoBox"     && bOk ) Options::setShadeGeoBox(     bVal );
00241     if ( op == "ShadeFocusBox"   && bOk ) Options::setShadeFocusBox(   bVal );
00242     if ( op == "ShowMainToolBar" && bOk ) Options::setShowMainToolBar( bVal );
00243     if ( op == "ShowViewToolBar" && bOk ) Options::setShowViewToolBar( bVal );
00244 
00245     //[View]
00246     if ( op == "FOVName"                ) Options::setFOVName(         val );
00247     if ( op == "FOVSize"         && dOk ) Options::setFOVSize( (float)dVal );
00248     if ( op == "FOVShape"        && nOk ) Options::setFOVShape(       nVal );
00249     if ( op == "FOVColor"               ) Options::setFOVColor(        val );
00250     if ( op == "ShowStars"       && bOk ) Options::setShowStars(      bVal );
00251     if ( op == "ShowMessier"     && bOk ) Options::setShowMessier(    bVal );
00252     if ( op == "ShowMessierImages" && bOk ) Options::setShowMessierImages( bVal );
00253     if ( op == "ShowNGC"         && bOk ) Options::setShowNGC( bVal );
00254     if ( op == "ShowIC"          && bOk ) Options::setShowIC(  bVal );
00255     if ( op == "ShowCLines"      && bOk ) Options::setShowCLines(   bVal );
00256     if ( op == "ShowCBounds"     && bOk ) Options::setShowCBounds(  bVal );
00257     if ( op == "ShowCNames"      && bOk ) Options::setShowCNames(   bVal );
00258     if ( op == "ShowMilkyWay"    && bOk ) Options::setShowMilkyWay( bVal );
00259     if ( op == "ShowGrid"        && bOk ) Options::setShowGrid(     bVal );
00260     if ( op == "ShowEquator"     && bOk ) Options::setShowEquator(  bVal );
00261     if ( op == "ShowEcliptic"    && bOk ) Options::setShowEcliptic( bVal );
00262     if ( op == "ShowHorizon"     && bOk ) Options::setShowHorizon(  bVal );
00263     if ( op == "ShowGround"      && bOk ) Options::setShowGround(   bVal );
00264     if ( op == "ShowSun"         && bOk ) Options::setShowSun(      bVal );
00265     if ( op == "ShowMoon"        && bOk ) Options::setShowMoon(     bVal );
00266     if ( op == "ShowMercury"     && bOk ) Options::setShowMercury(  bVal );
00267     if ( op == "ShowVenus"       && bOk ) Options::setShowVenus(    bVal );
00268     if ( op == "ShowMars"        && bOk ) Options::setShowMars(     bVal );
00269     if ( op == "ShowJupiter"     && bOk ) Options::setShowJupiter(  bVal );
00270     if ( op == "ShowSaturn"      && bOk ) Options::setShowSaturn(   bVal );
00271     if ( op == "ShowUranus"      && bOk ) Options::setShowUranus(   bVal );
00272     if ( op == "ShowNeptune"     && bOk ) Options::setShowNeptune(  bVal );
00273     if ( op == "ShowPluto"       && bOk ) Options::setShowPluto(    bVal );
00274     if ( op == "ShowAsteroids"   && bOk ) Options::setShowAsteroids( bVal );
00275     if ( op == "ShowComets"      && bOk ) Options::setShowComets(  bVal );
00276     if ( op == "ShowPlanets"     && bOk ) Options::setShowPlanets( bVal );
00277     if ( op == "ShowDeepSky"     && bOk ) Options::setShowDeepSky( bVal );
00278     if ( op == "ShowStarNames"      && bOk ) Options::setShowStarNames(      bVal );
00279     if ( op == "ShowStarMagnitudes" && bOk ) Options::setShowStarMagnitudes( bVal );
00280     if ( op == "ShowAsteroidNames"  && bOk ) Options::setShowAsteroidNames(  bVal );
00281     if ( op == "ShowCometNames"     && bOk ) Options::setShowCometNames(     bVal );
00282     if ( op == "ShowPlanetNames"    && bOk ) Options::setShowPlanetNames(    bVal );
00283     if ( op == "ShowPlanetImages"   && bOk ) Options::setShowPlanetImages(   bVal );
00284     if ( op == "HideOnSlew"  && bOk ) Options::setHideOnSlew(  bVal );
00285     if ( op == "HideStars"   && bOk ) Options::setHideStars(   bVal );
00286     if ( op == "HidePlanets" && bOk ) Options::setHidePlanets( bVal );
00287     if ( op == "HideMessier" && bOk ) Options::setHideMessier( bVal );
00288     if ( op == "HideNGC"     && bOk ) Options::setHideNGC(     bVal );
00289     if ( op == "HideIC"      && bOk ) Options::setHideIC(      bVal );
00290     if ( op == "HideMilkyWay" && bOk ) Options::setHideMilkyWay( bVal );
00291     if ( op == "HideCNames"  && bOk ) Options::setHideCNames(  bVal );
00292     if ( op == "HideCLines"  && bOk ) Options::setHideCLines(  bVal );
00293     if ( op == "HideCBounds" && bOk ) Options::setHideCBounds( bVal );
00294     if ( op == "HideGrid"    && bOk ) Options::setHideGrid(    bVal );
00295 
00296     if ( op == "UseAltAz"         && bOk ) Options::setUseAltAz(      bVal );
00297     if ( op == "UseRefraction"    && bOk ) Options::setUseRefraction( bVal );
00298     if ( op == "UseAutoLabel"     && bOk ) Options::setUseAutoLabel(  bVal );
00299     if ( op == "UseHoverLabel"    && bOk ) Options::setUseHoverLabel( bVal );
00300     if ( op == "UseAutoTrail"     && bOk ) Options::setUseAutoTrail(  bVal );
00301     if ( op == "UseAnimatedSlewing"   && bOk ) Options::setUseAnimatedSlewing( bVal );
00302     if ( op == "FadePlanetTrails" && bOk ) Options::setFadePlanetTrails( bVal );
00303     if ( op == "SlewTimeScale"    && dOk ) Options::setSlewTimeScale(    dVal );
00304     if ( op == "ZoomFactor"       && dOk ) Options::setZoomFactor(       dVal );
00305     if ( op == "MagLimitDrawStar"     && dOk )    Options::setMagLimitDrawStar(    dVal );
00306     if ( op == "MagLimitDrawDeepSky"     && dOk ) Options::setMagLimitDrawDeepSky( dVal );
00307     if ( op == "MagLimitDrawStarZoomOut" && dOk ) Options::setMagLimitDrawStarZoomOut(        dVal );
00308     if ( op == "MagLimitDrawDeepSkyZoomOut" && dOk ) Options::setMagLimitDrawDeepSkyZoomOut(  dVal );
00309     if ( op == "MagLimitDrawStarInfo" && dOk ) Options::setMagLimitDrawStarInfo( dVal );
00310     if ( op == "MagLimitHideStar"     && dOk ) Options::setMagLimitHideStar(     dVal );
00311     if ( op == "MagLimitAsteroid"     && dOk ) Options::setMagLimitAsteroid(     dVal );
00312     if ( op == "MagLimitAsteroidName" && dOk ) Options::setMagLimitAsteroidName( dVal );
00313     if ( op == "MaxRadCometName"      && dOk ) Options::setMaxRadCometName(      dVal );
00314 
00315     //these three are a "radio group"
00316     if ( op == "UseLatinConstellationNames" && bOk ) {
00317         Options::setUseLatinConstellNames( true );
00318         Options::setUseLocalConstellNames( false );
00319         Options::setUseAbbrevConstellNames( false );
00320     }
00321     if ( op == "UseLocalConstellationNames" && bOk ) {
00322         Options::setUseLatinConstellNames( false );
00323         Options::setUseLocalConstellNames( true );
00324         Options::setUseAbbrevConstellNames( false );
00325     }
00326     if ( op == "UseAbbrevConstellationNames" && bOk ) {
00327         Options::setUseLatinConstellNames( false );
00328         Options::setUseLocalConstellNames( false );
00329         Options::setUseAbbrevConstellNames( true );
00330     }
00331 
00332     map()->forceUpdate();
00333 }
00334 
00335 void KStars::setColor( const QString name, const QString value ) {
00336     ColorScheme *cs = data()->colorScheme();
00337     if ( cs->hasColorNamed( name ) ) {
00338         cs->setColor( name, value );
00339         map()->forceUpdate();
00340     }
00341 }
00342 
00343 void KStars::loadColorScheme( const QString _name ) {
00344     QString name( _name );
00345     QString filename = name.lower().stripWhiteSpace();
00346     bool ok( false );
00347     
00348     //Parse default names which don't follow the regular file-naming scheme
00349     if ( name == i18n("use default color scheme", "Default Colors") ) filename = "default.colors";
00350     if ( name == i18n("use 'star chart' color scheme", "Star Chart") ) filename = "chart.colors"; 
00351     if ( name == i18n("use 'night vision' color scheme", "Night Vision") ) filename = "night.colors"; 
00352     
00353     //Try the filename if it ends with ".colors"
00354     if ( filename.endsWith( ".colors" ) )
00355         ok = data()->colorScheme()->load( filename );
00356 
00357     //If that didn't work, try assuming that 'name' is the color scheme name
00358     //convert it to a filename exactly as ColorScheme::save() does
00359     if ( ! ok ) {
00360         if ( !filename.isEmpty() ) {
00361             for( unsigned int i=0; i<filename.length(); ++i)
00362                 if ( filename.at(i)==' ' ) filename.replace( i, 1, "-" );
00363             
00364             filename = filename.append( ".colors" );
00365             ok = data()->colorScheme()->load( filename );
00366         }
00367         
00368         if ( ! ok ) kdDebug() << i18n( "Unable to load color scheme named %1. Also tried %2." ).arg( name ).arg( filename ); 
00369     }
00370     
00371     if ( ok ) {
00372         map()->setStarColorMode( data()->colorScheme()->starColorMode() );
00373         map()->setStarColorIntensity( data()->colorScheme()->starColorIntensity() );
00374         
00375         //set the application colors for the Night Vision scheme
00376         if ( Options::darkAppColors() == false && filename == "night.colors" )  {
00377             Options::setDarkAppColors( true );
00378             OriginalPalette = QApplication::palette();
00379             QApplication::setPalette( DarkPalette, true );
00380         }
00381         
00382         if ( Options::darkAppColors() && filename != "night.colors" ) {
00383             Options::setDarkAppColors( false );
00384             QApplication::setPalette( OriginalPalette, true );
00385         }
00386         
00387         map()->forceUpdate();
00388     }
00389 }
00390 
00391 void KStars::exportImage( const QString url, int w, int h ) {
00392     //If the filename string contains no "/" separators, assume the 
00393     //user wanted to place a file in their home directory.
00394     KURL fileURL;
00395     if ( ! url.contains( "/" ) ) fileURL = QDir::homeDirPath() + "/" + url;
00396     else fileURL = url;
00397 
00398     KTempFile tmpfile;
00399     QString fname;
00400     tmpfile.setAutoDelete(true);
00401     
00402     QPixmap skyimage( map()->width(), map()->height() );
00403     QPixmap outimage( w, h );
00404     outimage.fill();
00405     
00406     if ( fileURL.isValid() ) {
00407         if ( fileURL.isLocalFile() ) {
00408             fname = fileURL.path();
00409         } else {
00410             fname = tmpfile.name();
00411         }
00412 
00413         //Determine desired image format from filename extension
00414         QString ext = fname.mid( fname.findRev(".")+1 );
00415         const char* format = "PNG";
00416         if ( ext.lower() == "png" ) { format = "PNG"; }
00417         else if ( ext.lower() == "jpg" || ext.lower() == "jpeg" ) { format = "JPG"; }
00418         else if ( ext.lower() == "gif" ) { format = "GIF"; }
00419         else if ( ext.lower() == "pnm" ) { format = "PNM"; }
00420         else if ( ext.lower() == "bmp" ) { format = "BMP"; }
00421         else { kdWarning() << i18n( "Could not parse image format of %1; assuming PNG." ).arg( fname ) << endl; }
00422 
00423         map()->exportSkyImage( &skyimage );
00424         kapp->processEvents(10000);
00425 
00426         //skyImage is the size of the sky map.  The requested image size is w x h.
00427         //If w x h is smaller than the skymap, then we simply crop the image.  
00428         //If w x h is larger than the skymap, pad the skymap image with a white border.
00429         if ( w == map()->width() && h == map()->height() ) {
00430             outimage = skyimage;
00431         } else {
00432             int dx(0), dy(0), sx(0), sy(0);
00433             int sw(map()->width()), sh(map()->height());
00434             if ( w > map()->width() ) {
00435                 dx = (w - map()->width())/2;
00436             } else { 
00437                 sx = (map()->width() - w)/2; 
00438                 sw = w; 
00439             }
00440             if ( h > map()->height() ) {
00441                 dy = (h - map()->height())/2;
00442             } else { 
00443                 sy = (map()->height() - h)/2; 
00444                 sh = h; 
00445             }
00446             
00447             bitBlt( &outimage, dx, dy, &skyimage, sx, sy, sw, sh );
00448         }
00449         
00450         if ( ! outimage.save( fname, format ) ) kdDebug() << i18n( "Error: Unable to save image: %1 " ).arg( fname ) << endl;
00451         else kdDebug() << i18n( "Image saved to file: %1" ).arg( fname ) << endl;
00452 
00453         if ( tmpfile.name() == fname ) { //attempt to upload image to remote location
00454             if ( ! KIO::NetAccess::upload( tmpfile.name(), fileURL, this ) ) {
00455                 QString message = i18n( "Could not upload image to remote location: %1" ).arg( fileURL.prettyURL() );
00456                 KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
00457             }
00458         }
00459     }
00460 }
00461 
00462 void KStars::printImage( bool usePrintDialog, bool useChartColors ) {
00463     KPrinter printer( true, QPrinter::HighResolution );
00464     printer.setFullPage( false );
00465     
00466     //Set up the printer (either with the Print Dialog, 
00467     //or using the default settings)
00468     bool ok( false );
00469     if ( usePrintDialog )
00470         ok = printer.setup( this, i18n("Print Sky") );
00471     else 
00472         ok = printer.autoConfigure();
00473     
00474     if( ok ) {
00475         kapp->setOverrideCursor( waitCursor );
00476 
00477         //Save current colorscheme and switch to Star Chart colors
00478         //(if requested)
00479         ColorScheme cs;
00480         if ( useChartColors ) {
00481             cs.copy( * data()->colorScheme() );
00482             loadColorScheme( "chart.colors" );
00483         }
00484 
00485         map()->setMapGeometry();
00486         map()->exportSkyImage( &printer );
00487 
00488         //Restore old color scheme if necessary
00489         //(if printing was aborted, the colorscheme is still restored)
00490         if ( useChartColors ) {
00491             data()->colorScheme()->copy( cs );
00492             
00493             // restore colormode and colorintensity in skymap
00494             map()->setStarColorMode( cs.starColorMode() );
00495             map()->setStarColorIntensity( cs.starColorIntensity() );
00496             map()->forceUpdate();
00497         }
00498         
00499         kapp->restoreOverrideCursor();
00500     }
00501 }
00502 
00503 void KStars::startINDI (QString deviceName, bool useLocal)
00504 {
00505 
00506   establishINDI();
00507   
00508   if (!indidriver || !indimenu)
00509   {
00510     kdDebug() << "establishINDI() failed." << endl;
00511     return;
00512   }
00513       
00514     QListViewItem *driverItem = NULL;
00515     driverItem = indidriver->localListView->findItem(deviceName, 0);
00516     if (driverItem == NULL)
00517     {
00518        kdDebug() << "Device " << deviceName << " not found!" << endl;
00519        return;
00520     }
00521 
00522     // If device is already running, we need to shut it down first
00523     if (indidriver->isDeviceRunning(deviceName))
00524     {
00525         indidriver->localListView->setSelected(driverItem, true);
00526         indidriver->processDeviceStatus(1);
00527     }
00528        
00529     // Set custome label for device
00530     indimenu->setCustomLabel(deviceName);
00531     // Select it
00532     indidriver->localListView->setSelected(driverItem, true);
00533     
00534     // Start it either locally or as series
00535     if (useLocal)
00536         indidriver->localR->setChecked(true);
00537     else
00538         indidriver->serverR->setChecked(true);
00539     
00540     // Run it
00541     indidriver->processDeviceStatus(0);
00542 
00543 }
00544 
00545 void KStars::shutdownINDI (QString deviceName)
00546 {
00547   if (!indidriver || !indimenu)
00548   {
00549     kdDebug() << "establishINDI() failed." << endl;
00550     return;
00551   }
00552       
00553     QListViewItem *driverItem = NULL;
00554     driverItem = indidriver->localListView->findItem(deviceName, 0);
00555     if (driverItem == NULL)
00556     {
00557        kdDebug() << "Device " << deviceName << " not found!" << endl;
00558        return;
00559     }
00560 
00561     indidriver->processDeviceStatus(1);
00562 
00563 }
00564 
00565 
00566 void KStars::switchINDI(QString deviceName, bool turnOn)
00567 {
00568   INDI_D *dev;
00569   INDI_P *prop;
00570   
00571   if (!indidriver || !indimenu)
00572   {
00573     kdDebug() << "switchINDI: establishINDI() failed." << endl;
00574     return;
00575   }
00576   
00577   dev = indimenu->findDevice(deviceName);
00578   if (!dev)
00579     dev = indimenu->findDeviceByLabel(deviceName);
00580   if (!dev)
00581   {
00582     kdDebug() << "Device " << deviceName << " not found!" << endl;
00583     return;
00584   }
00585   
00586   if (turnOn && dev->isOn() || (!turnOn && !dev->isOn()))
00587    return;
00588    
00589   prop = dev->findProp("CONNECTION");
00590   if (!prop) return;
00591   
00592   if (turnOn)
00593     prop->newSwitch(0);
00594   else
00595     prop->newSwitch(1);
00596   
00597 }
00598 
00599     
00600 void KStars::setINDIPort(QString deviceName, QString port)
00601 {
00602   INDI_D *dev;
00603   INDI_P *prop;
00604   INDI_E *el;
00605   
00606    if (!indidriver || !indimenu)
00607   {
00608     kdDebug() << "setINDIPort: establishINDI() failed." << endl;
00609     return;
00610   }
00611   
00612   dev = indimenu->findDevice(deviceName);
00613   if (!dev)
00614     dev = indimenu->findDeviceByLabel(deviceName);
00615   if (!dev)
00616   {
00617     kdDebug() << "Device " << deviceName << " not found!" << endl;
00618     return;
00619   }
00620   
00621   prop = dev->findProp("DEVICE_PORT");
00622   if (!prop) return;
00623   
00624   el   = prop->findElement("PORT");
00625   
00626   if (!el->write_w)
00627    return;
00628    
00629   el->write_w->setText(port);
00630   
00631   prop->newText();
00632 
00633 }
00634 
00635     
00636 void KStars::setINDITargetCoord(QString deviceName, double RA, double DEC)
00637 {
00638   INDI_D *dev;
00639   INDI_P *prop;
00640   INDI_E *el;
00641   
00642   if (!indidriver || !indimenu)
00643   {
00644     kdDebug() << "setINDITarget: establishINDI() failed." << endl;
00645     return;
00646   }
00647   
00648   dev = indimenu->findDevice(deviceName);
00649   if (!dev)
00650      dev = indimenu->findDeviceByLabel(deviceName);
00651   if (!dev)
00652   {
00653     kdDebug() << "Device " << deviceName << " not found!" << endl;
00654     return;
00655   }
00656   
00657   prop = dev->findProp("EQUATORIAL_EOD_COORD");
00658   if (!prop) return;
00659   
00660   el   = prop->findElement("RA");
00661   if (!el) return;
00662   if (!el->write_w) return;
00663   
00664   el->write_w->setText(QString("%1").arg(RA));
00665   
00666   el  = prop->findElement("DEC");
00667   if (!el) return;
00668   if (!el->write_w) return;
00669   
00670   el->write_w->setText(QString("%1").arg(DEC));
00671   
00672   prop->newText();
00673   
00674 }
00675 
00676     
00677 void KStars::setINDITargetName(QString deviceName, QString objectName)
00678 {
00679   INDI_D *dev;
00680   INDI_P *prop;
00681   INDI_E *el;
00682   
00683   if (!indidriver || !indimenu)
00684   {
00685     kdDebug() << "setINDITarget: establishINDI() failed." << endl;
00686     return;
00687   }
00688 
00689   SkyObject *target = data()->objectNamed( objectName );
00690   if (!target) return;
00691   
00692   dev = indimenu->findDevice(deviceName);
00693   if (!dev)
00694     dev = indimenu->findDeviceByLabel(deviceName);
00695   if (!dev)
00696   {
00697     kdDebug() << "Device " << deviceName << " not found!" << endl;
00698     return;
00699   }
00700   
00701   prop = dev->findProp("EQUATORIAL_EOD_COORD");
00702   if (!prop) return;
00703   
00704   el   = prop->findElement("RA");
00705   if (!el) return;
00706   if (!el->write_w) return;
00707   
00708   el->write_w->setText(QString("%1").arg(target->ra()->Hours()));
00709   
00710   el  = prop->findElement("DEC");
00711   if (!el) return;
00712   if (!el->write_w) return;
00713   
00714   el->write_w->setText(QString("%1").arg(target->dec()->Degrees()));
00715   
00716   prop->newText();
00717 
00718 }
00719 
00720     
00721 void KStars::setINDIAction(QString deviceName, QString action)
00722 {
00723   INDI_D *dev;
00724   INDI_E *el;
00725   
00726   if (!indidriver || !indimenu)
00727   {
00728     kdDebug() << "setINDIAction: establishINDI() failed." << endl;
00729     return;
00730   }
00731   
00732   dev = indimenu->findDevice(deviceName);
00733   if (!dev)
00734     dev = indimenu->findDeviceByLabel(deviceName);
00735   if (!dev)
00736   {
00737     kdDebug() << "Device " << deviceName << " not found!" << endl;
00738     return;
00739   }
00740   
00741   el = dev->findElem(action);
00742   if (!el) return;
00743   
00744   el->pp->activateSwitch(action);
00745   
00746 }
00747 
00748     
00749 void KStars::waitForINDIAction(QString deviceName, QString action)
00750 {
00751 
00752   INDI_D *dev;
00753   INDI_P *prop;
00754   INDI_E *el;
00755   
00756   if (!indidriver || !indimenu)
00757   {
00758     kdDebug() << "waitForINDIAction: establishINDI() failed." << endl;
00759     return;
00760   }
00761   
00762   dev = indimenu->findDevice(deviceName);
00763   if (!dev)
00764     dev = indimenu->findDeviceByLabel(deviceName);
00765   if (!dev)
00766   {
00767     kdDebug() << "Device " << deviceName << " not found!" << endl;
00768     return;
00769   }
00770   
00771   prop = dev->findProp(action);
00772   
00773   if (prop == NULL)
00774   {
00775     el = dev->findElem(action);
00776     if (!el) return;
00777     
00778     QObject::connect(el->pp, SIGNAL(okState()), this, SLOT(resumeDCOP(void )));
00779   }
00780   else
00781     QObject::connect(prop, SIGNAL(okState()), this, SLOT(resumeDCOP(void )));
00782   
00783   kapp->dcopClient()->suspend();
00784   
00785 }
00786 
00787     
00788 void KStars::setINDIFocusSpeed(QString deviceName, unsigned int speed)
00789 {
00790   INDI_D *dev;
00791   INDI_P *prop;
00792   INDI_E *el;
00793 
00794   if (!indidriver || !indimenu)
00795   {
00796     kdDebug() << "setINDIFocusSpeed: establishINDI() failed." << endl;
00797     return;
00798   }
00799 
00800   dev = indimenu->findDevice(deviceName);
00801   if (!dev)
00802     dev = indimenu->findDeviceByLabel(deviceName);
00803   if (!dev)
00804   {
00805     kdDebug() << "Device " << deviceName << " not found!" << endl;
00806     return;
00807   }
00808   
00809   prop = dev->findProp("FOCUS_SPEED");
00810   if (!prop) return;
00811   
00812   el   = prop->findElement("SPEED");
00813   if (!el) return;
00814   if (!el->write_w) return;
00815   
00816   el->write_w->setText(QString("%1").arg(speed));
00817 
00818   prop->newText();
00819 
00820 }
00821 
00822     
00823 void KStars::startINDIFocus(QString deviceName, int focusDir)
00824 {
00825   if (!indidriver || !indimenu)
00826   {
00827     kdDebug() << "setINDIFocusSpeed: establishINDI() failed!" << endl;
00828     return;
00829   }
00830 
00831   if (focusDir == 0)
00832     setINDIAction(deviceName, "IN");
00833   else if (focusDir == 1)
00834     setINDIAction(deviceName, "OUT");
00835 
00836 }
00837 
00838     
00839 void KStars::setINDIGeoLocation(QString deviceName, double longitude, double latitude)
00840 {
00841   
00842   INDI_D *dev;
00843   INDI_P *prop;
00844   INDI_E *el;
00845   
00846   if (!indidriver || !indimenu)
00847   {
00848     kdDebug() << "setINDIGeoLocation: establishINDI() failed." << endl;
00849     return;
00850   }
00851   
00852   dev = indimenu->findDevice(deviceName);
00853   if (!dev)
00854     dev = indimenu->findDeviceByLabel(deviceName);
00855   if (!dev)
00856   {
00857     kdDebug() << "Device " << deviceName << " not found!" << endl;
00858     return;
00859   }
00860   
00861   prop = dev->findProp("GEOGRAPHICAL_COORD");
00862   if (!prop) return;
00863   
00864   el   = prop->findElement("LONG");
00865   if (!el) return;
00866   if (!el->write_w) return;
00867   
00868   el->write_w->setText(QString("%1").arg(longitude));
00869   
00870   el  = prop->findElement("LAT");
00871   if (!el) return;
00872   if (!el->write_w) return;
00873   
00874   el->write_w->setText(QString("%1").arg(latitude));
00875   
00876   prop->newText();
00877 
00878 }
00879 
00880     
00881 void KStars::setINDIFocusTimeout(QString deviceName, int timeout)
00882 {
00883   INDI_D *dev;
00884   INDI_P *prop;
00885   INDI_E *el;
00886   
00887   if (!indidriver || !indimenu)
00888   {
00889     kdDebug() << "startINDIFocus: establishINDI() failed." << endl;
00890     return;
00891   }
00892 
00893   dev = indimenu->findDevice(deviceName);
00894   if (!dev)
00895     dev = indimenu->findDeviceByLabel(deviceName);
00896   if (!dev)
00897   {
00898     kdDebug() << "Device " << deviceName << " not found!" << endl;
00899     return;
00900   }
00901   
00902   prop = dev->findProp("FOCUS_TIMEOUT");
00903   if (!prop)
00904    return;
00905   
00906   el   = prop->findElement("TIMEOUT");
00907   if (!el) return;
00908   
00909   if (el->write_w)
00910     el->write_w->setText(QString("%1").arg(timeout));
00911   else if (el->spin_w)
00912     el->spin_w->setValue(timeout);
00913   
00914   prop->newText();
00915 
00916 }
00917 
00918     
00919 void KStars::startINDIExposure(QString deviceName, int timeout)
00920 {
00921   INDI_D *dev;
00922   INDI_P *prop;
00923   INDI_E *el;
00924   
00925   if (!indidriver || !indimenu)
00926   {
00927     kdDebug() << "startINDIExposure: establishINDI() failed." << endl;
00928     return;
00929   }
00930   
00931   dev = indimenu->findDevice(deviceName);
00932   if (!dev)
00933     dev = indimenu->findDeviceByLabel(deviceName);
00934   if (!dev)
00935   {
00936     kdDebug() << "Device " << deviceName << " not found!" << endl;
00937     return;
00938   }
00939   
00940   prop = dev->findProp("CCD_EXPOSE_DURATION");
00941   if (!prop) return;
00942   
00943   el   = prop->findElement("EXPOSE_DURATION");
00944   if (!el) return;
00945   
00946   if (el->write_w)
00947     el->write_w->setText(QString("%1").arg(timeout));
00948   else if (el->spin_w)
00949     el->spin_w->setValue(timeout);
00950   
00951   
00952   prop->newText();
00953   
00954 }
00955 
00956 void KStars::setINDIFilterNum(QString deviceName, int filter_num)
00957 {
00958   INDI_D *dev;
00959   INDI_P *prop;
00960   INDI_E *el;
00961   
00962   if (!indidriver || !indimenu)
00963   {
00964     kdDebug() << "setINDIFilterNum: establishINDI() failed." << endl;
00965     return;
00966   }
00967   
00968   dev = indimenu->findDevice(deviceName);
00969   if (!dev)
00970     dev = indimenu->findDeviceByLabel(deviceName);
00971   if (!dev)
00972   {
00973     kdDebug() << "Device " << deviceName << " not found!" << endl;
00974     return;
00975   }
00976   
00977   prop = dev->findProp("FILTER_SLOT");
00978   if (!prop) return;
00979   
00980   el   = prop->findElement("SLOT");
00981   if (!el) return;
00982   
00983   if (el->write_w)
00984     el->write_w->setText(QString("%1").arg(filter_num));
00985   else if (el->spin_w)
00986     el->spin_w->setValue(filter_num);
00987   
00988   prop->newText();
00989   
00990 }
00991         
00992 void KStars::setINDIUTC(QString deviceName, QString UTCDateTime)
00993 {
00994   INDI_D *dev;
00995   INDI_P *prop;
00996   INDI_E *el;
00997   
00998   if (!indidriver || !indimenu)
00999   {
01000     kdDebug() << "startINDIUTC: establishINDI() failed." << endl;
01001     return;
01002   }
01003   
01004   dev = indimenu->findDevice(deviceName);
01005   if (!dev)
01006     dev = indimenu->findDeviceByLabel(deviceName);
01007   if (!dev)
01008   {
01009     kdDebug() << "Device " << deviceName << " not found!" << endl;
01010     return;
01011   }
01012   
01013   prop = dev->findProp("TIME");
01014   if (!prop) return;
01015   
01016   el   = prop->findElement("UTC");
01017   if (!el) return;
01018   if (!el->write_w) return;
01019   
01020   el->write_w->setText(UTCDateTime);
01021   
01022   prop->newText();
01023 
01024 }
01025 
01026 void KStars::setINDIScopeAction(QString deviceName, QString action)
01027 {
01028   setINDIAction(deviceName, action);
01029 }
01030         
01031 void KStars::setINDIFrameType(QString deviceName, QString type)
01032 {
01033   setINDIAction(deviceName, type);
01034 }
01035 
01036 void KStars::setINDICCDTemp(QString deviceName, int temp)
01037 {
01038   INDI_D *dev;
01039   INDI_P *prop;
01040   INDI_E *el;
01041   
01042   if (!indidriver || !indimenu)
01043   {
01044     kdDebug() << "setINDICCDTemp: establishINDI() failed." << endl;
01045     return;
01046   }
01047   
01048   dev = indimenu->findDevice(deviceName);
01049   if (!dev)
01050     dev = indimenu->findDeviceByLabel(deviceName);
01051   if (!dev)
01052   {
01053     kdDebug() << "Device " << deviceName << " not found!" << endl;
01054     return;
01055   }
01056   
01057   prop = dev->findProp("CCD_TEMPERATURE");
01058   if (!prop) return;
01059   
01060   el   = prop->findElement("TEMPERATURE");
01061   if (!el) return;
01062   
01063   if (el->write_w)
01064     el->write_w->setText(QString("%1").arg(temp));
01065   else if (el->spin_w)
01066     el->spin_w->setValue(temp);
01067   
01068   
01069   prop->newText();
01070   
01071 }

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