Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 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
********************************************************************************************/
19
 
185 werner 20
#ifndef MANAGEMENT_H
21
#define MANAGEMENT_H
22
 
23
#include <QObject>
250 werner 24
#include <QList>
414 werner 25
#include <QtCore/QVariantList>
552 werner 26
#include "scriptglobal.h"
185 werner 27
 
216 werner 28
class Tree;
793 werner 29
class QJSEngine;
30
class Management : public QObject //, protected QScriptable
185 werner 31
{
32
    Q_OBJECT
250 werner 33
    Q_PROPERTY(int count READ count)
564 werner 34
    Q_PROPERTY(double removeFoliage READ removeFoliage WRITE setRemoveFoliage)
35
    Q_PROPERTY(double removeBranch READ removeBranch WRITE setRemoveBranch)
36
    Q_PROPERTY(double removeStem READ removeStem WRITE setRemoveStem)
185 werner 37
public:
38
    Management();
39
    ~Management();
40
    void run();
41
    void loadScript(const QString &fileName);
216 werner 42
    QString scriptFile() const { return mScriptFile; }
767 werner 43
 
564 werner 44
    // property getter & setter for removal fractions
45
    /// removal fraction foliage: 0: 0% will be removed, 1: 100% will be removed from the forest by management operations (i.e. calls to manage() instead of kill())
46
    double removeFoliage() const { return mRemoveFoliage; }
47
    /// removal fraction branch biomass: 0: 0% will be removed, 1: 100% will be removed from the forest by management operations (i.e. calls to manage() instead of kill())
48
    double removeBranch() const { return mRemoveBranch; }
49
    /// removal fraction stem biomass: 0: 0% will be removed, 1: 100% will be removed from the forest by management operations (i.e. calls to manage() instead of kill())
50
    double removeStem() const { return mRemoveStem; }
51
 
52
    void setRemoveFoliage(const double fraction)  { mRemoveFoliage = fraction; }
53
    void setRemoveBranch(const double fraction)  { mRemoveBranch = fraction; }
54
    void setRemoveStem(const double fraction)  { mRemoveStem = fraction; }
55
 
56
    int count() const {return mTrees.count();} ///< return number of trees currently in list
57
 
185 werner 58
public slots:
579 werner 59
    /// calculate the mean value for all trees in the internal list for 'expression' (filtered by the filter criterion)
60
    double mean(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "mean"); }
61
    /// calculate the sum for all trees in the internal list for the 'expression' (filtered by the filter criterion)
62
    double sum(QString expression, QString filter=QString()) { return aggregate_function( expression, filter, "sum"); }
566 werner 63
    /// remove randomly trees until only 'number' of trees remain.
64
    /// return number of removed trees
65
    int remain(int number);
564 werner 66
    /** kill "number" of stems
67
     *  in the percentile interval "from" - "to".
68
     *  remove all if "number" is higher than the count.
69
     *  return the number of removed trees. */
825 werner 70
    int killPct(int pctfrom, int pctto, int number);
71
    int killAll(); ///< kill all trees in the list
914 werner 72
    int disturbanceKill(); ///< kill all trees (disturbance related)
579 werner 73
    /** kill 'fraction' of all trees with 'filter'=true */
825 werner 74
    int kill(QString filter, double fraction);
564 werner 75
    // management
76
    /** kill "number" of stems
77
     *  in the percentile interval "from" - "to".
78
     *  remove all if "number" is higher than the count.
79
     * Use the removal fractions set by the removeStem, removeBranch and removeFoliage properties.
80
     *  return the number of removed trees. */
825 werner 81
    int managePct(int pctfrom, int pctto, int number);
82
    int manageAll(); ///< manage all trees in the list
579 werner 83
    /** manage 'fraction' of all trees with 'filter'=true */
825 werner 84
    int manage(QString filter, double fraction);
1044 werner 85
    /// kill trees, cut down to the ground
86
    void cutAndDrop();
564 werner 87
 
217 werner 88
    double percentile(int pct); ///< get value for the pct th percentile (1..100)
825 werner 89
    int loadAll() { return load(QString()); } ///< load all trees, return number of trees
250 werner 90
    int load(QString filter); ///< load all trees passing the filter in a list, return number of trees
825 werner 91
    int loadResourceUnit(int ruindex); ///< load all trees of a resource index
544 werner 92
    void loadFromTreeList(QList<Tree*>tree_list); ///< load a previously present tree list
555 werner 93
    void loadFromMap(const MapGrid *map_grid, int key); ///< load all trees that are on the area denoted by 'key' of the given grid
604 werner 94
    void loadFromMap(MapGridWrapper *wrap, int key); ///< load all trees that are on the area denoted by 'key' of the given grid (script access)
95
    void killSaplings(MapGridWrapper *wrap, int key); ///< kill all saplings that are on the area denoted by 'key' of the given grid (script access)
565 werner 96
    /** hacky access function to resource units covered by a polygon.
97
     the parameters are "remove-fractions": i.e. value=0: no change, value=1: set to zero. */
604 werner 98
    void removeSoilCarbon(MapGridWrapper *wrap, int key, double SWDfrac, double DWDfrac, double litterFrac, double soilFrac);
607 werner 99
    /** slash snags (SWD and otherWood-Pools) of polygon 'key' on the map 'wrap'.
100
      @param slash_fraction 0: no change, 1: 100%
101
       */
102
    void slashSnags(MapGridWrapper *wrap, int key, double slash_fraction);
216 werner 103
    void sort(QString statement); ///< sort trees in the list according to a criterion
250 werner 104
    int filter(QString filter); ///< apply a filter on the list of trees (expression), return number of remaining trees.
848 werner 105
    int filterIdList(QVariantList idList); ///< apply filter in form of a list of ids, return number of remaining trees
579 werner 106
    void randomize(); ///< random shuffle of all trees in the list
185 werner 107
private:
767 werner 108
    QString executeScript(QString cmd="");
564 werner 109
    int remove_percentiles(int pctfrom, int pctto, int number, bool management);
579 werner 110
    int remove_trees(QString expression, double fraction, bool management);
111
    double aggregate_function(QString expression, QString filter, QString type);
793 werner 112
    void throwError(const QString &errormessage);
564 werner 113
 
114
    // removal fractions
115
    double mRemoveFoliage, mRemoveBranch, mRemoveStem;
216 werner 116
    QString mScriptFile;
117
    QList<QPair<Tree*, double> > mTrees;
793 werner 118
    QJSEngine *mEngine;
186 werner 119
    int mRemoved;
185 werner 120
};
121
 
122
#endif // MANAGEMENT_H