GemaLib
The GeMA library
Signals | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
GmSimulationLoader Class Reference

Auxiliary class responsible for loading simulation information from a Lua File. More...

#include <gmSimulationLoader.h>

Inheritance diagram for GmSimulationLoader:
Inheritance graph
[legend]
Collaboration diagram for GmSimulationLoader:
Collaboration graph
[legend]

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...
 
LuaEnvprepareSimulationEnvironment (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...
 
GmPluginLoaderpluginLoader () const
 Returns the plugin loader.
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () 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)
 
QThreadthread () 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)
 
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 &regExp, 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< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 

Private Member Functions

LuaEnvloadSharedEnv (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

- Static Public Member Functions inherited from QObject
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)
 
- Protected Member Functions inherited from QObject
QObjectsender () 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)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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.

Member Function Documentation

◆ emmitSectionParsed()

int GmSimulationLoader::emmitSectionParsed ( lua_State *  L)
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

◆ load()

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.

Parameters
simDataThe simulation object that will be filled with loaded data
simFilePath for the simulation file
rsrcFileCan the simulation file be a resource file?
envThe already prepared environment where the simulation will be loaded.
Returns
Returns false if fatal errors where found OR if the simulation was canceled during model parsing.

◆ loadModelInfo()

bool GmSimulationLoader::loadModelInfo ( GmSimulationData simData,
LuaTable globalTab 
)
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.

◆ loadResultsInfo()

bool GmSimulationLoader::loadResultsInfo ( GmSimulationData simData,
LuaTable globalTab 
)
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.

◆ loadSharedBlocks()

bool GmSimulationLoader::loadSharedBlocks ( GmSimulationData simData,
LuaTable globalTab 
)
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.

◆ loadSharedEnv()

LuaEnv * GmSimulationLoader::loadSharedEnv ( GmSimulationData simData,
const QMap< QString, QString > &  globalVars,
bool  redirectPrint,
int  tid 
)
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.

◆ loadSharedEnvironments()

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.

◆ loadSimulationInfo()

bool GmSimulationLoader::loadSimulationInfo ( GmSimulationData simData,
LuaTable globalTab 
)
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.

◆ loadSolutionInfo()

bool GmSimulationLoader::loadSolutionInfo ( GmSimulationData simData,
LuaTable globalTab 
)
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.

◆ prepareSimulationEnvironment()

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.

Parameters
simDataThe simulation object that will be filled with loaded data
simFilePath for the simulation file. Use to define the GemaCurrentFile control variable.
globalVarsUser 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.
stateIf different from NULL, uses the given Lua state as the base for the environment used for loading the simulation.
redirectPrintControls 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).
tidFlag set to 0 when preparing the environment for the main thread and with the thread id otherwise.

◆ replaceDofileInEnv()

void GmSimulationLoader::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.

Parameters
envEnvironment where the dofile() function should be replaced
trackFilesIf true, the dofile replacement tracks which files where loaded and the current file through the global variables GemaCurrentFile and GemaLoadedFiles.
tableIf different from NULL, defines the table where global symbols will be accessed by dofile.

◆ sectionParsed

void GmSimulationLoader::sectionParsed ( QString  section,
LuaTable data 
)
signal

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.

Parameters
sectionThe name of the parsed section ('Simulation', 'Mesh', 'StateVar', ...)
dataA reference to the table storing the section data

◆ setupPlugins()

bool GmSimulationLoader::setupPlugins ( QString  pluginDirs)

Setup plugins, loading information from available options.

Parameters
pluginDirsString with search path for plugins. Different directories are separated by ';'
Returns
Returns false in case of fatal errors that prevent model use

◆ translateDofilePath()

int GmSimulationLoader::translateDofilePath ( lua_State *  L)
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

◆ translatePath()

QString GmSimulationLoader::translatePath ( QString  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.

Parameters
pathPath to be translated

The documentation for this class was generated from the following files: