iLand
fmstp.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 FOMESTP_H
20#define FOMESTP_H
21
22#include "fmstand.h"
23#include "activity.h"
24#include "actsalvage.h"
25
26#include <QJSValue>
27#include <QList>
28
29class Expression; // forward
30
31namespace ABE {
32
36class Activity; // forward
37
38class FMSTP
39{
40public:
41 FMSTP();
42 ~FMSTP();
43 const QString &name() const {return mName; }
45 Activity *activity(const QString &name) const;
46 int activityIndex(Activity* act) { return mActivities.indexOf(act); }
47
49 void setup(QJSValue &js_value, const QString name=QString());
51 QVector<ActivityFlags> defaultFlags() {return mActivityStand; }
52 Events &events() { return mEvents; }
53 QJSValue *JSoptions() { return &mOptions; }
54
56 int rotationLengthOfType(const int type) { if (type>0 && type<4) return mRotationLength[type-1]; return 0;}
57 int rotationLengthType(const int length) const { for (int i=0;i<3;++i) if (mRotationLength[i]==length) return i+1; return -1; } // TODO: fix
58 ActSalvage *salvageActivity() const { return mSalvage; }
59
62
65 // helper functions
66 void dumpInfo();
68 static void setVerbose(bool verbose) {mVerbose = verbose; }
69 static bool verbose() {return mVerbose; }
72 static QJSValue valueFromJs(const QJSValue &js_value, const QString &key, const QString default_value=QString(), const QString &errorMessage=QString());
73 static bool boolValueFromJs(const QJSValue &js_value, const QString &key, const bool default_bool_value, const QString &errorMessage=QString());
74
75 static bool checkObjectProperties(const QJSValue &js_value, const QStringList &allowed_properties, const QString &errorMessage=QString());
77 static QJSValue evaluateJS(QJSValue value);
78
79private:
80 void internalSetup(const QJSValue &js_value, int level=0);
81 QString mName;
82 void setupActivity(const QJSValue &js_value, const QString &name);
83 void clear();
84 Events mEvents;
85 static bool mVerbose;
86 bool mHasRepeatingActivities;
87 QVector<Activity*> mActivities;
88 QVector<ActivityFlags> mActivityStand;
89 QStringList mActivityNames;
90 // special activities
91 ActSalvage *mSalvage;
92
93 // STP-level properties
94 int mRotationLength[3];
95
96 QJSValue mOptions;
97
98};
99
100} // namespace
101
102#endif // FOMESTP_H
The ActSalvage class handles salvage logging after disturbances.
Definition: actsalvage.h:33
Activity is the base class for management activities.
Definition: activity.h:162
Definition: activity.h:64
The FMSTP class encapsulates a stand treatment program, which is defined in Javascript.
Definition: fmstp.h:39
int activityIndex(Activity *act)
Definition: fmstp.h:46
const QString & name() const
Definition: fmstp.h:43
static bool checkObjectProperties(const QJSValue &js_value, const QStringList &allowed_properties, const QString &errorMessage=QString())
Definition: fmstp.cpp:247
bool executeRepeatingActivities(FMStand *stand)
run repeating activities
Definition: fmstp.cpp:101
static QJSValue evaluateJS(QJSValue value)
Definition: fmstp.cpp:261
void dumpInfo()
Definition: fmstp.cpp:176
Events & events()
Definition: fmstp.h:52
Activity * activity(const QString &name) const
returns the (first) Activity with the name 'name', or 0 if the activity could not be found.
Definition: fmstp.cpp:55
FMSTP()
Definition: fmstp.cpp:41
int rotationLengthType(const int length) const
Definition: fmstp.h:57
static bool verbose()
returns true in debug mode
Definition: fmstp.h:69
int rotationLengthOfType(const int type)
rotation length (years)
Definition: fmstp.h:56
~FMSTP()
Definition: fmstp.cpp:50
void evaluateDynamicExpressions(FMStand *stand)
evaluate bound expressions for all activities of the STP for the given stand
Definition: fmstp.cpp:123
static bool boolValueFromJs(const QJSValue &js_value, const QString &key, const bool default_bool_value, const QString &errorMessage=QString())
Definition: fmstp.cpp:235
static void setVerbose(bool verbose)
if verbose is true, detailed debug information is provided.
Definition: fmstp.h:68
ActSalvage * salvageActivity() const
Definition: fmstp.h:58
QVector< ActivityFlags > defaultFlags()
defaultFlags() is used to initalized the flags for indiv. forest stands
Definition: fmstp.h:51
static QJSValue valueFromJs(const QJSValue &js_value, const QString &key, const QString default_value=QString(), const QString &errorMessage=QString())
get a property of 'js_value' with the name 'key'.
Definition: fmstp.cpp:222
void setup(QJSValue &js_value, const QString name=QString())
read the options from a javascript structure / object
Definition: fmstp.cpp:68
QJSValue * JSoptions()
Definition: fmstp.h:53
FMStand encapsulates a forest stand for the forest management engine.
Definition: fmstand.h:49
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
Definition: abegrid.h:22