• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
main.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  main.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon Feb 5 01:11:45 PST 2001
5  copyright : (C) 2001 by Jason Harris
6  email : jharris@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
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. *
15  * *
16  ***************************************************************************/
17 
18 #include <kcmdlineargs.h>
19 #include <kaboutdata.h>
20 #include <klocale.h>
21 #include <kdebug.h>
22 #include <kapplication.h>
23 
24 #include "kstars.h"
25 #include "kstarsdata.h"
26 #include "kstarsdatetime.h"
27 #include "skymap.h"
28 #include "simclock.h"
29 #include "ksnumbers.h"
30 #include "version.h"
31 #include "Options.h"
32 //Added by qt3to4:
33 #include <QPixmap>
34 #include <kglobal.h>
35 
36 
37 static const char description[] =
38  I18N_NOOP("Desktop Planetarium");
39 static const char notice[] =
40  I18N_NOOP("Some images in KStars are for non-commercial use only. See README.images.");
41 
42 
43 int main(int argc, char *argv[])
44 {
45  KAboutData aboutData( "kstars", 0, ki18n("KStars"),
46  KSTARS_VERSION, ki18n(description), KAboutData::License_GPL,
47  ki18n("(c) 2001-2013, The KStars Team"), ki18n(notice), "http://edu.kde.org/kstars");
48  aboutData.addAuthor(ki18n("Jason Harris"),KLocalizedString(), "jharris@30doradus.org", "http://www.30doradus.org");
49  aboutData.addAuthor(ki18n("Jasem Mutlaq"), KLocalizedString(), "mutlaqja@ikarustech.com");
50  aboutData.addAuthor(ki18n("James Bowlin"), KLocalizedString(), "bowlin@mindspring.com");
51  aboutData.addAuthor(ki18n("Pablo de Vicente"), KLocalizedString(), "pvicentea@wanadoo.es");
52  aboutData.addAuthor(ki18n("Thomas Kabelmann"), KLocalizedString(), "tk78@gmx.de");
53  aboutData.addAuthor(ki18n("Heiko Evermann"),KLocalizedString(), "heiko@evermann.de", "http://www.evermann.de");
54  aboutData.addAuthor(ki18n("Carsten Niehaus"), KLocalizedString(), "cniehaus@gmx.de");
55  aboutData.addAuthor(ki18n("Mark Hollomon"), KLocalizedString(), "mhh@mindspring.com");
56  aboutData.addAuthor(ki18n("Alexey Khudyakov"), KLocalizedString(), "alexey.skladnoy@gmail.com");
57  aboutData.addAuthor(ki18n("M&eacute;d&eacute;ric Boquien"), KLocalizedString(), "mboquien@free.fr");
58  aboutData.addAuthor(ki18n("Akarsh Simha"), KLocalizedString(), "akarsh.simha@kdemail.net", "http://www.ph.utexas.edu/~asimha");
59  aboutData.addAuthor(ki18n("J&eacute;r&ocirc;me Sonrier"), KLocalizedString(), "jsid@emor3j.fr.eu.org");
60  aboutData.addAuthor(ki18n("Prakash Mohan"), KLocalizedString(), "prakash.mohan@kdemail.net");
61  aboutData.addAuthor(ki18n("Victor Cărbune"), KLocalizedString(), "victor.carbune@kdemail.net");
62  aboutData.addAuthor(ki18n("Henry de Valence"), KLocalizedString(), "hdevalence@gmail.com");
63  aboutData.addAuthor(ki18n("Samikshan Bairagya"), KLocalizedString(), "samikshan.bairagya@kdemail.net");
64  aboutData.addAuthor(ki18n("Rafał Kułaga"), KLocalizedString(), "rl.kulaga@gmail.com");
65  aboutData.addAuthor(ki18n("Rishab Arora"), KLocalizedString(), "ra.rishab@gmail.com");
66 
67  aboutData.addCredit(ki18n("Valery Kharitonov"), ki18n("Converted labels containing technical terms to links to documentation") );
68  aboutData.addCredit(ki18n("Ana-Maria Constantin"), ki18n("Technical documentation on Astronomy and KStars") );
69  aboutData.addCredit(ki18n("Andrew Stepanenko"), ki18n("Guiding code based on lin_guider") );
70  aboutData.addCredit(ki18n("Nuno Pinheiro"), ki18n("Artwork") );
71 
72  KCmdLineArgs::init( argc, argv, &aboutData );
73 
74  KCmdLineOptions options;
75  options.add("!dump", ki18n( "Dump sky image to file" ));
76  options.add("script ", ki18n( "Script to execute" ));
77  options.add("width ", ki18n( "Width of sky image" ), "640");
78  options.add("height ", ki18n( "Height of sky image" ), "480");
79  options.add("filename ", ki18n( "Filename for sky image" ), "kstars.png");
80  options.add("date ", ki18n( "Date and time" ));
81  options.add("!paused", ki18n( "Start with clock paused" ));
82  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
83  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
84 
85  KApplication a;
86 
87  if ( args->isSet( "dump" ) ) {
88  kDebug() << i18n( "Dumping sky image" );
89 
90  //parse filename and image format
91  const char* format = "PNG";
92  QString fname = args->getOption( "filename" );
93  QString ext = fname.mid( fname.lastIndexOf(".")+1 );
94  if ( ext.toLower() == "png" ) { format = "PNG"; }
95  else if ( ext.toLower() == "jpg" || ext.toLower() == "jpeg" ) { format = "JPG"; }
96  else if ( ext.toLower() == "gif" ) { format = "GIF"; }
97  else if ( ext.toLower() == "pnm" ) { format = "PNM"; }
98  else if ( ext.toLower() == "bmp" ) { format = "BMP"; }
99  else { kWarning() << i18n( "Could not parse image format of %1; assuming PNG.", fname ) ; }
100 
101  //parse width and height
102  bool ok(false);
103  int w(0), h(0);
104  w = args->getOption( "width" ).toInt( &ok );
105  if ( ok ) h = args->getOption( "height" ).toInt( &ok );
106  if ( !ok ) {
107  kWarning() << "Unable to parse arguments: " ;
108  kWarning() << "Width: " << args->getOption( "width" )
109  << " Height: " << args->getOption( "height" ) << endl;
110  return 1;
111  }
112 
113  KStarsData *dat = KStarsData::Create();
114  QObject::connect( dat, SIGNAL( progressText(QString) ), dat, SLOT( slotConsoleMessage(QString) ) );
115  dat->initialize();
116 
117  //Set Geographic Location
118  dat->setLocationFromOptions();
119 
120  //Set color scheme
121  dat->colorScheme()->loadFromConfig();
122 
123  //set clock now that we have a location:
124  //Check to see if user provided a date/time string. If not, use current CPU time
125  QString datestring = args->getOption( "date" );
126  KStarsDateTime kdt;
127  if ( ! datestring.isEmpty() ) {
128  if ( datestring.contains( "-" ) ) { //assume ISODate format
129  if ( datestring.contains( ":" ) ) { //also includes time
130  kdt = KDateTime::fromString( datestring, KDateTime::ISODate );
131  } else { //string probably contains date only
132  kdt.setDate( QDate::fromString( datestring, Qt::ISODate ) );
133  kdt.setTime( QTime( 0, 0, 0 ) );
134  }
135  } else { //assume Text format for date string
136  kdt = dat->geo()->LTtoUT( KDateTime::fromString( datestring, KDateTime::QtTextDate ) );
137  }
138 
139  if ( ! kdt.isValid() ) {
140  kWarning() << i18n( "Using CPU date/time instead." ) ;
141 
142  kdt = KStarsDateTime::currentUtcDateTime();
143  }
144  } else {
145  kdt = KStarsDateTime::currentUtcDateTime();
146  }
147  dat->clock()->setUTC( kdt );
148 
149  KSNumbers num( dat->ut().djd() );
150  // dat->initGuides(&num);
151 
152  SkyMap *map = SkyMap::Create();
153  map->resize( w, h );
154  QPixmap sky( w, h );
155 
156  dat->setFullTimeUpdate();
157  dat->updateTime(dat->geo(), map );
158 
159  SkyPoint dest( Options::focusRA(), Options::focusDec() );
160  map->setDestination( dest );
161  map->destination()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
162  map->setFocus( map->destination() );
163  map->focus()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
164 
165  //Execute the specified script
166  QString scriptfile = args->getOption( "script" );
167  if ( ! scriptfile.isEmpty() ) {
168  if ( dat->executeScript( scriptfile, map ) ) {
169  std::cout << i18n( "Script executed." ).toUtf8().data() << std::endl;
170  } else {
171  kWarning() << i18n( "Could not execute script." ) ;
172  }
173  }
174 
175  qApp->processEvents();
176  map->setupProjector();
177  map->exportSkyImage( &sky );
178  qApp->processEvents();
179 
180  if ( ! sky.save( fname, format ) ) kWarning() << i18n( "Unable to save image: %1 ", fname ) ;
181  else kDebug() << i18n( "Saved to file: %1", fname );
182 
183  delete map;
184  delete dat;
185  return 0;
186  }
187 
188  //start up normally in GUI mode
189 
190  //Try to parse the given date string
191  QString datestring = args->getOption( "date" );
192  //DEBUG
193  kDebug() << "Date string: " << datestring;
194 
195  if ( ! datestring.isEmpty() && ! KStarsDateTime::fromString( datestring ).isValid() ) {
196  kWarning() << i18n( "Using CPU date/time instead." ) ;
197  datestring.clear();
198  }
199 
200  KStars::createInstance( true, ! args->isSet( "paused" ), datestring );
201  args->clear();
202  QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
203  return a.exec();
204 
205 }
Options::focusRA
static double focusRA()
Get Right Ascension of focus position.
Definition: Options.h:1018
notice
static const char notice[]
Definition: main.cpp:39
Options::focusDec
static double focusDec()
Get Declination of focus position.
Definition: Options.h:1037
KStarsDateTime::fromString
static KStarsDateTime fromString(const QString &s)
Definition: kstarsdatetime.cpp:75
KStarsData::clock
SimClock * clock()
Definition: kstarsdata.h:158
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
KStarsData::colorScheme
ColorScheme * colorScheme()
Definition: kstarsdata.h:149
KStarsData::setLocationFromOptions
void setLocationFromOptions()
Set the GeoLocation according to the values stored in the configuration file.
Definition: kstarsdata.cpp:317
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::initialize
bool initialize()
Initialize KStarsData while running splash screen.
Definition: kstarsdata.cpp:138
GeoLocation::LTtoUT
KStarsDateTime LTtoUT(const KStarsDateTime &lt) const
Definition: geolocation.h:234
KStarsData::executeScript
bool executeScript(const QString &name, SkyMap *map)
Execute a script.
Definition: kstarsdata.cpp:746
KStarsDateTime::setDate
void setDate(const QDate &d)
Assign the Date according to a QDate object.
Definition: kstarsdatetime.cpp:119
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
KStarsData::setFullTimeUpdate
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets...
Definition: kstarsdata.cpp:260
KStarsDateTime::setTime
void setTime(const QTime &t)
Assign the Time according to a QTime object.
Definition: kstarsdatetime.cpp:133
SkyMap::Create
static SkyMap * Create()
Definition: skymap.cpp:134
KStarsData::Create
static KStarsData * Create()
Definition: kstarsdata.cpp:93
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
ColorScheme::loadFromConfig
void loadFromConfig()
Read color-scheme data from the Config object.
Definition: colorscheme.cpp:266
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
skymap.h
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
ksnumbers.h
simclock.h
Options.h
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
SkyMap
This is the canvas on which the sky is painted.
Definition: skymap.h:72
description
static const char description[]
Definition: main.cpp:37
KStarsData::updateTime
void updateTime(GeoLocation *geo, SkyMap *skymap, const bool automaticDSTchange=true)
Update the Simulation Clock.
Definition: kstarsdata.cpp:189
kstarsdatetime.h
kstarsdata.h
KStarsData::ut
const KStarsDateTime & ut() const
Definition: kstarsdata.h:140
KStars::createInstance
static KStars * createInstance(bool doSplash, bool clockrunning=true, const QString &startDateString=QString())
Create an instance of this class.
Definition: kstars.cpp:129
main
int main(int argc, char *argv[])
Definition: main.cpp:43
kstars.h
SimClock::setUTC
Q_SCRIPTABLE Q_NOREPLY void setUTC(const KStarsDateTime &newtime)
DBUS function to set the time of the SimClock.
Definition: simclock.cpp:136
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal