![]() |
GemaLib
The GeMA library
|
Auxiliary class responsible for loading simulation information from a Lua File. More...
#include <gmSimulationLoader.h>
Signals | |
void | sectionParsed (QString section, LuaTable &data) |
Signal emmited whenever a model section has been parsed from the Lua file. More... | |
Public Member Functions | |
GmSimulationLoader (GmPath *paths) | |
Constructor. Receives as a parameter the object used to control application paths. | |
~GmSimulationLoader () | |
Destructor. | |
void | replaceDofileInEnv (LuaEnv &env, bool trackFiles, QString table="") |
Utilitary function used to replace the dofile method inside the given environment so that it can translate path macros in the same way as translatePath() and load data from resources. It also adjusts the loading path for resources. More... | |
QString | translatePath (QString path) |
Utilitary function used to translate macros in a path, replacing them by the appropriate location. More... | |
bool | setupPlugins (QString pluginDirs) |
Setup plugins, loading information from available options. More... | |
bool | load (GmSimulationData *simData, QString simFile, bool rsrcFile, LuaEnv *env) |
Loads data defining the model to be simulated. More... | |
bool | loadSharedEnvironments (GmSimulationData *simData, const QMap< QString, QString > &globalVars, bool redirectPrint, QList< LuaEnv * > &workerEnvList) |
Similar to load(), this function creates and prepares the Lua environments needed by worker threads, already "populated" with shared code blocks obtained from the load of the main simulation file. It also patches function definitions with the appropriate function references for each environment. More... | |
LuaEnv * | prepareSimulationEnvironment (GmSimulationData *simData, QString simFile, const QMap< QString, QString > &globalVars, lua_State *state, bool redirectPrint, int tid) |
Creates and prepares the Lua environment that will be used to load the simulation file / shared code block. More... | |
GmPluginLoader * | pluginLoader () const |
Returns the plugin loader. | |
![]() | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Private Member Functions | |
LuaEnv * | loadSharedEnv (GmSimulationData *simData, const QMap< QString, QString > &globalVars, bool redirectPrint, int tid) |
Worker function for loadSharedEnvironments(), creating the environment for a single thread. More... | |
bool | loadSimulationInfo (GmSimulationData *simData, LuaTable &globalTab) |
Loads simulation data from the Lua environment. More... | |
bool | loadModelInfo (GmSimulationData *simData, LuaTable &globalTab) |
Loads model data from the Lua table received as a parameter. More... | |
bool | loadSolutionInfo (GmSimulationData *simData, LuaTable &globalTab) |
Loads solution data from the Lua table received as a parameter. More... | |
bool | loadResultsInfo (GmSimulationData *simData, LuaTable &globalTab) |
Loads results configuration data from the Lua table received as a parameter. More... | |
bool | loadSharedBlocks (GmSimulationData *simData, LuaTable &globalTab) |
Loads shared block code from the set of files containing shared blocks stored in the given Lua table. More... | |
Static Private Member Functions | |
static int | emmitSectionParsed (lua_State *L) |
Function called by the Lua script to emmit a sectionParsed() signal. More... | |
static int | translateDofilePath (lua_State *L) |
Function called by the Lua script while executing a dofile() call to translate path strings. More... | |
static QString | translateScriptName (void *context, QString scriptName) |
Callback called by the replaced dofile from LuaEnv to adjust the given script name for use in error messages. | |
Private Attributes | |
GmLogCategory | _logger |
The logger object used to emmit messages. | |
GmPath * | _paths |
Object storing information about relevant paths used in the simulation. | |
GmPluginLoader * | _pluginLoader |
Plugin loader. | |
Additional Inherited Members | |
![]() | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
![]() | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
![]() | |
objectName | |
Auxiliary class responsible for loading simulation information from a Lua File.
Besides providing methods to load the contents of the multpile sections present in a simulation file, this class also presents services to handle path translation (replacing macros) that can be usefull while reading other configuration files, through the use of a global GmPath object.
The simulation loading routines use as support some Lua routines that can be found in the simulationLoader.lua and its auxiliary Lua files included in the library resources.
|
staticprivate |
Function called by the Lua script to emmit a sectionParsed() signal.
Expects as parameters in the Lua stack the section name and a reference to the Lua table defining the section
bool GmSimulationLoader::load | ( | GmSimulationData * | simData, |
QString | simFile, | ||
bool | rsrcFile, | ||
LuaEnv * | env | ||
) |
Loads data defining the model to be simulated.
Must be called AFTER a succesfull call to setupPlugins(), AFTER the path object has been informed about the simulation file by a call to gmPath::setSimulationPath() and AFTER setting up the simulation environment by calling prepareSimulationEnvironment().
The filled Lua environment must be kept by the caller as the model might hold references to functions loaded inside this environment. It's the caller responsibility to delete the environment after simulation execution.
simData | The simulation object that will be filled with loaded data |
simFile | Path for the simulation file |
rsrcFile | Can the simulation file be a resource file? |
env | The already prepared environment where the simulation will be loaded. |
|
private |
Loads model data from the Lua table received as a parameter.
The actual data loading is done by an instance of a GmModelLoader object and attribute checking by routines in modelDataLoader.lua.
Returns false in case of errors while parsing the model.
|
private |
Loads results configuration data from the Lua table received as a parameter.
The actual data loading is done by an instance of a GmResultsLoader object and attribute checking by routines in resultsDataLoader.lua.
Returns false in case of errors while parsing the results configuration.
|
private |
Loads shared block code from the set of files containing shared blocks stored in the given Lua table.
The actual data loading is done by an instance of a GmSharedCodeLoader object and attribute checking by routines in simulationLoader.lua.
Returns false in case of errors while parsing code blocks.
|
private |
Worker function for loadSharedEnvironments(), creating the environment for a single thread.
The tid parameter defines the thread index to which this Lua environment will be associated. Remaining function parameters are the same as the ones received by load()
Returns NULL if the environment could not be prepared. On success, returns the prepared environment.
bool GmSimulationLoader::loadSharedEnvironments | ( | GmSimulationData * | simData, |
const QMap< QString, QString > & | globalVars, | ||
bool | redirectPrint, | ||
QList< LuaEnv * > & | workerEnvList | ||
) |
Similar to load(), this function creates and prepares the Lua environments needed by worker threads, already "populated" with shared code blocks obtained from the load of the main simulation file. It also patches function definitions with the appropriate function references for each environment.
Main function parameters are the same as the ones received by load(). The last parameter, workerEnvList, is filled with the set of created environments, one for each of the worker threads in the thread manager.
Returns false if the environments could not be prepared.
|
private |
Loads simulation data from the Lua environment.
Obs: Check for required fields where done by the Simulation() call while parsing the simulation file. All data read from the file is accessible through the globalTab table.
Returns false if the simulation can't be loaded.
|
private |
Loads solution data from the Lua table received as a parameter.
The actual data loading is done by an instance of a GmSolutionLoader object and attribute checking by routines in solutionDataLoader.lua.
Returns false in case of errors while parsing the solution defintion.
LuaEnv * GmSimulationLoader::prepareSimulationEnvironment | ( | GmSimulationData * | simData, |
QString | simFile, | ||
const QMap< QString, QString > & | globalVars, | ||
lua_State * | state, | ||
bool | redirectPrint, | ||
int | tid | ||
) |
Creates and prepares the Lua environment that will be used to load the simulation file / shared code block.
The tid parameter should be set to 0 when preparing the environment for loading the main simulation code and to the associated thread id when preparing to load shared blocks code.
If the state parameter is different from NULL, uses the given Lua state as the base for the simulation environment. If NULL, creates a new Lua state.
Returns NULL if the environment could not be prepared and the simulation cannot be loaded. On success, returns the prepared environment.
simData | The simulation object that will be filled with loaded data |
simFile | Path for the simulation file. Use to define the GemaCurrentFile control variable. |
globalVars | User supplied values for global variables that will be definied on the simulation environment. The map should be keyed by the variable name and its value should be equal the string needed to initialize the variable following the Lua syntax, such as that the statement key = value can be interpreted by Lua. This is used, for example, to fill the userParams global variable. |
state | If different from NULL, uses the given Lua state as the base for the environment used for loading the simulation. |
redirectPrint | Controls whether the standard Lua print() function will be redirected to the GeMA logger or not (this might be important when embedding the GeMA library inside other applications that already handle the print() call). |
tid | Flag set to 0 when preparing the environment for the main thread and with the thread id otherwise. |
Utilitary function used to replace the dofile method inside the given environment so that it can translate path macros in the same way as translatePath() and load data from resources. It also adjusts the loading path for resources.
env | Environment where the dofile() function should be replaced |
trackFiles | If true, the dofile replacement tracks which files where loaded and the current file through the global variables GemaCurrentFile and GemaLoadedFiles. |
table | If different from NULL, defines the table where global symbols will be accessed by dofile. |
Signal emmited whenever a model section has been parsed from the Lua file.
This signal is emmited while the model file is beeing parsed during the Lua file load.
section | The name of the parsed section ('Simulation', 'Mesh', 'StateVar', ...) |
data | A reference to the table storing the section data |
bool GmSimulationLoader::setupPlugins | ( | QString | pluginDirs | ) |
Setup plugins, loading information from available options.
pluginDirs | String with search path for plugins. Different directories are separated by ';' |
|
staticprivate |
Function called by the Lua script while executing a dofile() call to translate path strings.
Expects as parameters in the Lua stack the path name. Returns the translated path
Utilitary function used to translate macros in a path, replacing them by the appropriate location.
Works as a simple wrapper above the function GmPath::translatePath(). See the associated documentation for a list of accepted macros.
path | Path to be translated |