Subversion Repositories public iLand

Rev

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
********************************************************************************************/
19
 
961 werner 20
#ifndef BARKBEETLESCRIPT_H
21
#define BARKBEETLESCRIPT_H
22
 
23
#include <QObject>
24
#include <QJSValue>
25
 
26
class BarkBeetleModule; // forward
27
 
28
class BarkBeetleScript : public QObject
29
{
30
    Q_OBJECT
962 werner 31
    Q_PROPERTY(QJSValue onClick READ onClick WRITE setOnClick)
1024 werner 32
    Q_PROPERTY(bool simulate READ simulate WRITE setSimulate)
1037 werner 33
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
1024 werner 34
 
961 werner 35
public:
36
    explicit BarkBeetleScript(QObject *parent = 0);
37
    void setBBModule(BarkBeetleModule *module) { mBeetle = module; }
962 werner 38
    QJSValue onClick() const { return mOnClick; }
39
    void setOnClick(QJSValue handler) { mOnClick = handler; }
1029 werner 40
    // properties
41
    bool simulate();
42
    void setSimulate(bool do_simulate);
1037 werner 43
    bool enabled();
44
    void setEnabled(bool do_set_enable);
961 werner 45
signals:
46
 
47
public slots:
48
    void test(QString value);
49
 
50
    void init(QJSValue fun);
51
    void run(QJSValue fun);
52
    double pixelValue(int ix, int iy);
53
    void setPixelValue(int ix, int iy, double val);
1010 werner 54
 
1014 werner 55
    /// access the number of bark beetle generation at position ix/iy (indices on the 10m grid)
1008 werner 56
    double generations(int ix, int iy);
961 werner 57
 
1008 werner 58
    // the real thing
1010 werner 59
    void reloadSettings(); ///< reload the BB-Module settings from the XML-File
1055 werner 60
    void newYear(); ///< start a new "year" (not synced with iLand clock)
1013 werner 61
    void runBB(int iteration); ///< run a full cycle of the bark beetle module
62
    void clear(); ///< reset the barkbeetle module (clear damage and spread data - makes only sense if in simulation mode)
1036 werner 63
    bool gridToFile(QString type, QString filename);
1008 werner 64
 
1081 werner 65
    /// get a JS representation of the grid given by 'type'
66
    QJSValue grid(QString type);
67
    /// number of damaged pixels with a patchsize>'threshold'; save to grid to "fileName" (if not empty)
68
    int damagedArea(int threshold, QString fileName);
1014 werner 69
 
1088 werner 70
    /// clear the 'infested' flags on the stand 'stand_id' (on the given 'standmap').
71
    /// this does not remove trees!
72
    int clearInfestedPixels(QJSValue standmap, int stand_id, double fraction);
1014 werner 73
 
1157 werner 74
    /// initiate damage
75
    /// sets pixel at (x/y) (grid indices) as infested, return true if pixel was a potential host pixel
76
    bool setInfested(int x, int y);
1081 werner 77
 
961 werner 78
private:
1024 werner 79
 
962 werner 80
    QJSValue mOnClick;
961 werner 81
    BarkBeetleModule *mBeetle;
82
 
83
};
84
 
85
#endif // BARKBEETLESCRIPT_H