Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1577 #1610

Merged
merged 5 commits into from
Dec 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/casewin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/main_add.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
118 changes: 91 additions & 27 deletions src/variablegrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ 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() + "_";
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++) {
// if ((!((*it)->Lookup(as[i])->Flags & VF_CALCULATED)) &&
Expand All @@ -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);

Expand All @@ -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;
}
Expand Down Expand Up @@ -216,16 +226,17 @@ 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++) {
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));
}
}
}
// }
return true;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -613,27 +624,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;
}
}
Expand All @@ -648,6 +670,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:
Expand All @@ -659,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)
Expand Down Expand Up @@ -706,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<Case*>::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;
}
Expand All @@ -734,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)
{
Expand Down Expand Up @@ -1091,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++)
{
Expand All @@ -1110,7 +1170,6 @@ void VariableGridFrame::UpdateGrid()
m_grid->HideRow(row);
}
m_grid->Thaw();
m_grid->ForceRefresh();
}

void VariableGridFrame::OnCommand(wxCommandEvent &evt)
Expand Down Expand Up @@ -1197,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)
Expand All @@ -1207,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)
Expand Down
2 changes: 2 additions & 0 deletions src/variablegrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down