DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
mainwindow.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
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 2 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 along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 
22 #ifndef MAINWINDOW_H
23 #define MAINWINDOW_H
24 
25 #include <outputfileparser.h>
26 #include <statscontroller.h>
27 
28 #include <memoryinfo.h>
29 
30 #include <QMainWindow>
31 #include <QProcess>
32 #include <QTimer>
33 
34 #include <memory>
35 #include <functional>
36 
37 #include <QMapControl/Point.h>
38 
39 #include <graphbuilder_shp.h>
40 #include <backgroundworker.h>
41 
42 #include <mousemode.h>
43 
44 using namespace qmapcontrol;
45 
46 namespace Ui {
47 class MainWindow;
48 }
49 
50 namespace qmapcontrol {
51 class QMapControl;
52 class PointWorldCoord;
53 }
54 
55 namespace displace {
56 namespace workers {
57 class DataMerger;
58 }
59 }
60 
61 using namespace displace::workers;
62 
63 class ObjectTreeModel;
64 class DisplaceModel;
65 class Simulator;
67 class WaitDialog;
68 class MouseMode;
69 class OGRGeometry;
70 struct GraphProperties;
71 
72 QT_BEGIN_NAMESPACE
73 QT_END_NAMESPACE
74 
75 class MainWindow : public QMainWindow, public MouseModeInterface
76 {
77  Q_OBJECT
78 
79 public:
80  static constexpr int MAX_MODELS = 5;
81 
82 private:
83  static constexpr int ModelIdxEditor = MAX_MODELS-1;
84  static constexpr int ModelIdxSimulator = 0;
85 
86 
87 public:
88  explicit MainWindow(QWidget *parent = 0);
89  ~MainWindow();
90 
91 private slots:
92  void simulatorLogging(QString);
93  void simulationEnded(int exitcode);
94  void simulatorProcessStateChanged (QProcess::ProcessState oldstate, QProcess::ProcessState newstate);
95  void simulatorProcessStepChanged (int step);
96  void simulatorNodeStatsUpdate(QString);
97  void simulatorDebugMemoryStats(long,long);
98  void simulatorCaptureLine(QString);
99 
100  void vesselMoved (int step, int idx, float x, float y, float course, float fuel, int state);
101  void shipMoved (int step, int idx, float x, float y, float course);
102  void updateModelState();
103  void updateOutputFile (QString,int);
104  void outputUpdated();
105  void mapFocusPointChanged(PointWorldCoord);
106  void mapMousePress(QMouseEvent*,PointWorldCoord);
107  void mapMouseRelease(QMouseEvent*,PointWorldCoord,PointWorldCoord);
108  void mapMouseMove(QMouseEvent*,PointWorldCoord,PointWorldCoord);
109  void showMessage(const QString &);
110  void abortMouseMode ();
111  void completeMouseMode();
112  void simulatorSqlStorageChanged(QString path);
113 
114  void showWarningMessageBox(QString,QString);
115  void edgeSelectionsChanged(int);
116  void treeViewContextMenuRequested(QPoint);
117 
118  void errorImportingStatsFile(QString);
119 
120  void playTimerTimeout();
121  void memoryTimerTimeout();
122 
123  void waitStart();
124  void waitEnd();
125 
126  void editorAddNode(QPointF);
127  void editorAddEdge(int from, int to);
128 
129  void mergeCompleted(DataMerger *merger);
130 
131  void on_action_Load_triggered();
132  void on_modelSelector_currentIndexChanged(int index);
133  void on_cmdStart_clicked();
134  void on_cmdStop_clicked();
135  void on_actionScenario_triggered();
136  void on_treeView_doubleClicked(const QModelIndex &index);
137  void on_saveConsoleButton_clicked();
138  void on_cmdSetup_clicked();
139  void on_actionLoad_results_triggered();
140  void on_play_step_valueChanged(int step);
141  void on_play_fwd_clicked();
142  void on_play_bk_clicked();
143  void on_play_fbk_clicked();
144  void on_play_ffwd_clicked();
145  void on_play_first_clicked();
146  void on_play_last_clicked();
147  void on_play_auto_clicked();
148  void on_actionPalettes_triggered();
149  void on_actionPalettes0to1_triggered();
150  void on_popStatSelector_currentIndexChanged(int index);
151  void on_nationsStatsSelector_currentIndexChanged(int index);
152  void on_vesselsStatsSelector_currentIndexChanged(int index);
153  void on_harbStatSelector_currentIndexChanged(int index);
154  void on_actionPopulations_triggered();
155  void on_actionTariffs_triggered();
156  void on_actionBathymetry_triggered();
157  void on_actionShippingDensity_triggered();
158  void on_actionSiltFraction_triggered();
159  void on_actionSalinity_triggered();
160  void on_actionSST_triggered();
161  void on_actionWind_triggered();
162  void on_actionNitrogen_triggered();
163  void on_actionPhosphorus_triggered();
164  void on_actionOxygen_triggered();
165  void on_actionDissolvedCarbon_triggered();
166  void on_actionConfiguration_triggered();
167  void on_play_params_clicked();
168  void on_actionQuit_triggered();
169  void on_actionImport_Shapefile_triggered();
170  void on_actionGraph_toggled(bool arg1);
171  void on_actionEdge_Edit_toggled(bool arg1);
172  void on_actionDelete_triggered();
173  void on_actionNode_Editor_toggled(bool arg1);
174  void on_actionClear_Graph_triggered();
175  void on_actionCreate_Graph_triggered();
176  void on_actionExport_Graph_triggered();
177  void on_actionLoad_Harbours_triggered();
178  void on_actionLink_Shortest_Path_Folder_triggered();
179  void on_actionCreate_Shortest_Path_triggered();
180  void on_actionAdd_Penalty_on_Polygon_triggered();
181  void on_actionAdd_Penalty_from_File_triggered();
182  void on_actionLoad_Graph_triggered();
183  void on_actionSave_Graph_triggered();
184  void on_actionLink_Harbours_to_Graph_triggered();
185  void on_actionAdd_triggered();
186  void on_actionAbort_Operation_triggered();
187  void on_actionAbout_displace_triggered();
188  void on_cmdProfileEnable_toggled(bool checked);
189  void on_cmdProfileSave_clicked();
190  void on_actionCSV_Editor_triggered();
191  void on_actionMergeWeights_triggered();
192  void on_actionMergePings_triggered();
193  void on_actionExport_Map_triggered();
194  void on_actionExport_Harbours_triggered();
195  void on_actionExport_Populations_triggered();
196  void on_actionExport_Nations_triggered();
197  void on_actionAssign_Landscape_codes_triggered();
198  void on_actionAssign_Wind_triggered();
199  void on_actionAssign_SST_triggered();
200  void on_actionAssign_Salinity_triggered();
201  void on_actionAssign_Nitrogen_triggered();
202  void on_actionAssign_Phosphorus_triggered();
203  void on_actionAssign_Oxygen_triggered();
204  void on_actionAssign_DissolvedCarbon_triggered();
205  void on_actionAssign_Total_benthos_biomass_triggered();
206  void on_actionAssign_Total_benthos_number_triggered();
207  void on_actionAssign_Area_codes_triggered();
208  void on_actionCalcPopDistribution_triggered();
209  void on_actionLoadStockNames_triggered();
210  void on_actionDecision_Trees_Editor_triggered();
211  void on_actionCheck_for_isolated_subgraphs_triggered();
212  void on_actionRemove_isolated_subgraphs_triggered();
213 
214  void on_actionR_Console_triggered();
215 
216  void on_actionTime_Series_Editor_triggered();
217  void on_actionVessel_Creation_Editor_triggered();
218 
219  void on_actionScheduler_Editor_triggered();
220 
221  void on_actionExportAllGraphics_triggered();
222 
223  void on_metierStatSelector_currentIndexChanged(int index);
224 
225  void on_actionShortest_Path_to_Binary_triggered();
226 
227  void on_action_Record_Current_Map_Position_triggered();
228 
229  void on_actionClear_configuration_triggered();
230 
231  void on_actionSet_Node_Symbol_Size_triggered();
232 
233  void on_benthosStatSelector_currentIndexChanged(int index);
234 
235  void on_fishfarmsStatSelector_currentIndexChanged(int index);
236 
237  void on_windfarmsStatSelector_currentIndexChanged(int index);
238 
239  void on_shipsStatSelector_currentIndexChanged(int index);
240 
241 public slots:
242  void end_ShortestPathCreated(bool);
243 
244 signals:
245  void modelStateChanged();
246 
247 public:
248  bool loadLiveModel(QString path, QString *error, int model_idx = 0);
249 
250  void graphCreated(const QList<GraphBuilder::Node> &nodes);
251  void addPenaltyPolygon (const QList<QPointF> &points);
252 
253 protected:
254  void updateModelList();
255  void updateAllDisplayObjects();
256  void updateCalendarDisplay(int tstep);
257  void closeEvent ( QCloseEvent * event );
258 
259  void centerMap(const qmapcontrol::PointWorldCoord &pt);
260  void centerMapOnHarbourId (int id);
261  void centerMapOnNodeId (int id);
262  void centerMapOnVesselId (int id);
263  void centerMapOnFirmId (int id);
264  void centerMapOnShipId (int id);
265  void centerMapOnFishfarmId(int id);
266  void centerMapOnWindmillId(int id);
267 
268  void showPaletteDialog(PaletteRole role);
269 
270  int newEditorModel(QString name);
271 
272  void startBackgroundOperation (BackgroundWorker *work, WaitDialog *waitdialog);
273  void startBackgroundOperation (BackgroundWorkerWithWaitDialog *work);
274  QProcess *prepareAppExecutableStart(QString exename);
275  void startMouseMode (MouseMode *);
276  void endMouseMode (bool success = true);
277 
278  bool isEditorModel();
279 
280  void openScenarioDialog(QString suggestedPath, bool askForReload, bool forceRename);
281  void exportGraphics(QString label, QWidget *widget);
282  void exportPlot (QString outpath, StatsController::StatType type, int subtype, const GraphProperties &properties);
283 
284  void assignCodesFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
285  void assignWindFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
286  void assignSSTFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
287  void assignSalinityFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
288  void assignNitrogenFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
289  void assignPhosphorusFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
290  void assignOxygenFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
291  void assignDissolvedCarbonFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
292  void assignBenthosBiomassFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
293  void assignBenthosNumberFromShapefileGen(QString title, QString shp, const char * const fieldname, std::function<void(OGRGeometry *, int)> func);
294 
295 
296 private:
297  Ui::MainWindow *ui;
298 
299  // Data model
300  std::shared_ptr<DisplaceModel> models[MAX_MODELS];
301  std::shared_ptr<DisplaceModel> currentModel;
302  int currentModelIdx;
303  Simulator *mSimulation;
304  MapObjectsController *mMapController;
305  StatsController *mStatsController;
306 
307  // Geospatial objects
308  qmapcontrol::QMapControl *map;
309 
310  // tree model adapter
311  ObjectTreeModel *treemodel;
312 
313  QTimer mPlayTimer;
314  int mPlayTimerInterval;
315  QTimer mMemoryWatchTimer;
316  MemoryInfo mMemInfo;
317  QLabel *mMemInfoLabel;
318  QLabel *mMouseModeInfoLabel;
319  QLabel *mCoordinatesInfoLabel;
320  QLabel *mStatusInfoLabel;
321 
322  QString mLastRunSimulationName;
323  QString mLastRunDatabase;
324 
325  /* Other objects */
326 
327  MouseMode *mMouseMode;
328  WaitDialog *mWaitDialog;
329 
330  static const QString dbSuffix;
331  static const QString dbFilter;
332  static const QString dbLastDirKey;
333  static const int maxModels;
334  static const int playTimerDefault;
335  static const int playTimerRates[];
336 };
337 
338 #endif // MAINWINDOW_H
Definition: graphexportproperties.h:10
Definition: datamerger.h:16
PaletteRole
Definition: palettemanager.h:54
Definition: decisiontreemanager.h:13
Definition: dteditorwindow.h:32
vector< Node * > nodes
Definition: main.cpp:270
Definition: mousemode.h:48
int tstep
Definition: main.cpp:205
An ongoing simulation process.
Definition: simulator.h:57
The MouseMode class.
Definition: mousemode.h:61
Definition: statscontroller.h:45
Definition: backgroundworker.h:82
Definition: objecttreemodel.h:39
Definition: displacemodel.h:71
Definition: mainwindow.h:56
StatType
Definition: statscontroller.h:63
Definition: waitdialog.h:56
Definition: mapobjectscontroller.h:91
Definition: memoryinfo.h:30
Definition: ui_mainwindow.h:1357
Definition: mainwindow.h:75
Definition: backgroundworker.h:49
Definition: csvspecspage.h:20