Subversion Repositories public iLand

Rev

Rev 1041 | Rev 1064 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
671 werner 2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
6
**
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
9
**    the Free Software Foundation, either version 3 of the License, or
10
**    (at your option) any later version.
11
**
12
**    This program is distributed in the hope that it will be useful,
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
**    GNU General Public License for more details.
16
**
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/>.
19
********************************************************************************************/
20
 
105 Werner 21
#ifndef MODELCONTROLLER_H
22
#define MODELCONTROLLER_H
128 Werner 23
#include <QObject>
514 werner 24
#include <QHash>
642 werner 25
#include "grid.h"
646 werner 26
#include "layeredgrid.h"
128 Werner 27
class Model;
590 werner 28
class MainWindow;
596 werner 29
class MapGrid;
30
 
128 Werner 31
class ModelController: public QObject
105 Werner 32
{
128 Werner 33
    Q_OBJECT
105 Werner 34
public:
35
    ModelController();
128 Werner 36
    ~ModelController();
590 werner 37
    void setMainWindow(MainWindow *mw) { mViewerWindow = mw; }
1041 werner 38
    MainWindow *mainWindow() { return mViewerWindow; }
590 werner 39
    void connectSignals(); // connect signal/slots to the main window if available
128 Werner 40
    Model *model() const { return mModel; }
41
    // bool checkers...
145 Werner 42
    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 canRun(); ///< model may be run
161 werner 45
    bool isRunning(); ///< model is running
225 werner 46
    bool isFinished(); ///< returns true if there is a valid model state, but the run is finished
776 werner 47
    bool isPaused(); ///< returns true if the model is currently paused
837 werner 48
    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
632 werner 50
    // simulation length
497 werner 51
    int currentYear() const; ///< return current year of the model
498 werner 52
    int totalYears() const { return mYearsToRun; } ///< returns total number of years to simulate
632 werner 53
    // error handling
54
    void throwError(const QString msg);
161 werner 55
    // dynamic outputs (variable fields)
802 werner 56
    void setDynamicOutputEnabled(bool enabled) { mDynamicOutputEnabled = enabled; }
161 werner 57
    void setupDynamicOutput(QString fieldList);
58
    QString dynamicOutput();
514 werner 59
    // some informational services
60
    QHash<QString, QString> availableSpecies();
61
 
590 werner 62
    void saveScreenshot(QString file_name); ///< saves a screenshot of the central view widget to 'file_name'
649 werner 63
    void addGrid(const FloatGrid *grid, const QString &name, const GridViewType view_type, double min_value, double max_value);
596 werner 64
    void paintMap(MapGrid *map, double min_value, double max_value);
646 werner 65
 
647 werner 66
    void addLayers(const LayeredGridBase *layers, const QString &name);
893 werner 67
    void removeLayers(const LayeredGridBase *layers);
634 werner 68
    void setViewport(QPointF center_point, double scale_px_per_m);
1061 werner 69
 
70
    void setUIShortcuts(QVariantMap shortcuts);
222 werner 71
signals:
776 werner 72
    void finished(QString errorMessage); ///< model has finished run (errorMessage is empty in case of success)
73
    void year(int year); ///< signal indicating a year of the simulation has been processed
74
    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
75
    void stateChanged(); ///< is emitted when model started/stopped/paused
128 Werner 76
public slots:
77
    void setFileName(QString initFileName); ///< set project file name
78
    void create(); ///< create the model
79
    void destroy(); ///< delete the model
222 werner 80
    void run(int years); ///< run the model
223 werner 81
    bool runYear(); ///< runs a single time step
222 werner 82
    bool pause(); ///< pause execution, and if paused, continue to run. returns state *after* change, i.e. true=now in paused mode
776 werner 83
    bool continueRun(); ///< continues execution if simulation was paused
222 werner 84
    void cancel(); ///< cancel execution of the model
652 werner 85
    void repaint(); ///< force a repaint of the main drawing window
223 werner 86
private slots:
87
    void runloop();
128 Werner 88
private:
776 werner 89
    bool internalRun(); ///< runs the main loop
90
    void internalStop(); ///< save outputs, stop the model execution
802 werner 91
    void fetchDynamicOutput(); ///< execute the dynamic output and fetch data
590 werner 92
    MainWindow *mViewerWindow;
128 Werner 93
    Model *mModel;
223 werner 94
    bool mPaused;
225 werner 95
    bool mRunning;
96
    bool mFinished;
97
    bool mCanceled;
837 werner 98
    bool mHasError;
99
    QString mLastError;
223 werner 100
    int mYearsToRun;
128 Werner 101
    QString mInitFile;
802 werner 102
    bool mDynamicOutputEnabled;
161 werner 103
    QStringList mDynFieldList;
104
    QStringList mDynData;
105
 
105 Werner 106
};
107
 
108
#endif // MODELCONTROLLER_H