FFSM++  1.1.0
French Forest Sector Model ++
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 
29 using namespace std;
30 
31 
32 // *************** Initializzation functions... *******************
33 
34 /**
35 
36 It 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/";
52  setCurrentLogFileName("");
53  createStatusBar();
54  curLogFileName ="";
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 
69  readSettings();
70  modelMainThread.setInputFileName(curModelFileName);
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...
139  scenarioWidget = new ScenarioSelectionWidget(this);
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 
159 void
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
180 void
181 MainWindow::closeEvent(QCloseEvent *event) {
182  if (okToContinue()) {
183  writeSettings();
184  modelMainThread.stop();
185  modelMainThread.wait();
186  event->accept();
187  } else {
188  event->ignore();
189  }
190 }
191 
192 void
193 MainWindow::resizeEvent (QResizeEvent *event) {
194  emit resized();
195 }
196 
197 
198 // *************** open model / log saving functions.. ************************
199 
200 void
201 MainWindow::setCurrentLogFileName(const QString &fileName) {
202  curLogFileName = fileName;
203 }
204 
205 void
206 MainWindow::setCurrentModelFileName(const QString &fileName) {
207  curModelFileName = fileName;
208  //setWindowModified(false);
209  modelMainThread.setInputFileName(curModelFileName);
210 
211  QString shownName = "Untitled";
212  if (!curModelFileName.isEmpty()) {
213  shownName = strippedName(curModelFileName);
214  recentFiles.removeAll(curModelFileName);
215  recentFiles.prepend(curModelFileName);
216  updateRecentFileActions();
217  }
218  setWindowTitle(tr("%2 - [%1]").arg(shownName).arg(tr("FFSM - Forest Sector Simulator")));
219 }
220 
221 QString
222 MainWindow::strippedName(const QString &fullFileName) {
223  return QFileInfo(fullFileName).fileName();
224 }
225 
226 void
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 
250 bool
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) {
262  modelMainThread.stop();
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 
288 void
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 
311 void
313  QSettings settings("LEF", "FFSM");
314  recentFiles = settings.value("recentFiles").toStringList();
315  updateRecentFileActions();
316 }
317 
318 void
320  if (okToContinue()) {
321  QAction *action = qobject_cast<QAction *>(sender());
322  if (action){
323  curModelFileName=action->data().toString();
324  setCurrentModelFileName(curModelFileName);
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 
336 bool
338  if (curLogFileName.isEmpty()) {
339  return saveAs();
340  } else {
341  cerr <<(curLogFileName.toStdString())<<endl;
342  cerr <<(outputDirName.toStdString())<<endl;
343  return saveLogFile(curLogFileName);
344  }
345  unsavedStatus = false;
346  return true;
347 }
348 
349 bool
351  QString logFileName = QFileDialog::getSaveFileName(
352  this,
353  tr("Save output log"),
354  outputDirName,
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 
364 bool
365 MainWindow::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 
393 void
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 
405 void
407  if (! modelMainThread.isRunning()) {
408  return ;
409  } else {
410  modelMainThread.stop();
411  modelMainThread.wait();
412  }
413 }
414 
415 void
417  modelMainThread.pauseOrResume();
418 }
419 
420 // ************ display px info **********************
421 /*void
422 MainWindow::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 /**
434 Perform 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 */
439 void
440 MainWindow::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 /**
451 Perform all the operation needed when switching layer:
452  - call mapBox to switch its current layer;
453  - call layerLegend to switch its layer);
454 I don't think it is used anywhere, but any how.. it is here...
455 */
456 void
457 MainWindow::switchToLayer(QString layerName_h) {
458  mapBox->switchToLayer(layerName_h);
459  int index = mapBox->getLayerIndex(layerName_h);
460  layerSelector->setCurrentIndex(index);
461  update();
462 }
463 
464 void
466  QString layerName= layerSelector->itemData(layerIndex_h, Qt::UserRole ).toString();
467  mapBox->switchToLayer(layerName);
468  update();
469 }
470 
471 void
472 MainWindow::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 
477 void
478 MainWindow::updateImage(QString layerName_h, const QImage &image_h) {
479  mapBox->updateImage(layerName_h, image_h);
480  update();
481 }
482 
483 // ************** Status viewer operations ***********************
484 void
485 MainWindow::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 
501 void
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 
527 void
528 MainWindow::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 ***********************
551 void
552 MainWindow::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 
563 void
565  if(hide) debugMsgsEnable = false;
566  else debugMsgsEnable = true;
567 }
568 
569 void
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 
584 void
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 
606 void
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 
663 void
664 MainWindow::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 
670  scenarioWidget->receiveScenarioOptions(scenarios_h);
671  scenarioWidget->show();
672  scenarioWidget->scenarioSelector->setFocus();
673  //scenarioWidget->scenarioSelector->grabMouse();
674  //scenarioWidget->scenarioSelector->grabKeyboard();
675 
676 
677 }
678 
679 void
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 createStatusBar()
Definition: MainWindow.cpp:160
void openRecentFile()
Definition: MainWindow.cpp:319
bool save()
Definition: MainWindow.cpp:337
void startModelMainThread()
Definition: MainWindow.cpp:394
void hideDebugMsgs(bool hide)
Definition: MainWindow.cpp:564
void closeEvent(QCloseEvent *event)
Manage the event of closing the application.
Definition: MainWindow.cpp:181
def text(cat, text_h)
void setCurrentLogFileName(const QString &fileName)
Definition: MainWindow.cpp:201
void stopModelMainThread()
Definition: MainWindow.cpp:406
void pauseOrResumeModelMainThread()
Definition: MainWindow.cpp:416
void open()
Definition: MainWindow.cpp:289
STL namespace.
bool saveAs()
Definition: MainWindow.cpp:350
QString strippedName(const QString &fullFileName)
Definition: MainWindow.cpp:222
void updatePixel(QString layerName_h, int x_h, int y_h, QColor color_h)
Definition: MainWindow.cpp:472
void treeViewerItemRemove(string itemID)
Definition: MainWindow.cpp:502
bool okToContinue()
Definition: MainWindow.cpp:251
void about()
Definition: MainWindow.cpp:570
void treeViewerAddItem(string text, string itemID, string parentID)
e.g. manager_farmer_manager agents or agent_12345_ownedHa
Definition: MainWindow.cpp:528
void readSettings()
Definition: MainWindow.cpp:312
void resizeEvent(QResizeEvent *event)
Manage the event of resizing the application.
Definition: MainWindow.cpp:193
MainWindow()
Constructor.
Definition: MainWindow.cpp:39
bool saveLogFile(const QString &logFileName)
Definition: MainWindow.cpp:365
void openResults()
Definition: MainWindow.cpp:680
void updateRecentFileActions()
Definition: MainWindow.cpp:227
void processLogArea(const QString &message_h)
Definition: MainWindow.cpp:552
void resetGUIForNewSimulation()
Reset the graphical elements for a new simulation // Send the request of getting the pixel info to th...
Definition: MainWindow.cpp:607
void updateImage(QString layerName_h, const QImage &image_h)
Definition: MainWindow.cpp:478
void treeViewerItemChangeValue(string itemID, string newValue)
Change value to an existing item in the Status Viewer.
Definition: MainWindow.cpp:485
void showDocumentation()
Definition: MainWindow.cpp:585
void receiveScenarioOptions(const QVector< QString > &scenarios_h)
Definition: MainWindow.cpp:664
void setCurrentModelFileName(const QString &fileName)
Definition: MainWindow.cpp:206
void writeSettings()
Definition: MainWindow.cpp:386
void switchToLayer(QString layerName_h)
Definition: MainWindow.cpp:457
void switchToLayerFromLayerSelector(int layerIndex_h)
Definition: MainWindow.cpp:465
void addLayer(QString layerName_h, QString layerLabel_h)
Definition: MainWindow.cpp:440