From 80042045d70028f95f81a5da87e213ee12e5829c Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Thu, 16 Nov 2023 05:13:26 -0700 Subject: [PATCH 1/2] Fix crashing inputs browser for #1577 Technology comparison working but financial comparison not working between hybrids and non-hybrids --- src/variablegrid.cpp | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/variablegrid.cpp b/src/variablegrid.cpp index 2fe5680ba5..dd73a2a38a 100644 --- a/src/variablegrid.cpp +++ b/src/variablegrid.cpp @@ -151,8 +151,8 @@ void VariableGridData::Init() ConfigInfo* ci = m_cases[iCase]->GetConfiguration(); for (size_t iVarTable = 0; iVarTable < m_var_info_lookup_vec[iCase].size(); iVarTable++) { // iterate over case vartables - wxString prepend = ""; - if (ci->Technology.size() > 1) prepend = ci->Technology[iVarTable].Lower() + "_"; + wxString prepend = ci->Technology[iVarTable].Lower() + "_"; + wxArrayString as = m_var_info_lookup_vec[iCase][iVarTable]->ListAll(); for (size_t i = 0; i < as.Count(); i++) { // if ((!((*it)->Lookup(as[i])->Flags & VF_CALCULATED)) && @@ -216,7 +216,7 @@ bool VariableGridData::UpdateVarNameNdxHybrid(Case *c, const wxString& input_nam *var_name = input_name; if (!c) return false; // decode if necessary for hybrids varname for unsorted index - if (c->GetConfiguration()->Technology.size() > 1) { +// if (c->GetConfiguration()->Technology.size() > 1) { // split hybrid name and match with Technology name or use "Hybrid" for remainder wxArrayString as = wxSplit(input_name, '_'); for (size_t j = 0; j < c->GetConfiguration()->Technology.size(); j++) { @@ -225,7 +225,7 @@ bool VariableGridData::UpdateVarNameNdxHybrid(Case *c, const wxString& input_nam *var_name = input_name.Right(input_name.length() - (as[0].length() + 1)); } } - } +// } return true; } @@ -613,27 +613,38 @@ bool VariableGridData::ShowRow(int row, int comparison_type, bool show_calculate case COMPARE_SHOW_DIFFERENT: case COMPARE_SHOW_SAME: { // note that the comparison starts with first case and then check other cases if variable exists - ORDER DEPENDENT - int lookup_row = row; - if (m_sorted) lookup_row = m_sorted_index[row]; - Case* c = m_cases[0]; - wxString var_name; - size_t ndx_hybrid; + int lookup_row = row; + if (m_sorted) lookup_row = m_sorted_index[row]; + Case* c = m_cases[0]; + wxString var_name; + size_t ndx_hybrid; + if (m_var_names.size() > 0) { if (UpdateVarNameNdxHybrid(c, m_var_names[lookup_row], &var_name, &ndx_hybrid)) { if (m_var_table_vec[0][ndx_hybrid]->Get(var_name)) { VarValue* vv = m_var_table_vec[0][ndx_hybrid]->Get(var_name); bool row_varvalues_same = true; for (int col = 1; col < (int)m_cases.size(); col++) { - if (m_var_table_vec[col][ndx_hybrid]->Get(var_name)) { - VarValue* vv_new = m_var_table_vec[col][ndx_hybrid]->Get(var_name); - if (vv->Type() == vv_new->Type()) - row_varvalues_same = (row_varvalues_same && (vv->ValueEqual(*vv_new))); - else{ - show = false; // different variable type in row - should not happen + // decode and key off of m_var_names[lookup_row] + wxString col_var_name; + size_t col_ndx_hybrid; + if (UpdateVarNameNdxHybrid(m_cases[col], m_var_names[lookup_row], &col_var_name, &col_ndx_hybrid)) { + + if (m_var_table_vec[col][col_ndx_hybrid]->Get(col_var_name)) { + VarValue* vv_new = m_var_table_vec[col][col_ndx_hybrid]->Get(col_var_name); + if (vv->Type() == vv_new->Type()) + row_varvalues_same = (row_varvalues_same && (vv->ValueEqual(*vv_new))); + else { + show = false; // different variable type in row - should not happen + continue; + } + } + else { + show = false; // no variable value for (row, col) continue; } } else { - show = false; // no variable value for (row, col) + show = false; // no m_var_names[lookup_row] value for (row, col) continue; } } @@ -648,6 +659,9 @@ bool VariableGridData::ShowRow(int row, int comparison_type, bool show_calculate else show = false; // no variable value for (row, col=0) } + else + show = false; // no var name for (row, col=0) + } break; case COMPARE_SHOW_ALL: default: From cfbbf2947b223adace7a2560566dde8ad90cf1a8 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Fri, 1 Dec 2023 02:57:52 -0700 Subject: [PATCH 2/2] Fix issues with adding and removing cases with input browser opened Fix feedback in spaces in names in #1610 --- src/casewin.cpp | 2 +- src/main.cpp | 6 ++-- src/main_add.h | 1 - src/variablegrid.cpp | 74 +++++++++++++++++++++++++++++++++++++------- src/variablegrid.h | 2 ++ 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index 6ae605e887..82086ca691 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -1406,7 +1406,7 @@ void CaseWindow::UpdateConfiguration() wxString Ts_lower = Ts.Lower(); wxArrayString Ts_split = wxSplit(Ts, '-'); wxDataViewItem cont_pv; - wxDataViewItemArray dvia{ m_pageGroups.size() + 1 }; + wxDataViewItemArray dvia( m_pageGroups.size() + 1 ); wxArrayString bin_list; wxArrayString page_list; wxString bin_name; diff --git a/src/main.cpp b/src/main.cpp index bc15beebe5..47f109f21b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -472,9 +472,11 @@ bool MainWindow::CreateNewCase( const wxString &_name, wxString tech, wxString f if ( m_topBook->GetSelection() != 1 ) m_topBook->SetSelection( 1 ); // switch to cases view if currently in welcome window - Case *c = m_project.AddCase( GetUniqueCaseName(_name ) ); + // Case *c = m_project.AddCase( GetUniqueCaseName(_name ) ); + Case* c = new Case; c->SetConfiguration( tech, fin ); c->LoadDefaults(); + m_project.AddCase(GetUniqueCaseName(_name), c); CreateCaseWindow( c ); return true; } @@ -2944,7 +2946,7 @@ void ConfigDialog::PopulateTech() nodes.Add(node); } - wxDataViewItemArray dvia{containers.Count()}; + wxDataViewItemArray dvia(containers.Count()); // order from startup.lk configopt("TechnologyTreeOrder", ... wxString TreeOrder = SamApp::Config().Options("TechnologyTreeOrder").Description; diff --git a/src/main_add.h b/src/main_add.h index 68f33b236e..4071e466fe 100644 --- a/src/main_add.h +++ b/src/main_add.h @@ -74,7 +74,6 @@ static SamApp::ver releases[] = { //intermediate version numbers are required in this list in order for the version upgrade script (versions.lk) to work correctly //please clarify the reason for the new version in a comment. Examples: public release, variable changes, internal release, public beta release, etc. //the top version should always be the current working version - { 2023, 11, 18 }, { 2023, 10, 31 }, // 2023.10.31 ssc 286 public beta release from develop expires 11/30/2023 { 2023, 10, 6 }, // 2023.10.6 ssc 285 beta release from develop with hybrids expires 1/6/2024 { 2023, 10, 2 }, // 2023.10.2 ssc 284 beta release from develop with hybrids expires 1/2/2024 diff --git a/src/variablegrid.cpp b/src/variablegrid.cpp index dd73a2a38a..36cd5970de 100644 --- a/src/variablegrid.cpp +++ b/src/variablegrid.cpp @@ -151,7 +151,8 @@ void VariableGridData::Init() ConfigInfo* ci = m_cases[iCase]->GetConfiguration(); for (size_t iVarTable = 0; iVarTable < m_var_info_lookup_vec[iCase].size(); iVarTable++) { // iterate over case vartables - wxString prepend = ci->Technology[iVarTable].Lower() + "_"; +// wxString prepend = ci->Technology[iVarTable].Lower() + "_"; + wxString prepend = ci->Simulations[iVarTable].Lower() + "_"; wxArrayString as = m_var_info_lookup_vec[iCase][iVarTable]->ListAll(); for (size_t i = 0; i < as.Count(); i++) { @@ -170,7 +171,15 @@ void VariableGridData::Init() var_names.insert(as[i]); } */ + int row_change = (int)var_names.size() - m_rows; + if (m_rows > 0) { + if (row_change > 0) + AppendRows(row_change); + else if (row_change < 0) + DeleteRows(0,-row_change); + } m_rows = var_names.size(); + for (int row = 0; row < m_rows; row++) m_sorted_index.Add(row); @@ -187,7 +196,8 @@ void VariableGridData::Init() if (m_var_info_lookup_vec[iCase][ndx_hybrid]->Lookup(var_name)) { found = true; wxString prepend = ""; - if (ci->Technology.size() > 1) prepend = ci->Technology[ndx_hybrid] + " "; +// if (ci->Technology.size() > 1) prepend = ci->Technology[ndx_hybrid] + " "; + if (ci->Technology.size() > 1) prepend = ci->Simulations[ndx_hybrid] + " "; str_label = m_var_info_lookup_vec[iCase][ndx_hybrid]->Label(var_name); if (str_label.length() > 0) str_label = prepend + str_label; } @@ -220,7 +230,8 @@ bool VariableGridData::UpdateVarNameNdxHybrid(Case *c, const wxString& input_nam // split hybrid name and match with Technology name or use "Hybrid" for remainder wxArrayString as = wxSplit(input_name, '_'); for (size_t j = 0; j < c->GetConfiguration()->Technology.size(); j++) { - if (c->GetConfiguration()->Technology[j].Lower() == as[0]) { +// if (c->GetConfiguration()->Technology[j].Lower() == as[0]) { + if (c->GetConfiguration()->Simulations[j].Lower() == as[0]) { *ndx_hybrid = j; *var_name = input_name.Right(input_name.length() - (as[0].length() + 1)); } @@ -262,7 +273,7 @@ bool VariableGridData::IsEmptyCell(int row, int col) wxString VariableGridData::GetColLabelValue(int col) { - if (col <= (int)m_col_hdrs.size()) + if (col < (int)m_col_hdrs.size()) return m_col_hdrs[col]; else return wxEmptyString; @@ -529,7 +540,7 @@ wxString VariableGridData::GetTypeName(int row, int col) Case* c = GetCase(row, col); wxString var_name; size_t ndx_hybrid; - if (UpdateVarNameNdxHybrid(c, m_var_names[lookup_row], &var_name, &ndx_hybrid)) { + if (lookup_row < m_var_names.size() && UpdateVarNameNdxHybrid(c, m_var_names[lookup_row], &var_name, &ndx_hybrid)) { if (VarInfo* var_info = m_var_info_lookup_vec[col - 2][ndx_hybrid]->Lookup(var_name)) { // TODO - better control list maintenance here and in UIEditorPanel wxString type = var_info->UIObject; @@ -673,12 +684,13 @@ bool VariableGridData::ShowRow(int row, int comparison_type, bool show_calculate bool calculated = false; int lookup_row = row; if ((row < (int)m_sorted_index.Count()) && (m_sorted)) lookup_row = m_sorted_index[row]; + // calculated = calculated in any case! for (size_t iCase = 0; iCase < m_cases.size(); iCase++) { Case* c = m_cases[iCase]; wxString var_name; size_t ndx_hybrid; - if (UpdateVarNameNdxHybrid(c, m_var_names[lookup_row], &var_name, &ndx_hybrid)) { + if (lookup_row < m_var_names.size() && UpdateVarNameNdxHybrid(c, m_var_names[lookup_row], &var_name, &ndx_hybrid)) { if ((lookup_row < (int)m_var_names.Count()) && (m_var_info_lookup_vec[iCase][ndx_hybrid]->Lookup(var_name))) { VarInfo* vi = m_var_info_lookup_vec[iCase][ndx_hybrid]->Lookup(var_name); if (vi) @@ -720,15 +732,34 @@ bool VariableGridData::DeleteCols(size_t pos, size_t numCols) return true; } + +bool VariableGridData::DeleteRows(size_t pos, size_t numRows) +{ + if (GetView()) + { + wxGridTableMessage msg(this, + wxGRIDTABLE_NOTIFY_ROWS_DELETED, + pos, + numRows); + + GetView()->ProcessTableMessage(msg); + } + + return true; +} + bool VariableGridData::AddCase(Case *c) { std::vector::iterator it = std::find(m_cases.begin(), m_cases.end(), c); if (it == m_cases.end()) { m_cases.push_back(c); - Init(); - AppendCols(); - return true; + + if (c->GetConfiguration()) { + Init(); + AppendCols(); + return true; + } } return false; } @@ -748,6 +779,20 @@ bool VariableGridData::AppendCols(size_t numCols) return true; } +bool VariableGridData::AppendRows(size_t numRows) +{ + if (GetView()) + { + wxGridTableMessage msg(this, + wxGRIDTABLE_NOTIFY_ROWS_APPENDED, + numRows); + + GetView()->ProcessTableMessage(msg); + } + + return true; +} + bool VariableGridData::RenameCase(const wxString &old_name, const wxString &new_name) { @@ -1105,6 +1150,7 @@ void VariableGridFrame::SizeColumns() void VariableGridFrame::UpdateGrid() { wxString filter(m_filter->GetValue().Lower()); +// m_grid->SetTable(m_griddata); m_grid->Freeze(); for (int row = 0; row < m_grid->GetNumberRows(); row++) { @@ -1124,7 +1170,6 @@ void VariableGridFrame::UpdateGrid() m_grid->HideRow(row); } m_grid->Thaw(); - m_grid->ForceRefresh(); } void VariableGridFrame::OnCommand(wxCommandEvent &evt) @@ -1211,6 +1256,7 @@ void VariableGridFrame::OnProjectFileEvent(ProjectFile* WXUNUSED(p), ProjectFile m_griddata->DeleteCase(c); m_grid->Refresh(); UpdateGrid(); + m_grid->ForceRefresh(); } } else if (evt.GetType() == ProjectFileEvent::CASE_ADDED) @@ -1221,8 +1267,12 @@ void VariableGridFrame::OnProjectFileEvent(ProjectFile* WXUNUSED(p), ProjectFile { m_cases.push_back(c); m_griddata->AddCase(c); - m_grid->Refresh(); - UpdateGrid(); + if (c->GetConfiguration()) { + + m_grid->Refresh(); + UpdateGrid(); + m_grid->ForceRefresh(); + } } } else if (evt.GetType() == ProjectFileEvent::CASE_RENAMED) diff --git a/src/variablegrid.h b/src/variablegrid.h index be03e85547..b620e044cd 100644 --- a/src/variablegrid.h +++ b/src/variablegrid.h @@ -80,7 +80,9 @@ class VariableGridData : public GridChoiceData virtual void SetColLabelValue(int col, const wxString &label); virtual wxString GetTypeName(int row, int col); virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1); + virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1); virtual bool AppendCols(size_t numCols = 1); + virtual bool AppendRows(size_t numRows = 1); // set cell background based on input and output status virtual wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);