FFSM++ 1.1.0
French Forest Sector Model ++
Loading...
Searching...
No Matches
MainWindow.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3 * http://ffsm-project.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version, given the compliance with the *
9 * exceptions listed in the file COPYING that is distribued together *
10 * with this file. *
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, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22//#include <QtGui> // Qt4
23#include <QtWidgets> // Qt5
24
25#include "MainWindow.h"
27#include "QApplication"
28
29using namespace std;
30
31
32// *************** Initializzation functions... *******************
33
34/**
35
36It setup the Gui from the QTDesiger autogenerated code and connect various GUI signal/slots
37
38*/
40 yearSBLabel=NULL;
41 mainSBLabel=NULL;
42 for (uint i=0;i<MaxRecentFiles;i++) recentFileActions[i] = NULL;
43 separatorAction=NULL;
44
45 setupUi(this);
46 unsavedStatus=false;
47 curModelFileName="data/ffsmInput.ods";
48 curBaseDirectory = QApplication::applicationDirPath();
49 curBaseDirectory.append("/data/");
50 //curBaseDirectory = "data/";
51 outputDirName="output/";
55 debugMsgsEnable = true;
56
57 for (int i = 0; i < MaxRecentFiles; ++i) {
58 recentFileActions[i] = new QAction(this);
59 recentFileActions[i]->setVisible(false);
60 connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
61 }
62
63 separatorAction = menuFile->addSeparator();
64 for (int i = 0; i < MaxRecentFiles; ++i)
65 menuFile->addAction(recentFileActions[i]);
66 menuFile->addSeparator();
67 menuFile->addAction(actionExit);
68
71 //modelMainThread.setBaseDirectory(curBaseDirectory);
72
73 // Status viewer....
74 statusView->setColumnCount(2);
75 statusView->setHeaderLabels(QStringList()<< tr ("Label") << tr ("Value"));
76 statusView->clear();
77 statusView->sortByColumn(0);
78 statusView->setFocus(); //????
79
80
81
82
83 /*
84 DONE: statusView should be implemented like this:
85
86 Model
87 -> year
88 -> total plots
89 -> rented plots
90 -> abandoned plots
91 Managers
92 -> Manager_farmer
93 -> number of agents
94 Agents
95 Agent_0
96 -> Type
97 -> ID
98 -> mould
99 -> owned plots
100 ...
101 Agent_1
102 -> Type
103 -> ID
104 -> mould
105 -> owned plots
106 ...
107 ...
108 */
109
110 qRegisterMetaType<string>("string"); // allows string objects to be thread-safely queued within signal-slots comunications
111 qRegisterMetaType<QString>("QString");
112 qRegisterMetaType< QVector<QString> >("QVector<QString>");
113
114
115 connect(actionRun, SIGNAL(triggered()), this, SLOT(startModelMainThread()));
116 connect(actionPause, SIGNAL(triggered()), this, SLOT(pauseOrResumeModelMainThread()));
117 connect(actionStop, SIGNAL(triggered()), this, SLOT(stopModelMainThread()));
118 connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
119 connect(actionSaveLog, SIGNAL(triggered()), this, SLOT(save()));
120 connect(actionSaveLogAs, SIGNAL(triggered()), this, SLOT(saveAs()));
121 connect(actionLoadConfiguration, SIGNAL(triggered()), this, SLOT(open()));
122 connect(actionHideDebugMsgs, SIGNAL(triggered(bool)), this, SLOT(hideDebugMsgs(bool)));
123 connect(actionAboutRegMAS, SIGNAL(triggered()), this, SLOT(about()));
124 connect(actionRegMASDocumentation, SIGNAL(triggered()), this, SLOT(showDocumentation()));
125 connect(actionFitMap, SIGNAL(triggered()), mapBox, SLOT(fitInWindow()));
126 connect(this, SIGNAL(resized()),mapBox, SLOT(fitInWindow()));
127 connect(viewResultsButton, SIGNAL(clicked()),this, SLOT(openResults()));
128
129 connect(&modelMainThread, SIGNAL(upgradeLogArea(const QString&)), this, SLOT(processLogArea(const QString&)));
130 connect(&modelMainThread, SIGNAL(addLayerToGui(QString, QString)), this, SLOT( addLayer(QString, QString)));
131 connect(layerSelector, SIGNAL(activated(int)), this, SLOT(switchToLayerFromLayerSelector(int)));
132 connect(&modelMainThread, SIGNAL(updatePixelToGui(QString, int, int, QColor)), this, SLOT (updatePixel(QString, int, int, QColor)));
133 connect(&modelMainThread, SIGNAL(updateImageToGui(QString, QImage)), this, SLOT (updateImage(QString, QImage)));
134 connect(&modelMainThread, SIGNAL(setOutputDirNameToGui(string)), this, SLOT(setOutputDirName(string)));
135 connect(&modelMainThread, SIGNAL(setGUIUnsavedStatus(bool)), this, SLOT(setUnsavedStatus(bool)));
136 connect(&modelMainThread, SIGNAL(sendScenarioOptionsToGUI(const QVector<QString> &)), this, SLOT( receiveScenarioOptions(const QVector<QString> &) ));
137
138 // Scenario selection widget...
140 connect(scenarioWidget->scenarioSelector, SIGNAL( activated(const QString&)), scenarioWidget, SLOT( close()));
141 connect(scenarioWidget->scenarioSelector, SIGNAL( activated(const QString&)), &modelMainThread, SLOT( retrieveScenarioNameFromGUI(const QString &)));
142 //connect(scenarioWidget, SIGNAL( selectedScenarioName(const QString&)), scenarioWidget, SLOT( close()));
143 //connect(scenarioWidget, SIGNAL( selectedScenarioName(const QString&)), &modelMainThread, SLOT( retrieveScenarioNameFromGUI(const QString &)));
144
145 // Model tree viewer...
146 connect(&modelMainThread, SIGNAL( treeViewerItemChangeValueToGui(string, string) ), this, SLOT( treeViewerItemChangeValue(string, string) ));
147 connect(&modelMainThread, SIGNAL( treeViewerItemRemoveToGui(string) ), this, SLOT( treeViewerItemRemove(string) ));
148 connect(&modelMainThread, SIGNAL( treeViewerAddItemToGui(string, string, string) ), this, SLOT( treeViewerAddItem(string, string, string) ));
149 connect(&modelMainThread, SIGNAL( fitInWindowToGui()), mapBox, SLOT(fitInWindow()));
150
151 connect(mapBox, SIGNAL( queryRequestOnPx(int, int, bool) ), &modelMainThread, SLOT ( checkQuery(int, int, bool) ) );
152 connect(&modelMainThread,SIGNAL(publishQueryResults(const QString&)), pxInfoArea, SLOT (setHtml(const QString&)));
153 connect(&modelMainThread,SIGNAL(activateTab(int)), tabWidget, SLOT (setCurrentIndex(int)));
154
155 connect(&modelMainThread, SIGNAL( resetGUIForNewSimulation() ), this, SLOT( resetGUIForNewSimulation() ));
156
157}
158
159void
161 yearSBLabel = new QLabel(" 2000 ");
162 yearSBLabel->setAlignment(Qt::AlignHCenter);
163 yearSBLabel->setMinimumSize(yearSBLabel->sizeHint());
164
165 mainSBLabel = new QLabel;
166 mainSBLabel->setIndent(3);
167
168 statusBar()->addWidget(yearSBLabel);
169 statusBar()->addWidget(mainSBLabel, 1);
170
171 yearSBLabel->setText("0");
172 mainSBLabel->setText("Welcome to FFSM!");
173
174 connect(&modelMainThread, SIGNAL(upgradeYearSBLabelToGui(const QString&)), yearSBLabel, SLOT(setText(const QString&)));
175 connect(&modelMainThread, SIGNAL(upgradeMainSBLabelToGui(const QString&)), mainSBLabel, SLOT(setText(const QString&)));
176
177}
178
179// Manage the event of closing the application
180void
181MainWindow::closeEvent(QCloseEvent *event) {
182 if (okToContinue()) {
185 modelMainThread.wait();
186 event->accept();
187 } else {
188 event->ignore();
189 }
190}
191
192void
193MainWindow::resizeEvent (QResizeEvent *event) {
194 emit resized();
195}
196
197
198// *************** open model / log saving functions.. ************************
199
200void
201MainWindow::setCurrentLogFileName(const QString &fileName) {
202 curLogFileName = fileName;
203}
204
205void
206MainWindow::setCurrentModelFileName(const QString &fileName) {
207 curModelFileName = fileName;
208 //setWindowModified(false);
210
211 QString shownName = "Untitled";
212 if (!curModelFileName.isEmpty()) {
213 shownName = strippedName(curModelFileName);
214 recentFiles.removeAll(curModelFileName);
217 }
218 setWindowTitle(tr("%2 - [%1]").arg(shownName).arg(tr("FFSM - Forest Sector Simulator")));
219}
220
221QString
222MainWindow::strippedName(const QString &fullFileName) {
223 return QFileInfo(fullFileName).fileName();
224}
225
226void
228 QMutableStringListIterator i(recentFiles);
229 while (i.hasNext()) {
230 if (!QFile::exists(i.next()))
231 i.remove();
232 }
233
234 for (int j = 0; j < MaxRecentFiles; ++j) {
235 if (j < recentFiles.count()) {
236 QString text = tr("&%1 %2")
237 .arg(j + 1)
238 .arg(strippedName(recentFiles.at(j)));
239 //cerr <<text.toStdString()<<endl;
240 recentFileActions[j]->setText(text);
241 recentFileActions[j]->setData(recentFiles.at(j));
242 recentFileActions[j]->setVisible(true);
243 } else {
244 recentFileActions[j]->setVisible(false);
245 }
246 }
247 separatorAction->setVisible(!recentFiles.isEmpty());
248}
249
250bool
252 if (modelMainThread.isRunning()) {
253 int t = QMessageBox::warning(
254 this, // parent
255 tr("FFSM"), // title
256 tr("The model is still running.\n" // message
257 "Do you want to stop it?"),
258 QMessageBox::Yes | QMessageBox::Default, // 1st button
259 QMessageBox::Cancel | QMessageBox::Escape // 3rd button
260 );
261 if (t == QMessageBox::Yes) {
263 modelMainThread.wait();
264 } else if (t == QMessageBox::Cancel) {
265 return false;
266 }
267 }
268
269 if (unsavedStatus) {
270 int r = QMessageBox::warning(
271 this, // parent
272 tr("FFSM"), // title
273 tr("The model log has not been saved.\n" // message
274 "Do you want to save it?"),
275 QMessageBox::Yes , // 1st button
276 QMessageBox::No | QMessageBox::Default, // 2nd button
277 QMessageBox::Cancel | QMessageBox::Escape // 3rd button
278 );
279 if (r == QMessageBox::Yes) {
280 return save();
281 } else if (r == QMessageBox::Cancel) {
282 return false;
283 }
284 }
285 return true;
286}
287
288void
290 if (okToContinue()) {
291 QString fileName = QFileDialog::getOpenFileName(
292 this,
293 tr("Load model file.."),
294 "data/",
295 tr("OpenDocument Spreadsheet (*.ods)\n" "All files (*.*)")
296 );
297 if (!fileName.isEmpty()){
298 statusBar()->showMessage(tr("Loaded new FFSM model file"), 2000);
299 setCurrentModelFileName(fileName);
300 // getting the baseData path information...
301 QFileInfo info(fileName);
302 QString path;
303 path = info.absolutePath();
304 path = path+"/";
305 curBaseDirectory = path;
306 //modelMainThread.setBaseDirectory(curBaseDirectory);
307 }
308 }
309}
310
311void
313 QSettings settings("LEF", "FFSM");
314 recentFiles = settings.value("recentFiles").toStringList();
316}
317
318void
320 if (okToContinue()) {
321 QAction *action = qobject_cast<QAction *>(sender());
322 if (action){
323 curModelFileName=action->data().toString();
325 // getting the baseData path information...
326 QFileInfo info(curModelFileName);
327 QString path;
328 path = info.absolutePath();
329 path = path+"/";
330 curBaseDirectory = path;
331 //modelMainThread.setBaseDirectory(curBaseDirectory);
332 }
333 }
334}
335
336bool
338 if (curLogFileName.isEmpty()) {
339 return saveAs();
340 } else {
341 cerr <<(curLogFileName.toStdString())<<endl;
342 cerr <<(outputDirName.toStdString())<<endl;
344 }
345 unsavedStatus = false;
346 return true;
347}
348
349bool
351 QString logFileName = QFileDialog::getSaveFileName(
352 this,
353 tr("Save output log"),
355 tr("Log files (*.log)\n" "All files (*.*)")
356 );
357 if (logFileName.isEmpty())
358 return false;
359 return saveLogFile(logFileName);
360 unsavedStatus = false;
361 return true;
362}
363
364bool
365MainWindow::saveLogFile(const QString &logFileName) {
366 QFile file(logFileName);
367 if (!file.open(QIODevice::WriteOnly)) {
368 QMessageBox::warning(this, tr("FFSM"),
369 tr("Cannot write log file file %1:\n%2.")
370 .arg(file.fileName())
371 .arg(file.errorString()));
372 return false;
373 }
374 //QString logAreaContent = logArea->toHtml();
375 QString logAreaContent = logArea->toPlainText(); // Also available "toHtml()"
376 QTextStream stream( &file );
377 stream << logAreaContent;
378 file.close();
379
380 setCurrentLogFileName(logFileName);
381 statusBar()->showMessage(tr("Log file saved"), 2000);
382 unsavedStatus = false;
383 return true;
384}
385
387 QSettings settings("LEF", "FFSM");
388 settings.setValue("recentFiles", recentFiles);
389}
390
391// ****************** Main thread controllers ***********************
392
393void
395 if (modelMainThread.isRunning()) {
396 return ;
397 cout <<"It seems that the model is already running..."<<endl;
398 } else {
399 logArea->clear();
400 modelMainThread.start();
401 unsavedStatus=true;
402 }
403}
404
405void
407 if (! modelMainThread.isRunning()) {
408 return ;
409 } else {
411 modelMainThread.wait();
412 }
413}
414
415void
419
420// ************ display px info **********************
421/*void
422MainWindow::sendQueryToMainThread(int px_ID){
423 modelMainThread.pause();
424 //modelMainThread.wait();
425 modelMainThread.computeQuery(px_ID);
426 modelMainThread.resume();
427}*/
428
429
430// ************** Map operations ***********************
431
432
433/**
434Perform all the operation needed when adding a new layer:
435 - add a layer to mapBox;
436 - add the layer to layerSelector;
437 - (NOTNEEDED: add the layer to layerLegend); Not needed any longer, as legend was dropped in name of the Model Status Viewer
438*/
439void
440MainWindow::addLayer(QString layerName_h, QString layerLabel_h) {
441 static int counter =0;
442 mapBox->addLayer(layerName_h);
443 layerSelector->addItem(layerLabel_h,layerName_h);
444 // first layer added only. it is not needed as MapBox::addLayer() and QComboBox automatically switch to the new value if it is the first one :-))
445 //if (counter == 0) switchToLayer(layerName_h);
446 update();
447 counter ++;
448}
449
450/**
451Perform all the operation needed when switching layer:
452 - call mapBox to switch its current layer;
453 - call layerLegend to switch its layer);
454I don't think it is used anywhere, but any how.. it is here...
455*/
456void
457MainWindow::switchToLayer(QString layerName_h) {
458 mapBox->switchToLayer(layerName_h);
459 int index = mapBox->getLayerIndex(layerName_h);
460 layerSelector->setCurrentIndex(index);
461 update();
462}
463
464void
466 QString layerName= layerSelector->itemData(layerIndex_h, Qt::UserRole ).toString();
467 mapBox->switchToLayer(layerName);
468 update();
469}
470
471void
472MainWindow::updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h) {
473 mapBox->updatePixel(layerName_h,x_h,y_h,color_h.rgb());
474 update();
475}
476
477void
478MainWindow::updateImage(QString layerName_h, const QImage &image_h) {
479 mapBox->updateImage(layerName_h, image_h);
480 update();
481}
482
483// ************** Status viewer operations ***********************
484void
485MainWindow::treeViewerItemChangeValue(string itemID, string newValue) {
486
487 map<string, QTreeWidgetItem*>::iterator p;
488 p=svIndex.find(itemID);
489 if(p != svIndex.end())
490 p->second->setText(1,newValue.c_str());
491 else {
492 QString tempString;
493 QString tempString2 = itemID.c_str();
494 tempString = "**** ERROR, Coud not change value for item "+tempString2+" in the Model Status Viewer. Item doesn't found.";
495 logArea->append(tempString);
496 }
497 return;
498
499}
500
501void
503 map<string, QTreeWidgetItem*>::iterator p;
504 p=svIndex.find(itemID);
505 if(p != svIndex.end()){
506 QTreeWidgetItem *parent = p->second->parent();
507 int index;
508 if (parent) {
509 index = parent->indexOfChild(p->second); //DONE: check if it works !!! While it should not ???? After 15 years of simulation agents should be deleted, but htey are still here in the tree.. mayme it is true it is NOT working!!! To be checken. 20071108: It works, it works.. agents are deleted when go out of the model
510 delete parent->takeChild(index);
511 svIndex.erase(p);
512 } else {
513 QString tempString = "**** ERROR, I will not delete a top level item in the Model Satus Viewer";
514 logArea->append(tempString);
515 }
516
517 }
518 else {
519 QString tempString;
520 QString tempString2 = itemID.c_str();
521 tempString = "**** ERROR, Coud not delete for item "+tempString2+" in the Model Status Viewer. Item doesn't found.";
522 //logArea->append(tempString); //20080111 lots of this errors when re-starting a simulation, so hidding them
523 }
524 return;
525}
526
527void
528MainWindow::treeViewerAddItem(string text, string itemID, string parentID){
529 // searching for the parent item...
530 map<string, QTreeWidgetItem*>::iterator p;
531 QTreeWidgetItem *parentItem;
532
533 p=svIndex.find(parentID);
534 if(p != svIndex.end()){
535 parentItem = p->second;
536 QTreeWidgetItem *node = new QTreeWidgetItem(parentItem);
537 svIndex.insert(pair<string, QTreeWidgetItem*>(itemID, node));
538 node->setText(0, text.c_str());
539 }
540 else {
541 QString tempString;
542 QString tempString2 = itemID.c_str();
543 QString tempString3 = parentID.c_str();
544 tempString = "**** ERROR, Coud not add sub item "+tempString2+" to the Model Status Viewer. Parent item ("+tempString3+") doesn't found.";
545 logArea->append(tempString);
546 }
547
548}
549
550// ************** Other ***********************
551void
552MainWindow::processLogArea(const QString& message_h){
553 if(debugMsgsEnable){
554 logArea->append(message_h);
555 }
556 else {
557 if( ! message_h.startsWith("*DEBUG")){
558 logArea->append(message_h);
559 }
560 }
561}
562
563void
565 if(hide) debugMsgsEnable = false;
566 else debugMsgsEnable = true;
567}
568
569void
571 QMessageBox::about(this, tr("About FFSM"),
572 tr("<h2>FFSM</h2>"
573 "<p>Copyright &copy; 2012 Laboratoire d'Economie Forestière - LEF"
574 "<br/>"
575 "<p>FFSM is a flexible, spatially explicit, coupled resource and economic simulator of the Forest Sector, "
576 "designed for long-term simulations of effects of government policies "
577 "over different forest systems."
578 "<br>It is released under the GNU GPL licence."
579 "<p>For documentation and credits please refer to the project site:"
580 "<br><a href=\"http://www.ffsm-project.org\">http://www.ffsm-project.org</a>"
581 ));
582}
583
584void
586 QMessageBox::question(this, tr("FFSM Documentation"), // QMessageBox::information or QMessageBox::question
587 tr("<h2>FFSM Documentation</h2>"
588 "<p align=\"justify\">FFSM documentation is organised in three main categories: "
589 "<p align=\"left\">(1) <b>official documentation</b> "
590 "(comprising the <i>User Manual</i> and the <i>Reference Manual</i>); <br>(2) <b>contributed "
591 "documentation</b> (<i>wiki</i>);<br>(3) <b>community project</b> (<i>forum</i> and <i>mailing list</i>). "
592 "<p align=\"justify\">The documentation is located at "
593 "<a href=\"http://www.ffsm-project.org/doc\">http://www.ffsm-project.org/doc</a>"
594 "<p align=\"justify\">If you have chosen to instal a local copy of the documentation, "
595 "you can access it also from the <i>Start menu</i>-><i>Programs</i>-><i>FFSM</i> "
596 "(MS Windows) or directly from the following links (Linux):"
597 "<br><a href=\"doc/userManual/regmasUserManual.pdf\">User Manual</a> "
598 "&nbsp;-&nbsp;<a href=\"doc/referenceManual/html/index.html\">Reference Manual</a> "
599 "<p>Tips:"
600 "<br> - right click on a pixel to get its value across the layers;"
601 "<br> - use the mouse and its wheel over the map to zoom/scroll it;"
602 "</p>"
603 ));
604}
605
606void
608
609 static int simulationCounter = 0;
610 //reset map <string, QTreeWidgetItem*> svIndex and clean the tree widget
611 statusView->clear();
612 map<string, QTreeWidgetItem*>::iterator p;
613 //for(p=svIndex.begin(); p= svIndex.end(); p++){
614 //delete p->second; // no need because they are destroyed already from statusView->clear();
615 //}
616 svIndex.clear();
617
618 QTreeWidgetItem* svGeneralNode = new QTreeWidgetItem(statusView);
619 svIndex.insert(pair<string, QTreeWidgetItem*>("general", svGeneralNode));
620 svGeneralNode -> setText(0, "General");
621 QTreeWidgetItem* svYearItem = new QTreeWidgetItem(svGeneralNode);
622 svIndex.insert(pair<string, QTreeWidgetItem*>("general_year", svYearItem));
623 svYearItem->setText(0, "year");
624 svYearItem->setText(1, "0");
625 QTreeWidgetItem* svTotalPlotsItem = new QTreeWidgetItem(svGeneralNode);
626 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total plots", svTotalPlotsItem));
627 svTotalPlotsItem->setText(0, "total plots");
628 svTotalPlotsItem->setText(1, "0");
629 QTreeWidgetItem* svTotalLandItem = new QTreeWidgetItem(svGeneralNode);
630 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total land", svTotalLandItem));
631 svTotalLandItem->setText(0, "total land");
632 QTreeWidgetItem* svTotalAgrLandItem = new QTreeWidgetItem(svGeneralNode);
633 svIndex.insert(pair<string, QTreeWidgetItem*>("general_total agr land", svTotalAgrLandItem));
634 svTotalAgrLandItem->setText(0, "total agr land");
635 QTreeWidgetItem* svOwnedAgrLandItem = new QTreeWidgetItem(svGeneralNode);
636 svIndex.insert(pair<string, QTreeWidgetItem*>("general_owned agr land", svOwnedAgrLandItem));
637 svOwnedAgrLandItem->setText(0, "owned agr land");
638 QTreeWidgetItem* svRentedAgrLandItem = new QTreeWidgetItem(svGeneralNode);
639 svIndex.insert(pair<string, QTreeWidgetItem*>("general_rented agr land", svRentedAgrLandItem));
640 svRentedAgrLandItem->setText(0, "rented agr land");
641
642 QTreeWidgetItem* svManagersNode = new QTreeWidgetItem(statusView);
643 svIndex.insert(pair<string, QTreeWidgetItem*>("managers", svManagersNode));
644 svManagersNode->setText(0,"Managers");
645
646 QTreeWidgetItem* svAgentsNode = new QTreeWidgetItem(statusView);
647 svIndex.insert(pair<string, QTreeWidgetItem*>("agents", svAgentsNode));
648 svAgentsNode->setText(0,"Agents");
649
650 // reset layer selector
651 layerSelector->clear();
652 // reset pixel info area
653 pxInfoArea->setHtml("<i>Tip: Right click over a plot to retrieve its values across layers.</i>");
654 // reset log area
655 logArea->clear();
656 // reset map
657
658 if (simulationCounter) logArea->append("***WARNING: You are running more simulations from the GUI without closing/reopening it. It should works, but there are no guarantees. The best way is to run only one simulation from the GUI, eventually closing and opening FFSM again for further simulations.");
659 simulationCounter++;
660
661}
662
663void
664MainWindow::receiveScenarioOptions(const QVector<QString> &scenarios_h){
665
666 //for(uint i=0;i<scenarios_h.size();i++){
667 // cout << scenarios_h.at(i).toStdString() << endl;
668 //} // stange.. it works like expected !!!!
669
671 scenarioWidget->show();
672 scenarioWidget->scenarioSelector->setFocus();
673 //scenarioWidget->scenarioSelector->grabMouse();
674 //scenarioWidget->scenarioSelector->grabKeyboard();
675
676
677}
678
679void
681 //QLabel *label = new QLabel("Hello World!");
682 //label->show();
683 //string aaa = curBaseDirectory.toStdString();
684 //cout << "curBaseDirectory " << aaa << endl;
685 //cout << "outputDirName: " << outputDirName.toStdString() << endl;
686 QUrl resultsUrl(curBaseDirectory+outputDirName+"results/results.ods", QUrl::TolerantMode);
687 QDesktopServices::openUrl(resultsUrl);
688
689}
void stopModelMainThread()
void createStatusBar()
bool unsavedStatus
Definition MainWindow.h:110
void setCurrentLogFileName(const QString &fileName)
ScenarioSelectionWidget * scenarioWidget
Definition MainWindow.h:120
QString outputDirName
Definition MainWindow.h:111
ThreadManager modelMainThread
Definition MainWindow.h:107
void resized()
void treeViewerItemChangeValue(string itemID, string newValue)
Change value to an existing item in the Status Viewer.
bool okToContinue()
void resetGUIForNewSimulation()
Reset the graphical elements for a new simulation // Send the request of getting the pixel info to th...
void treeViewerAddItem(string text, string itemID, string parentID)
e.g. manager_farmer_manager agents or agent_12345_ownedHa
void treeViewerItemRemove(string itemID)
void pauseOrResumeModelMainThread()
void readSettings()
QLabel * yearSBLabel
Status bar current year label.
Definition MainWindow.h:108
void openRecentFile()
void closeEvent(QCloseEvent *event)
Manage the event of closing the application.
QString strippedName(const QString &fullFileName)
void setOutputDirName(string outputDirName_h)
Definition MainWindow.h:66
void resizeEvent(QResizeEvent *event)
Manage the event of resizing the application.
void receiveScenarioOptions(const QVector< QString > &scenarios_h)
void updateRecentFileActions()
void setUnsavedStatus(bool unsavedStatus_h)
Definition MainWindow.h:65
void writeSettings()
bool debugMsgsEnable
Allow debug messages to be show in the logArea.
Definition MainWindow.h:119
void openResults()
bool saveAs()
map< string, QTreeWidgetItem * > svIndex
Map containing the ID and the pointers to the status viewer.
Definition MainWindow.h:132
QAction * separatorAction
Definition MainWindow.h:118
QStringList recentFiles
Definition MainWindow.h:115
void updateImage(QString layerName_h, const QImage &image_h)
QString curLogFileName
Definition MainWindow.h:112
void setCurrentModelFileName(const QString &fileName)
void addLayer(QString layerName_h, QString layerLabel_h)
void processLogArea(const QString &message_h)
void switchToLayer(QString layerName_h)
void updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h)
QString curModelFileName
Definition MainWindow.h:113
void showDocumentation()
QAction * recentFileActions[MaxRecentFiles]
Definition MainWindow.h:117
void startModelMainThread()
void hideDebugMsgs(bool hide)
MainWindow()
Constructor
QString curBaseDirectory
Definition MainWindow.h:114
QLabel * mainSBLabel
Status bar main label.
Definition MainWindow.h:109
bool saveLogFile(const QString &logFileName)
void switchToLayerFromLayerSelector(int layerIndex_h)
void receiveScenarioOptions(const QVector< QString > &scenarios_h)
void setInputFileName(QString inputFileName_h)