diff --git a/crhmcode/vcc/CRHMGUI.rc b/crhmcode/vcc/CRHMGUI.rc index dac75e3bf..72cb80331 100644 Binary files a/crhmcode/vcc/CRHMGUI.rc and b/crhmcode/vcc/CRHMGUI.rc differ diff --git a/crhmcode/vcc/gui/CRHMmainDlg.cpp b/crhmcode/vcc/gui/CRHMmainDlg.cpp index 5e756525a..bbdcfc5be 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.cpp +++ b/crhmcode/vcc/gui/CRHMmainDlg.cpp @@ -143,6 +143,9 @@ BEGIN_MESSAGE_MAP(CRHMmainDlg, CDialogEx) ON_NOTIFY(DTN_DATETIMECHANGE, ID_START_DATE_PICKER, &CRHMmainDlg::OnStartDateChange) ON_NOTIFY(DTN_DATETIMECHANGE, ID_END_DATE_PICKER, &CRHMmainDlg::OnEndDateChange) + //HRU names button + ON_BN_CLICKED(ID_HRU_NAMES, &CRHMmainDlg::OnHRU) + //Flip ticks button ON_MESSAGE(UWM_FLIP_TICKS_LEFT, &CRHMmainDlg::OnLeftClickFlipTicks) ON_MESSAGE(UWM_FLIP_TICKS_RIGHT, &CRHMmainDlg::OnRightClickFlipTicks) @@ -2054,17 +2057,46 @@ void CRHMmainDlg::DecreaseHRUDimension() CString newValue; int dimension = 0; - GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); - dimension = _ttoi(currentValue); - if (currentValue.Trim().GetLength() > 0) + if (this->using_hru_names) { - if (dimension > 1) + GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); + CT2CA pszConvertedAnsiString(currentValue); + std::string nameString(pszConvertedAnsiString); + int pos = 0; + + for (int i = 0; i < this->hru_names_vec.size(); i++) { - dimension = _ttoi(currentValue) - 1; - newValue.Format(_T("%d"), dimension); - SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + if (this->hru_names_vec.at(i) == nameString) + { + pos = i + 1; + } + } + dimension = pos; + if (currentValue.Trim().GetLength() > 0) + { + if (dimension > 1) + { + dimension--; + newValue = this->hru_names_vec.at(dimension - 1).c_str(); + SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + } } } + else + { + GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); + dimension = _ttoi(currentValue); + if (currentValue.Trim().GetLength() > 0) + { + if (dimension > 1) + { + dimension = _ttoi(currentValue) - 1; + newValue.Format(_T("%d"), dimension); + SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + } + } + } + } @@ -2073,17 +2105,48 @@ void CRHMmainDlg::IncreaseHRUDimension() CString currentValue; CString newValue; int dimension = 0; - GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); - dimension = _ttoi(currentValue); - if (currentValue.Trim().GetLength() > 0) + + if (this->using_hru_names) { - if (dimension < Global::maxhru) + GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); + CT2CA pszConvertedAnsiString(currentValue); + std::string nameString(pszConvertedAnsiString); + int pos = 0; + + for (int i = 0; i < this->hru_names_vec.size(); i++) { - dimension = _ttoi(currentValue) + 1; - newValue.Format(_T("%d"), dimension); - SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + if (this->hru_names_vec.at(i) == nameString) + { + pos = i + 1; + } + } + + dimension = pos; + if (currentValue.Trim().GetLength() > 0) + { + if (dimension < Global::maxhru) + { + dimension++; + newValue = this->hru_names_vec.at(dimension - 1).c_str(); + SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + } + } + } + else + { + GetDlgItemText(ID_HRU_DIM_DISPLAY, currentValue); + dimension = _ttoi(currentValue); + if (currentValue.Trim().GetLength() > 0) + { + if (dimension < Global::maxhru) + { + dimension = _ttoi(currentValue) + 1; + newValue.Format(_T("%d"), dimension); + SetDlgItemText(ID_HRU_DIM_DISPLAY, newValue); + } } } + } @@ -2549,6 +2612,159 @@ void CRHMmainDlg::OnClickFlipTicks() } +void CRHMmainDlg::OnHRU() +{ + CRHMmain* main = CRHMmain::getInstance(); + + if (!this->using_hru_names) + { + std::map::iterator moduleIt = main->getAllmodules()->find("basin"); + + std::list>::iterator hru_names; + + bool names_found = false; + + if (moduleIt != main->getAllmodules()->end()) + { + ClassModule* module = moduleIt->second; + std::list>* paramList = module->getParametersList(); + + std::list>::iterator hru_names_par = paramList->end(); + for ( + std::list>::iterator parIt = paramList->begin(); + parIt != paramList->end(); + parIt++ + ) + { + if (parIt->first == "hru_names") + { + hru_names_par = parIt; + break; + } + } + + if (hru_names_par != paramList->end()) + { + hru_names = hru_names_par; + names_found = true; + } + } + + if (names_found) + { + this->hru_names_vec.clear(); + + for (int i = 0; i < Global::maxhru; i++) + { + this->hru_names_vec.push_back(hru_names->second->Strings->at(i)); + } + + /* Check that the names are unique and not empty strings.*/ + bool unique_names = true; + bool empty_names = false; + for (int i = 0; i < this->hru_names_vec.size(); i++) + { + /* Checks for name uniqueness. */ + for (int j = 0; j < this->hru_names_vec.size(); j++) + { + if (i != j) + { + if (this->hru_names_vec.at(i) == this->hru_names_vec.at(j)) + { + unique_names = false; + } + } + } + + /* Checks for any empty names. */ + if (this->hru_names_vec.at(i) == "") + { + empty_names = true; + } + } + + if (unique_names && !empty_names) + { + this->using_hru_names = true; + + this->ChangeToHRUNamesDisplay(); + + } + else + { + if (!unique_names) + { + this->using_hru_names = false; + this->hru_names_vec.clear(); + MessageBox(L"Cannot switch to show HRU names because the names are not unique."); + } + else if (empty_names) + { + this->using_hru_names = false; + this->hru_names_vec.clear(); + MessageBox(L"Cannot switch to show HRU names because some names are empty strings."); + } + + } + + } + else + { + MessageBox(L"The parameter hru_names in basin module was not found.\nCannot switch display to HRU names."); + } + } + else + { + this->ChangeToHRUNumberDisplay(); + this->using_hru_names = false; + this->hru_names_vec.clear(); + + } + + + +} + + +void CRHMmainDlg::ChangeToHRUNamesDisplay() +{ + /* Change the HRU Selector to display a name */ + CString hruText; + GetDlgItemText(ID_HRU_DIM_DISPLAY, hruText); + CT2CA pszConvertedAnsiString(hruText); + std::string hruString(pszConvertedAnsiString); + int hruNum = std::stoi(hruString) - 1; + std::string hruNameString = this->hru_names_vec.at(hruNum); + CString hruNameText(hruNameString.c_str()); + SetDlgItemText(ID_HRU_DIM_DISPLAY, hruNameText); + +} + + +void CRHMmainDlg::ChangeToHRUNumberDisplay() +{ + /* Change the HRU Selector to display a number */ + CString hruText; + GetDlgItemText(ID_HRU_DIM_DISPLAY, hruText); + CT2CA pszConvertedAnsiString(hruText); + std::string hruString(pszConvertedAnsiString); + int pos = 0; + for (size_t i = 0; i < this->hru_names_vec.size(); i++) + { + if (this->hru_names_vec.at(i) == hruString) + { + pos = i + 1; + break; + } + } + std::string hruNumberString = std::to_string(pos); + CString hruNumberText(hruNumberString.c_str()); + SetDlgItemText(ID_HRU_DIM_DISPLAY, hruNumberText); + + +} + + LRESULT CRHMmainDlg::OnLeftClickFlipTicks(WPARAM, LPARAM) { CRHMmain* model = CRHMmain::getInstance(); diff --git a/crhmcode/vcc/gui/CRHMmainDlg.h b/crhmcode/vcc/gui/CRHMmainDlg.h index a48a67c40..d81a3df00 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.h +++ b/crhmcode/vcc/gui/CRHMmainDlg.h @@ -229,6 +229,19 @@ class CRHMmainDlg : public CDialogEx */ std::map>* openObsFiles; + /** + * Associates the ith element to the i-1 hru. + */ + std::vector hru_names_vec; + + /** + * Tracks if hru names are being used in place of hru number designations + * + * True if hru names are being used. + * False if hru numbers are bing used. + */ + bool using_hru_names = false; + /** * Initalizes the dialog elements after creating the dialog. */ @@ -871,6 +884,17 @@ class CRHMmainDlg : public CDialogEx */ afx_msg void OnClickFlipTicks(); + /** + * Handler for clicking on the HRU button. + * + * Switches the display to use HRU names instead of numbers. + */ + afx_msg void OnHRU(); + + void ChangeToHRUNamesDisplay(); + + void ChangeToHRUNumberDisplay(); + /** * Handler for when the user left clicks on the flip ticks button * handles the UWM_FLIP_TICKS_LEFT message. diff --git a/crhmcode/vcc/resource.h b/crhmcode/vcc/resource.h index 63441fb0c..7b4426ace 100644 --- a/crhmcode/vcc/resource.h +++ b/crhmcode/vcc/resource.h @@ -204,6 +204,7 @@ #define ID_CTX_ALL_VAR_ADD_ARRAY 34008 #define ID_CTX_SEL_VAR_REMOVE 34009 #define ID_CTX_SEL_VAR_APPLY 34010 +#define ID_HRU_NAMES 34011 #define ID_OBS_DIM_DISPLAY 35100 #define ID_OBS_DIM_DECREASE 35101