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
********************************************************************************************/
908 werner 19
#include "abe_global.h"
873 werner 20
#include "global.h"
909 werner 21
#include "abegrid.h"
873 werner 22
#include "fmstand.h"
23
#include "fmunit.h"
24
#include "modelcontroller.h"
889 werner 25
#include "scheduler.h"
939 werner 26
#include "agent.h"
1058 werner 27
#include "fmstp.h"
873 werner 28
 
29
 
1095 werner 30
/** @class ABELayers
31
    @ingroup abe
32
    ABELayers is a helper class for spatial visualization of ABE data.
873 werner 33
 
1095 werner 34
  */
35
 
909 werner 36
ABELayers::~ABELayers()
893 werner 37
{
38
    GlobalSettings::instance()->controller()->removeLayers(this);
39
}
40
 
909 werner 41
double ABELayers::value(const FMStandPtr &data, const int index) const
873 werner 42
{
882 werner 43
    if (data == 0 && index<2) return -1; // for classes
877 werner 44
    if (data == 0) return 0;
873 werner 45
    switch (index) {
877 werner 46
    case 0:
47
        if(!mStandIndex.contains(data->id()))
48
            mStandIndex[data->id()] = mStandIndex.count();
49
        return mStandIndex[data->id()]; // "id"
50
    case 1:
51
        if(!mUnitIndex.contains(data->unit()->id()))
52
            mUnitIndex[data->unit()->id()] = mUnitIndex.count();
53
        return mUnitIndex[data->unit()->id()]; // unit
939 werner 54
    case 2:
55
        if(!mAgentIndex.contains(data->unit()->agent()))
56
            mAgentIndex[data->unit()->agent()] = mAgentIndex.count();
57
        return mAgentIndex[data->unit()->agent()]; // unit
58
 
873 werner 59
    case 3: return data->volume(); // "volume"
903 werner 60
    case 4: return data->meanAnnualIncrement(); // mean annual increment m3/ha
930 werner 61
    case 5: return data->meanAnnualIncrementTotal(); // mean annual increment m3/ha
62
    case 6: return data->basalArea(); // "basalArea"
63
    case 7: return data->age(); // "age"
64
    case 8: return data->lastExecution(); // "last evaluation"
65
    case 9: return data->sleepYears(); // "next evaluation"
66
    case 10: return data->lastUpdate(); // last update
67
    case 11: return data->unit()->constScheduler()?data->unit()->constScheduler()->scoreOf(data->id()) : -1.; // scheduler score
1058 werner 68
    case 12: if (!mSTPIndex.contains(data->stp()->name())) // stand treatment program
69
                mSTPIndex[data->stp()->name()] = mSTPIndex.count();
70
             return mSTPIndex[data->stp()->name()];
71
 
889 werner 72
    default: throw IException("ABELayers:value(): Invalid index");
873 werner 73
    }
74
}
75
 
1014 werner 76
const QVector<LayeredGridBase::LayerElement> &ABELayers::names()
873 werner 77
{
1014 werner 78
    if (mNames.isEmpty())
79
        mNames= QVector<LayeredGridBase::LayerElement>()
80
                << LayeredGridBase::LayerElement(QStringLiteral("id"), QStringLiteral("stand ID"), GridViewBrewerDiv)
81
                << LayeredGridBase::LayerElement(QStringLiteral("unit"), QStringLiteral("ID of the management unit"), GridViewBrewerDiv)
82
                << LayeredGridBase::LayerElement(QStringLiteral("agent"), QStringLiteral("managing agent"), GridViewBrewerDiv)
83
                << LayeredGridBase::LayerElement(QStringLiteral("volume"), QStringLiteral("stocking volume (m3/ha)"), GridViewRainbow)
84
                << LayeredGridBase::LayerElement(QStringLiteral("MAI"), QStringLiteral("mean annual increment (of the decade) (m3/ha)"), GridViewRainbow)
85
                << LayeredGridBase::LayerElement(QStringLiteral("MAITotal"), QStringLiteral("mean annual increment (full rotation) (m3/ha)"), GridViewRainbow)
86
                << LayeredGridBase::LayerElement(QStringLiteral("basalArea"), QStringLiteral("stocking basal area (m2/ha)"), GridViewRainbow)
87
                << LayeredGridBase::LayerElement(QStringLiteral("age"), QStringLiteral("stand age"), GridViewRainbow)
88
                << LayeredGridBase::LayerElement(QStringLiteral("last execution"), QStringLiteral("years since the last execution of an activity on the stand."), GridViewHeat)
89
                << LayeredGridBase::LayerElement(QStringLiteral("next evaluation"), QStringLiteral("year of the last execution"), GridViewHeat)
90
                << LayeredGridBase::LayerElement(QStringLiteral("last update"), QStringLiteral("year of the last update of the forest state."), GridViewRainbowReverse)
1058 werner 91
                << LayeredGridBase::LayerElement(QStringLiteral("scheduler score"), QStringLiteral("score of a stand in the scheduler (higher scores: higher prob. to be executed)."), GridViewRainbow)
92
                << LayeredGridBase::LayerElement(QStringLiteral("stp"), QStringLiteral("Stand treatment program currently active"), GridViewBrewerDiv);
1014 werner 93
    return mNames;
873 werner 94
}
95
 
909 werner 96
const QString ABELayers::labelvalue(const int value, const int index) const
877 werner 97
{
98
    switch(index) {
99
    case 0: // stand id
100
        return QString::number(mStandIndex.key(value));
101
    case 1: // unit
102
        return mUnitIndex.key(value);
939 werner 103
    case 2: // agent
104
        return mAgentIndex.key(value)->name();
1058 werner 105
    case 12: // stp
106
        return mSTPIndex.key(value);
877 werner 107
    default: return QString::number(value);
108
    }
109
}
110
 
909 werner 111
void ABELayers::registerLayers()
873 werner 112
{
909 werner 113
    GlobalSettings::instance()->controller()->addLayers(this, "ABE");
873 werner 114
}
877 werner 115
 
909 werner 116
void ABELayers::clearClasses()
877 werner 117
{
118
    mAgentIndex.clear();
119
    mStandIndex.clear();
120
    mUnitIndex.clear();
121
}