From b2a5dc3abffcfdcd348b9efacba5457f436ab76f Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 8 May 2016 23:00:52 -0700 Subject: [PATCH] #424 number of selected in status bar incorrect --- DataViewer/TableBase.cpp | 81 ++++++---- DialogTools/CalculatorDlg.cpp | 16 +- DialogTools/CatClassifDlg.cpp | 48 +++--- DialogTools/DataMovieDlg.cpp | 21 ++- DialogTools/RangeSelectionDlg.cpp | 83 ++-------- Explore/3DPlotView.cpp | 59 +++---- Explore/BoxNewPlotView.cpp | 31 ++-- Explore/ConditionalHistogramView.cpp | 46 +++--- Explore/ConnectivityHistView.cpp | 67 ++++---- Explore/ConnectivityMapView.cpp | 87 ++++------- Explore/CovSpHLStateProxy.cpp | 20 +-- Explore/GetisOrdMapNewView.cpp | 15 +- Explore/HistogramView.cpp | 48 +++--- Explore/LisaMapNewView.cpp | 15 +- Explore/SimpleHistCanvas.cpp | 42 +++-- HighlightState.cpp | 20 +++ Project.cpp | 15 +- TemplateCanvas.cpp | 226 ++++++++++++++++----------- 18 files changed, 459 insertions(+), 481 deletions(-) diff --git a/DataViewer/TableBase.cpp b/DataViewer/TableBase.cpp index cf277080d..d657d40ab 100644 --- a/DataViewer/TableBase.cpp +++ b/DataViewer/TableBase.cpp @@ -155,57 +155,77 @@ bool TableBase::FromGridIsSelectedRow(int row) /** Only wxGrid should call this */ void TableBase::FromGridSelectOnlyRow(int row) { - int total_newly_selected = 0; - int total_newly_unselected = 0; int hl_size = highlight_state->GetHighlightSize(); + std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); + bool selection_changed = false; + for (int i=0; iSetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - highlight_state->notifyObservers(); + + if (selection_changed) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); + } } /** Only wxGrid should call this */ void TableBase::FromGridSelectRowRange(int first_row, int last_row) { - int total_newly_selected = 0; - int total_newly_unselected = 0; int hl_size = highlight_state->GetHighlightSize(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); + bool selection_changed = false; + for (int i=0; i last_row) { - if (hs[row_order[i]]) nuh[total_newly_unselected++] = row_order[i]; + if (hs[row_order[i]]) { + hs[i] = false; + selection_changed = true; + } } else { - if (!hs[row_order[i]]) nh[total_newly_selected++] = row_order[i]; + if (!hs[row_order[i]]) { + hs[i] = true; + selection_changed = true; + } } } - highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - highlight_state->notifyObservers(); + + if (selection_changed) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); + } } /** Only wxGrid should call this, others should use Select(int row) */ void TableBase::FromGridSelectRow(int row) { //LOG_MSG(wxString::Format("selecting %d", (int) row_order[row])); + int hl_size = highlight_state->GetHighlightSize(); + std::vector& hs = highlight_state->GetHighlight(); + + hs[ row_order[row] ] = true; + /* + for (int i=0; iSetEventType(HLStateInt::delta); - std::vector& nhl = highlight_state->GetNewlyHighlighted(); - nhl[0] = row_order[row]; - //highlight_state->SetNewlyHighlighted(0, row_order[row]); - highlight_state->SetTotalNewlyHighlighted(1); - highlight_state->SetTotalNewlyUnhighlighted(0); highlight_state->notifyObservers(); } @@ -213,12 +233,13 @@ void TableBase::FromGridSelectRow(int row) void TableBase::FromGridDeselectRow(int row) { //LOG_MSG(wxString::Format("deselecting %d", (int) row_order[row])); + + int hl_size = highlight_state->GetHighlightSize(); + std::vector& hs = highlight_state->GetHighlight(); + + hs[ row_order[row] ] = false; + highlight_state->SetEventType(HLStateInt::delta); - std::vector& nuhl = highlight_state->GetNewlyUnhighlighted(); - nuhl[0] = row_order[row]; - //highlight_state->SetNewlyUnhighlighted(0, row_order[row]); - highlight_state->SetTotalNewlyHighlighted(0); - highlight_state->SetTotalNewlyUnhighlighted(1); highlight_state->notifyObservers(); } diff --git a/DialogTools/CalculatorDlg.cpp b/DialogTools/CalculatorDlg.cpp index dfd958254..24bac32c1 100644 --- a/DialogTools/CalculatorDlg.cpp +++ b/DialogTools/CalculatorDlg.cpp @@ -585,22 +585,20 @@ void CalculatorDlg::AssignOrSelect(bool assign) HighlightState& hs = *project->GetHighlightState(); std::vector& h = hs.GetHighlight(); - std::vector& nh = hs.GetNewlyHighlighted(); - std::vector& nuh = hs.GetNewlyUnhighlighted(); - int nh_cnt = 0; - int nuh_cnt = 0; - int total_obs = h.size(); + bool selection_changed = false; + for (size_t i=0; i& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; int total_sel_shps = selectable_shps.size(); @@ -212,30 +209,33 @@ void CatClassifHistCanvas::UpdateSelection(bool shiftdown, bool pointsel) // unselect all in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; } } else if (!all_sel && selected) { // select currently unselected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { if (hs[*it]) continue; - nh[total_newly_selected++] = (*it); + hs[(*it)] = true; + selection_changed = true; } } else if (!selected && !shiftdown) { // unselect all selected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { if (!hs[*it]) continue; - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; } } } - - if (total_newly_selected > 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } + UpdateStatusBar(); } @@ -268,10 +268,6 @@ void CatClassifHistCanvas::update(HLStateInt* o) { LOG_MSG("Entering CatClassifHistCanvas::update"); - int total = highlight_state->GetTotalNewlyHighlighted(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - - HLStateInt::EventType type = highlight_state->GetEventType(); layer0_valid = false; layer1_valid = false; layer2_valid = false; @@ -491,17 +487,17 @@ void CatClassifHistCanvas::UpdateIvalSelCnts() ival_obs_sel_cnt[i] = 0; } } else if (type == HLStateInt::delta) { - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); - int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); - - for (int i=0; i& hs = highlight_state->GetHighlight(); + + for (int i=0; i& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; // the passed-in new_pos_num refers to the observations starting // from 1 to num_obs, rather than 0 to num_obs-1. @@ -207,25 +204,27 @@ void DataMovieDlg::ChangePosNum(int new_pos_num) for (int i=0; i pos && hs[id]) { - nuh[total_newly_unselected++] = id; + hs[id] = false; + selection_changed = true; } else if (i <= pos && !hs[id]) { - nh[total_newly_selected++] = id; + hs[id] = true; + selection_changed = true; } } } else { for (int i=0; i 0 || total_newly_unselected > 0) { + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } Refresh(); diff --git a/DialogTools/RangeSelectionDlg.cpp b/DialogTools/RangeSelectionDlg.cpp index 241b30df8..44e972524 100644 --- a/DialogTools/RangeSelectionDlg.cpp +++ b/DialogTools/RangeSelectionDlg.cpp @@ -229,8 +229,6 @@ void RangeSelectionDlg::OnSelRangeClick( wxCommandEvent& event ) LOG_MSG("Entering RangeSelectionDlg::OnApplySelClick"); HighlightState& hs = *project->GetHighlightState(); std::vector& h = hs.GetHighlight(); - std::vector& nh = hs.GetNewlyHighlighted(); - std::vector& nuh = hs.GetNewlyUnhighlighted(); int n = table_int->GetNumberRows(); int nh_cnt = 0; @@ -299,20 +297,17 @@ void RangeSelectionDlg::OnSelRangeClick( wxCommandEvent& event ) if (cur_sel[i] == true) { h[i] = true; update_flag = true; - nh[nh_cnt++] = i; } } else { if (sub_select) { if (h[i] == true && cur_sel[i] == false) { h[i] = false; update_flag = true; - nuh[nuh_cnt++] = i; } } else if (append_select) { if (h[i] == false && cur_sel[i] == true) { h[i] = true; update_flag = true; - nh[nh_cnt++] = i; } } } @@ -320,8 +315,6 @@ void RangeSelectionDlg::OnSelRangeClick( wxCommandEvent& event ) if (update_flag) { hs.SetEventType(HLStateInt::delta); - hs.SetTotalNewlyHighlighted(nh_cnt); - hs.SetTotalNewlyUnhighlighted(nuh_cnt); hs.notifyObservers(); } current_sel_mcol = mcol; @@ -333,14 +326,9 @@ void RangeSelectionDlg::OnSelRangeClick( wxCommandEvent& event ) void RangeSelectionDlg::OnSelUndefClick( wxCommandEvent& event ) { HighlightState& hs = *project->GetHighlightState(); - hs.SetEventType(HLStateInt::unhighlight_all); - hs.notifyObservers(); - std::vector& h = hs.GetHighlight(); - std::vector& nh = hs.GetNewlyHighlighted(); - std::vector& nuh = hs.GetNewlyUnhighlighted(); - int nh_cnt = 0; - int nuh_cnt = 0; + bool selection_changed = false; + if (m_field_choice->GetSelection() == wxNOT_FOUND) return; int mcol = GetSelColInt(); int f_tm = GetSelColTmInt(); @@ -348,12 +336,20 @@ void RangeSelectionDlg::OnSelUndefClick( wxCommandEvent& event ) std::vector undefined; table_int->GetColUndefined(mcol, f_tm, undefined); for (int i=0, iend=h.size(); i 0) { + if (selection_changed) { hs.SetEventType(HLStateInt::delta); - hs.SetTotalNewlyHighlighted(nh_cnt); - hs.SetTotalNewlyUnhighlighted(nuh_cnt); hs.notifyObservers(); } m_selection_made = true; @@ -362,56 +358,7 @@ void RangeSelectionDlg::OnSelUndefClick( wxCommandEvent& event ) void RangeSelectionDlg::OnRandomSelClick( wxCommandEvent& event ) { - /* - size_t num_obs = project->GetNumRecords(); - long num_to_rand_sel = 0; - { - wxString v(m_num_to_rand_sel_txt->GetValue()); - if (v.IsEmpty()) v = "0"; - if (!v.ToLong(&num_to_rand_sel)) return; - if (num_to_rand_sel > num_obs) num_to_rand_sel = num_obs; - } - - // Mersenne Twister random number generator, randomly seeded - // with current time in seconds since Jan 1 1970. - static boost::mt19937 rng(std::time(0)); - //static boost::uniform_01 X(rng); - static boost::random::uniform_int_distribution<> X(0, num_obs-1); - // X(rng) -> returns a uniform random number from 0 to num_obs-1; - - std::vector perm(num_obs); - for (size_t i=0; iGetHighlightState(); - std::vector& h = hs.GetHighlight(); - std::vector& nh = hs.GetNewlyHighlighted(); - std::vector& nuh = hs.GetNewlyUnhighlighted(); - int nh_cnt = 0; - int nuh_cnt = 0; - for (size_t i=0; iGetHighlightSize(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; double minx = xp - xs; double maxx = xp + xs; @@ -424,33 +421,29 @@ void C3DPlotCanvas::UpdateSelect() (scaled_d[2][zt][i] >= minz) && (scaled_d[2][zt][i] <= maxz)); if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } - - if (total_newly_selected == 0 && total_newly_unselected == 0) return; - if (total_newly_selected == 0 && - total_newly_unselected == highlight_state->GetTotalHighlighted()) { - highlight_state->SetEventType(HLStateInt::unhighlight_all); - highlight_state->notifyObservers(); - } else { + + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); - } + } } void C3DPlotCanvas::SelectByRect() { int hl_size = highlight_state->GetHighlightSize(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; double world11[3], world12[3], world22[3], world21[3]; double world113[3], world123[3], world223[3], world213[3]; @@ -545,23 +538,21 @@ void C3DPlotCanvas::SelectByRect() bool contains = (inside[i] && inside[num_obs+i] && inside[2*num_obs+i] && inside[3*num_obs+i]); if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } - - if (total_newly_selected == 0 && total_newly_unselected == 0) return; - if (total_newly_selected == 0 && - total_newly_unselected == highlight_state->GetTotalHighlighted()) { - highlight_state->SetEventType(HLStateInt::unhighlight_all); - highlight_state->notifyObservers(); - } else { + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); - } + } } void C3DPlotCanvas::InitGL(void) @@ -1026,10 +1017,6 @@ void C3DPlotCanvas::update(HLStateInt* o) { LOG_MSG("In C3DPlotCanvas::update"); - int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); - int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - HLStateInt::EventType type = highlight_state->GetEventType(); if (type == HLStateInt::delta) { LOG_MSG("processing HLStateInt::delta"); diff --git a/Explore/BoxNewPlotView.cpp b/Explore/BoxNewPlotView.cpp index 518f0f8bc..88c60c20d 100644 --- a/Explore/BoxNewPlotView.cpp +++ b/Explore/BoxNewPlotView.cpp @@ -274,10 +274,7 @@ void BoxPlotCanvas::UpdateSelection(bool shiftdown, bool pointsel) { //LOG_MSG("Entering BoxPlotCanvas::UpdateSelectionPoints"); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; for (int i=0; i 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } //LOG_MSG("Exiting BoxPlotCanvas::UpdateSelectionPoints"); } @@ -393,10 +396,6 @@ void BoxPlotCanvas::update(HLStateInt* o) { LOG_MSG("Entering BoxPlotCanvas::update"); - int total = highlight_state->GetTotalNewlyHighlighted(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - - HLStateInt::EventType type = highlight_state->GetEventType(); layer0_valid = false; layer1_valid = false; layer2_valid = false; diff --git a/Explore/ConditionalHistogramView.cpp b/Explore/ConditionalHistogramView.cpp index 478284ee5..6e3f7b055 100644 --- a/Explore/ConditionalHistogramView.cpp +++ b/Explore/ConditionalHistogramView.cpp @@ -546,10 +546,7 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) int t = var_info[HIST_VAR].time; std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; int total_sel_shps = selectable_shps.size(); @@ -594,7 +591,8 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) for (std::list::iterator it = cell_data[t][r][c].ival_to_obs_ids[ival].begin(); it != cell_data[t][r][c].ival_to_obs_ids[ival].end(); it++) { - nuh[total_newly_unselected++] = (*it); + hs[(*it)]= false; + selection_changed = true; } } else if (!all_sel && selected) { // select currently unselected in ival @@ -602,7 +600,8 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) cell_data[t][r][c].ival_to_obs_ids[ival].begin(); it != cell_data[t][r][c].ival_to_obs_ids[ival].end(); it++) { if (hs[*it]) continue; - nh[total_newly_selected++] = (*it); + hs[(*it)]= true; + selection_changed = true; } } else if (!selected && !shiftdown) { // unselect all selected in ival @@ -610,15 +609,15 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) cell_data[t][r][c].ival_to_obs_ids[ival].begin(); it != cell_data[t][r][c].ival_to_obs_ids[ival].end(); it++) { if (!hs[*it]) continue; - nuh[total_newly_unselected++] = (*it); + hs[(*it)]= false; + selection_changed = true; } } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } UpdateStatusBar(); } @@ -847,7 +846,7 @@ void ConditionalHistogramCanvas::UpdateIvalSelCnts() } } } else if (type == HLStateInt::delta) { - std::vector& nh = highlight_state->GetNewlyHighlighted(); + std::vector& hs = highlight_state->GetHighlight(); std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); @@ -861,16 +860,21 @@ void ConditionalHistogramCanvas::UpdateIvalSelCnts() int cols = horiz_cat_data.categories[ht].cat_vec.size(); int ivals = cell_data[t][0][0].ival_obs_cnt.size(); - int r, c, ival; - for (int i=0; i& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; - + bool selection_changed = false; int total_sel_shps = selectable_shps.size(); wxPoint lower_left; @@ -208,30 +204,32 @@ void ConnectivityHistCanvas::UpdateSelection(bool shiftdown, bool pointsel) if (pointsel && all_sel && selected) { // unselect all in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); - it != ival_to_obs_ids[i].end(); it++) { - nuh[total_newly_unselected++] = (*it); + it != ival_to_obs_ids[i].end(); it++) { + hs[(*it)] = false; + selection_changed = true; } } else if (!all_sel && selected) { // select currently unselected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { if (hs[*it]) continue; - nh[total_newly_selected++] = (*it); + hs[(*it)] = true; + selection_changed = true; } } else if (!selected && !shiftdown) { // unselect all selected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { - if (!hs[*it]) continue; - nuh[total_newly_unselected++] = (*it); + if (!hs[*it]) continue; + hs[(*it)] = false; + selection_changed = true; } } } - - if (total_newly_selected > 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } UpdateStatusBar(); } @@ -265,10 +263,6 @@ void ConnectivityHistCanvas::update(HLStateInt* o) { LOG_MSG("Entering ConnectivityHistCanvas::update"); - int total = highlight_state->GetTotalNewlyHighlighted(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - - HLStateInt::EventType type = highlight_state->GetEventType(); layer0_valid = false; layer1_valid = false; layer2_valid = false; @@ -510,22 +504,19 @@ void ConnectivityHistCanvas::ChangeWeights(boost::uuids::uuid new_id) void ConnectivityHistCanvas::SelectIsolates() { std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; for (int i=0; i 0 || total_newly_unselected > 0) { + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } } @@ -653,17 +644,17 @@ void ConnectivityHistCanvas::UpdateIvalSelCnts() ival_obs_sel_cnt[i] = 0; } } else if (type == HLStateInt::delta) { - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); - int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); - - for (int i=0; i& hs = highlight_state->GetHighlight(); + + for (int i=0; i& hs = shared_core_hs->GetHighlight(); - std::vector& nh = shared_core_hs->GetNewlyHighlighted(); - std::vector& nuh = shared_core_hs->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; + for (size_t i=0, sz=project->GetNumRecords(); i 0 || total_newly_unselected > 0) { - shared_core_hs->SetTotalNewlyHighlighted(total_newly_selected); - shared_core_hs->SetTotalNewlyUnhighlighted(total_newly_unselected); - - if (total_newly_selected == 0 && - total_newly_unselected == highlight_state->GetTotalHighlighted()) { - shared_core_hs->SetEventType(HLStateInt::unhighlight_all); - shared_core_hs->notifyObservers(); - } else { - shared_core_hs->SetEventType(HLStateInt::delta); - shared_core_hs->SetTotalNewlyHighlighted(total_newly_selected); - shared_core_hs->SetTotalNewlyUnhighlighted(total_newly_unselected); - shared_core_hs->notifyObservers(); - } + if (selection_changed) { + shared_core_hs->SetEventType(HLStateInt::delta); + shared_core_hs->notifyObservers(); } LOG_MSG("Exiting ConnectivityMapCanvas::UpdateSelection"); @@ -315,10 +304,7 @@ void ConnectivityMapCanvas::UpdateFromSharedCore() } std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; // find set of all neighbors of cores core_nbrs.clear(); @@ -327,17 +313,18 @@ void ConnectivityMapCanvas::UpdateFromSharedCore() for (size_t i=0, sz=project->GetNumRecords(); i 0 || total_newly_unselected > 0) { - LOG_MSG("notify private highlight_state"); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } UpdateStatusBar(); @@ -420,10 +407,7 @@ void ConnectivityMapCanvas::ChangeWeights(boost::uuids::uuid new_id) int hl_size = highlight_state->GetHighlightSize(); if (hl_size != selectable_shps.size()) return; std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; // find set of all neighbors of cores core_nbrs.clear(); @@ -435,18 +419,17 @@ void ConnectivityMapCanvas::ChangeWeights(boost::uuids::uuid new_id) for (int i=0; i 0 || total_newly_unselected > 0) { - // Note: this will require a full redraw - invalidateBms(); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } } @@ -612,23 +595,21 @@ void ConnectivityMapFrame::CoreSelectHelper(const std::vector& elem) { HighlightState* highlight_state = project->GetHighlightState(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; int num_obs = project->GetNumRecords(); for (int i=0; i 0 || total_newly_unselected > 0) { + + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } } diff --git a/Explore/CovSpHLStateProxy.cpp b/Explore/CovSpHLStateProxy.cpp index 31ebc41f5..3183fc559 100644 --- a/Explore/CovSpHLStateProxy.cpp +++ b/Explore/CovSpHLStateProxy.cpp @@ -164,16 +164,13 @@ void CovSpHLStateProxy::notifyHighlightState() { using namespace std; vector hs(highlight_state->GetHighlight()); // make a copy - vector& nhl = highlight_state->GetNewlyHighlighted(); - int tot_nhl = 0; - vector& nuhl = highlight_state->GetNewlyUnhighlighted(); - int tot_nuhl = 0; + bool selection_changed = false; + highlight_state->SetEventType(HLStateInt::empty); if (event_type == HLStateInt::unhighlight_all) { highlight_state->SetEventType(HLStateInt::unhighlight_all); - } else if (event_type == HLStateInt::delta || - event_type == HLStateInt::invert) - { + + } else if (event_type == HLStateInt::delta || event_type == HLStateInt::invert) { // Notice that we must be careful not to highlight or unhighlight // the same observations multiple times. // We will the following logic: For observation i, if any of i @@ -194,16 +191,15 @@ void CovSpHLStateProxy::notifyHighlightState() bool sel_i = any_hl[i]; if (sel_i && !hs[i]) { hs[i] = true; - nhl[tot_nhl++] = i; + selection_changed = true; } else if (!sel_i && hs[i]) { hs[i] = false; - nuhl[tot_nuhl++] = i; + selection_changed = true; } } - if (tot_nhl > 0 || tot_nuhl > 0) { + + if ( selection_changed ) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(tot_nhl); - highlight_state->SetTotalNewlyUnhighlighted(tot_nuhl); } } // notify HighlightState, but exclude self diff --git a/Explore/GetisOrdMapNewView.cpp b/Explore/GetisOrdMapNewView.cpp index a6c8faa86..78d42d084 100644 --- a/Explore/GetisOrdMapNewView.cpp +++ b/Explore/GetisOrdMapNewView.cpp @@ -661,22 +661,19 @@ void GetisOrdMapFrame::CoreSelectHelper(const std::vector& elem) { HighlightState* highlight_state = project->GetHighlightState(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; for (int i=0; inum_obs; i++) { if (!hs[i] && elem[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } else if (hs[i] && !elem[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { + if (selection_changed ) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } } diff --git a/Explore/HistogramView.cpp b/Explore/HistogramView.cpp index 1adc1e719..cc7dede8c 100644 --- a/Explore/HistogramView.cpp +++ b/Explore/HistogramView.cpp @@ -303,10 +303,7 @@ void HistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) int t = var_info[0].time; std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed =false; int total_sel_shps = selectable_shps.size(); @@ -347,29 +344,32 @@ void HistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) // unselect all in ival for (std::list::iterator it=ival_to_obs_ids[t][i].begin(); it != ival_to_obs_ids[t][i].end(); it++) { - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; } } else if (!all_sel && selected) { // select currently unselected in ival for (std::list::iterator it=ival_to_obs_ids[t][i].begin(); it != ival_to_obs_ids[t][i].end(); it++) { if (hs[*it]) continue; - nh[total_newly_selected++] = (*it); + hs[(*it)] = true; + selection_changed = true; } } else if (!selected && !shiftdown) { // unselect all selected in ival for (std::list::iterator it=ival_to_obs_ids[t][i].begin(); it != ival_to_obs_ids[t][i].end(); it++) { if (!hs[*it]) continue; - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; + } } } - - if (total_newly_selected > 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } UpdateStatusBar(); } @@ -899,21 +899,21 @@ void HistogramCanvas::UpdateIvalSelCnts() } } } else if (type == HLStateInt::delta) { - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); - int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); - - for (int i=0; i& hs = highlight_state->GetHighlight(); + + for (int t=0; t& elem) { HighlightState* highlight_state = project->GetHighlightState(); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; for (int i=0; inum_obs; i++) { if (!hs[i] && elem[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } else if (hs[i] && !elem[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { + if (selection_changed) { highlight_state->SetEventType(HLStateInt::delta); - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); highlight_state->notifyObservers(); } } diff --git a/Explore/SimpleHistCanvas.cpp b/Explore/SimpleHistCanvas.cpp index b9ee93b26..94ac6e8cb 100644 --- a/Explore/SimpleHistCanvas.cpp +++ b/Explore/SimpleHistCanvas.cpp @@ -170,10 +170,7 @@ void SimpleHistCanvas::UpdateSelection(bool shiftdown, bool pointsel) bool rect_sel = (!pointsel && (brushtype == rectangle)); std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; int total_sel_shps = selectable_shps.size(); @@ -214,29 +211,30 @@ void SimpleHistCanvas::UpdateSelection(bool shiftdown, bool pointsel) // unselect all in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; } } else if (!all_sel && selected) { // select currently unselected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { if (hs[*it]) continue; - nh[total_newly_selected++] = (*it); + hs[(*it)] = true; + selection_changed = true; } } else if (!selected && !shiftdown) { // unselect all selected in ival for (std::list::iterator it=ival_to_obs_ids[i].begin(); it != ival_to_obs_ids[i].end(); it++) { if (!hs[*it]) continue; - nuh[total_newly_unselected++] = (*it); + hs[(*it)] = false; + selection_changed = true; } } } - - if (total_newly_selected > 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } UpdateStatusBar(); } @@ -365,17 +363,17 @@ void SimpleHistCanvas::UpdateIvalSelCnts() ival_obs_sel_cnt[i] = 0; } } else if (type == HLStateInt::delta) { - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int nh_cnt = highlight_state->GetTotalNewlyHighlighted(); - int nuh_cnt = highlight_state->GetTotalNewlyUnhighlighted(); - - for (int i=0; i& hs = highlight_state->GetHighlight(); + + for (int i=0; i& h = hs.GetHighlight(); - std::vector& nh = hs.GetNewlyHighlighted(); - std::vector& nuh = hs.GetNewlyUnhighlighted(); int nh_cnt = 0; std::vector add_elem(gal_weights->num_obs, false); - + + std::vector new_highlight_ids; + for (int i=0; inum_obs; i++) { if (h[i]) { GalElement& e = gal_weights->gal[i]; @@ -872,16 +872,19 @@ void Project::AddNeighborsToSelection(boost::uuids::uuid weights_id) int obs = e[j]; if (!h[obs] && !add_elem[obs]) { add_elem[obs] = true; - nh[nh_cnt++] = obs; + new_highlight_ids.push_back(obs); } } } } + + for (int i=0; i<(int)new_highlight_ids.size(); i++) { + h[ new_highlight_ids[i] ] = true; + nh_cnt ++; + } if (nh_cnt > 0) { hs.SetEventType(HLStateInt::delta); - hs.SetTotalNewlyHighlighted(nh_cnt); - hs.SetTotalNewlyUnhighlighted(0); hs.notifyObservers(); } else { LOG_MSG("No elements to add to current selection"); diff --git a/TemplateCanvas.cpp b/TemplateCanvas.cpp index 16cf019d4..51f0963f4 100644 --- a/TemplateCanvas.cpp +++ b/TemplateCanvas.cpp @@ -2592,43 +2592,26 @@ void TemplateCanvas::UpdateSelectionPoints(bool shiftdown, bool pointsel) LOG_MSG("Entering TemplateCanvas::UpdateSelectionPoints"); int hl_size = GetSelBitVec().size(); if (hl_size != selectable_shps.size()) return; + std::vector& hs = GetSelBitVec(); - std::vector& nh = GetNewlySelList(); - std::vector& nuh = GetNewlyUnselList(); - int total_newly_selected = 0; - int total_newly_unselected = 0; - + bool selection_changed = false; + if (pointsel) { // a point selection for (int i=0; ipointWithin(sel1)) { - // A useful way to get polygon data by clicking - // on a polygon - //if (GdaPolygon* p = - // dynamic_cast(selectable_shps[i])) { - // if (p->pc) { - // LOG_MSG(wxString::Format("polygon %d bounding box:",i)); - // LOG_MSG(wxString::Format(" %f, %f", p->pc->box[0], - // p->pc->box[1])); - // LOG_MSG(wxString::Format(" %f, %f", p->pc->box[2], - // p->pc->box[3])); - // LOG_MSG(wxString::Format("polygon %d:",i)); - // for (int j=0; jpc->num_points; j++) { - // LOG_MSG(wxString::Format(" %f, %f", - // p->pc->points[j].x, - // p->pc->points[j].y)); - // } - // } - //} if (hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } else { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } else { if (!shiftdown && hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } } } @@ -2642,13 +2625,20 @@ void TemplateCanvas::UpdateSelectionPoints(bool shiftdown, bool pointsel) wxOutRegion); if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2662,18 +2652,24 @@ void TemplateCanvas::UpdateSelectionPoints(bool shiftdown, bool pointsel) for (int i=0; icenter) + bool contains = (GenUtils::distance(sel1, selectable_shps[i]->center) <= radius); if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2708,22 +2704,28 @@ void TemplateCanvas::UpdateSelectionPoints(bool shiftdown, bool pointsel) } if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { - SetNumNewlySel(total_newly_selected); - SetNumNewlyUnsel(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } LOG_MSG("Exiting TemplateCanvas::UpdateSelectionPoints"); } @@ -2735,11 +2737,9 @@ void TemplateCanvas::UpdateSelectionCircles(bool shiftdown, bool pointsel) LOG_MSG("Entering TemplateCanvas::UpdateSelectionCircles"); int hl_size = GetSelBitVec().size(); if (hl_size != selectable_shps.size()) return; + std::vector& hs = GetSelBitVec(); - std::vector& nh = GetNewlySelList(); - std::vector& nuh = GetNewlyUnselList(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; if (pointsel) { // a point selection for (int i=0; iisNull()) continue; if (GenUtils::distance(s->center, sel1) <= s->radius) { if (hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } else { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } else { if (!shiftdown && hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } } } @@ -2784,13 +2787,20 @@ void TemplateCanvas::UpdateSelectionCircles(bool shiftdown, bool pointsel) } if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2804,13 +2814,20 @@ void TemplateCanvas::UpdateSelectionCircles(bool shiftdown, bool pointsel) GenUtils::distance(sel1, s->center)); if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2827,22 +2844,29 @@ void TemplateCanvas::UpdateSelectionCircles(bool shiftdown, bool pointsel) hp_rad + s->radius)); if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { - SetNumNewlySel(total_newly_selected); - SetNumNewlyUnsel(total_newly_unselected); - NotifyObservables(); + + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } LOG_MSG("Exiting TemplateCanvas::UpdateSelectionCircles"); } @@ -2854,11 +2878,9 @@ void TemplateCanvas::UpdateSelectionPolylines(bool shiftdown, bool pointsel) LOG_MSG("Entering TemplateCanvas::UpdateSelectionPolylines"); int hl_size = GetSelBitVec().size(); if (hl_size != selectable_shps.size()) return; + std::vector& hs = GetSelBitVec(); - std::vector& nh = GetNewlySelList(); - std::vector& nuh = GetNewlyUnselList(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; GdaPolyLine* p; if (pointsel) { // a point selection @@ -2887,13 +2909,16 @@ void TemplateCanvas::UpdateSelectionPolylines(bool shiftdown, bool pointsel) } if (contains) { if (hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } else { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } else { if (!shiftdown && hs[i]) { - nuh[total_newly_unselected++] = i; + hs[i] = false; + selection_changed = true; } } } @@ -2932,13 +2957,20 @@ void TemplateCanvas::UpdateSelectionPolylines(bool shiftdown, bool pointsel) } if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2958,13 +2990,20 @@ void TemplateCanvas::UpdateSelectionPolylines(bool shiftdown, bool pointsel) } if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } @@ -2994,22 +3033,28 @@ void TemplateCanvas::UpdateSelectionPolylines(bool shiftdown, bool pointsel) } if (!shiftdown) { if (contains) { - if (!hs[i]) nh[total_newly_selected++] = i; + if (!hs[i]) { + hs[i] = true; + selection_changed = true; + } } else { - if (hs[i]) nuh[total_newly_unselected++] = i; + if (hs[i]) { + hs[i] = false; + selection_changed = true; + } } } else { // do not unhighlight if not in intersection region if (contains && !hs[i]) { - nh[total_newly_selected++] = i; + hs[i] = true; + selection_changed = true; } } } } } - if (total_newly_selected > 0 || total_newly_unselected > 0) { - SetNumNewlySel(total_newly_selected); - SetNumNewlyUnsel(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } LOG_MSG("Exiting TemplateCanvas::UpdateSelectionPolylines"); } @@ -3024,11 +3069,9 @@ void TemplateCanvas::SelectAllInCategory(int category, } int hl_size = highlight_state->GetHighlightSize(); if (hl_size != selectable_shps.size()) return; + std::vector& hs = highlight_state->GetHighlight(); - std::vector& nh = highlight_state->GetNewlyHighlighted(); - std::vector& nuh = highlight_state->GetNewlyUnhighlighted(); - int total_newly_selected = 0; - int total_newly_unselected = 0; + bool selection_changed = false; std::vector obs_in_cat(hl_size, false); std::vector& ids = cat_data.GetIdsRef(cc_ts, category); @@ -3037,17 +3080,18 @@ void TemplateCanvas::SelectAllInCategory(int category, for (int i=0; i 0 || total_newly_unselected > 0) { - highlight_state->SetTotalNewlyHighlighted(total_newly_selected); - highlight_state->SetTotalNewlyUnhighlighted(total_newly_unselected); - NotifyObservables(); + if ( selection_changed ) { + highlight_state->SetEventType(HLStateInt::delta); + highlight_state->notifyObservers(); } LOG_MSG("Exiting TemplateCanvas::SelectAllInCategory"); }