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

kstars

main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           main.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Mon Feb  5 01:11:45 PST 2001
00005     copyright            : (C) 2001 by Jason Harris
00006     email                : jharris@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 <kcmdlineargs.h>
00019 #include <kaboutdata.h>
00020 #include <dcopclient.h>
00021 #include <klocale.h>
00022 #include <kdebug.h>
00023 
00024 #include "kstars.h"
00025 #include "kstarsdata.h"
00026 #include "kstarsdatetime.h"
00027 #include "skymap.h"
00028 #include "simclock.h"
00029 #include "ksnumbers.h"
00030 #include "Options.h"
00031 
00032 #define KSTARS_VERSION "1.2.9"
00033 
00034 static const char description[] =
00035     I18N_NOOP("Desktop Planetarium");
00036 static const char notice[] =
00037     I18N_NOOP("Some images in KStars are for non-commercial use only.  See README.images.");
00038 
00039 
00040 static KCmdLineOptions options[] =
00041 {
00042     { "!dump", I18N_NOOP( "Dump sky image to file" ), 0 },
00043     { "script ", I18N_NOOP( "Script to execute" ), 0 },
00044     { "width ", I18N_NOOP( "Width of sky image" ), "640" },
00045     { "height ", I18N_NOOP( "Height of sky image" ), "480" },
00046     { "filename ", I18N_NOOP( "Filename for sky image" ), "kstars.png" },
00047     { "date ", I18N_NOOP( "Date and time" ), "" },
00048     { "!paused", I18N_NOOP( "Start with clock paused" ), 0 },
00049     KCmdLineLastOption
00050 };
00051 
00052 int main(int argc, char *argv[])
00053 {
00054     KAboutData aboutData( "kstars", I18N_NOOP("KStars"),
00055         KSTARS_VERSION, description, KAboutData::License_GPL,
00056         I18N_NOOP("(c) 2001-2003, The KStars Team"), notice, "http://edu.kde.org/kstars");
00057     aboutData.addAuthor("Jason Harris",0, "jharris@30doradus.org", "http://www.30doradus.org");
00058     aboutData.addAuthor("Heiko Evermann",0, "heiko@evermann.de", "http://www.evermann.de");
00059     aboutData.addAuthor("Thomas Kabelmann", 0, "tk78@gmx.de", 0);
00060     aboutData.addAuthor("Pablo de Vicente", 0, "pvicentea@wanadoo.es", 0);
00061     aboutData.addAuthor("Jasem Mutlaq", 0, "mutlaqja@ikarustech.com", 0 );
00062     aboutData.addAuthor("Carsten Niehaus", 0, "cniehaus@gmx.de", 0);
00063     aboutData.addAuthor("Mark Hollomon", 0, "mhh@mindspring.com", 0);
00064     KCmdLineArgs::init( argc, argv, &aboutData );
00065     KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
00066     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00067 
00068     KApplication a;
00069 
00070     if ( args->isSet( "dump" ) ) {
00071         kdDebug() << i18n( "Dumping sky image" ) << endl;
00072 
00073         //parse filename and image format
00074         const char* format = "PNG";
00075         QString fname = args->getOption( "filename" );
00076         QString ext = fname.mid( fname.findRev(".")+1 );
00077         if ( ext.lower() == "png" ) { format = "PNG"; }
00078         else if ( ext.lower() == "jpg" || ext.lower() == "jpeg" ) { format = "JPG"; }
00079         else if ( ext.lower() == "gif" ) { format = "GIF"; }
00080         else if ( ext.lower() == "pnm" ) { format = "PNM"; }
00081         else if ( ext.lower() == "bmp" ) { format = "BMP"; }
00082         else { kdWarning() << i18n( "Could not parse image format of %1; assuming PNG." ).arg( fname ) << endl; }
00083 
00084         //parse width and height
00085         bool ok(false);
00086         int w(0), h(0);
00087         w = args->getOption( "width" ).toInt( &ok );
00088         if ( ok ) h =  args->getOption( "height" ).toInt( &ok );
00089         if ( !ok ) {
00090             kdWarning() << "Unable to parse arguments: " << endl;
00091             kdWarning() << "Width: " << args->getOption( "width" )
00092                 << "  Height: " << args->getOption( "height" ) << endl;
00093             return 1;
00094         }
00095 
00096         KStarsData *dat = new KStarsData();
00097         QObject::connect( dat, SIGNAL( progressText(QString) ), dat, SLOT( slotConsoleMessage(QString) ) );
00098         dat->initialize();
00099         while (!dat->startupComplete) { kapp->processEvents(50); }
00100 
00101         //Set Geographic Location
00102         dat->setLocationFromOptions(); 
00103 
00104         //Set color scheme
00105         dat->colorScheme()->loadFromConfig( kapp->config() );
00106 
00107         //set clock now that we have a location:
00108         //Check to see if user provided a date/time string.  If not, use current CPU time
00109         QString datestring = args->getOption( "date" );
00110         KStarsDateTime kdt;
00111         if ( ! datestring.isEmpty() ) {
00112             if ( datestring.contains( "-" ) ) { //assume ISODate format
00113                 if ( datestring.contains( ":" ) ) { //also includes time
00114                     kdt = KStarsDateTime::fromString( datestring, Qt::ISODate );
00115                 } else { //string probably contains date only
00116                     kdt.setDate( ExtDate::fromString( datestring, Qt::ISODate ) );
00117                     kdt.setTime( QTime( 0, 0, 0 ) );
00118                 }
00119             } else { //assume Text format for date string
00120                 kdt = dat->geo()->LTtoUT( KStarsDateTime::fromString( datestring, Qt::TextDate ) );
00121             }
00122             
00123             if ( ! kdt.isValid() ) {
00124                 kdWarning() << i18n( "Could not parse Date/Time string: " ) << datestring << endl;
00125                 kdWarning() << i18n( "Valid date formats: " ) << endl;
00126                 kdWarning() << "  1950-02-25  ;  1950-02-25 05:30:00" << endl;
00127                 kdWarning() << "  Feb 25 1950 ;  Feb 25 1950 05:30:00" << endl;
00128                 kdWarning() << "  25 Feb 1950 ;  25 Feb 1950 05:30:00" << endl;
00129                 kdWarning() << i18n( "Using CPU date/time instead." ) << endl;
00130                 
00131                 kdt = dat->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
00132             }
00133         } else { 
00134             kdt = dat->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
00135         }
00136         dat->clock()->setUTC( kdt );
00137         
00138         KSNumbers num( dat->ut().djd() );
00139         dat->initGuides(&num);
00140 
00141         SkyMap *map = new SkyMap( dat );
00142         map->resize( w, h );
00143         QPixmap sky( w, h );
00144 
00145         map->setDestination( new SkyPoint( Options::focusRA(), Options::focusDec() ) );
00146         map->destination()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
00147         map->setFocus( map->destination() );
00148         map->focus()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
00149 
00150         //Execute the specified script
00151         QString scriptfile = args->getOption( "script" );
00152         if ( ! scriptfile.isEmpty() ) {
00153             if ( dat->executeScript( scriptfile, map ) ) {
00154                 std::cout << i18n( "Script executed." ).utf8() << std::endl;
00155             } else {
00156                 kdWarning() << i18n( "Could not execute script." ) << endl;
00157             }
00158         }
00159 
00160         dat->setFullTimeUpdate();
00161         dat->updateTime(dat->geo(), map );
00162 
00163         kapp->processEvents(100000);
00164         map->setMapGeometry();
00165         map->exportSkyImage( &sky );
00166         kapp->processEvents(100000);
00167 
00168         if ( ! sky.save( fname, format ) ) kdWarning() << i18n( "Unable to save image: %1 " ).arg( fname ) << endl;
00169         else kdDebug() << i18n( "Saved to file: %1" ).arg( fname ) << endl;
00170 
00171         delete map;
00172         delete dat;
00173         return 0;
00174     }
00175 
00176     //start up normally in GUI mode
00177     
00178     //Try to parse the given date string
00179     QString datestring = args->getOption( "date" );
00180 
00181     if ( ! datestring.isEmpty() && ! KStarsDateTime::fromString( datestring ).isValid() ) {
00182         kdWarning() << i18n("Specified date (%1) is invalid.  Will use current CPU date instead." ).arg( datestring ) << endl;
00183         datestring = "";
00184     }
00185     
00186     new KStars( true, ! args->isSet( "paused" ), datestring );
00187     args->clear();
00188     QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
00189     return a.exec();
00190 
00191 }

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