Subversion Repositories public iLand

Rev

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

Rev Author Line No. Line
674 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
#include "firescript.h"
20
#include "firemodule.h"
680 werner 21
#include "helper.h"
674 werner 22
 
697 werner 23
/** @class FireScript
24
    @ingroup firemodule
25
    FireScript is the scripting shell for the fire module.
26
  */
674 werner 27
FireScript::FireScript(QObject *parent) :
28
    QObject(parent)
29
{
30
    mFire = 0;
31
}
32
 
33
double FireScript::ignite(double x, double y, double firesize, double windspeed, double winddirection)
34
{
757 werner 35
    double result=-1.;
756 werner 36
    if (x>=0 && y>=0) {
757 werner 37
        result = mFire->prescribedIgnition(x, y, firesize, windspeed, winddirection);
756 werner 38
        qDebug() << "FireeBvent triggered by javascript: " << x << y << firesize << windspeed << winddirection;
39
    } else {
758 werner 40
        //int idx, gen, refill;
41
        //RandomGenerator::debugState(idx, gen, refill);
42
        //qDebug() << "before-ignite:" << idx << gen << refill;
43
 
756 werner 44
        int old_id = mFire->fireId();
757 werner 45
        bool only_ignite = firesize == -1;
46
        result = mFire->ignition(only_ignite);
756 werner 47
        if (mFire->fireId() != old_id)
757 werner 48
            qDebug() << "Burning fire triggered from javascript!" << result;
756 werner 49
       }
757 werner 50
    return result;
674 werner 51
}
680 werner 52
 
802 werner 53
QString FireScript::fireRUValueType=QLatin1String("");
54
 
680 werner 55
QString fireRUValue(const FireRUData &data) {
802 werner 56
    if (FireScript::fireRUValueType=="kbdi") return QString::number(data.kbdi());
57
    if (FireScript::fireRUValueType=="dbh") return QString::number(data.fireRUStats.avg_dbh);
58
    if (FireScript::fireRUValueType=="crownkill") return QString::number(data.fireRUStats.crown_kill);
59
    if (FireScript::fireRUValueType=="basalarea") return QString::number(data.fireRUStats.basal_area>0?data.fireRUStats.died_basal_area / data.fireRUStats.basal_area:0.);
60
    if (FireScript::fireRUValueType=="baseIgnition") return QString::number(data.baseIgnitionProbability());
680 werner 61
    return "Error";
62
}
63
 
64
bool FireScript::gridToFile(QString grid_type, QString file_name)
65
{
66
    if (!GlobalSettings::instance()->model())
67
        return false;
68
    QString result;
69
    if (grid_type == "spread") {
70
        result = gridToESRIRaster(mFire->mGrid);
71
    } else {
72
        fireRUValueType = grid_type;
73
        result = gridToESRIRaster(mFire->mRUGrid, &fireRUValue); // use a specific value function (see above)
74
    }
75
 
76
    if (!result.isEmpty()) {
77
        file_name = GlobalSettings::instance()->path(file_name);
78
        Helper::saveToTextFile(file_name, result);
79
        qDebug() << "saved grid to " << file_name;
80
        return true;
81
    }
82
    qDebug() << "could not save gridToFile because" << grid_type << "is not a valid grid.";
83
    return false;
84
 
85
}
696 werner 86
 
757 werner 87
double FireScript::x() const
88
{
89
    if (mFire) return mFire->fireX(); else return -1;
90
}
91
 
92
double FireScript::y() const
93
{
94
    if (mFire) return mFire->fireY(); else return -1;
95
}
96
 
696 werner 97
int FireScript::id() const
98
{
757 werner 99
    if (!mFire) return -1;
696 werner 100
    return mFire->fireId();
101
}