Skip to content

Commit fc5e9f0

Browse files
authored
Merge pull request #748 from firelab/GUI-Redesign-someFixes
Various small fixes to the Qt6 GUI
2 parents 0ec1408 + 0b130fb commit fc5e9f0

8 files changed

Lines changed: 424 additions & 47 deletions

src/gui/mainWindow.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ void MainWindow::solveButtonClicked()
536536

537537
if(ui->pointInitializationTreeView->property("timeSeriesFlag").toBool())
538538
{
539+
CPLDebug("STATION_FETCH", "Time Series option selected...");
540+
539541
QDateTime start = ui->weatherStationDataStartDateTimeEdit->dateTime();
540542
QDateTime end = ui->weatherStationDataEndDateTimeEdit->dateTime();
541543

@@ -607,6 +609,8 @@ void MainWindow::solveButtonClicked()
607609

608610
if(nTimeSteps == 1)
609611
{
612+
CPLDebug("STATION_FETCH", "USER WANTS 1 STEP, USING START TIME...");
613+
610614
int startYear = year[0];
611615
int startMonth = month[0];
612616
int startDay = day[0];
@@ -640,6 +644,8 @@ void MainWindow::solveButtonClicked()
640644
}
641645
else
642646
{
647+
CPLDebug("STATION_FETCH", "USING TIME LIST...");
648+
643649
ninjaErr = NinjaGetTimeList(
644650
ninjaTools,
645651
year.data(), month.data(), day.data(),
@@ -672,6 +678,8 @@ void MainWindow::solveButtonClicked()
672678

673679
if(ninjaErr == NINJA_SUCCESS)
674680
{
681+
CPLDebug("STATION_FETCH", "TIME LIST GENERATED...");
682+
675683
numNinjas = ui->weatherStationDataTimestepsSpinBox->value();
676684

677685
ninjaErr = NinjaMakePointArmy( ninjaArmy,
@@ -749,6 +757,8 @@ void MainWindow::solveButtonClicked()
749757
}
750758
else
751759
{
760+
CPLDebug("STATION_FETCH", "USING CURRENT/LATEST TIME DATA...");
761+
752762
int year, month, day, hour, minute;
753763
QDateTime date = ui->weatherStationDataLabel->property("simulationTime").toDateTime();
754764
year = date.date().year();
@@ -806,6 +816,8 @@ void MainWindow::solveButtonClicked()
806816

807817
if(ninjaErr == NINJA_SUCCESS)
808818
{
819+
CPLDebug("STATION_FETCH", "TIME LIST GENERATED...");
820+
809821
ninjaErr = NinjaMakePointArmy( ninjaArmy,
810822
yearVec.data(), monthVec.data(), dayVec.data(),
811823
hourVec.data(), minuteVec.data(), nTimeSteps,
@@ -1102,6 +1114,10 @@ bool MainWindow::prepareArmy(NinjaArmyH *ninjaArmy, int numNinjas, const char* i
11021114
{
11031115
if(ui->pointInitializationWriteStationKMLCheckBox->isChecked())
11041116
{
1117+
if(i == 0)
1118+
{
1119+
writeToConsole("Writing Weather Station .kml");
1120+
}
11051121
// function needs MAJOR rework to get the testing to work, direct call to non-ninjaArmy function makes this process tougher
11061122
ninjaErr = NinjaSetStationKML(ninjaArmy, i, ui->elevationInputFileLineEdit->property("fullpath").toString().toUtf8().constData(), ui->outputDirectoryLineEdit->text().toUtf8().constData(), ui->outputSpeedUnitsComboBox->currentText().toUtf8().constData(), papszOptions);
11071123
//ninjaErr = NinjaSetStationKML(ninjaArmy, i+10, ui->elevationInputFileLineEdit->property("fullpath").toString().toUtf8().constData(), ui->outputDirectoryLineEdit->text().toUtf8().constData(), ui->outputSpeedUnitsComboBox->currentText().toUtf8().constData(), papszOptions); // test error handling // function needs reorganized to handle this test
@@ -1169,6 +1185,14 @@ bool MainWindow::prepareArmy(NinjaArmyH *ninjaArmy, int numNinjas, const char* i
11691185
return false;
11701186
}
11711187

1188+
ninjaErr = NinjaSetStabilityFlag(ninjaArmy, i, ui->stabilityCheckBox->isChecked(), papszOptions);
1189+
//ninjaErr = NinjaSetStabilityFlag(ninjaArmy, i+10, ui->stabilityCheckBox->isChecked(), papszOptions); // test error handling
1190+
if(ninjaErr != NINJA_SUCCESS)
1191+
{
1192+
qDebug() << "NinjaSetStabilityFlag: ninjaErr =" << ninjaErr;
1193+
return false;
1194+
}
1195+
11721196
if(ui->vegetationStackedWidget->currentIndex() == 0)
11731197
{
11741198
ninjaErr = NinjaSetUniVegetation(ninjaArmy, i, ui->vegetationComboBox->currentText().toLower().toUtf8().constData(), papszOptions);
@@ -1663,7 +1687,7 @@ void MainWindow::writeSettings()
16631687
settings.setValue("customRes", ui->meshResolutionSpinBox->value());
16641688
settings.setValue("nProcessors", ui->numberOfProcessorsSpinBox->value());
16651689

1666-
writeToConsole("Settings saved.");
1690+
writeToConsole("Settings saved successfully.", Qt::darkGreen);
16671691
}
16681692

16691693
void MainWindow::readSettings()
@@ -1706,7 +1730,7 @@ void MainWindow::readSettings()
17061730
ui->numberOfProcessorsSpinBox->setValue(settings.value("nProcessors").toInt());
17071731
}
17081732

1709-
writeToConsole("Settings read.");
1733+
writeToConsole("Settings read successfully.", Qt::darkGreen);
17101734
}
17111735

17121736
void MainWindow::showEvent(QShowEvent *event)

src/gui/pointInitializationInput.cpp

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void PointInitializationInput::weatherStationDownloadBetweenDatesStartTimeDateTi
9393
{
9494
if(ui->downloadBetweenDatesEndTimeDateTimeEdit->dateTime() < ui->downloadBetweenDatesStartTimeDateTimeEdit->dateTime())
9595
{
96+
emit writeToConsoleSignal("Start Time is greater than End Time!, fixing End Time...");
97+
CPLDebug("STATION_FETCH", "START TIME > END TIME, FIXING END TIME");
9698
ui->downloadBetweenDatesEndTimeDateTimeEdit->setDateTime(ui->downloadBetweenDatesStartTimeDateTimeEdit->dateTime().addSecs(3600));
9799
}
98100
updateTimeSteps();
@@ -102,6 +104,8 @@ void PointInitializationInput::weatherStationDownloadBetweenDatesEndTimeDateTime
102104
{
103105
if(ui->downloadBetweenDatesEndTimeDateTimeEdit->dateTime() < ui->downloadBetweenDatesStartTimeDateTimeEdit->dateTime())
104106
{
107+
emit writeToConsoleSignal("Start Time is greater than End Time!, fixing Start Time...");
108+
CPLDebug("STATION_FETCH", "START TIME > END TIME, FIXING START TIME");
105109
ui->downloadBetweenDatesStartTimeDateTimeEdit->setDateTime(ui->downloadBetweenDatesEndTimeDateTimeEdit->dateTime().addSecs(-3600));
106110
}
107111
updateTimeSteps();
@@ -183,7 +187,7 @@ static void comMessageHandler(const char *pszMessage, void *pUser)
183187
//emit self->updateProgressMessageSignal(QString::fromStdString(clipStr));
184188
//emit self->writeToConsoleSignal(QString::fromStdString(clipStr));
185189
emit self->updateProgressMessageSignal(QString::fromStdString("StationFetch ended in warning:\n"+clipStr));
186-
emit self->writeToConsoleSignal(QString::fromStdString("StationFetch warning: "+clipStr), Qt::yellow);
190+
emit self->writeToConsoleSignal(QString::fromStdString("StationFetch warning: "+clipStr), QColor(255, 140, 0));
187191
}
188192
else
189193
{
@@ -194,9 +198,9 @@ static void comMessageHandler(const char *pszMessage, void *pUser)
194198

195199
void PointInitializationInput::weatherStationDataDownloadButtonClicked()
196200
{
197-
emit writeToConsoleSignal("Fetching station data...");
201+
emit writeToConsoleSignal("Downloading station data...");
198202

199-
progress = new QProgressDialog("Fetching Station Data...", QString(), 0, 0, ui->centralwidget);
203+
progress = new QProgressDialog("Downloading Station Data...", QString(), 0, 0, ui->centralwidget);
200204
progress->setWindowModality(Qt::WindowModal);
201205
progress->setCancelButton(nullptr);
202206
progress->setMinimumDuration(0);
@@ -212,11 +216,21 @@ void PointInitializationInput::weatherStationDataDownloadButtonClicked()
212216
qDebug() << "NinjaSetToolsComMessageHandler(): ninjaErr =" << ninjaErr;
213217
}
214218

219+
CPLDebug("STATION_FETCH", "Fetch Station GUI Function");
220+
CPLDebug("STATION_FETCH", "---------------------------------------");
221+
215222
QString DEMTimeZone = ui->timeZoneComboBox->currentText();
216223
QByteArray DEMTimeZoneBytes = ui->timeZoneComboBox->currentText().toUtf8();
217224
QDateTime start = ui->downloadBetweenDatesStartTimeDateTimeEdit->dateTime();
218225
QDateTime end = ui->downloadBetweenDatesEndTimeDateTimeEdit->dateTime();
219226

227+
CPLDebug("STATION_FETCH", "DEM FILE NAME: %s", QFileInfo(ui->elevationInputFileLineEdit->property("fullpath").toString()).absoluteFilePath().toStdString().c_str());
228+
CPLDebug("STATION_FETCH", "TIME ZONE: %s", DEMTimeZone.toStdString().c_str());
229+
CPLDebug("STATION_FETCH", "geoLoc: %i, (0=\"Download From DEM\",1=\"Download From Station ID\")", ui->weatherStationDataSourceComboBox->currentIndex());
230+
CPLDebug("STATION_FETCH", "timeLoc: %i, (0=\"Download Most Recent Data\",1=\"Download Between Two Dates\")", ui->weatherStationDataTimeComboBox->currentIndex());
231+
CPLDebug("STATION_FETCH", "---------------------------------------");
232+
CPLDebug("STATION_FETCH", "USING DEM: %s", ui->elevationInputFileLineEdit->text().toStdString().c_str());
233+
220234
QVector<int> year = {start.date().year(), end.date().year()};
221235
QVector<int> month = {start.date().month(), end.date().month()};
222236
QVector<int> day = {start.date().day(), end.date().day()};
@@ -387,6 +401,14 @@ void PointInitializationInput::weatherStationDataDownloadButtonClicked()
387401
QFuture<int> future;
388402
if(ui->weatherStationDataSourceComboBox->currentIndex() == 0)
389403
{
404+
if(fetchLatestFlag == true)
405+
{
406+
CPLDebug("STATION_FETCH", "Fetch Params: DEM and Current Data");
407+
}
408+
else
409+
{
410+
CPLDebug("STATION_FETCH", "Fetch Params: DEM and Time series");
411+
}
390412
QString units = ui->downloadFromDEMComboBox->currentText();
391413
double buffer = ui->downloadFromDEMSpinBox->value();
392414
future = QtConcurrent::run(&PointInitializationInput::fetchStationFromBbox, this,
@@ -397,6 +419,14 @@ void PointInitializationInput::weatherStationDataDownloadButtonClicked()
397419
}
398420
else
399421
{
422+
if(fetchLatestFlag == true)
423+
{
424+
CPLDebug("STATION_FETCH", "STID and Current Data");
425+
}
426+
else
427+
{
428+
CPLDebug("STATION_FETCH", "STID and Timeseries");
429+
}
400430
QString stationList = ui->downloadFromStationIDLineEdit->text();
401431
future = QtConcurrent::run(&PointInitializationInput::fetchStationByName, this,
402432
ninjaTools,
@@ -561,10 +591,11 @@ void PointInitializationInput::fetchStationDataFinished()
561591
{
562592
// get the return value of the QtConcurrent::run() function
563593
int result = futureWatcher->future().result();
594+
CPLDebug("STATION_FETCH", "station fetch return value: %i", result);
564595

565596
if(result == NINJA_SUCCESS)
566597
{
567-
emit writeToConsoleSignal("Finished fetching station data.", Qt::darkGreen);
598+
emit writeToConsoleSignal("Finished downloading station data.", Qt::darkGreen);
568599

569600
if (progress)
570601
{
@@ -577,7 +608,7 @@ void PointInitializationInput::fetchStationDataFinished()
577608

578609
} else
579610
{
580-
emit writeToConsoleSignal("Failed to fetch station data.");
611+
emit writeToConsoleSignal("Failed to download station data.");
581612
}
582613
}
583614
// delete the futureWatcher every time, whether success or failure
@@ -633,6 +664,8 @@ void PointInitializationInput::pointInitializationTreeViewItemSelectionChanged(c
633664
{
634665
AppState& state = AppState::instance();
635666
QModelIndexList selectedRows = ui->pointInitializationTreeView->selectionModel()->selectedRows();
667+
CPLDebug("STATION_FETCH", "========================================");
668+
CPLDebug("STATION_FETCH", "NUMBER OF SELECTED STATIONS: %lli", selectedRows.count());
636669

637670
stationFiles.clear();
638671
stationFileTypes.clear();
@@ -641,32 +674,39 @@ void PointInitializationInput::pointInitializationTreeViewItemSelectionChanged(c
641674
minStationLocalDateTime = QDateTime();
642675

643676
state.isStationFileSelected = false;
644-
if (selectedRows.count() > 0)
677+
if(selectedRows.count() > 0)
645678
{
646679
state.isStationFileSelected = true;
647680
}
648681

649682
for(int i = 0; i < selectedRows.count(); i++)
650683
{
684+
// If its a directory, make it so that it can't be selected
651685
if(stationFileSystemModel->isDir(selectedRows[i]))
652686
{
687+
CPLDebug("STATION_FETCH", "IGNORING SELECTED DIRECTORY!");
653688
ui->pointInitializationTreeView->selectionModel()->select(selectedRows[i], QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
654689
return;
655690
}
656691

692+
CPLDebug("STATION_FETCH", "----------------------------------------");
693+
CPLDebug("STATION_FETCH", "STATION NAME: %s", stationFileSystemModel->filePath(selectedRows[i]).toStdString().c_str());
694+
657695
QString recentFileSelected = stationFileSystemModel->filePath(selectedRows[i]);
658696
stationFiles.push_back(recentFileSelected); // note, selected vs valid are two separate things
659697
//qDebug() << "[GUI-Point] Selected file path:" << recentFileSelected;
698+
CPLDebug("STATION_FETCH", "Selected file path: %s", recentFileSelected.toStdString().c_str());
660699

661700
QByteArray filePathBytes = recentFileSelected.toUtf8();
662701
const char* filePath = filePathBytes.constData();
663702
char** options = nullptr;
664703
int stationHeader = NinjaGetWxStationHeaderVersion(filePath, options);
665704
//qDebug() << "[GUI-Point] Station Header: " << stationHeader;
705+
CPLDebug("STATION_FETCH", "STATION HEADER TYPE: %i", stationHeader);
666706

667707
if(stationHeader == 1)
668708
{
669-
writeToConsoleSignal("Station has old station format, which is no longer allowed!");
709+
emit writeToConsoleSignal("Station has old station format, which is no longer allowed!");
670710
state.isStationFileSelectionValid = false;
671711
return;
672712
}
@@ -684,45 +724,54 @@ void PointInitializationInput::pointInitializationTreeViewItemSelectionChanged(c
684724

685725
if(hDS == NULL)
686726
{
687-
writeToConsoleSignal("Cannot open station file!");
727+
emit writeToConsoleSignal("Cannot open station file!");
688728
state.isStationFileSelectionValid = false;
689729
return;
690730
}
691731

692732
OGRLayer* poLayer = hDS->GetLayer(0);
693733
poLayer->ResetReading();
694-
qint64 lastIndex = poLayer->GetFeatureCount();
734+
qint64 lastIndex = poLayer->GetFeatureCount(); // How many lines are on disk
695735
//qDebug() << "[GUI-Point] Number of Time Entries:" << lastIndex;
736+
CPLDebug("STATION_FETCH", "Number of Time Entries: %llu", lastIndex);
696737

697738
OGRFeature* poFeature = poLayer->GetFeature(1); // Skip header, row 1 is first time in series
698739
if(poFeature == NULL)
699740
{
700-
writeToConsoleSignal("No Stations Found in file!");
741+
emit writeToConsoleSignal("No Stations Found in file!");
701742
state.isStationFileSelectionValid = false;
702743
return;
703744
}
704745

705746
QString startDateTimeStr(poFeature->GetFieldAsString(15)); // Time should be in 15th (last) column (0-14)
706-
//qDebug() << "[GUI-Point] Station start time:" << startDateTimeStr;
707747

708748
poFeature = poLayer->GetFeature(lastIndex); // last time in series
709749
QString stopDateTimeStr(poFeature->GetFieldAsString(15));
710-
//qDebug() << "[GUI-Point] Station end Time:" << stopDateTimeStr;
750+
751+
//qDebug() << "[GUI-Point] Station start time:" << startDateTimeStr;
752+
//qDebug() << "[GUI-Point] Station end time:" << stopDateTimeStr;
753+
CPLDebug("STATION_FETCH", "STATION START TIME: %s", startDateTimeStr.toStdString().c_str());
754+
CPLDebug("STATION_FETCH", "STATION END TIME: %s", stopDateTimeStr.toStdString().c_str());
711755

712756
if(startDateTimeStr.isEmpty() && stopDateTimeStr.isEmpty()) // No time series
713757
{
714758
//qDebug() << "[GUI-Point] File cannot be used for Time Series";
759+
CPLDebug("STATION_FETCH", "File cannot be used for Time Series");
715760
timeSeriesFlag = false;
716761
stationFileTypes.push_back(0);
717762
}
718763
else if(!startDateTimeStr.isEmpty() && !stopDateTimeStr.isEmpty()) // Some type of time series
719764
{
720765
//qDebug() << "[GUI-Point] File can be used for Time Series, suggesting time series parameters...";
766+
CPLDebug("STATION_FETCH", "File can be used for Times Series, suggesting time series parameters...");
767+
CPLDebug("STATION_FETCH", "Suggesting Potentially Reasonable Time Series Parameters...");
721768
readStationTime(startDateTimeStr, stopDateTimeStr);
722769
stationFileTypes.push_back(1);
723770
}
724771
}
725772

773+
CPLDebug("STATION_FETCH", "Type of Station File: %i", stationFileTypes[i]);
774+
726775
ui->pointInitializationDataTimeStackedWidget->setCurrentIndex(timeSeriesFlag ? 0 : 1);
727776

728777
if (!timeSeriesFlag)
@@ -735,9 +784,13 @@ void PointInitializationInput::pointInitializationTreeViewItemSelectionChanged(c
735784
}
736785

737786
state.isStationFileSelectionValid = true;
738-
for (int i = 0; i < stationFileTypes.size(); i++)
787+
for(int i = 0; i < stationFileTypes.size(); i++)
739788
{
740-
if (stationFileTypes[i] != stationFileTypes[0]) {
789+
CPLDebug("STATION_FETCH", "stationFileTypes[%i] = %i", i, stationFileTypes[i]);
790+
if(stationFileTypes[i] != stationFileTypes[0])
791+
{
792+
CPLDebug("STATION_FETCH", "found unique stationFileType at: %i", i);
793+
CPLDebug("STATION_FETCH", "WARNING NOT ALL CSVS ARE OF THE SAME TYPE, CANNOT CONTINUE");
741794
state.isStationFileSelectionValid = false;
742795
break;
743796
}
@@ -819,6 +872,11 @@ void PointInitializationInput::readStationTime(QString startDateTimeStr, QString
819872
ui->weatherStationDataStartDateTimeEdit->setEnabled(true);
820873
ui->weatherStationDataEndDateTimeEdit->setEnabled(true);
821874

875+
CPLDebug("STATION_FETCH", "minStationLocalDateTime = %s", minStationLocalDateTime.toString("MM/dd/yyyy HH:mm").toStdString().c_str());
876+
CPLDebug("STATION_FETCH", "maxStationLocalDateTime = %s", maxStationLocalDateTime.toString("MM/dd/yyyy HH:mm").toStdString().c_str());
877+
emit writeToConsoleSignal("Start Time (local): "+minStationLocalDateTime.toString());
878+
emit writeToConsoleSignal("End Time (local): "+maxStationLocalDateTime.toString());
879+
822880
updateTimeSteps();
823881
}
824882

@@ -852,6 +910,8 @@ void PointInitializationInput::weatherStationDataStartDateTimeEditChanged()
852910
{
853911
if(ui->weatherStationDataEndDateTimeEdit->dateTime() < ui->weatherStationDataStartDateTimeEdit->dateTime())
854912
{
913+
emit writeToConsoleSignal("Start Time is greater than End Time!, fixing End Time...");
914+
CPLDebug("STATION_FETCH", "START TIME > END TIME, FIXING END TIME!");
855915
ui->weatherStationDataEndDateTimeEdit->setDateTime(ui->weatherStationDataStartDateTimeEdit->dateTime().addSecs(3600));
856916
}
857917
updateTimeSteps();
@@ -861,13 +921,17 @@ void PointInitializationInput::weatherStationDataEndDateTimeEditChanged()
861921
{
862922
if(ui->weatherStationDataEndDateTimeEdit->dateTime() < ui->weatherStationDataStartDateTimeEdit->dateTime())
863923
{
924+
emit writeToConsoleSignal("Start Time is greater than End Time!, fixing Start Time...");
925+
CPLDebug("STATION_FETCH", "START TIME > END TIME, FIXING START TIME!");
864926
ui->weatherStationDataStartDateTimeEdit->setDateTime(ui->weatherStationDataEndDateTimeEdit->dateTime().addSecs(-3600));
865927
}
866928
updateTimeSteps();
867929
}
868930

869931
void PointInitializationInput::updateTimeSteps()
870932
{
933+
CPLDebug("STATION_FETCH", "Updating suggested time steps...");
934+
871935
int timesteps;
872936

873937
if(ui->weatherStationDataStartDateTimeEdit->dateTime() == ui->weatherStationDataEndDateTimeEdit->dateTime())
@@ -884,6 +948,7 @@ void PointInitializationInput::updateTimeSteps()
884948

885949
if(timesteps == 1)
886950
{
951+
CPLDebug("STATION_FETCH", "One Step Set for Timeseries, greying out stop time!");
887952
ui->weatherStationDataEndDateTimeEdit->setEnabled(false);
888953
ui->weatherStationDataEndDateTimeEdit->setToolTip("Stop time is disabled for 1 time step simulations");
889954
}

0 commit comments

Comments
 (0)