26 #include <QMutexLocker> 73 emit upgradeLogArea(
"**INFO: Start running the model...");
77 deleteDeadOldPointers();
78 emit resetGUIForNewSimulation();
81 QFileInfo file(inputFileName);
82 QDir baseDir = file.absoluteDir();
83 baseDirectory = baseDir.absolutePath()+
"/";
88 vector<string>
scenarios = MD->getScenarios();
89 QVector<QString> qscenarios;
90 for(uint i=0;i<scenarios.size();i++){
91 qscenarios.push_back(scenarios.at(i).c_str());
94 emit sendScenarioOptionsToGUI(qscenarios);
110 emit upgradeLogArea(
"**INFO: Model has stopped or rised an error (read previous line).");
112 emit upgradeLogArea(
"**INFO: Model has ended.");
118 scenarioName = scenarioName_h;
119 msgOut(
MSG_INFO,
"Selected scenario: "+scenarioName.toStdString());
120 cout <<
"Selected scenario: "+scenarioName.toStdString() << endl;
128 scenarioName = scenarioName_h;
129 inputFileName = inputFileName_h;
130 QFileInfo file(inputFileName);
131 QDir baseDir = file.absoluteDir();
132 baseDirectory = baseDir.absolutePath()+
"/";
133 cout <<
"Using base directory: "<< baseDirectory.toStdString() << endl;
138 if( scenarioName_h ==
""){
139 vector<string>
scenarios = MD->getScenarios();
140 scenarioName = scenarios.at(0).c_str();
152 inputFileName= inputFileName_h;
153 QFileInfo file(inputFileName);
154 QDir baseDir = file.absoluteDir();
155 baseDirectory = baseDir.absolutePath()+
"/";
166 if (DO) {
delete DO; DO=0;}
167 if (INIT) {
delete INIT; INIT=0;}
168 if (SCD) {
delete SCD; SCD=0;}
169 if (GIS) {
delete GIS; GIS=0;}
170 if (MD) {
delete MD; MD=0;}
171 if (CORE){
delete CORE; CORE=0;}
172 if (SCORE){
delete SCORE; SCORE=0;}
173 if (CBAL) {
delete CBAL; CBAL=0;}
175 if(TEST){
delete TEST; TEST=0;}
177 if(gen){
delete gen; gen=0;}
183 emit upgradeLogArea(
"STOP cliccked stopping");
191 emit upgradeLogArea(
"PAUSE cliccked PAUSING");
195 emit upgradeLogArea(
"PAUSE cliccked RESUMING");
196 emit setGUIUnsavedStatus(
true);
223 emit setGUIUnsavedStatus(
true);
231 checkQuery(0,0,
false);
238 emit upgradeLogArea(
"Model has been stopped.");
246 QString message = message_h.c_str();
247 emit upgradeLogArea(message);
249 emit upgradeMainSBLabelToGui(message);
255 emit setOutputDirNameToGui(outputDirname_h);
260 QString layerName = layerName_h.c_str();
261 QString layerLabel = layerLabel_h.c_str();
262 emit addLayerToGui(layerName, layerLabel);
267 emit updatePixelToGui(layerName_h.c_str(), x_h, y_h, color_h);
272 emit updateImageToGui(layerName_h.c_str(), image_h);
277 emit upgradeMainSBLabelToGui(message_h.c_str());
283 temp= i2s(year).c_str();
284 emit upgradeYearSBLabelToGui(temp);
294 QMutexLocker locker(&mutex);
297 layerQueryPos = currentLayerIndex;
298 if(stopped){computeQuery(pxQueryID, layerQueryPos);layerQueryPos = -1;}
299 else{emit publishQueryResults(
"<i>..wait.. processing query..</i>");}
305 computeQuery(pxQueryID, layerQueryPos);
317 vector<Layers*> layers;
319 layers = GIS->getLayerPointers();
322 emit publishQueryResults(
"GIS pointer is dead.. maybe simulation has ended???");
326 int realID = GIS->sub2realID(px_ID);
328 emit publishQueryResults(
"Query result: Spatial data is not yet ready in the model. Please click again later.");
333 px = GIS->getPixel(realID);
336 emit publishQueryResults(
"Query result: Spatial data is not yet ready in the model. Please click again later.");
340 result += i2s(realID).c_str();
342 result += i2s(px->
getX()).c_str();
344 result += i2s(px->
getY()).c_str();
346 result +=
"<p><table>";
347 uint countVisibleLayers = 0;
348 for (uint i=0;i<layers.size();i++){
349 if(!layers[i]->getDisplay()){
352 QString boldStart=
"";
353 QString boldEnd =
"";
354 if (countVisibleLayers == currentLayerIndex){
359 string layerName = layers[i]->getName();
361 string category = layers[i]->getCategory(value);
365 result += layerName.c_str();
367 result +=
"</td><td>";
369 result += category.c_str();
373 if(layers[i]->getDisplay()){
374 countVisibleLayers++;
377 result +=
"</table>";
379 emit publishQueryResults(result);
Main program scheleton. It control the flow of the program.
void upgradeYearSBLabel(int year)
void upgradeMainSBLabel(const string message_h)
void setOutputDirName(string outputDirname_h)
void deleteDeadOldPointers()
Useful for several model running without leaving the GUI.
double getDoubleValue(const string &layerName_h, const bool &returnZeroForNoValue=false) const
Return the value for a specific layer.
void computeQuery(int px_ID, int currentLayerIndex)
Compute the pixel query and return it to the GUI (with a signal)
void setInputFileName(QString inputFileName_h)
void checkQuery(int px_ID, int currentLayerIndex, bool newRequest=true)
Switch and control the access to pxQueryID and layerQueryPos members.
void retrieveScenarioNameFromGUI(const QString &scenarioName_h)
void addLayer(string layerName_h, string layerLabel_h)
void runFromConsole(QString inputFileName_h, QString scenarioName_h)
Re-draw the map making it to fit (with the right proportions) to the widget.
void run()
Run the program.
void setMessage(const QString &message)
void updateImage(string layerName_h, const QImage &image_h)
This file is the header of BaseClass and it is included by ALL compiled code.
void msgOut(const int msgCode_h, const string message_h)
void updatePixel(string layerName_h, int x_h, int y_h, QColor color)