Subversion Repositories public iLand

Rev

Rev 1064 | Rev 1104 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1064 Rev 1066
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/modelcontroller.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/modelcontroller.h':
2
/********************************************************************************************
2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
6
**
6
**
7
**    This program is free software: you can redistribute it and/or modify
7
**    This program is free software: you can redistribute it and/or modify
8
**    it under the terms of the GNU General Public License as published by
8
**    it under the terms of the GNU General Public License as published by
9
**    the Free Software Foundation, either version 3 of the License, or
9
**    the Free Software Foundation, either version 3 of the License, or
10
**    (at your option) any later version.
10
**    (at your option) any later version.
11
**
11
**
12
**    This program is distributed in the hope that it will be useful,
12
**    This program is distributed in the hope that it will be useful,
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
**    GNU General Public License for more details.
15
**    GNU General Public License for more details.
16
**
16
**
17
**    You should have received a copy of the GNU General Public License
17
**    You should have received a copy of the GNU General Public License
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************************************/
19
********************************************************************************************/
20
20
21
#ifndef MODELCONTROLLER_H
21
#ifndef MODELCONTROLLER_H
22
#define MODELCONTROLLER_H
22
#define MODELCONTROLLER_H
23
#include <QObject>
23
#include <QObject>
24
#include <QHash>
24
#include <QHash>
25
#include "grid.h"
25
#include "grid.h"
26
#include "layeredgrid.h"
26
#include "layeredgrid.h"
27
class Model;
27
class Model;
28
class MainWindow;
28
class MainWindow;
29
class MapGrid;
29
class MapGrid;
-
 
