1 /***************************************************************************
2 main.cpp - K Desktop Planetarium
4 begin : Mon Feb 5 01:11:45 PST 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <kcmdlineargs.h>
19 #include <kaboutdata.h>
20 #include <dcopclient.h>
25 #include "kstarsdata.h"
26 #include "kstarsdatetime.h"
29 #include "ksnumbers.h"
32 #define KSTARS_VERSION "1.1"
34 static const char description
[] =
35 I18N_NOOP("Desktop Planetarium");
36 static const char notice
[] =
37 I18N_NOOP("Some images in KStars are for non-commercial use only. See README.images.");
40 static KCmdLineOptions options
[] =
42 { "!dump", I18N_NOOP( "Dump sky image to file" ), 0 },
43 { "script ", I18N_NOOP( "Script to execute" ), 0 },
44 { "width ", I18N_NOOP( "Width of sky image" ), "640" },
45 { "height ", I18N_NOOP( "Height of sky image" ), "480" },
46 { "filename ", I18N_NOOP( "Filename for sky image" ), "kstars.png" },
47 { "date ", I18N_NOOP( "Date and time" ), "" },
48 { "!paused", I18N_NOOP( "Start with clock paused" ), 0 },
52 int main(int argc
, char *argv
[])
54 KAboutData
aboutData( "kstars", I18N_NOOP("KStars"),
55 KSTARS_VERSION
, description
, KAboutData::License_GPL
,
56 I18N_NOOP("(c) 2001-2003, The KStars Team"), notice
, "http://edu.kde.org/kstars");
57 aboutData
.addAuthor("Jason Harris",0, "jharris@30doradus.org", "http://www.30doradus.org");
58 aboutData
.addAuthor("Heiko Evermann",0, "heiko@evermann.de", "http://www.evermann.de");
59 aboutData
.addAuthor("Thomas Kabelmann", 0, "tk78@gmx.de", 0);
60 aboutData
.addAuthor("Pablo de Vicente", 0, "pvicentea@wanadoo.es", 0);
61 aboutData
.addAuthor("Jasem Mutlaq", 0, "mutlaqja@ikarustech.com", 0 );
62 aboutData
.addAuthor("Carsten Niehaus", 0, "cniehaus@gmx.de", 0);
63 aboutData
.addAuthor("Mark Hollomon", 0, "mhh@mindspring.com", 0);
64 KCmdLineArgs::init( argc
, argv
, &aboutData
);
65 KCmdLineArgs::addCmdLineOptions( options
); // Add our own options.
66 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
70 if ( args
->isSet( "dump" ) ) {
71 kdDebug() << i18n( "Dumping sky image" ) << endl
;
73 //parse filename and image format
74 const char* format
= "PNG";
75 QString fname
= args
->getOption( "filename" );
76 QString ext
= fname
.mid( fname
.findRev(".")+1 );
77 if ( ext
.lower() == "png" ) { format
= "PNG"; }
78 else if ( ext
.lower() == "jpg" || ext
.lower() == "jpeg" ) { format
= "JPG"; }
79 else if ( ext
.lower() == "gif" ) { format
= "GIF"; }
80 else if ( ext
.lower() == "pnm" ) { format
= "PNM"; }
81 else if ( ext
.lower() == "bmp" ) { format
= "BMP"; }
82 else { kdWarning() << i18n( "Could not parse image format of %1; assuming PNG." ).arg( fname
) << endl
; }
84 //parse width and height
87 w
= args
->getOption( "width" ).toInt( &ok
);
88 if ( ok
) h
= args
->getOption( "height" ).toInt( &ok
);
90 kdWarning() << "Unable to parse arguments: " << endl
;
91 kdWarning() << "Width: " << args
->getOption( "width" )
92 << " Height: " << args
->getOption( "height" ) << endl
;
96 KStarsData
*dat
= new KStarsData();
97 QObject::connect( dat
, SIGNAL( progressText(QString
) ), dat
, SLOT( slotConsoleMessage(QString
) ) );
99 while (!dat
->startupComplete
) { kapp
->processEvents(50); }
101 //Set Geographic Location
102 dat
->setLocationFromOptions();
105 dat
->colorScheme()->loadFromConfig( kapp
->config() );
107 //set clock now that we have a location:
108 //Check to see if user provided a date/time string. If not, use current CPU time
109 QString datestring
= args
->getOption( "date" );
111 if ( ! datestring
.isEmpty() ) {
112 if ( datestring
.contains( "-" ) ) { //assume ISODate format
113 if ( datestring
.contains( ":" ) ) { //also includes time
114 kdt
= KStarsDateTime::fromString( datestring
, Qt::ISODate
);
115 } else { //string probably contains date only
116 kdt
.setDate( ExtDate::fromString( datestring
, Qt::ISODate
) );
117 kdt
.setTime( QTime( 0, 0, 0 ) );
119 } else { //assume Text format for date string
120 kdt
= dat
->geo()->LTtoUT( KStarsDateTime::fromString( datestring
, Qt::TextDate
) );
123 if ( ! kdt
.isValid() ) {
124 kdWarning() << i18n( "Could not parse Date/Time string: " ) << datestring
<< endl
;
125 kdWarning() << i18n( "Valid date formats: " ) << endl
;
126 kdWarning() << " 1950-02-25 ; 1950-02-25 05:30:00" << endl
;
127 kdWarning() << " Feb 25 1950 ; Feb 25 1950 05:30:00" << endl
;
128 kdWarning() << " 25 Feb 1950 ; 25 Feb 1950 05:30:00" << endl
;
129 kdWarning() << i18n( "Using CPU date/time instead." ) << endl
;
131 kdt
= dat
->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
134 kdt
= dat
->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
136 dat
->clock()->setUTC( kdt
);
138 KSNumbers
num( dat
->ut().djd() );
139 dat
->initGuides(&num
);
141 SkyMap
*map
= new SkyMap( dat
);
145 dat
->setFullTimeUpdate();
146 dat
->updateTime(dat
->geo(), map
);
148 map
->setDestination( new SkyPoint( Options::focusRA(), Options::focusDec() ) );
149 map
->destination()->EquatorialToHorizontal( dat
->lst(), dat
->geo()->lat() );
150 map
->setFocus( map
->destination() );
151 map
->focus()->EquatorialToHorizontal( dat
->lst(), dat
->geo()->lat() );
153 //Execute the specified script
154 QString scriptfile
= args
->getOption( "script" );
155 if ( ! scriptfile
.isEmpty() ) {
156 if ( dat
->executeScript( scriptfile
, map
) ) {
157 std::cout
<< i18n( "Script executed." ).utf8() << std::endl
;
159 kdWarning() << i18n( "Could not execute script." ) << endl
;
163 map
->setMapGeometry();
164 map
->exportSkyImage( &sky
);
165 kapp
->processEvents(100000);
167 if ( ! sky
.save( fname
, format
) ) kdWarning() << i18n( "Unable to save image: %1 " ).arg( fname
) << endl
;
168 else kdDebug() << i18n( "Saved to file: %1" ).arg( fname
) << endl
;
175 //start up normally in GUI mode
177 //warn about invalid dates
178 QString datestring
= args
->getOption( "date" );
179 if ( ! datestring
.isEmpty() && ! KStarsDateTime::fromString( datestring
).isValid() )
180 kdWarning() << i18n("Specified date (%1) is invalid. Will use current CPU date instead." ).arg( datestring
) << endl
;
182 new KStars( true, ! args
->isSet( "paused" ), datestring
);
183 QObject::connect(kapp
, SIGNAL(lastWindowClosed()), kapp
, SLOT(quit()));