Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified crhmcode/vcc/CRHMGUI.rc
Binary file not shown.
244 changes: 230 additions & 14 deletions crhmcode/vcc/gui/CRHMmainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}

}


Expand All @@ -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);
}
}
}

}


Expand Down Expand Up @@ -2549,6 +2612,159 @@ void CRHMmainDlg::OnClickFlipTicks()
}


void CRHMmainDlg::OnHRU()
{
CRHMmain* main = CRHMmain::getInstance();

if (!this->using_hru_names)
{
std::map<std::string, ClassModule*>::iterator moduleIt = main->getAllmodules()->find("basin");

std::list<std::pair<std::string, ClassPar*>>::iterator hru_names;

bool names_found = false;

if (moduleIt != main->getAllmodules()->end())
{
ClassModule* module = moduleIt->second;
std::list<std::pair<std::string, ClassPar*>>* paramList = module->getParametersList();

std::list<std::pair<std::string, ClassPar*>>::iterator hru_names_par = paramList->end();
for (
std::list<std::pair<std::string, ClassPar*>>::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();
Expand Down
24 changes: 24 additions & 0 deletions crhmcode/vcc/gui/CRHMmainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ class CRHMmainDlg : public CDialogEx
*/
std::map<UINT, std::pair<std::string, std::string>>* openObsFiles;

/**
* Associates the ith element to the i-1 hru.
*/
std::vector<std::string> 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.
*/
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crhmcode/vcc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down