iLand
biteengine.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef BITEENGINE_H
20#define BITEENGINE_H
21
22#include "biteagent.h"
23#include "bitescript.h"
24
25
26namespace BITE {
27
28class BiteOutput; // forward
30{
31public:
33 static BiteEngine *instance() {if (mInstance) return mInstance; mInstance=new BiteEngine(); return mInstance; }
35
36 void setup();
37 void addAgent(BiteAgent *new_agent);
39 BiteAgent *agentByName(QString name);
40 QStringList agentNames();
41
42 // properties
43 QJSEngine *scriptEngine();
44
45 // the current simulation year
46 int currentYear() const {return mYear; }
47 void setYear(int year) {mYear = year; }
48
49 Grid<double>* preparePaintGrid(QObject *handler, QString name);
50 QStringList evaluateClick(QObject *handler, const QPointF coord, const QString &grid_name);
51 double variableValueAt(QObject *handler, const QPointF coord, const int layer_id);
52
53 // functions
54 void run();
55
57 void error(QString error_msg);
58
60 QMutex *serializeJS() { return &mSerialize; }
61
63 void notifyTreeRemoval(Tree* tree, int reason);
64 void addTreeRemovalFunction(int reason, BiteAgent* agent) { mTreeRemovalNotifiers.insert(reason, agent); }
65
66
67 // static functions
68 static QJSValue valueFromJs(const QJSValue &js_value, const QString &key, const QString default_value=QLatin1Literal(""), const QString &errorMessage=QLatin1Literal(""));
69private:
70 void resetErrors();
71 BiteEngine(); // private ctor
72 static BiteEngine *mInstance;
73 QList<BiteAgent*> mAgents;
74 BiteScript mScript;
75 QStringList mErrorStack;
76 bool mHasScriptError;
77 QMutex mSerialize;
78 int mYear;
79 bool mRunning;
80 QMultiHash<int, BiteAgent*> mTreeRemovalNotifiers;
81
82 friend class BiteOutput;
83};
84
85} // end namespaec
86#endif // BITEENGINE_H
Definition: biteagent.h:71
Definition: biteengine.h:30
void error(QString error_msg)
called from agents/items if an error occured during script execution
Definition: biteengine.cpp:217
static QJSValue valueFromJs(const QJSValue &js_value, const QString &key, const QString default_value=QLatin1Literal(""), const QString &errorMessage=QLatin1Literal(""))
Definition: biteengine.cpp:243
double variableValueAt(QObject *handler, const QPointF coord, const int layer_id)
Definition: biteengine.cpp:176
QStringList agentNames()
Definition: biteengine.cpp:131
QStringList evaluateClick(QObject *handler, const QPointF coord, const QString &grid_name)
Definition: biteengine.cpp:160
QJSEngine * scriptEngine()
Definition: biteengine.cpp:139
void run()
Definition: biteengine.cpp:192
BiteAgent * agentByName(QString name)
get agent by name
Definition: biteengine.cpp:123
void addAgent(BiteAgent *new_agent)
Definition: biteengine.cpp:104
~BiteEngine()
Definition: biteengine.cpp:51
int currentYear() const
Definition: biteengine.h:46
QMutex * serializeJS()
safe guard calls to the JS engine (only 1 thread allowed)
Definition: biteengine.h:60
void addTreeRemovalFunction(int reason, BiteAgent *agent)
Definition: biteengine.h:64
void setup()
Definition: biteengine.cpp:61
Grid< double > * preparePaintGrid(QObject *handler, QString name)
Definition: biteengine.cpp:146
static BiteEngine * instance()
get singleton of the BiteEngine
Definition: biteengine.h:33
void setYear(int year)
Definition: biteengine.h:47
void notifyTreeRemoval(Tree *tree, int reason)
called by iLand for every tree that is removed/harvested/died due to disturbance.
Definition: biteengine.cpp:227
Definition: biteoutput.h:27
Definition: bitescript.h:29
Grid class (template).
Definition: grid.h:44
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
Definition: biteagent.cpp:32