StelScriptMgr.hpp   StelScriptMgr.hpp 
skipping to change at line 43 skipping to change at line 43
#ifdef ENABLE_SCRIPT_CONSOLE #ifdef ENABLE_SCRIPT_CONSOLE
class ScriptConsole; class ScriptConsole;
#endif #endif
//! Manage scripting in Stellarium //! Manage scripting in Stellarium
class StelScriptMgr : public QObject class StelScriptMgr : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString runningScriptId READ runningScriptId NOTIFY runni
ngScriptIdChanged)
#ifdef ENABLE_SCRIPT_CONSOLE #ifdef ENABLE_SCRIPT_CONSOLE
friend class ScriptConsole; friend class ScriptConsole;
#endif #endif
public: public:
StelScriptMgr(QObject *parent=0); StelScriptMgr(QObject *parent=0);
~StelScriptMgr(); ~StelScriptMgr();
QStringList getScriptList(); QStringList getScriptList();
//! Find out if a script is running //! Find out if a script is running
//! @return true if a script is running, else false //! @return true if a script is running, else false
bool scriptIsRunning(); bool scriptIsRunning();
//! Get the ID (filename) of the currently running script //! Get the ID (usually filename) of the currently running script
//! @return Empty string if no script is running, else the //! @return Empty string if no script is running, else the
//! ID of the script which is running. //! ID of the script which is running.
QString runningScriptId(); QString runningScriptId();
// Pre-processor functions // Pre-processor functions
//! Preprocess script, esp. process include instructions.
//! if the command line option --verbose has been given,
//! this dumps the preprocessed script with line numbers attached to
log.
//! This helps to understand the line number given by the usual erro
r message.
bool preprocessScript(const QString& input, QString& output, const Q String& scriptDir); bool preprocessScript(const QString& input, QString& output, const Q String& scriptDir);
bool preprocessScript(QFile &input, QString& output, const QString& scriptDir); bool preprocessScript(QFile &input, QString& output, const QString& scriptDir);
//! Add all the StelModules into the script engine //! Add all the StelModules into the script engine
void addModules(); void addModules();
public slots: public slots:
//! Returns a HTML description of the specified script.
//! Includes name, author, description...
//! @param s the file name of the script whose HTML description is t
o be returned.
//! @param generateDocumentTags if true, the main wrapping document
tags (\<html\>\<body\>...\</body\>\</html\>) are also generated
QString getHtmlDescription(const QString& s, bool generateDocumentTa
gs=true) const;
//! Gets a single line name of the script. //! Gets a single line name of the script.
//! @param s the file name of the script whose name is to be returne d. //! @param s the file name of the script whose name is to be returne d.
//! @return text following a comment with Name: at the start. If no //! @return text following a comment with Name: at the start. If no
//! such comment is found, the file name will be returned. If the f ile //! such comment is found, the file name will be returned. If the f ile
//! is not found or cannot be opened for some reason, an Empty strin g //! is not found or cannot be opened for some reason, an Empty strin g
//! will be returned. //! will be returned.
const QString getName(const QString& s); QString getName(const QString& s) const;
//! Gets the name of the script Author //! Gets the name of the script Author
//! @param s the file name of the script whose name is to be returne d. //! @param s the file name of the script whose name is to be returne d.
//! @return text following a comment with Author: at the start. If no //! @return text following a comment with Author: at the start. If no
//! such comment is found, "" is returned. If the file //! such comment is found, "" is returned. If the file
//! is not found or cannot be opened for some reason, an Empty strin g //! is not found or cannot be opened for some reason, an Empty strin g
//! will be returned. //! will be returned.
const QString getAuthor(const QString& s); QString getAuthor(const QString& s) const;
//! Gets the licensing terms for the script //! Gets the licensing terms for the script
//! @param s the file name of the script whose name is to be returne d. //! @param s the file name of the script whose name is to be returne d.
//! @return text following a comment with License: at the start. If no //! @return text following a comment with License: at the start. If no
//! such comment is found, "" is returned. If the file //! such comment is found, "" is returned. If the file
//! is not found or cannot be opened for some reason, an Empty strin g //! is not found or cannot be opened for some reason, an Empty strin g
//! will be returned. //! will be returned.
const QString getLicense(const QString& s); QString getLicense(const QString& s) const;
//! Gets a description of the script. //! Gets a description of the script.
//! @param s the file name of the script whose name is to be returne d. //! @param s the file name of the script whose name is to be returne d.
//! @return text following a comment with Description: at the start. //! @return text following a comment with Description: at the start.
//! The description is considered to be over when a line with no com ment //! The description is considered to be over when a line with no com ment
//! is found. If no such comment is found, QString("") is returned. //! is found. If no such comment is found, QString("") is returned.
//! If the file is not found or cannot be opened for some reason, an //! If the file is not found or cannot be opened for some reason, an
//! Empty string will be returned. //! Empty string will be returned.
const QString getDescription(const QString& s); QString getDescription(const QString& s) const;
//! Gets the default shortcut of the script. //! Gets the default shortcut of the script.
//! @param s the file name of the script whose name is to be returne d. //! @param s the file name of the script whose name is to be returne d.
//! @return text following a comment with Shortcut: at the start. //! @return text following a comment with Shortcut: at the start.
//! If no such comment is found, QString("") is returned. //! If no such comment is found, QString("") is returned.
//! If the file is not found or cannot be opened for some reason, an //! If the file is not found or cannot be opened for some reason, an
//! Empty string will be returned. //! Empty string will be returned.
const QString getShortcut(const QString& s); QString getShortcut(const QString& s) const;
//! Run the prprocessed script //! Run the script located in the given file. In essence, this calls
//! @param preprocessedScript the string containing the preprocessed prepareScript and runPreprocessedScript.
script. //! @note This is a blocking call! The event queue is held up by cal
//! @return false if the given script could not be run, true otherwi ls of QCoreApplication::processEvents().
se //! @param fileName the location of the file containing the script.
bool runPreprocessedScript(const QString& preprocessedScript); //! @param includePath the directory to use when searching for inclu
de files
//! in the SSC preprocessor. If empty, this will be the same as the
//! directory where the script file resides. If you're running a gen
erated script from
//! a temp directory, but want to include a file from elsewhere, it
//! can be usetul to set it to something else (e.g. in ScriptConsole
).
//! @return false if the named script could not be prepared or run,
true otherwise
bool runScript(const QString& fileName, const QString& includePath="
");
//! Run the script located at the given location //! Runs the script code given. This can be used for quick script ex
ecutions, without having to create a
//! temporary file first.
//! @note This is a blocking call! The event queue is held up by cal
ls of QCoreApplication::processEvents().
//! @param scriptCode The script to execute
//! @param includePath If a null string (the default), no pre-proces
sing is done. If an empty string, the default
//! script directories are used (script/ in both user and install di
rectory). Otherwise, the given directory is used.
//! @return false if the named script code could not be prepared or
run, true otherwise
bool runScriptDirect(const QString& scriptCode, const QString &inclu
dePath = QString());
//! Runs preprocessed script code which has been generated using run
PreprocessedScript().
//! In general, you do not want to use this method, use runScript()
or runScriptDirect() instead.
//! @note This is a blocking call! The event queue is held up by cal
ls of QCoreApplication::processEvents().
//! @param preprocessedScript the string containing the preprocessed
script.
//! @param scriptId The name of the script. Usually should correspon
d to the file name.
//! @return false if the given script code could not be run, true ot
herwise
bool runPreprocessedScript(const QString& preprocessedScript, const
QString &scriptId);
//! Loads a script file and does all preparatory steps except for ac
tually executing the script in the engine.
//! Use runPreprocessedScript to execute the script.
//! It should be safe to call this method from another thread.
//! @param script returns the preprocessed script text
//! @param fileName the location of the file containing the script. //! @param fileName the location of the file containing the script.
//! @param includePath the directory to use when searching for inclu de files //! @param includePath the directory to use when searching for inclu de files
//! in the SSC preprocessor. Usually this will be the same as the //! in the SSC preprocessor. Usually this will be the same as the
//! script file itself, but if you're running a generated script fro m //! script file itself, but if you're running a generated script fro m
//! a temp directory, but want to include a file from elsewhere, it //! a temp directory, but want to include a file from elsewhere, it
//! can be usetul to set it to something else (e.g. in ScriptConsole ). //! can be usetul to set it to something else (e.g. in ScriptConsole ).
//! @return false if the named script could not be run, true otherwi //! @return false if the named script could not be prepared, true ot
se herwise
bool runScript(const QString& fileName, const QString& includePath=" bool prepareScript(QString& script, const QString& fileName, const Q
"); String& includePath="");
//! Stops any running script. //! Stops any running script.
//! @return false if no script was running, true otherwise. //! @return false if no script was running, true otherwise.
void stopScript(); void stopScript();
//! Changes the rate at which the script executes as a multiple of r eal time. //! Changes the rate at which the script executes as a multiple of r eal time.
//! Note that this is not the same as the rate at which simulation t ime passes //! Note that this is not the same as the rate at which simulation t ime passes
//! because the script running at normal rate might set the simulati on time rate //! because the script running at normal rate might set the simulati on time rate
//! to be non-real time. //! to be non-real time.
//! @param r rate, e.g. 2.0 = script runs at twice the normal rate //! @param r rate, e.g. 2.0 = script runs at twice the normal rate
skipping to change at line 150 skipping to change at line 188
//! StelMainScriptAPI can explicitly send information to the ScriptC onsole //! StelMainScriptAPI can explicitly send information to the ScriptC onsole
void debug(const QString& msg); void debug(const QString& msg);
//! cause the emission of the scriptOutput signal. This is so that f unctions in //! cause the emission of the scriptOutput signal. This is so that f unctions in
//! StelMainScriptAPI can explicitly send information to the ScriptC onsole //! StelMainScriptAPI can explicitly send information to the ScriptC onsole
void output(const QString& msg); void output(const QString& msg);
//! Reset output file and cause the emission of an (empty) scriptOut put signal. //! Reset output file and cause the emission of an (empty) scriptOut put signal.
void resetOutput(void); void resetOutput(void);
//! Save output file to new file (in same directory as output.txt).
//! This is required to allow reading with other program on Windows
while output.txt is still open.
void saveOutputAs(const QString &filename);
//! Pause a running script. //! Pause a running script.
void pauseScript(); void pauseScript();
//! Resume a paused script. //! Resume a paused script.
void resumeScript(); void resumeScript();
private slots: private slots:
//! Called at the end of the running threa //! Called at the end of the running threa
void scriptEnded(); void scriptEnded();
signals: signals:
//! Emitted when the running script id changes (also on start/stop)
void runningScriptIdChanged(const QString& id);
//! Notification when a script starts running //! Notification when a script starts running
void scriptRunning(); void scriptRunning();
//! Notification when a script has stopped running //! Notification when a script has stopped running
void scriptStopped(); void scriptStopped();
//! Notification of a script event - warnings, current execution lin e etc. //! Notification of a script event - warnings, current execution lin e etc.
void scriptDebug(const QString&); void scriptDebug(const QString&) const;
//! Notification of a script event - output line. //! Notification of a script event - output line.
void scriptOutput(const QString&); void scriptOutput(const QString&) const;
private: private:
// Utility functions for preprocessor // Utility functions for preprocessor
QMap<QString, QString> mappify(const QStringList& args, bool lowerKe y=false); QMap<QString, QString> mappify(const QStringList& args, bool lowerKe y=false);
bool strToBool(const QString& str); bool strToBool(const QString& str);
//! Generate one StelAction per script. //! Generate one StelAction per script.
//! The name of the action is of the form: "actionScript/<script-pat h>" //! The name of the action is of the form: "actionScript/<script-pat h>"
void initActions(); void initActions();
//! This function is for use with getName, getAuthor and getLicense. //! This function is for use with getName, getAuthor and getLicense.
//! @param s the script id //! @param s the script id
//! @param id the command line id, e.g. "Name" //! @param id the command line id, e.g. "Name"
//! @param notFoundText the text to be returned if the key is not fo und //! @param notFoundText the text to be returned if the key is not fo und
//! @return the text following the id and : on a comment line near t he top of //! @return the text following the id and : on a comment line near t he top of
//! the script file (i.e. before there is a non-comment line). //! the script file (i.e. before there is a non-comment line).
const QString getHeaderSingleLineCommentText(const QString& s, const QString& id, const QString& notFoundText=""); QString getHeaderSingleLineCommentText(const QString& s, const QStri ng& id, const QString& notFoundText="") const;
QScriptEngine engine; QScriptEngine engine;
//! The thread in which scripts are run //! The thread in which scripts are run
StelMainScriptAPI *mainAPI; StelMainScriptAPI *mainAPI;
QString scriptFileName; QString scriptFileName;
//Script engine agent //Script engine agent
StelScriptEngineAgent *agent; StelScriptEngineAgent *agent;
 End of changes. 17 change blocks. 
20 lines changed or deleted 90 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/