Stellarium 0.12.0
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · Renderer · File Structure

StelScriptMgr.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Fabien Chereau, 2009 Matthew Gates
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _STELSCRIPTMGR_HPP_
00021 #define _STELSCRIPTMGR_HPP_
00022 
00023 #include <QObject>
00024 #include <QtScript>
00025 #include <QStringList>
00026 #include <QFile>
00027 #include <QTime>
00028 #include <QTimer>
00029 #include <QScriptEngineAgent>
00030 
00031 class StelMainScriptAPI;
00032 class StelScriptEngineAgent;
00033 
00034 #ifdef ENABLE_SCRIPT_CONSOLE
00035 class ScriptConsole;
00036 #endif
00037 
00039 class StelScriptMgr : public QObject
00040 {
00041     Q_OBJECT
00042         
00043 #ifdef ENABLE_SCRIPT_CONSOLE
00044 friend class ScriptConsole;
00045 #endif
00046 
00047 public:
00048     StelScriptMgr(QObject *parent=0);
00049     ~StelScriptMgr();
00050 
00051     QStringList getScriptList();
00052 
00055     bool scriptIsRunning();
00059     QString runningScriptId();
00060 
00061     // Pre-processor functions
00062     bool preprocessScript(const QString& input, QString& output, const QString& scriptDir);
00063     bool preprocessScript(QFile &input, QString& output, const QString& scriptDir);
00064     
00066     void addModules();
00067 public slots:
00074     const QString getName(const QString& s);
00075 
00082     const QString getAuthor(const QString& s);
00083 
00090     const QString getLicense(const QString& s);
00091 
00099     const QString getDescription(const QString& s);
00100 
00104     bool runPreprocessedScript(const QString& preprocessedScript);
00105 
00114     bool runScript(const QString& fileName, const QString& includePath="");
00115 
00118     void stopScript();
00119 
00125     void setScriptRate(float r);
00126     
00129     double getScriptRate();
00130 
00133     void debug(const QString& msg);
00134 
00136     void pauseScript();
00137 
00139     void resumeScript();
00140 
00141 private slots:
00143     void scriptEnded();
00144 signals:
00146     void scriptRunning();
00148     void scriptStopped();
00150     void scriptDebug(const QString&);
00151 
00152 private:
00153     // Utility functions for preprocessor
00154     QMap<QString, QString> mappify(const QStringList& args, bool lowerKey=false);
00155     bool strToBool(const QString& str);
00156 
00157 #ifdef ENABLE_STRATOSCRIPT_COMPAT
00158     bool preprocessStratoScript(QFile& input, QString& output, const QString& scriptDir);
00159 #endif
00160 
00167     const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText="");  
00168     QScriptEngine engine;
00169     
00171     StelMainScriptAPI *mainAPI;
00172 
00173     QString scriptFileName;
00174     
00175     //Script engine agent
00176     StelScriptEngineAgent *agent;
00177     
00178 };
00179 
00180 class StelScriptEngineAgent : public QScriptEngineAgent
00181 {
00182 public:
00183     explicit StelScriptEngineAgent(QScriptEngine *engine);
00184     virtual ~StelScriptEngineAgent() {}
00185 
00186     void setPauseScript(bool pause) { isPaused=pause; }
00187     bool getPauseScript() { return isPaused; }
00188 
00189     void positionChange(qint64 scriptId, int lineNumber, int columnNumber);
00190     
00191 private:
00192     bool isPaused;
00193 
00194 };
00195 
00196 #endif // _STELSCRIPTMGR_HPP_
Generated on Thu Jan 31 14:05:42 2013 for Stellarium by  doxygen 1.6.3