30
class Species;
30
31
31
class ModelController: public QObject
32
class ModelController: public QObject
32
{
33
{
33
    Q_OBJECT
34
    Q_OBJECT
34
public:
35
public:
35
    ModelController();
36
    ModelController();
36
    ~ModelController();
37
    ~ModelController();
37
    void setMainWindow(MainWindow *mw) { mViewerWindow = mw; }
38
    void setMainWindow(MainWindow *mw) { mViewerWindow = mw; }
38
    MainWindow *mainWindow() { return mViewerWindow; }
39
    MainWindow *mainWindow() { return mViewerWindow; }
39
    void connectSignals(); // connect signal/slots to the main window if available
40
    void connectSignals(); // connect signal/slots to the main window if available
40
    Model *model() const { return mModel; }
41
    Model *model() const { return mModel; }
41
    // bool checkers...
42
    // bool checkers...
42
    bool canCreate(); ///< return true if the model can be created (settings loaded and model does not exist)
43
    bool canCreate(); ///< return true if the model can be created (settings loaded and model does not exist)
43
    bool canDestroy(); ///< model may be destroyed
44
    bool canDestroy(); ///< model may be destroyed
44
    bool canRun(); ///< model may be run
45
    bool canRun(); ///< model may be run
45
    bool isRunning(); ///< model is running
46
    bool isRunning(); ///< model is running
46
    bool isFinished(); ///< returns true if there is a valid model state, but the run is finished
47
    bool isFinished(); ///< returns true if there is a valid model state, but the run is finished
47
    bool isPaused(); ///< returns true if the model is currently paused
48
    bool isPaused(); ///< returns true if the model is currently paused
48
    bool hasError() { return mHasError; } ///< returns true if an error occured during the last operation
49
    bool hasError() { return mHasError; } ///< returns true if an error occured during the last operation
49
    QString lastError() { return mLastError; } ///< error message of the last received error
50
    QString lastError() { return mLastError; } ///< error message of the last received error
50
    // simulation length
51
    // simulation length
51
    int currentYear() const; ///< return current year of the model
52
    int currentYear() const; ///< return current year of the model
52
    int totalYears() const { return mYearsToRun; } ///< returns total number of years to simulate
53
    int totalYears() const { return mYearsToRun; } ///< returns total number of years to simulate
53
    // error handling
54
    // error handling
54
    void throwError(const QString msg);
55
    void throwError(const QString msg);
55
    // dynamic outputs (variable fields)
56
    // dynamic outputs (variable fields)
56
    void setDynamicOutputEnabled(bool enabled) { mDynamicOutputEnabled = enabled; }
57
    void setDynamicOutputEnabled(bool enabled) { mDynamicOutputEnabled = enabled; }
57
    void setupDynamicOutput(QString fieldList);
58
    void setupDynamicOutput(QString fieldList);
58
    QString dynamicOutput();
59
    QString dynamicOutput();
59
    // some informational services
60
    // some informational services
60
    QHash<QString, QString> availableSpecies();
-
 
-
 
61
    QList<const Species *> availableSpecies();
61
    void setLoadedJavascriptFile(QString filename) { mLastLoadedJSFile = filename; }
62
    void setLoadedJavascriptFile(QString filename) { mLastLoadedJSFile = filename; }
62
    QString loadedJavascriptFile() const { return mLastLoadedJSFile; }
63
    QString loadedJavascriptFile() const { return mLastLoadedJSFile; }
63
64
64
65
65
    void saveScreenshot(QString file_name); ///< saves a screenshot of the central view widget to 'file_name'
66
    void saveScreenshot(QString file_name); ///< saves a screenshot of the central view widget to 'file_name'
66
    void addGrid(const FloatGrid *grid, const QString &name, const GridViewType view_type, double min_value, double max_value);
67
    void addGrid(const FloatGrid *grid, const QString &name, const GridViewType view_type, double min_value, double max_value);
67
    void paintMap(MapGrid *map, double min_value, double max_value);
68
    void paintMap(MapGrid *map, double min_value, double max_value);
68
69
69
    void addLayers(const LayeredGridBase *layers, const QString &name);
70
    void addLayers(const LayeredGridBase *layers, const QString &name);
70
    void removeLayers(const LayeredGridBase *layers);
71
    void removeLayers(const LayeredGridBase *layers);
71
    void setViewport(QPointF center_point, double scale_px_per_m);
72
    void setViewport(QPointF center_point, double scale_px_per_m);
72
73
73
    void setUIShortcuts(QVariantMap shortcuts);
74
    void setUIShortcuts(QVariantMap shortcuts);
74
signals:
75
signals:
75
    void finished(QString errorMessage); ///< model has finished run (errorMessage is empty in case of success)
76
    void finished(QString errorMessage); ///< model has finished run (errorMessage is empty in case of success)
76
    void year(int year); ///< signal indicating a year of the simulation has been processed
77
    void year(int year); ///< signal indicating a year of the simulation has been processed
77
    void bufferLogs(bool do_buffer); ///< signal indicating that logs should be buffered (true, model run mode) or that buffering should stop (false) for "interactive" mode
78
    void bufferLogs(bool do_buffer); ///< signal indicating that logs should be buffered (true, model run mode) or that buffering should stop (false) for "interactive" mode
78
    void stateChanged(); ///< is emitted when model started/stopped/paused
79
    void stateChanged(); ///< is emitted when model started/stopped/paused
79
public slots:
80
public slots:
80
    void setFileName(QString initFileName); ///< set project file name
81
    void setFileName(QString initFileName); ///< set project file name
81
    void create(); ///< create the model
82
    void create(); ///< create the model
82
    void destroy(); ///< delete the model
83
    void destroy(); ///< delete the model
83
    void run(int years); ///< run the model
84
    void run(int years); ///< run the model
84
    bool runYear(); ///< runs a single time step
85
    bool runYear(); ///< runs a single time step
85
    bool pause(); ///< pause execution, and if paused, continue to run. returns state *after* change, i.e. true=now in paused mode
86
    bool pause(); ///< pause execution, and if paused, continue to run. returns state *after* change, i.e. true=now in paused mode
86
    bool continueRun(); ///< continues execution if simulation was paused
87
    bool continueRun(); ///< continues execution if simulation was paused
87
    void cancel(); ///< cancel execution of the model
88
    void cancel(); ///< cancel execution of the model
88
    void repaint(); ///< force a repaint of the main drawing window
89
    void repaint(); ///< force a repaint of the main drawing window
89
private slots:
90
private slots:
90
    void runloop();
91
    void runloop();
91
private:
92
private:
92
    bool internalRun(); ///< runs the main loop
93
    bool internalRun(); ///< runs the main loop
93
    void internalStop(); ///< save outputs, stop the model execution
94
    void internalStop(); ///< save outputs, stop the model execution
94
    void fetchDynamicOutput(); ///< execute the dynamic output and fetch data
95
    void fetchDynamicOutput(); ///< execute the dynamic output and fetch data
95
    MainWindow *mViewerWindow;
96
    MainWindow *mViewerWindow;
96
    Model *mModel;
97
    Model *mModel;
97
    bool mPaused;
98
    bool mPaused;
98
    bool mRunning;
99
    bool mRunning;
99
    bool mFinished;
100
    bool mFinished;
100
    bool mCanceled;
101
    bool mCanceled;
101
    bool mHasError;
102
    bool mHasError;
102
    QString mLastError;
103
    QString mLastError;
103
    int mYearsToRun;
104
    int mYearsToRun;
104
    QString mInitFile;
105
    QString mInitFile;
105
    bool mDynamicOutputEnabled;
106
    bool mDynamicOutputEnabled;
106
    QStringList mDynFieldList;
107
    QStringList mDynFieldList;
107
    QStringList mDynData;
108
    QStringList mDynData;
108
    QString mLastLoadedJSFile;
109
    QString mLastLoadedJSFile;
109
110
110
};
111
};
111
112
112
#endif // MODELCONTROLLER_H
113
#endif // MODELCONTROLLER_H
113
 
114