00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _QTSCRIPTMGR_HPP_
00021 #define _QTSCRIPTMGR_HPP_
00022
00023 #include <QObject>
00024 #include <QtScript>
00025 #include <QStringList>
00026 #include <QFile>
00027 #include "VecMath.hpp"
00028
00035 class StelMainScriptAPI : public QObject
00036 {
00037 Q_OBJECT
00038 Q_PROPERTY(double JDay READ getJDay WRITE setJDay)
00039 Q_PROPERTY(double timeSpeed READ getTimeRate WRITE setTimeRate)
00040
00041 public:
00042 StelMainScriptAPI(QObject *parent = 0);
00043 ~StelMainScriptAPI();
00044
00045
00046 public slots:
00049 void setJDay(double JD);
00052 double getJDay(void) const;
00053
00071 void setDate(const QString& dt, const QString& spec="utc");
00072
00078 void setTimeRate(double ts);
00081 double getTimeRate(void) const;
00082
00085 void wait(double t);
00086
00095 void waitFor(const QString& dt, const QString& spec="utc");
00096
00102 void selectObjectByName(const QString& name, bool pointer=false);
00103
00111 void clear(const QString& state="natural");
00112
00118 void moveToAltAzi(const QString& alt, const QString& azi, float duration=1.);
00119
00125 void moveToRaDec(const QString& ra, const QString& dec, float duration=1.);
00126
00144 void setObserverLocation(double longitude, double latitude, double altitude, double duration=1., const QString& name="", const QString& planet="");
00145
00151 void setObserverLocation(const QString id, double duration=1.);
00152
00158 void screenshot(const QString& prefix, bool invert=false, const QString& dir="");
00159
00163 void setHideGui(bool b);
00164
00170 void setMinFps(float m);
00171
00173 float getMinFps();
00174
00177 void setMaxFps(float m);
00178
00180 float getMaxFps();
00181
00200 void loadSkyImage(const QString& id, const QString& filename,
00201 double ra0, double dec0,
00202 double ra1, double dec1,
00203 double ra2, double dec2,
00204 double ra3, double dec3,
00205 double minRes=2.5, double maxBright=14, bool visible=true);
00206
00210 void loadSkyImage(const QString& id, const QString& filename,
00211 const QString& ra0, const QString& dec0,
00212 const QString& ra1, const QString& dec1,
00213 const QString& ra2, const QString& dec2,
00214 const QString& ra3, const QString& dec3,
00215 double minRes=2.5, double maxBright=14, bool visible=true);
00216
00219 void loadSkyImage(const QString& id, const QString& filename,
00220 double ra, double dec, double angSize, double rotation,
00221 double minRes=2.5, double maxBright=14, bool visible=true);
00222
00225 void loadSkyImage(const QString& id, const QString& filename,
00226 const QString& ra, const QString& dec, double angSize, double rotation,
00227 double minRes=2.5, double maxBright=14, bool visible=true);
00228
00231 void removeSkyImage(const QString& id);
00232
00237 void loadSound(const QString& filename, const QString& id);
00238
00241 void playSound(const QString& id);
00242
00246 void pauseSound(const QString& id);
00247
00252 void stopSound(const QString& id);
00253
00257 void dropSound(const QString& id);
00258
00261 void debug(const QString& s);
00262
00263 signals:
00264 void requestLoadSkyImage(const QString& id, const QString& filename,
00265 double c1, double c2,
00266 double c3, double c4,
00267 double c5, double c6,
00268 double c7, double c8,
00269 double minRes, double maxBright, bool visible);
00270
00271 void requestRemoveSkyImage(const QString& id);
00272
00273 void requestLoadSound(const QString& filename, const QString& id);
00274 void requestPlaySound(const QString& id);
00275 void requestPauseSound(const QString& id);
00276 void requestStopSound(const QString& id);
00277 void requestDropSound(const QString& id);
00278
00279 private:
00283 double jdFromDateString(const QString& dt, const QString& spec);
00284
00285 };
00286
00288 class StelScriptMgr : public QObject
00289 {
00290 Q_OBJECT
00291
00292 public:
00293 StelScriptMgr(QObject *parent=0);
00294 ~StelScriptMgr();
00295
00296 QStringList getScriptList(void);
00297
00300 bool scriptIsRunning(void);
00304 QString runningScriptId(void);
00305
00306 public slots:
00313 const QString getName(const QString& s);
00314
00321 const QString getAuthor(const QString& s);
00322
00329 const QString getLicense(const QString& s);
00330
00338 const QString getDescription(const QString& s);
00339
00343 bool runScript(const QString& fileName);
00344
00347 bool stopScript(void);
00348
00349 private slots:
00351 void scriptEnded();
00352
00353 signals:
00355 void scriptRunning();
00357 void scriptStopped();
00358
00359 private:
00360
00361 QMap<QString, QString> mappify(const QStringList& args, bool lowerKey=false);
00362 bool strToBool(const QString& str);
00363
00364 bool preprocessScript(QFile& input, QFile& output, const QString& scriptDir);
00365
00366 #ifdef ENABLE_STRATOSCRIPT_COMPAT
00367 bool preprocessStratoScript(QFile& input, QFile& output, const QString& scriptDir);
00368 #endif
00369
00376 const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText="");
00377 QScriptEngine engine;
00378
00380 class StelScriptThread* thread;
00381 };
00382
00383 #endif // _QTSCRIPTMGR_HPP_