00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 );
00066 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00067
00068 KApplication a;
00069
00070 if ( args->isSet( "dump" ) ) {
00071 kdDebug() << i18n( "Dumping sky image" ) << endl;
00072
00073
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
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
00102 dat->setLocationFromOptions();
00103
00104
00105 dat->colorScheme()->loadFromConfig( kapp->config() );
00106
00107
00108
00109 QString datestring = args->getOption( "date" );
00110 KStarsDateTime kdt;
00111 if ( ! datestring.isEmpty() ) {
00112 if ( datestring.contains( "-" ) ) {
00113 if ( datestring.contains( ":" ) ) {
00114 kdt = KStarsDateTime::fromString( datestring, Qt::ISODate );
00115 } else {
00116 kdt.setDate( ExtDate::fromString( datestring, Qt::ISODate ) );
00117 kdt.setTime( QTime( 0, 0, 0 ) );
00118 }
00119 } else {
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
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
00177
00178
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 }