Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1033 | werner | 1 | /******************************************************************************************** |
2 | ** iLand - an individual based forest landscape and disturbance model |
||
3 | ** http://iland.boku.ac.at |
||
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 | ********************************************************************************************/ |
||
860 | werner | 19 | #ifndef FOMESTP_H |
20 | #define FOMESTP_H |
||
21 | |||
866 | werner | 22 | #include "fmstand.h" |
871 | werner | 23 | #include "activity.h" |
905 | werner | 24 | #include "actsalvage.h" |
871 | werner | 25 | |
867 | werner | 26 | #include <QJSValue> |
870 | werner | 27 | #include <QList> |
28 | |||
29 | class Expression; // forward |
||
30 | |||
907 | werner | 31 | namespace ABE { |
870 | werner | 32 | |
860 | werner | 33 | /** |
34 | * @brief The FMSTP class encapsulates one "stand treatment program", that consists of several "activities". |
||
35 | */ |
||
870 | werner | 36 | class Activity; // forward |
860 | werner | 37 | |
38 | class FMSTP |
||
39 | { |
||
40 | public: |
||
41 | FMSTP(); |
||
870 | werner | 42 | ~FMSTP(); |
871 | werner | 43 | const QString &name() const {return mName; } |
884 | werner | 44 | /// returns the (first) Activity with the name 'name', or 0 if the activity could not be found. |
45 | Activity *activity(const QString &name) const; |
||
888 | werner | 46 | int activityIndex(Activity* act) { return mActivities.indexOf(act); } |
47 | |||
869 | werner | 48 | /// read the options from a javascript structure / object |
871 | werner | 49 | void setup(QJSValue &js_value, const QString name=QString()); |
875 | werner | 50 | /// defaultFlags() is used to initalized the flags for indiv. forest stands |
51 | QVector<ActivityFlags> defaultFlags() {return mActivityStand; } |
||
52 | Events &events() { return mEvents; } |
||
1061 | werner | 53 | QJSValue JSoptions() { return mOptions; } |
866 | werner | 54 | |
875 | werner | 55 | /// rotation length (years) |
942 | werner | 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 |
||
905 | werner | 58 | ActSalvage *salvageActivity() const { return mSalvage; } |
869 | werner | 59 | |
905 | werner | 60 | /// run repeating activities |
897 | werner | 61 | bool executeRepeatingActivities(FMStand *stand); |
875 | werner | 62 | |
944 | werner | 63 | /// evaluate bound expressions for all activities of the STP for the given stand |
64 | void evaluateDynamicExpressions(FMStand *stand); |
||
870 | werner | 65 | // helper functions |
66 | void dumpInfo(); |
||
875 | werner | 67 | /// if verbose is true, detailed debug information is provided. |
68 | static void setVerbose(bool verbose) {mVerbose = verbose; } |
||
69 | static bool verbose() {return mVerbose; } ///< returns true in debug mode |
||
888 | werner | 70 | /// get a property of 'js_value' with the name 'key'. If 'errorMessage' is given, an error is thrown when the key does not exist. |
71 | /// If key is not present and a 'default_value' is given, it is returned. Otherwise, an "undefined" JS value is returned. |
||
72 | static QJSValue valueFromJs(const QJSValue &js_value, const QString &key, const QString default_value=QString(), const QString &errorMessage=QString()); |
||
875 | werner | 73 | static bool boolValueFromJs(const QJSValue &js_value, const QString &key, const bool default_bool_value, const QString &errorMessage=QString()); |
869 | werner | 74 | |
951 | werner | 75 | static bool checkObjectProperties(const QJSValue &js_value, const QStringList &allowed_properties, const QString &errorMessage=QString()); |
76 | |||
870 | werner | 77 | private: |
963 | werner | 78 | void internalSetup(const QJSValue &js_value, int level=0); |
870 | werner | 79 | QString mName; ///< the name of the stand treatment program |
963 | werner | 80 | void setupActivity(const QJSValue &js_value, const QString &name); |
870 | werner | 81 | void clear(); ///< remove all activites |
875 | werner | 82 | Events mEvents; |
869 | werner | 83 | static bool mVerbose; ///< debug mode |
897 | werner | 84 | bool mHasRepeatingActivities; ///< true, if the STP contains repeating activities |
871 | werner | 85 | QVector<Activity*> mActivities; ///< container for the activities of the STP |
86 | QVector<ActivityFlags> mActivityStand; ///< base data for stand-specific STP info. |
||
87 | QStringList mActivityNames; ///< names of all available activities |
||
905 | werner | 88 | // special activities |
89 | ActSalvage *mSalvage; |
||
867 | werner | 90 | |
942 | werner | 91 | // STP-level properties |
92 | int mRotationLength[3]; ///< three levels (low, medium,high) of rotation length |
||
93 | |||
1061 | werner | 94 | QJSValue mOptions; ///< user-defined options of the STP |
95 | |||
860 | werner | 96 | }; |
97 | |||
870 | werner | 98 | } // namespace |
99 | |||
860 | werner | 100 | #endif // FOMESTP_H |