From 153ea83f630e1f17b6270a62d4c97b59c3e5f255 Mon Sep 17 00:00:00 2001 From: jhs507 Date: Fri, 22 Jul 2022 15:04:05 -0600 Subject: [PATCH 1/5] Added function to handle pressing the HRU button. --- crhmcode/vcc/CRHMGUI.rc | Bin 111482 -> 111486 bytes crhmcode/vcc/gui/CRHMmainDlg.cpp | 11 +++++++++++ crhmcode/vcc/gui/CRHMmainDlg.h | 2 ++ crhmcode/vcc/resource.h | 1 + 4 files changed, 14 insertions(+) diff --git a/crhmcode/vcc/CRHMGUI.rc b/crhmcode/vcc/CRHMGUI.rc index dac75e3bf64174ac6bf45c406671549f9ba9a7c3..fad8f9878f9965d4789eda97e0321c1d1646a69a 100644 GIT binary patch delta 44 ycmezMjP2huwhbw9k_rr-3@!}u3?2+Y452{UkHL|_m%)`GxVbWJdu1FWV<-SVuncJc delta 24 gcmezOjP2Jmwhbw9ldt_1VKiy3joV%u$H*880Hn1GIRF3v diff --git a/crhmcode/vcc/gui/CRHMmainDlg.cpp b/crhmcode/vcc/gui/CRHMmainDlg.cpp index 5e756525a..f5af35dba 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) @@ -2549,6 +2552,14 @@ void CRHMmainDlg::OnClickFlipTicks() } +void CRHMmainDlg::OnHRU() +{ + CRHMmain* main = CRHMmain::getInstance(); + + main->getAllmodules()->find("basin"); +} + + 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..976a7ead8 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.h +++ b/crhmcode/vcc/gui/CRHMmainDlg.h @@ -871,6 +871,8 @@ class CRHMmainDlg : public CDialogEx */ afx_msg void OnClickFlipTicks(); + afx_msg void OnHRU(); + /** * 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 From 05f5660f13c322b423c458648c65a3482531f7ee Mon Sep 17 00:00:00 2001 From: jhs507 Date: Fri, 22 Jul 2022 16:35:44 -0600 Subject: [PATCH 2/5] Begining of the implimentation of HRU button --- crhmcode/vcc/gui/CRHMmainDlg.cpp | 82 +++++++++++++++++++++++++++++++- crhmcode/vcc/gui/CRHMmainDlg.h | 18 +++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/crhmcode/vcc/gui/CRHMmainDlg.cpp b/crhmcode/vcc/gui/CRHMmainDlg.cpp index f5af35dba..9ce599414 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.cpp +++ b/crhmcode/vcc/gui/CRHMmainDlg.cpp @@ -2556,7 +2556,87 @@ void CRHMmainDlg::OnHRU() { CRHMmain* main = CRHMmain::getInstance(); - main->getAllmodules()->find("basin"); + 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)); + } + + bool unique_names = true; + for (int i = 0; i < this->hru_names_vec.size(); i++) + { + 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; + } + } + } + } + + if (unique_names) + { + this->using_hru_names = true; + } + else + { + MessageBox(L"Cannot switch to show HRU names because the names are not unique."); + } + + } + else + { + MessageBox(L"The parameter hru_names in basin module was not found.\nCannot switch display to HRU names."); + } + } + else + { + this->using_hru_names = false; + this->hru_names_vec.clear(); + } + + + } diff --git a/crhmcode/vcc/gui/CRHMmainDlg.h b/crhmcode/vcc/gui/CRHMmainDlg.h index 976a7ead8..de3a5ee0e 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,11 @@ 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(); /** From ce8793603d6bf3bc183eebb17820e84a5f457aa3 Mon Sep 17 00:00:00 2001 From: jhs507 Date: Tue, 26 Jul 2022 14:43:06 -0600 Subject: [PATCH 3/5] Added a guard that prevents hru name mode from being entered if any of the names are empty strings. --- crhmcode/vcc/gui/CRHMmainDlg.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crhmcode/vcc/gui/CRHMmainDlg.cpp b/crhmcode/vcc/gui/CRHMmainDlg.cpp index 9ce599414..9d7239a62 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.cpp +++ b/crhmcode/vcc/gui/CRHMmainDlg.cpp @@ -2599,9 +2599,12 @@ void CRHMmainDlg::OnHRU() 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) @@ -2612,15 +2615,36 @@ void CRHMmainDlg::OnHRU() } } } + + /* Checks for any empty names. */ + if (this->hru_names_vec.at(i) == "") + { + empty_names = true; + } } - if (unique_names) + if (unique_names && !empty_names) { this->using_hru_names = true; + + + } else { - MessageBox(L"Cannot switch to show HRU names because the names are not unique."); + 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."); + } + } } From 186a93679c14627f30fefa9bf6be26c72dbce590 Mon Sep 17 00:00:00 2001 From: jhs507 Date: Tue, 26 Jul 2022 16:27:00 -0600 Subject: [PATCH 4/5] Repositioning components to make more room for HRU names to be displayed with the HRU name selector. --- crhmcode/vcc/CRHMGUI.rc | Bin 111486 -> 111484 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/crhmcode/vcc/CRHMGUI.rc b/crhmcode/vcc/CRHMGUI.rc index fad8f9878f9965d4789eda97e0321c1d1646a69a..72cb80331f44c1cca446e44442a804d538e118d2 100644 GIT binary patch delta 132 zcmezOjP1`ewhgnw_zfA%7<3qn8O#|BfVAP{i@~DP1p*n>CO-*N5Hv=SG+{8C+!;B0 z^M-I1MnQ-^69yxQKCo2o^aENzof9HBCMQHnKy|~E0CjKfjJ(a#oEEn|Esjwl6aeO? BAw2*9 delta 135 zcmezKjP2huwhgnw1dSLB7<3qn8O*`75rfI(gTBJk{2A3IKM7M1Gy%$>%63N1-n=24 zg%PUJgaKjzNMmPY?(_v}K%EmJI3_1VN&t160(B!P+1wd Date: Tue, 26 Jul 2022 16:27:48 -0600 Subject: [PATCH 5/5] Using HRU names implemented for the HRU dimension selector. --- crhmcode/vcc/gui/CRHMmainDlg.cpp | 131 +++++++++++++++++++++++++++---- crhmcode/vcc/gui/CRHMmainDlg.h | 4 + 2 files changed, 120 insertions(+), 15 deletions(-) diff --git a/crhmcode/vcc/gui/CRHMmainDlg.cpp b/crhmcode/vcc/gui/CRHMmainDlg.cpp index 9d7239a62..bbdcfc5be 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.cpp +++ b/crhmcode/vcc/gui/CRHMmainDlg.cpp @@ -2057,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); + } } } + } @@ -2076,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); + } + } + } + } @@ -2627,7 +2687,7 @@ void CRHMmainDlg::OnHRU() { this->using_hru_names = true; - + this->ChangeToHRUNamesDisplay(); } else @@ -2655,8 +2715,10 @@ void CRHMmainDlg::OnHRU() } else { + this->ChangeToHRUNumberDisplay(); this->using_hru_names = false; this->hru_names_vec.clear(); + } @@ -2664,6 +2726,45 @@ void CRHMmainDlg::OnHRU() } +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 de3a5ee0e..d81a3df00 100644 --- a/crhmcode/vcc/gui/CRHMmainDlg.h +++ b/crhmcode/vcc/gui/CRHMmainDlg.h @@ -891,6 +891,10 @@ class CRHMmainDlg : public CDialogEx */ 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.