diff --git a/Explore/ConditionalHistogramView.cpp b/Explore/ConditionalHistogramView.cpp index d6ce5ec93..005360969 100644 --- a/Explore/ConditionalHistogramView.cpp +++ b/Explore/ConditionalHistogramView.cpp @@ -96,7 +96,8 @@ show_axes(true), scale_x_over_time(true), scale_y_over_time(true), set_uniqueval } if (undef_tms.size() < num_time_vals) { - // case that histogram is non time variable, but horizontal / vertical may be time variable + // case that histogram is non time variable, + // but horizontal / vertical may be time variable for (int i=1; i undefs(num_obs, false); for (int j=0; j sel_data(num_obs); - data[HIST_VAR]; + for (int i=0; i 0) { + cur_intervals = std::max(cur_intervals, (int)unique_dict.size()); + } else { + cur_intervals = (int)unique_dict.size(); + } } } else { // restore bins for histogram @@ -208,11 +213,11 @@ void ConditionalHistogramCanvas::SetCheckMarks(wxMenu* menu) // following menu items if they were specified for this particular // view in the xrc file. Items that cannot be enable/disabled, // or are not checkable do not appear. - ConditionalNewCanvas::SetCheckMarks(menu); - GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SHOW_AXES"), - IsShowAxes()); + GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_SHOW_AXES"), IsShowAxes()); + // set as unique value menuitem + GeneralWxUtils::CheckMenuItem(menu, XRCID("ID_VIEW_HISTOGRAM_SET_UNIQUE"), set_uniquevalue); } /** Override of TemplateCanvas method. */ @@ -339,8 +344,6 @@ void ConditionalHistogramCanvas::ResizeSelectableShps(int virtual_scrn_w, GdaShape* s; if (show_axes) { int t = var_info[HIST_VAR].time; - double x_min = 0; - double x_max = left_pad_const + right_pad_const + interval_width_const * cur_intervals + interval_gap_const * (cur_intervals-1); // orig_x_pos is the center of each histogram bar std::vector orig_x_pos(cur_intervals); @@ -363,14 +366,8 @@ void ConditionalHistogramCanvas::ResizeSelectableShps(int virtual_scrn_w, double x0 = orig_x_pos[ival] - interval_width_const/2.0; double x1 = orig_x_pos[ival] + interval_width_const/2.0; double y0 = 0; - double y1 = cell_data[0][r][c].ival_obs_cnt[ival]; // add label for x-axis - - GdaShapeText* brk = new GdaShapeText(s_ival_breaks[t][ival], - *GdaConst::small_font, - wxRealPoint(x0 /2.0 + x1 /2.0, y0), 0, - GdaShapeText::h_center, - GdaShapeText::v_center, 0, 25); + GdaShapeText* brk = new GdaShapeText(s_ival_breaks[t][ival], *GdaConst::small_font, wxRealPoint(x0 /2.0 + x1 /2.0, y0), 0, GdaShapeText::h_center, GdaShapeText::v_center, 0, 25); brk->applyScaleTrans(st[r][c]); foreground_shps.push_back(brk); } @@ -588,10 +585,9 @@ void ConditionalHistogramCanvas::PopulateCanvas() for (int ival=0; ivalsetPen(GdaConst::qualitative_colors[ival%sz]); selectable_shps[i]->setBrush(GdaConst::qualitative_colors[ival%sz]); i++; @@ -631,7 +627,7 @@ void ConditionalHistogramCanvas::ShowAxes(bool show_axes_s) void ConditionalHistogramCanvas::DetermineMouseHoverObjects(wxPoint pt) { total_hover_obs = 0; - for (int i=0, iend=selectable_shps.size(); ipointWithin(pt)) { hover_obs[total_hover_obs++] = i; if (total_hover_obs == max_hover_obs) break; @@ -643,13 +639,13 @@ void ConditionalHistogramCanvas::DetermineMouseHoverObjects(wxPoint pt) // are all rectangles. void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) { + int t = var_info[HIST_VAR].time; bool rect_sel = (!pointsel && (brushtype == rectangle)); - int t = var_info[HIST_VAR].time; std::vector& hs = highlight_state->GetHighlight(); bool selection_changed = false; - int total_sel_shps = selectable_shps.size(); + int total_sel_shps = (int)selectable_shps.size(); wxPoint lower_left; wxPoint upper_right; @@ -687,17 +683,12 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) sel_shp_to_cell(i, r, c, ival); GdaRectangle* rec = (GdaRectangle*) selectable_shps[i]; bool selected = ((pointsel && rec->pointWithin(sel1)) || - (rect_sel && - GenGeomAlgs::RectsIntersect(rec->lower_left, - rec->upper_right, - lower_left, upper_right))); - bool all_sel = (cell_data[0][r][c].ival_obs_cnt[ival] == - cell_data[0][r][c].ival_obs_sel_cnt[ival]); + (rect_sel && GenGeomAlgs::RectsIntersect(rec->lower_left, rec->upper_right, lower_left, upper_right))); if (selected) { // select currently unselected in ival for (std::list::iterator it = - cell_data[0][r][c].ival_to_obs_ids[ival].begin(); - it != cell_data[0][r][c].ival_to_obs_ids[ival].end(); 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++) { new_hs[(*it)]= true; selection_changed = true; } @@ -723,12 +714,12 @@ void ConditionalHistogramCanvas::UpdateSelection(bool shiftdown, bool pointsel) void ConditionalHistogramCanvas::DrawSelectableShapes(wxMemoryDC &dc) { - int t = var_info[HIST_VAR].time; int i=0; + int t = var_info[HIST_VAR].time; for (int r=0; rpaintSelf(dc); } i++; @@ -739,14 +730,14 @@ void ConditionalHistogramCanvas::DrawSelectableShapes(wxMemoryDC &dc) void ConditionalHistogramCanvas::DrawHighlightedShapes(wxMemoryDC &dc) { - int t = var_info[HIST_VAR].time; int i=0; + int t = var_info[HIST_VAR].time; double s; for (int r=0; rSet as Unique Values\" is selected."); + wxMessageDialog dlg (this, msg, _("Warning"), wxOK | wxICON_ERROR); + dlg.ShowModal(); + return; + } cur_intervals = dlg.num_intervals; InitIntervals(); invalidateBms(); @@ -869,22 +866,22 @@ void ConditionalHistogramCanvas::InitIntervals() int rows = 1, cols = 1; if (!vert_cat_data.categories.empty()) { - rows = vert_cat_data.categories[vt].cat_vec.size(); + rows = (int)vert_cat_data.categories[vt].cat_vec.size(); } if (!horiz_cat_data.categories.empty()) { - cols = horiz_cat_data.categories[ht].cat_vec.size(); + cols = (int)horiz_cat_data.categories[ht].cat_vec.size(); } - cell_data[0].resize(boost::extents[rows][cols]); + cell_data[t].resize(boost::extents[rows][cols]); for (int r=0; r max_num_obs_in_ival[t]) + cell_data[t][r][c].ival_to_obs_ids[cur_ival].push_front(id); + cell_data[t][r][c].ival_obs_cnt[cur_ival]++; + if (cell_data[t][r][c].ival_obs_cnt[cur_ival] > max_num_obs_in_ival[t]) { - max_num_obs_in_ival[t] = cell_data[0][r][c].ival_obs_cnt[cur_ival]; + max_num_obs_in_ival[t] = cell_data[t][r][c].ival_obs_cnt[cur_ival]; if (max_num_obs_in_ival[t] > overall_max_num_obs_in_ival) { overall_max_num_obs_in_ival = max_num_obs_in_ival[t]; } } if (hs[s_data_sorted[dt][i].second]) { - cell_data[0][r][c].ival_obs_sel_cnt[cur_ival]++; + cell_data[t][r][c].ival_obs_sel_cnt[cur_ival]++; } } @@ -950,17 +947,17 @@ void ConditionalHistogramCanvas::InitIntervals() } obs_id_to_sel_shp[t][id] = cell_to_sel_shp_gen(r, c, cur_ival, cols, cur_intervals); - cell_data[0][r][c].ival_to_obs_ids[cur_ival].push_front(id); - cell_data[0][r][c].ival_obs_cnt[cur_ival]++; - if (cell_data[0][r][c].ival_obs_cnt[cur_ival] > max_num_obs_in_ival[t]) + cell_data[t][r][c].ival_to_obs_ids[cur_ival].push_front(id); + cell_data[t][r][c].ival_obs_cnt[cur_ival]++; + if (cell_data[t][r][c].ival_obs_cnt[cur_ival] > max_num_obs_in_ival[t]) { - max_num_obs_in_ival[t] = cell_data[0][r][c].ival_obs_cnt[cur_ival]; + max_num_obs_in_ival[t] = cell_data[t][r][c].ival_obs_cnt[cur_ival]; if (max_num_obs_in_ival[t] > overall_max_num_obs_in_ival) { overall_max_num_obs_in_ival = max_num_obs_in_ival[t]; } } if (hs[data_sorted[dt][i].second]) { - cell_data[0][r][c].ival_obs_sel_cnt[cur_ival]++; + cell_data[t][r][c].ival_obs_sel_cnt[cur_ival]++; } } } @@ -979,15 +976,15 @@ void ConditionalHistogramCanvas::UpdateIvalSelCnts() if (var_info[HOR_VAR].sync_with_global_time) ht += t; int rows = 1, cols = 1; if (!vert_cat_data.categories.empty()) { - rows = vert_cat_data.categories[vt].cat_vec.size(); + rows = (int)vert_cat_data.categories[vt].cat_vec.size(); } if (!horiz_cat_data.categories.empty()) { - cols = horiz_cat_data.categories[ht].cat_vec.size(); + cols = (int)horiz_cat_data.categories[ht].cat_vec.size(); } for (int r=0; rSetStatusText(s); } -void ConditionalHistogramCanvas::sel_shp_to_cell_gen(int i, - int& r, int& c, int& ival, - int cols, int ivals) +void ConditionalHistogramCanvas::sel_shp_to_cell_gen(int i, int& r, int& c, int& ival, int cols, int ivals) { int t = cols*ivals; r = t > 0 ? i/t : 0; @@ -1111,8 +1113,7 @@ void ConditionalHistogramCanvas::sel_shp_to_cell_gen(int i, ival = t%ivals; } -void ConditionalHistogramCanvas::sel_shp_to_cell(int i, int& r, - int& c, int& ival) +void ConditionalHistogramCanvas::sel_shp_to_cell(int i, int& r, int& c, int& ival) { // rows == vert_num_cats // cols == horiz_num_cats @@ -1149,10 +1150,7 @@ ConditionalHistogramFrame::ConditionalHistogramFrame(wxFrame *parent, int width, height; GetClientSize(&width, &height); - template_canvas = new ConditionalHistogramCanvas(this, this, project, - var_info, col_ids, - wxDefaultPosition, - wxSize(width,height)); + template_canvas = new ConditionalHistogramCanvas(this, this, project, var_info, col_ids, wxDefaultPosition, wxSize(width,height)); SetTitle(template_canvas->GetCanvasTitle()); template_canvas->SetScrollRate(1,1); DisplayStatusBar(true); @@ -1171,20 +1169,18 @@ void ConditionalHistogramFrame::OnActivate(wxActivateEvent& event) wxLogMessage("In ConditionalMapFrame::OnActivate()"); RegisterAsActive("ConditionalHistogramFrame", GetTitle()); } - if ( event.GetActive() && template_canvas ) + if ( event.GetActive() && template_canvas ) { template_canvas->SetFocus(); + } } void ConditionalHistogramFrame::MapMenus() { wxMenuBar* mb = GdaFrame::GetGdaFrame()->GetMenuBar(); // Map Options Menus - wxMenu* optMenu = wxXmlResource::Get()-> - LoadMenu("ID_COND_HISTOGRAM_VIEW_MENU_OPTIONS"); - ((ConditionalHistogramCanvas*) template_canvas)-> - AddTimeVariantOptionsToMenu(optMenu); - TemplateCanvas::AppendCustomCategories(optMenu, - project->GetCatClassifManager()); + wxMenu* optMenu = wxXmlResource::Get()->LoadMenu("ID_COND_HISTOGRAM_VIEW_MENU_OPTIONS"); + ((ConditionalHistogramCanvas*) template_canvas)->AddTimeVariantOptionsToMenu(optMenu); + TemplateCanvas::AppendCustomCategories(optMenu, project->GetCatClassifManager()); ((ConditionalHistogramCanvas*) template_canvas)->SetCheckMarks(optMenu); GeneralWxUtils::ReplaceMenu(mb, _("Options"), optMenu); UpdateOptionMenuItems(); @@ -1204,8 +1200,7 @@ void ConditionalHistogramFrame::UpdateOptionMenuItems() TemplateFrame::UpdateOptionMenuItems(); // set common items first wxMenuBar* mb = GdaFrame::GetGdaFrame()->GetMenuBar(); int menu = mb->FindMenu(_("Options")); - if (menu == wxNOT_FOUND) { - } else { + if (menu != wxNOT_FOUND) { ((ConditionalHistogramCanvas*) template_canvas)->SetCheckMarks(mb->GetMenu(menu)); } @@ -1217,7 +1212,6 @@ void ConditionalHistogramFrame::UpdateContextMenuItems(wxMenu* menu) // following menu items if they were specified for this particular // view in the xrc file. Items that cannot be enable/disabled, // or are not checkable do not appear. - TemplateFrame::UpdateContextMenuItems(menu); // set common items } @@ -1231,8 +1225,7 @@ void ConditionalHistogramFrame::update(TimeState* o) void ConditionalHistogramFrame::OnShowAxes(wxCommandEvent& ev) { wxLogMessage("In ConditionalHistogramFrame::OnShowAxes()"); - ConditionalHistogramCanvas* t = - (ConditionalHistogramCanvas*) template_canvas; + ConditionalHistogramCanvas* t = (ConditionalHistogramCanvas*) template_canvas; t->ShowAxes(!t->IsShowAxes()); UpdateOptionMenuItems(); } @@ -1240,14 +1233,15 @@ void ConditionalHistogramFrame::OnShowAxes(wxCommandEvent& ev) void ConditionalHistogramFrame::OnHistogramIntervals(wxCommandEvent& ev) { wxLogMessage("In ConditionalHistogramFrame::OnHistogramIntervals()"); - ConditionalHistogramCanvas* t = - (ConditionalHistogramCanvas*) template_canvas; + ConditionalHistogramCanvas* t = (ConditionalHistogramCanvas*) template_canvas; t->HistogramIntervals(); } void ConditionalHistogramFrame::OnSaveCanvasImageAs(wxCommandEvent& event) { - if (!template_canvas) return; + if (!template_canvas) { + return; + } wxString title = project->GetProjectTitle(); GeneralWxUtils::SaveWindowAsImage(template_canvas, title); } diff --git a/Explore/HistogramView.cpp b/Explore/HistogramView.cpp index 220f4ffc9..2bd30d55b 100644 --- a/Explore/HistogramView.cpp +++ b/Explore/HistogramView.cpp @@ -244,8 +244,12 @@ void HistogramCanvas::OnSetUniqueValue(wxCommandEvent& event) unique_dict[sel_data[i]] += 1; } // add current [id] to ival_to_obs_ids - max_intervals = (int)unique_dict.size(); - cur_intervals = (int)unique_dict.size(); + max_intervals = std::min(MAX_INTERVALS, (int)unique_dict.size()); + if (t > 0) { + cur_intervals = std::max(cur_intervals, (int)unique_dict.size()); + } else { + cur_intervals = (int)unique_dict.size(); + } } } else { // restore diff --git a/GeoDa.cpp b/GeoDa.cpp index adbc93429..e4d6690ba 100644 --- a/GeoDa.cpp +++ b/GeoDa.cpp @@ -228,9 +228,9 @@ bool GdaApp::OnInit(void) // initialize OGR connection OGRDataAdapter::GetInstance(); - - checker = new wxSingleInstanceChecker("GdaApp"); - +#ifdef __WIN32__ + checker = new wxSingleInstanceChecker(); +#endif // load preferences PreferenceDlg::ReadFromCache(); @@ -285,7 +285,7 @@ bool GdaApp::OnInit(void) GdaInitXmlResource(); // call the init function in GdaAppResources.cpp // check crash - if (GdaConst::disable_crash_detect == false && !checker->IsAnotherRunning()) { + if (GdaConst::disable_crash_detect == false && (checker && !checker->IsAnotherRunning())) { std::vector items = OGRDataAdapter::GetInstance().GetHistory("NoCrash"); if (items.size() > 0) { wxString no_crash = items[0];