GemaLib
The GeMA library
gmSimulationLoader.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMA_SIMULATION_LOADER_H_
25 #define _GEMA_SIMULATION_LOADER_H_
26 
27 #include <QObject>
28 #include <QString>
29 
30 #include <gmLog.h>
31 
32 class GmSimulationData;
33 
34 class GmPluginLoader;
35 class GmPluginInfo;
36 class GmPath;
37 class LuaEnv;
38 class LuaTable;
39 
40 struct lua_State;
41 
44 {
45 Q_OBJECT
46 
47 public:
48  GmSimulationLoader(GmPath* paths);
50 
51  void replaceDofileInEnv(LuaEnv& env, bool trackFiles, QString table = "");
53 
54  bool setupPlugins(QString pluginDirs);
55 
56  bool load(GmSimulationData* simData, QString simFile, bool rsrcFile, LuaEnv* env);
57 
58  bool loadSharedEnvironments(GmSimulationData* simData, const QMap<QString, QString>& globalVars,
59  bool redirectPrint, QList<LuaEnv*>& workerEnvList);
60 
62  const QMap<QString, QString>& globalVars,
63  lua_State* state, bool redirectPrint, int tid);
64 
67 
68 signals:
69 
78  void sectionParsed(QString section, LuaTable& data);
79 
80 private:
81  LuaEnv* loadSharedEnv(GmSimulationData* simData, const QMap<QString, QString>& globalVars,
82  bool redirectPrint, int tid);
83 
84  static int emmitSectionParsed (lua_State* L);
85  static int translateDofilePath(lua_State* L);
86  static QString translateScriptName(void* context, QString scriptName);
87 
88  bool loadSimulationInfo(GmSimulationData* simData, LuaTable& globalTab);
89  bool loadModelInfo (GmSimulationData* simData, LuaTable& globalTab);
90  bool loadSolutionInfo (GmSimulationData* simData, LuaTable& globalTab);
91  bool loadResultsInfo (GmSimulationData* simData, LuaTable& globalTab);
92  bool loadSharedBlocks (GmSimulationData* simData, LuaTable& globalTab);
93 
97 };
98 
99 #endif
100 
bool loadSharedBlocks(GmSimulationData *simData, LuaTable &globalTab)
Loads shared block code from the set of files containing shared blocks stored in the given Lua table.
Definition: gmSimulationLoader.cpp:859
static int translateDofilePath(lua_State *L)
Function called by the Lua script while executing a dofile() call to translate path strings.
Definition: gmSimulationLoader.cpp:727
GmPluginLoader * pluginLoader() const
Returns the plugin loader.
Definition: gmSimulationLoader.h:66
bool setupPlugins(QString pluginDirs)
Setup plugins, loading information from available options.
Definition: gmSimulationLoader.cpp:170
GmLogCategory _logger
The logger object used to emmit messages.
Definition: gmSimulationLoader.h:94
static int emmitSectionParsed(lua_State *L)
Function called by the Lua script to emmit a sectionParsed() signal.
Definition: gmSimulationLoader.cpp:700
Auxiliary class responsible for loading simulation information from a Lua File.
Definition: gmSimulationLoader.h:43
bool loadModelInfo(GmSimulationData *simData, LuaTable &globalTab)
Loads model data from the Lua table received as a parameter.
Definition: gmSimulationLoader.cpp:810
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,...
Definition: gmSimulationLoader.cpp:354
void replaceDofileInEnv(LuaEnv &env, bool trackFiles, QString table="")
Utilitary function used to replace the dofile method inside the given environment so that it can tran...
Definition: gmSimulationLoader.cpp:101
bool loadSolutionInfo(GmSimulationData *simData, LuaTable &globalTab)
Loads solution data from the Lua table received as a parameter.
Definition: gmSimulationLoader.cpp:826
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 ...
Definition: gmSimulationLoader.cpp:413
void sectionParsed(QString section, LuaTable &data)
Signal emmited whenever a model section has been parsed from the Lua file.
QString translatePath(QString path)
Utilitary function used to translate macros in a path, replacing them by the appropriate location.
Definition: gmSimulationLoader.cpp:158
bool load(GmSimulationData *simData, QString simFile, bool rsrcFile, LuaEnv *env)
Loads data defining the model to be simulated.
Definition: gmSimulationLoader.cpp:231
GmPath * _paths
Object storing information about relevant paths used in the simulation.
Definition: gmSimulationLoader.h:95
bool loadResultsInfo(GmSimulationData *simData, LuaTable &globalTab)
Loads results configuration data from the Lua table received as a parameter.
Definition: gmSimulationLoader.cpp:842
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 m...
Definition: gmSimulationLoader.cpp:746
LuaEnv * loadSharedEnv(GmSimulationData *simData, const QMap< QString, QString > &globalVars, bool redirectPrint, int tid)
Worker function for loadSharedEnvironments(), creating the environment for a single thread.
Definition: gmSimulationLoader.cpp:595
bool loadSimulationInfo(GmSimulationData *simData, LuaTable &globalTab)
Loads simulation data from the Lua environment.
Definition: gmSimulationLoader.cpp:766
GmPluginLoader * _pluginLoader
Plugin loader.
Definition: gmSimulationLoader.h:96
GmSimulationLoader(GmPath *paths)
Constructor. Receives as a parameter the object used to control application paths.
Definition: gmSimulationLoader.cpp:70
~GmSimulationLoader()
Destructor.
Definition: gmSimulationLoader.cpp:81