From e59f46f7518c2c92020ac1f0d63eab2f302c83d7 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Wed, 4 Oct 2023 02:59:21 -0600 Subject: [PATCH 01/12] Start of wxMetriDataViewCtrl and model --- src/casewin.h | 2 +- src/main.cpp | 4 ++-- src/main.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/casewin.h b/src/casewin.h index f1873b542c..c77b9a1553 100644 --- a/src/casewin.h +++ b/src/casewin.h @@ -150,7 +150,7 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener wxStaticText *m_techLabel; wxStaticText* m_finLabel; wxMetroButton *m_simButton, *m_resultsButton; - wxMetroDataViewTreeCtrl *m_navigationMenu; + wxMetroDataViewCtrl *m_navigationMenu; wxDataViewItem m_previousPage; // to allow switching case configurations with P50/P90 and PVUncertainty diff --git a/src/main.cpp b/src/main.cpp index 548d8fe76a..b53db7e399 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2762,8 +2762,8 @@ ConfigDialog::ConfigDialog( wxWindow *parent, const wxSize &size ) SetBackgroundColour( wxMetroTheme::Colour( wxMT_FOREGROUND ) ); CenterOnParent(); - m_pTech = new wxMetroDataViewTreeCtrl(this, ID_TechTree); - m_pFin = new wxMetroDataViewTreeCtrl(this, ID_FinTree); + m_pTech = new wxMetroDataViewCtrl(this, ID_TechTree); + m_pFin = new wxMetroDataViewCtrl(this, ID_FinTree); wxBoxSizer *choice_sizer = new wxBoxSizer( wxHORIZONTAL ); choice_sizer->Add( m_pTech, 1, wxALL|wxEXPAND, 0 ); diff --git a/src/main.h b/src/main.h index 83e56b54f2..30e925b1c5 100644 --- a/src/main.h +++ b/src/main.h @@ -408,7 +408,7 @@ DECLARE_APP( SamApp ); class wxCheckBox; class wxMetroButton; class wxMetroListBox; -class wxMetroDataViewTreeCtrl; +class wxMetroDataViewCtrl; class ConfigDialog : public wxDialog { @@ -434,7 +434,7 @@ class ConfigDialog : public wxDialog void UpdateFinTree(); - wxMetroDataViewTreeCtrl *m_pTech, *m_pFin; + wxMetroDataViewCtrl *m_pTech, *m_pFin; wxArrayString m_tnames, m_fnames; wxString m_techname, m_finname; From f3ac6a59de7f1766bf4591ef805c4263658bcf6e Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Thu, 5 Oct 2023 04:29:54 -0600 Subject: [PATCH 02/12] Working on wxMetroDataViewCtrl --- src/casewin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index ef82f8e462..33eb39659a 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -202,7 +202,7 @@ CaseWindow::CaseWindow( wxWindow *parent, Case *c ) szvl->Add(m_finLabel, 0, wxEXPAND | wxALL, 0); // navigation menu sizers - m_navigationMenu = new wxMetroDataViewTreeCtrl(m_left_panel, ID_TechTree); + m_navigationMenu = new wxMetroDataViewCtrl(m_left_panel, ID_TechTree); wxBoxSizer* choice_sizer = new wxBoxSizer(wxHORIZONTAL); choice_sizer->Add(m_navigationMenu, 1, wxALL | wxEXPAND, 0); m_navigationMenu->SetBackgroundColour(wxColour(243, 243, 243)); From cf514edd67423fb1d15383f4be6997879346d770 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Sat, 7 Oct 2023 02:56:53 -0600 Subject: [PATCH 03/12] implement wxMetroDataViewTreeCtrl and model based on wxWidgets source --- src/casewin.cpp | 2 +- src/casewin.h | 2 +- src/main.cpp | 4 ++-- src/main.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index 33eb39659a..ef82f8e462 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -202,7 +202,7 @@ CaseWindow::CaseWindow( wxWindow *parent, Case *c ) szvl->Add(m_finLabel, 0, wxEXPAND | wxALL, 0); // navigation menu sizers - m_navigationMenu = new wxMetroDataViewCtrl(m_left_panel, ID_TechTree); + m_navigationMenu = new wxMetroDataViewTreeCtrl(m_left_panel, ID_TechTree); wxBoxSizer* choice_sizer = new wxBoxSizer(wxHORIZONTAL); choice_sizer->Add(m_navigationMenu, 1, wxALL | wxEXPAND, 0); m_navigationMenu->SetBackgroundColour(wxColour(243, 243, 243)); diff --git a/src/casewin.h b/src/casewin.h index c77b9a1553..f1873b542c 100644 --- a/src/casewin.h +++ b/src/casewin.h @@ -150,7 +150,7 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener wxStaticText *m_techLabel; wxStaticText* m_finLabel; wxMetroButton *m_simButton, *m_resultsButton; - wxMetroDataViewCtrl *m_navigationMenu; + wxMetroDataViewTreeCtrl *m_navigationMenu; wxDataViewItem m_previousPage; // to allow switching case configurations with P50/P90 and PVUncertainty diff --git a/src/main.cpp b/src/main.cpp index b53db7e399..548d8fe76a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2762,8 +2762,8 @@ ConfigDialog::ConfigDialog( wxWindow *parent, const wxSize &size ) SetBackgroundColour( wxMetroTheme::Colour( wxMT_FOREGROUND ) ); CenterOnParent(); - m_pTech = new wxMetroDataViewCtrl(this, ID_TechTree); - m_pFin = new wxMetroDataViewCtrl(this, ID_FinTree); + m_pTech = new wxMetroDataViewTreeCtrl(this, ID_TechTree); + m_pFin = new wxMetroDataViewTreeCtrl(this, ID_FinTree); wxBoxSizer *choice_sizer = new wxBoxSizer( wxHORIZONTAL ); choice_sizer->Add( m_pTech, 1, wxALL|wxEXPAND, 0 ); diff --git a/src/main.h b/src/main.h index 30e925b1c5..8b72e0ebe0 100644 --- a/src/main.h +++ b/src/main.h @@ -434,7 +434,7 @@ class ConfigDialog : public wxDialog void UpdateFinTree(); - wxMetroDataViewCtrl *m_pTech, *m_pFin; + wxMetroDataViewTreeCtrl *m_pTech, *m_pFin; wxArrayString m_tnames, m_fnames; wxString m_techname, m_finname; From 475e2c73731b3b48ecb2828c83f78162e538a156 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Sun, 8 Oct 2023 04:13:21 -0600 Subject: [PATCH 04/12] testing updated tree control expanding and collapsing --- src/casewin.cpp | 1 + src/main.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index ef82f8e462..95386bbacd 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -698,6 +698,7 @@ void CaseWindow::OnTechTree(wxDataViewEvent&) void CaseWindow::OnTreeActivated(wxDataViewEvent& evt) { + wxString here = "yes"; evt.Veto(); } diff --git a/src/main.cpp b/src/main.cpp index 548d8fe76a..c13cab434a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3021,6 +3021,8 @@ void ConfigDialog::UpdateFinTree() void ConfigDialog::OnTreeActivated(wxDataViewEvent &evt) { + // when does this happen + wxString here = "yes"; evt.Veto(); } @@ -3033,12 +3035,13 @@ void ConfigDialog::OnFinTreeDoubleClick(wxDataViewEvent &evt) } -void ConfigDialog::OnTechTree(wxDataViewEvent &) +void ConfigDialog::OnTechTree(wxDataViewEvent &evt) { if (m_pTech->IsContainer(m_pTech->GetCurrentItem())) { - m_pTech->Expand(m_pTech->GetCurrentItem()); - m_techname = ""; +// m_pTech->Expand(m_pTech->GetCurrentItem()); +// m_techname = ""; +// evt.Veto(); return; } wxString title = m_pTech->GetItemText(m_pTech->GetCurrentItem()); From 65bf8b22aefb0b7f7cdae9a66edd8b7642ca8174 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Sun, 8 Oct 2023 04:14:01 -0600 Subject: [PATCH 05/12] reset tech tree selections --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c13cab434a..5240492ea6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3039,9 +3039,8 @@ void ConfigDialog::OnTechTree(wxDataViewEvent &evt) { if (m_pTech->IsContainer(m_pTech->GetCurrentItem())) { -// m_pTech->Expand(m_pTech->GetCurrentItem()); -// m_techname = ""; -// evt.Veto(); + m_pTech->Expand(m_pTech->GetCurrentItem()); + m_techname = ""; return; } wxString title = m_pTech->GetItemText(m_pTech->GetCurrentItem()); From 8e9d1b836561f8bc4bc17928305d7ece8079c895 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Mon, 9 Oct 2023 04:03:27 -0600 Subject: [PATCH 06/12] event testing for container selection --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5240492ea6..f248113616 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2740,6 +2740,8 @@ enum { ID_TechTree = wxID_HIGHEST+98, ID_FinTree }; BEGIN_EVENT_TABLE(ConfigDialog, wxDialog) EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, ConfigDialog::OnTreeActivated) +EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_TechTree, ConfigDialog::OnTreeActivated) +EVT_DATAVIEW_ITEM_EDITING_DONE(ID_TechTree, ConfigDialog::OnTreeActivated) EVT_DATAVIEW_ITEM_START_EDITING(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, ConfigDialog::OnTreeActivated) EVT_DATAVIEW_ITEM_ACTIVATED(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) @@ -3022,7 +3024,7 @@ void ConfigDialog::UpdateFinTree() void ConfigDialog::OnTreeActivated(wxDataViewEvent &evt) { // when does this happen - wxString here = "yes"; + wxMessageBox("Activated"); evt.Veto(); } From 32ed898d6678206ad3bd0a17c926f3b522963804 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Tue, 10 Oct 2023 03:28:46 -0600 Subject: [PATCH 07/12] Configuration tree working as desired on windows --- src/main.cpp | 131 ++++++++++++++++++++++++++++++++++++--------------- src/main.h | 6 ++- 2 files changed, 99 insertions(+), 38 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f248113616..03b191f1ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2739,13 +2739,15 @@ void SamApp::InstallPythonPackage(const std::string& pip_name) { enum { ID_TechTree = wxID_HIGHEST+98, ID_FinTree }; BEGIN_EVENT_TABLE(ConfigDialog, wxDialog) -EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, ConfigDialog::OnTreeActivated) -EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_TechTree, ConfigDialog::OnTreeActivated) -EVT_DATAVIEW_ITEM_EDITING_DONE(ID_TechTree, ConfigDialog::OnTreeActivated) -EVT_DATAVIEW_ITEM_START_EDITING(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) -EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, ConfigDialog::OnTreeActivated) -EVT_DATAVIEW_ITEM_ACTIVATED(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) -EVT_DATAVIEW_SELECTION_CHANGED(ID_TechTree, ConfigDialog::OnTechTree) + //EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, ConfigDialog::OnTreeActivated) + //EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_TechTree, ConfigDialog::OnTreeActivated) + //EVT_DATAVIEW_ITEM_EDITING_DONE(ID_TechTree, ConfigDialog::OnTreeActivated) + //EVT_DATAVIEW_ITEM_START_EDITING(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) + EVT_DATAVIEW_ITEM_COLLAPSING(ID_TechTree, ConfigDialog::OnTechTreeCollapsing) + EVT_DATAVIEW_ITEM_COLLAPSING(ID_FinTree, ConfigDialog::OnFinTreeCollapsing) + //EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, ConfigDialog::OnTreeActivated) + EVT_DATAVIEW_ITEM_ACTIVATED(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) + EVT_DATAVIEW_SELECTION_CHANGED(ID_TechTree, ConfigDialog::OnTechTree) EVT_DATAVIEW_SELECTION_CHANGED(ID_FinTree, ConfigDialog::OnFinTree) EVT_BUTTON( wxID_HELP, ConfigDialog::OnHelp ) EVT_BUTTON( wxID_OK, ConfigDialog::OnOk ) @@ -2969,6 +2971,7 @@ void ConfigDialog::PopulateTech() void ConfigDialog::UpdateFinTree() { + m_finDVI = wxDataViewItem(0); m_pFin->DeleteAllItems(); m_fnames = SamApp::Config().GetFinancingForTech(m_techname); @@ -2976,20 +2979,16 @@ void ConfigDialog::UpdateFinTree() wxDataViewItem cont_dist; //wxDataViewItem cont_tpo; //TPO - for (size_t i = 0; i < m_fnames.Count(); i++) - { + for (size_t i = 0; i < m_fnames.Count(); i++) { wxString TP(SamApp::Config().Options(m_fnames[i]).TreeParent); - if (TP.Find("PPA") != wxNOT_FOUND) - { + if (TP.Find("PPA") != wxNOT_FOUND) { cont_ppa = m_pFin->AppendContainer(wxDataViewItem(0), "Power Purchase Agreement"); break; } } - for (size_t i = 0; i < m_fnames.Count(); i++) - { + for (size_t i = 0; i < m_fnames.Count(); i++) { wxString TP(SamApp::Config().Options(m_fnames[i]).TreeParent); - if (TP.Find("DISTRIBUTED") != wxNOT_FOUND) - { + if (TP.Find("DISTRIBUTED") != wxNOT_FOUND) { cont_dist = m_pFin->AppendContainer(wxDataViewItem(0), "Distributed"); break; } @@ -3005,8 +3004,7 @@ void ConfigDialog::UpdateFinTree() }*/ - for (size_t i = 0; i < m_fnames.Count(); i++) - { + for (size_t i = 0; i < m_fnames.Count(); i++) { wxString L(SamApp::Config().Options(m_fnames[i]).LongName); if (L.IsEmpty()) L = m_fnames[i]; wxString TP(SamApp::Config().Options(m_fnames[i]).TreeParent); @@ -3021,12 +3019,43 @@ void ConfigDialog::UpdateFinTree() } } +/* void ConfigDialog::OnTreeActivated(wxDataViewEvent &evt) { // when does this happen wxMessageBox("Activated"); evt.Veto(); } +*/ + +void ConfigDialog::OnTechTreeCollapsing(wxDataViewEvent& evt) +{ + wxDataViewItem dvi = evt.GetItem(); + if (dvi.IsOk() && m_pTech->IsContainer(dvi)) { + auto selectedDVI = m_pTech->GetCurrentItem(); + if (selectedDVI.IsOk()) { + for (size_t i = 0; i < m_pTech->GetChildCount(dvi); i++) { + if (selectedDVI == m_pTech->GetNthChild(dvi, i)) + evt.Veto(); + } + } + } +} + +void ConfigDialog::OnFinTreeCollapsing(wxDataViewEvent& evt) +{ + wxDataViewItem dvi = evt.GetItem(); + if (dvi.IsOk() && m_pFin->IsContainer(dvi)) { + auto selectedDVI = m_pFin->GetCurrentItem(); + if (selectedDVI.IsOk()) { + for (size_t i = 0; i < m_pFin->GetChildCount(dvi); i++) { + if (selectedDVI == m_pFin->GetNthChild(dvi, i)) + evt.Veto(); + } + } + } +} + void ConfigDialog::OnFinTreeDoubleClick(wxDataViewEvent &evt) { @@ -3039,20 +3068,34 @@ void ConfigDialog::OnFinTreeDoubleClick(wxDataViewEvent &evt) void ConfigDialog::OnTechTree(wxDataViewEvent &evt) { - if (m_pTech->IsContainer(m_pTech->GetCurrentItem())) - { - m_pTech->Expand(m_pTech->GetCurrentItem()); - m_techname = ""; + wxDataViewItem dvi = evt.GetItem(); + if (!dvi.IsOk()) return; + + if (m_pTech->IsContainer(dvi)) + { + if (m_pTech->IsExpanded(dvi)) + m_pTech->Collapse(dvi); + else + m_pTech->Expand(dvi); + if (m_techDVI.IsOk()) {// keep current selection + m_pTech->SetCurrentItem(m_techDVI); + return; + } + else {// select first child + m_techDVI = m_pTech->GetNthChild(dvi, 0); + m_pTech->SetCurrentItem(m_techDVI); + } } - wxString title = m_pTech->GetItemText(m_pTech->GetCurrentItem()); + else { + m_techDVI = evt.GetItem(); + } + wxString title = m_pTech->GetItemText(m_techDVI); if (title.empty()) title = "None"; m_techname = title; - for (size_t i = 0; i < m_tnames.Count(); i++) - { - if (SamApp::Config().Options(m_tnames[i]).LongName == m_techname) - { + for (size_t i = 0; i < m_tnames.Count(); i++) { + if (SamApp::Config().Options(m_tnames[i]).LongName == m_techname) { m_techname = m_tnames[i]; break; } @@ -3061,22 +3104,36 @@ void ConfigDialog::OnTechTree(wxDataViewEvent &evt) UpdateFinTree(); } -void ConfigDialog::OnFinTree(wxDataViewEvent &) +void ConfigDialog::OnFinTree(wxDataViewEvent &evt) { - if (m_pFin->IsContainer(m_pFin->GetCurrentItem())) - { - m_pFin->Expand(m_pFin->GetCurrentItem()); - m_finname = ""; + wxDataViewItem dvi = evt.GetItem(); + if (!dvi.IsOk()) return; + + if (m_pFin->IsContainer(dvi)) + { + if (m_pFin->IsExpanded(dvi)) + m_pFin->Collapse(dvi); + else + m_pFin->Expand(dvi); + if (m_finDVI.IsOk()) {// keep current selection + m_pFin->SetCurrentItem(m_finDVI); + return; + } + else {// select first child + m_finDVI = m_pFin->GetNthChild(dvi, 0); + m_pFin->SetCurrentItem(m_finDVI); + } } - wxString title = m_pFin->GetItemText(m_pFin->GetCurrentItem()); - if (title.empty() || m_pFin->IsContainer(m_pFin->GetCurrentItem())) + else { + m_finDVI = evt.GetItem(); + } + wxString title = m_pFin->GetItemText(m_finDVI); + if (title.empty()) title = "None"; m_finname = title; - for (size_t i = 0; i < m_fnames.Count(); i++) - { - if (SamApp::Config().Options(m_fnames[i]).LongName == m_finname) - { + for (size_t i = 0; i < m_fnames.Count(); i++) { + if (SamApp::Config().Options(m_fnames[i]).LongName == m_finname) { m_finname = m_fnames[i]; break; } diff --git a/src/main.h b/src/main.h index 8b72e0ebe0..d62d0f40ef 100644 --- a/src/main.h +++ b/src/main.h @@ -427,8 +427,10 @@ class ConfigDialog : public wxDialog private: void PopulateTech(); bool ValidateSelections(); - void OnTreeActivated(wxDataViewEvent &evt); +// void OnTreeActivated(wxDataViewEvent& evt); + void OnTechTreeCollapsing(wxDataViewEvent& evt); void OnTechTree(wxDataViewEvent &); + void OnFinTreeCollapsing(wxDataViewEvent& evt); void OnFinTree(wxDataViewEvent &); void OnFinTreeDoubleClick(wxDataViewEvent &); @@ -437,6 +439,8 @@ class ConfigDialog : public wxDialog wxMetroDataViewTreeCtrl *m_pTech, *m_pFin; wxArrayString m_tnames, m_fnames; wxString m_techname, m_finname; + wxDataViewItem m_techDVI, m_finDVI; + void OnOk( wxCommandEvent & ); void OnCancel( wxCommandEvent & ); From 4dc328016dcde533d49aafd22aa9e177daba3b60 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Tue, 10 Oct 2023 03:36:05 -0600 Subject: [PATCH 08/12] Remove commented code with events no longer used --- src/main.cpp | 14 +------------- src/main.h | 1 - 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 03b191f1ea..230ef76ca0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2739,13 +2739,8 @@ void SamApp::InstallPythonPackage(const std::string& pip_name) { enum { ID_TechTree = wxID_HIGHEST+98, ID_FinTree }; BEGIN_EVENT_TABLE(ConfigDialog, wxDialog) - //EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, ConfigDialog::OnTreeActivated) - //EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_TechTree, ConfigDialog::OnTreeActivated) - //EVT_DATAVIEW_ITEM_EDITING_DONE(ID_TechTree, ConfigDialog::OnTreeActivated) - //EVT_DATAVIEW_ITEM_START_EDITING(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) EVT_DATAVIEW_ITEM_COLLAPSING(ID_TechTree, ConfigDialog::OnTechTreeCollapsing) EVT_DATAVIEW_ITEM_COLLAPSING(ID_FinTree, ConfigDialog::OnFinTreeCollapsing) - //EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, ConfigDialog::OnTreeActivated) EVT_DATAVIEW_ITEM_ACTIVATED(ID_FinTree, ConfigDialog::OnFinTreeDoubleClick) EVT_DATAVIEW_SELECTION_CHANGED(ID_TechTree, ConfigDialog::OnTechTree) EVT_DATAVIEW_SELECTION_CHANGED(ID_FinTree, ConfigDialog::OnFinTree) @@ -3019,14 +3014,7 @@ void ConfigDialog::UpdateFinTree() } } -/* -void ConfigDialog::OnTreeActivated(wxDataViewEvent &evt) -{ - // when does this happen - wxMessageBox("Activated"); - evt.Veto(); -} -*/ + void ConfigDialog::OnTechTreeCollapsing(wxDataViewEvent& evt) { diff --git a/src/main.h b/src/main.h index d62d0f40ef..5a7c65c8ae 100644 --- a/src/main.h +++ b/src/main.h @@ -427,7 +427,6 @@ class ConfigDialog : public wxDialog private: void PopulateTech(); bool ValidateSelections(); -// void OnTreeActivated(wxDataViewEvent& evt); void OnTechTreeCollapsing(wxDataViewEvent& evt); void OnTechTree(wxDataViewEvent &); void OnFinTreeCollapsing(wxDataViewEvent& evt); From bab97101b2a89eadb0b7f1320af6486b1022a2ce Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Wed, 11 Oct 2023 01:34:58 -0600 Subject: [PATCH 09/12] Fix financial market selection when switching technologies --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 230ef76ca0..909887d625 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2969,6 +2969,7 @@ void ConfigDialog::UpdateFinTree() m_finDVI = wxDataViewItem(0); m_pFin->DeleteAllItems(); m_fnames = SamApp::Config().GetFinancingForTech(m_techname); + m_finname = ""; wxDataViewItem cont_ppa; wxDataViewItem cont_dist; @@ -3006,7 +3007,7 @@ void ConfigDialog::UpdateFinTree() if (TP.Find("PPA") != wxNOT_FOUND) m_pFin->AppendItem(cont_ppa, L); else if (TP.Find("DISTRIBUTED") != wxNOT_FOUND) - m_pFin->AppendItem(cont_dist, L); + m_pFin->AppendItem(cont_dist, L); /*else if (TP.Find("TPO") != wxNOT_FOUND) //TPO m_pFin->AppendItem(cont_tpo, L);*/ else From 7e5f7ec953ce914e8bace7c0bb0327d47f6fc22d Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Wed, 11 Oct 2023 02:56:30 -0600 Subject: [PATCH 10/12] Left side tree navigation updates - still need sorting. --- src/casewin.cpp | 62 ++++++++++++++++++++++++++++++++++++++----------- src/casewin.h | 6 ++--- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index 95386bbacd..cdbb172c85 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -145,9 +145,11 @@ BEGIN_EVENT_TABLE( CaseWindow, wxSplitterWindow ) EVT_MENU(ID_PVUNCERTAINTY, CaseWindow::OnCommand) EVT_MENU( ID_MACRO, CaseWindow::OnCommand ) EVT_LISTBOX( ID_INPUTPAGELIST, CaseWindow::OnCommand ) - EVT_DATAVIEW_SELECTION_CHANGED(ID_TechTree, CaseWindow::OnTechTree) - EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, CaseWindow::OnTreeActivated) - EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, CaseWindow::OnTreeActivated) + EVT_DATAVIEW_SELECTION_CHANGED(ID_TechTree, CaseWindow::OnTree) + EVT_DATAVIEW_ITEM_COLLAPSING(ID_TechTree, CaseWindow::OnTreeCollapsing) + +// EVT_DATAVIEW_ITEM_START_EDITING(ID_TechTree, CaseWindow::OnTreeActivated) +// EVT_DATAVIEW_ITEM_ACTIVATED(ID_TechTree, CaseWindow::OnTreeActivated) //EVT_LISTBOX( ID_TechTree, CaseWindow::OnCommand) EVT_BUTTON( ID_EXCL_BUTTON, CaseWindow::OnCommand ) EVT_LISTBOX( ID_EXCL_RADIO, CaseWindow::OnCommand) @@ -626,8 +628,37 @@ bool CaseWindow::GenerateReport( wxString pdffile, wxString templfile, VarValue return false; } -void CaseWindow::OnTechTree(wxDataViewEvent&) +void CaseWindow::OnTree(wxDataViewEvent &evt) { + m_pageFlipper->SetSelection(0); + wxDataViewItem dvi = evt.GetItem(); + if (!dvi.IsOk()) + return; + + if (m_navigationMenu->IsContainer(dvi)) + { + if (m_navigationMenu->IsExpanded(dvi)) + m_navigationMenu->Collapse(dvi); + else + m_navigationMenu->Expand(dvi); + if (m_currentSelection.IsOk()) {// keep current selection + m_navigationMenu->SetCurrentItem(m_currentSelection); + return; + } + else {// select first child + m_currentSelection = m_navigationMenu->GetNthChild(dvi, 0); + m_navigationMenu->SetCurrentItem(m_currentSelection); + } + } + else { + m_currentSelection = evt.GetItem(); + } + wxString title = m_navigationMenu->GetItemText(m_currentSelection); + SwitchToInputPage(title); + + + + /* m_pageFlipper->SetSelection(0); if (m_navigationMenu->IsContainer(m_navigationMenu->GetCurrentItem())) { @@ -674,11 +705,6 @@ void CaseWindow::OnTechTree(wxDataViewEvent&) //m_navigationMenu->Update(); //wxDataViewItemArray dvia; - /* - m_navigationMenu->GetModel()->GetChildren(m_navigationMenu->GetCurrentItem(), dvia); - if (m_navigationMenu->GetItemText(dvia[0]) != L"") - SwitchToInputPage(m_navigationMenu->GetItemText(dvia[0])); - */ } else { @@ -693,13 +719,21 @@ void CaseWindow::OnTechTree(wxDataViewEvent&) } //m_navigationMenu->Update(); - + */ } -void CaseWindow::OnTreeActivated(wxDataViewEvent& evt) +void CaseWindow::OnTreeCollapsing(wxDataViewEvent& evt) { - wxString here = "yes"; - evt.Veto(); + wxDataViewItem dvi = evt.GetItem(); + if (dvi.IsOk() && m_navigationMenu->IsContainer(dvi)) { + auto selectedDVI = m_navigationMenu->GetCurrentItem(); + if (selectedDVI.IsOk()) { + for (size_t i = 0; i < m_navigationMenu->GetChildCount(dvi); i++) { + if (selectedDVI == m_navigationMenu->GetNthChild(dvi, i)) + evt.Veto(); + } + } + } } void CaseWindow::OnCommand( wxCommandEvent &evt ) @@ -1482,7 +1516,7 @@ void CaseWindow::UpdateConfiguration() m_navigationMenu->SetCurrentItem(dvic[0]); SwitchToInputPage(m_navigationMenu->GetItemText(m_navigationMenu->GetCurrentItem())); } - m_previousPage = (m_navigationMenu->GetCurrentItem()); + m_currentSelection = (m_navigationMenu->GetCurrentItem()); // check for orphaned notes and if any found add to first page per Github issue 796 CheckAndUpdateNotes(inputPageHelpContext); diff --git a/src/casewin.h b/src/casewin.h index f1873b542c..3505988f7d 100644 --- a/src/casewin.h +++ b/src/casewin.h @@ -151,7 +151,7 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener wxStaticText* m_finLabel; wxMetroButton *m_simButton, *m_resultsButton; wxMetroDataViewTreeCtrl *m_navigationMenu; - wxDataViewItem m_previousPage; + wxDataViewItem m_currentSelection; // to allow switching case configurations with P50/P90 and PVUncertainty wxGridSizer *m_szsims; @@ -169,8 +169,8 @@ class CaseWindow : public wxSplitterWindow, CaseEventListener wxString m_lastPageNoteId; void OnCommand( wxCommandEvent & ); - void OnTechTree(wxDataViewEvent&); - void OnTreeActivated(wxDataViewEvent &evt ); + void OnTree(wxDataViewEvent&); + void OnTreeCollapsing(wxDataViewEvent &evt ); virtual void OnCaseEvent( Case *, CaseEvent & ); void OnSubNotebookPageChanged( wxNotebookEvent &evt ); From ff87e7e41252926203c0b5f3903381627cbe96b2 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Fri, 13 Oct 2023 04:28:18 -0600 Subject: [PATCH 11/12] Add sorting specification in startup.lk for technology tree --- deploy/runtime/startup.lk | 4 ++ src/main.cpp | 112 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 5 deletions(-) diff --git a/deploy/runtime/startup.lk b/deploy/runtime/startup.lk index dce1d6bd36..555e587b6a 100644 --- a/deploy/runtime/startup.lk +++ b/deploy/runtime/startup.lk @@ -57,6 +57,10 @@ addconfig('PVWatts Wind FuelCell Battery Hybrid', ['Single Owner', 'Host Develop addconfig('Photovoltaic Wind Battery Hybrid', ['Single Owner', 'Host Developer']); addconfig('Generic PVWatts Wind FuelCell Battery Hybrid', ['Single Owner', 'Host Developer']); + +// order tech and fin trees +configopt("TechnologyTreeOrder", {'description' = 'Hybrid,Wind,Generic System,Photovoltaic,Geothermal'}); + // group names 'tree_parent' for performance models are defined in PopulateTech() in main.cpp configopt( 'Flat Plate PV', { 'tree_parent'='Photovoltaic', 'long_name'='Detailed PV Model', 'short_name'='Photovoltaic', 'description'='Photovoltaic system using detailed photovoltaic model with separate module and inverter component models' } ); configopt( 'PVWatts', { 'tree_parent'='Photovoltaic','long_name'='PVWatts', 'short_name'='PVWatts', 'description'='Photovoltaic system using basic NREL PVWatts V8 algorithm. Does not do detailed degradation or loss modeling. If those are important, please use pvsamv1.' } ); diff --git a/src/main.cpp b/src/main.cpp index 909887d625..3f7385d50c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2905,14 +2905,15 @@ void ConfigDialog::GetConfiguration(wxString &t, wxString &f) void ConfigDialog::PopulateTech() { + // clear tree m_pTech->DeleteAllItems(); - + // list all technologies m_tnames = SamApp::Config().GetTechnologies(); - wxString bin_name; - wxArrayString tech_list; - wxDataViewItemArray dvia{m_tnames.Count()}; - + //wxString bin_name; + //wxArrayString tech_list; + //wxDataViewItemArray dvia{m_tnames.Count()}; + /* for (int j = 0; j < m_tnames.Count(); j++) { wxString L(SamApp::Config().Options(m_tnames[j]).LongName); wxString TP(SamApp::Config().Options(m_tnames[j]).TreeParent); @@ -2929,6 +2930,107 @@ void ConfigDialog::PopulateTech() m_pTech->AppendItem(wxDataViewItem(0), L); } } + */ + // tree containers and nodes + wxArrayString containers, nodes, added; + for (int j = 0; j < m_tnames.Count(); j++) { + wxString node(SamApp::Config().Options(m_tnames[j]).LongName); + wxString container(SamApp::Config().Options(m_tnames[j]).TreeParent); + if (node.IsEmpty()) node = m_tnames[j]; + if (container != "" && containers.Index(container) == wxNOT_FOUND && container != "Retired") + containers.Add(container); + else if (node.Find("Retired") == wxNOT_FOUND) + nodes.Add(node); + } + + wxDataViewItemArray dvia{containers.Count()}; + + // order from startup.lk configopt("TechnologyTreeOrder", ... + wxString TreeOrder = SamApp::Config().Options("TechnologyTreeOrder").Description; + /* + if (TreeOrder.length() < 1) { // non-ordered + wxArrayString tech_list; + wxDataViewItemArray dvia{m_tnames.Count()}; + + for (int j = 0; j < m_tnames.Count(); j++) { + wxString L(SamApp::Config().Options(m_tnames[j]).LongName); + wxString TP(SamApp::Config().Options(m_tnames[j]).TreeParent); + if (L.IsEmpty()) L = m_tnames[j]; + if (tech_list.Index(TP) == wxNOT_FOUND && TP != "" && TP != "Retired") { + tech_list.Add(TP); + dvia[tech_list.Index(TP)] = m_pTech->AppendContainer(wxDataViewItem(0), TP); + } + if (TP.Find("Retired") != wxNOT_FOUND); //do nothing for Retired technologies + else if (tech_list.Index(TP) != wxNOT_FOUND) { + m_pTech->AppendItem(dvia[tech_list.Index(TP)],L); + } + else { + m_pTech->AppendItem(wxDataViewItem(0), L); + } + } + } + else*/ { // ordered per Description + wxArrayString order = wxSplit(TreeOrder, ','); + for (auto& item : order) { + if (containers.Index(item) != wxNOT_FOUND) + dvia[containers.Index(item)] = m_pTech->AppendContainer(wxDataViewItem(0), item); + else if (nodes.Index(item) != wxNOT_FOUND) + m_pTech->AppendItem(wxDataViewItem(0), item); + } + // append remaining nodes to appropriate containers + for (auto& item : m_tnames) { + wxString node(SamApp::Config().Options(item).LongName); + wxString container(SamApp::Config().Options(item).TreeParent); + if (node.IsEmpty()) node = item; + // skip those already added + if (order.Index(node) != wxNOT_FOUND) continue; + if (order.Index(container) != wxNOT_FOUND) + m_pTech->AppendItem(dvia[containers.Index(container)], node); + else { + if (added.Index(container) == wxNOT_FOUND && container != "" && container != "Retired") { + added.Add(container); + dvia[containers.Index(container)] = m_pTech->AppendContainer(wxDataViewItem(0), container); + } + if (container.Find("Retired") != wxNOT_FOUND); //do nothing for Retired technologies + else if (containers.Index(container) != wxNOT_FOUND) { + m_pTech->AppendItem(dvia[containers.Index(container)], node); + } + else { + m_pTech->AppendItem(wxDataViewItem(0), node); + } + + } + } + /* + // TODO - handle those not specified in TreeOrder + wxArrayString tech_list; +// dvia.Clear(); +// dvia.resize(m_tnames.Count()); +// wxDataViewItemArray dvia{ m_tnames.Count() }; + + for (int j = 0; j < m_tnames.Count(); j++) { + wxString L(SamApp::Config().Options(m_tnames[j]).LongName); + wxString TP(SamApp::Config().Options(m_tnames[j]).TreeParent); + if (L.IsEmpty()) L = m_tnames[j]; + if (order.Index(TP) != wxNOT_FOUND) continue; + if (order.Index(L) != wxNOT_FOUND) continue; + if (tech_list.Index(TP) == wxNOT_FOUND && TP != "" && TP != "Retired") { + tech_list.Add(TP); + dvia[tech_list.Index(TP)] = m_pTech->AppendContainer(wxDataViewItem(0), TP); + } + if (TP.Find("Retired") != wxNOT_FOUND); //do nothing for Retired technologies + else if (tech_list.Index(TP) != wxNOT_FOUND) { + m_pTech->AppendItem(dvia[tech_list.Index(TP)], L); + } + else { + m_pTech->AppendItem(wxDataViewItem(0), L); + } + + } + */ + } + + // Manually add groups here - eventually move to startup.lk //wxDataViewItem cont_pv = m_pTech->AppendContainer(wxDataViewItem(0), "Photovoltaic"); From 0b65a26fc22062dcfe001c3849a83ebf998418a9 Mon Sep 17 00:00:00 2001 From: Steven Janzou Date: Sun, 15 Oct 2023 02:39:34 -0600 Subject: [PATCH 12/12] Address feedback on #1498 about results viewing and clearing navigation selection --- src/casewin.cpp | 67 ++----------------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) diff --git a/src/casewin.cpp b/src/casewin.cpp index cdbb172c85..11aa81d920 100644 --- a/src/casewin.cpp +++ b/src/casewin.cpp @@ -379,7 +379,7 @@ bool CaseWindow::RunBaseCase( bool silent, wxString *messages ) m_inputPageList->Select( -1 ); //m_navigationMenu->SetCurrentItem(wxDataViewItem(0)); - wxDataViewItemArray dvia; + // wxDataViewItemArray dvia; m_navigationMenu->UnselectAll(); /* m_navigationMenu->GetModel()->GetChildren(wxDataViewItem(0), dvia); @@ -656,70 +656,6 @@ void CaseWindow::OnTree(wxDataViewEvent &evt) wxString title = m_navigationMenu->GetItemText(m_currentSelection); SwitchToInputPage(title); - - - /* - m_pageFlipper->SetSelection(0); - if (m_navigationMenu->IsContainer(m_navigationMenu->GetCurrentItem())) - { - wxDataViewItemArray dvic; - bool keep_open = false; - wxDataViewItem current_item; - wxString test = m_navigationMenu->GetItemText(m_navigationMenu->GetCurrentItem()); - wxString test_previous = m_navigationMenu->GetItemText(m_previousPage); - current_item = m_navigationMenu->GetCurrentItem(); - if (test == "") { //click arrow instead of word - keep_open = true; - current_item = m_previousPage; - //m_navigationMenu->UnselectAll(); - wxString string = m_navigationMenu->GetItemText(current_item); - m_navigationMenu->SetCurrentItem(current_item); - wxDataViewItem parent = m_navigationMenu->GetModel()->GetParent(m_navigationMenu->GetCurrentItem()); - wxString string2 = m_navigationMenu->GetItemText(parent); -// m_navigationMenu->UnselectAll(); -// m_navigationMenu->SetCurrentItem(parent); - SwitchToInputPage(string2 + " Summary"); - //m_navigationMenu->Expand(m_navigationMenu->GetModel()->GetParent(m_navigationMenu->GetCurrentItem())); - m_navigationMenu->Update(); - return; - } - m_navigationMenu->GetModel()->GetChildren(m_navigationMenu->GetCurrentItem(), dvic); - int children_count = dvic.Count(); - for (int i = 0; i < dvic.Count(); i++) { - if (dvic[i] == m_previousPage) { - keep_open = true; - current_item = dvic[i]; - m_navigationMenu->SetCurrentItem(dvic[i]); - //m_navigationMenu->Update(); - return; - } - } - if (!keep_open && m_navigationMenu->IsExpanded(m_navigationMenu->GetCurrentItem())) { - m_navigationMenu->Collapse(m_navigationMenu->GetCurrentItem()); - m_navigationMenu->SetCurrentItem(m_previousPage); - m_navigationMenu->Update(); - return; - } - m_navigationMenu->Expand(m_navigationMenu->GetCurrentItem()); - m_navigationMenu->SetCurrentItem(m_previousPage); - //m_navigationMenu->Update(); - //wxDataViewItemArray dvia; - - - } - else { - wxDataViewItemArray dvia; - wxDataViewItem parent = m_navigationMenu->GetModel()->GetParent(m_navigationMenu->GetCurrentItem()); - m_navigationMenu->GetModel()->GetChildren(parent, dvia); - if (dvia.Count() > 0) { - SwitchToInputPage(m_navigationMenu->GetItemText(m_navigationMenu->GetCurrentItem())); - m_previousPage = (m_navigationMenu->GetCurrentItem()); - } - m_navigationMenu->Update(); - - } - //m_navigationMenu->Update(); - */ } void CaseWindow::OnTreeCollapsing(wxDataViewEvent& evt) @@ -747,6 +683,7 @@ void CaseWindow::OnCommand( wxCommandEvent &evt ) { m_inputPageList->Select( -1 ); m_pageFlipper->SetSelection( 1 ); + m_navigationMenu->UnselectAll(); } else if ( evt.GetId() == ID_ADVANCED ) {