void SelectWeightsDlg::OnWListItemDeselect(wxListEvent& ev)
{
	LOG_MSG("In SelectWeightsDlg::OnWListItemDeselect");
	long item = ev.GetIndex();
	LOG(item);
	SelectId(boost::uuids::nil_uuid());
	UpdateButtons();
	Refresh();
}
void SelectWeightsDlg::OnWListItemSelect(wxListEvent& ev)
{
	LOG_MSG("In SelectWeightsDlg::OnWListItemSelect");
	long item = ev.GetIndex();
	LOG(item);
	SelectId(ids[item]);
	UpdateButtons();
	Refresh();
}
Exemple #3
0
/** Implementation of WeightsManStateObserver interface */
void WeightsManFrame::update(WeightsManState* o)
{
	LOG_MSG("In WeightsManFrame::update(WeightsManState* o)");
	if (suspend_w_man_state_updates) {
		LOG_MSG("WeightsManFrame ignoring WeightsManStateObserver::update");
		return;
	}
	boost::uuids::uuid id = o->GetWeightsId();
	if (o->GetEventType() == WeightsManState::add_evt) {
		ids.push_back(id);
		if (!ids.size()-1 == w_list->GetItemCount()) {
			LOG(ids.size());
			LOG(w_list->GetItemCount());
		}
		long x = w_list->InsertItem(ids.size(), wxEmptyString);
		if (x == -1) {
			LOG(x);
		} else {
			w_list->SetItem(x, TITLE_COL, w_man_int->GetTitle(id));
		}
		HighlightId(id);
		Refresh();
	} else if (o->GetEventType() == WeightsManState::remove_evt) {
		std::vector<boost::uuids::uuid> new_ids;
		for (size_t i=0; i<ids.size(); ++i) {
			if (ids[i] == id) {
				w_list->DeleteItem(i);
			} else {
				new_ids.push_back(ids[i]);
			}
		}
		ids = new_ids;
		if (ids.size() > 0) HighlightId(ids[0]);
		SelectId(GetHighlightId());
	} else if (o->GetEventType() == WeightsManState::name_change_evt) {
		for (size_t i=0; i<ids.size(); ++i) {
			if (ids[i] == id) {
				// no need to change default
				w_list->SetItem(i, TITLE_COL, w_man_int->GetTitle(ids[i]));
			}
		}
		Refresh();
	}
	UpdateButtons();
}
void SelectWeightsDlg::InitNormal()
{
	panel = new wxPanel(this);
	panel->SetBackgroundColour(*wxWHITE);
	SetBackgroundColour(*wxWHITE);
	
	ok_btn = new wxButton(panel, XRCID("wxID_OK"), "OK",
						  wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
	cancel_btn = new wxButton(panel, XRCID("wxID_CANCEL"), "Cancel",
							  wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
	
	Connect(XRCID("wxID_OK"), wxEVT_BUTTON,
			wxCommandEventHandler(SelectWeightsDlg::OnOkClick));
	Connect(XRCID("wxID_CANCEL"), wxEVT_BUTTON,
			wxCommandEventHandler(SelectWeightsDlg::OnCancelClick));
	
	w_list = new wxListCtrl(panel, XRCID("ID_W_LIST"), wxDefaultPosition,
							wxSize(-1, 100), wxLC_REPORT);
	// Note: search for "ungrouped_list" for examples of wxListCtrl usage.
	w_list->AppendColumn("Weights Name");
	w_list->SetColumnWidth(TITLE_COL, 300);
	InitWeightsList();
	
	Connect(XRCID("ID_W_LIST"), wxEVT_LIST_ITEM_ACTIVATED,
			wxListEventHandler(SelectWeightsDlg::OnWListItemDblClick));
	Connect(XRCID("ID_W_LIST"), wxEVT_LIST_ITEM_SELECTED,
			wxListEventHandler(SelectWeightsDlg::OnWListItemSelect));
	Connect(XRCID("ID_W_LIST"), wxEVT_LIST_ITEM_DESELECTED,
			wxListEventHandler(SelectWeightsDlg::OnWListItemDeselect));
	
	details_win = wxWebView::New(panel, wxID_ANY, wxWebViewDefaultURLStr,
								 wxDefaultPosition,
								 wxSize(-1, 200));
	
	// Arrange above widgets in panel using sizers.
	// Top level panel sizer will be panel_h_szr
	// Below that will be panel_v_szr
	// panel_v_szr will directly receive widgets
	
	wxBoxSizer* btns_row1_h_szr = new wxBoxSizer(wxHORIZONTAL);
	btns_row1_h_szr->Add(ok_btn, 0, wxALIGN_CENTER_VERTICAL);
	btns_row1_h_szr->AddSpacer(10);
	btns_row1_h_szr->Add(cancel_btn, 0, wxALIGN_CENTER_VERTICAL);
	
	wxBoxSizer* wghts_list_h_szr = new wxBoxSizer(wxHORIZONTAL);
	wghts_list_h_szr->Add(w_list);
	
	wxBoxSizer* panel_v_szr = new wxBoxSizer(wxVERTICAL);
	panel_v_szr->Add(wghts_list_h_szr, 0,
					 wxALIGN_CENTER_HORIZONTAL);
	
	panel_v_szr->Add(details_win, 1, wxEXPAND);
	
	panel_v_szr->Add(btns_row1_h_szr, 0,
					 wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
	
	wxBoxSizer* panel_h_szr = new wxBoxSizer(wxHORIZONTAL);
	panel_h_szr->Add(panel_v_szr, 1, wxEXPAND);
	
	panel->SetSizer(panel_h_szr);
	
	boost::uuids::uuid default_id = w_man_int->GetDefault();
	SelectId(default_id);
	UpdateButtons();
	
	// Top Sizer
	wxBoxSizer* top_h_sizer = new wxBoxSizer(wxHORIZONTAL);
	top_h_sizer->Add(panel, 1, wxEXPAND|wxALL, 8);
	
	SetSizerAndFit(top_h_sizer);
	w_list->SetFocus();
}
Exemple #5
0
WeightsManFrame::WeightsManFrame(wxFrame *parent, Project* project,
								 const wxString& title, const wxPoint& pos,
								 const wxSize& size, const long style)
: TemplateFrame(parent, project, title, pos, size, style),
conn_hist_canvas(0),
conn_map_canvas(0),
project_p(project),
w_man_int(project->GetWManInt()), w_man_state(project->GetWManState()),
table_int(project->GetTableInt()), suspend_w_man_state_updates(false),
create_btn(0), load_btn(0), remove_btn(0), w_list(0)
{
	LOG_MSG("Entering WeightsManFrame::WeightsManFrame");
	
	panel = new wxPanel(this);
	panel->SetBackgroundColour(*wxWHITE);
	SetBackgroundColour(*wxWHITE);
	
	create_btn = new wxButton(panel, XRCID("ID_CREATE_BTN"), "Create",  wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
    
	load_btn = new wxButton(panel, XRCID("ID_LOAD_BTN"), "Load", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
    
	remove_btn = new wxButton(panel, XRCID("ID_REMOVE_BTN"), "Remove", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
    
    histogram_btn = new wxButton(panel, XRCID("ID_HISTOGRAM_BTN"), "Histogram", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
    
    connectivity_map_btn = new wxButton(panel, XRCID("ID_CONNECT_MAP_BTN"), "Connectivity Map", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
	
	Connect(XRCID("ID_CREATE_BTN"), wxEVT_BUTTON, wxCommandEventHandler(WeightsManFrame::OnCreateBtn));
	Connect(XRCID("ID_LOAD_BTN"), wxEVT_BUTTON, wxCommandEventHandler(WeightsManFrame::OnLoadBtn));
	Connect(XRCID("ID_REMOVE_BTN"), wxEVT_BUTTON, wxCommandEventHandler(WeightsManFrame::OnRemoveBtn));
    Connect(XRCID("ID_HISTOGRAM_BTN"), wxEVT_BUTTON, wxCommandEventHandler(WeightsManFrame::OnHistogramBtn));
    Connect(XRCID("ID_CONNECT_MAP_BTN"), wxEVT_BUTTON, wxCommandEventHandler(WeightsManFrame::OnConnectMapBtn));

	w_list = new wxListCtrl(panel, XRCID("ID_W_LIST"), wxDefaultPosition, wxSize(-1, 100), wxLC_REPORT);
    
	// Note: search for "ungrouped_list" for examples of wxListCtrl usage.
	w_list->AppendColumn("Weights Name");
	w_list->SetColumnWidth(TITLE_COL, 300);
	InitWeightsList();
	
	Connect(XRCID("ID_W_LIST"), wxEVT_LIST_ITEM_SELECTED, wxListEventHandler(WeightsManFrame::OnWListItemSelect));
	Connect(XRCID("ID_W_LIST"), wxEVT_LIST_ITEM_DESELECTED, wxListEventHandler(WeightsManFrame::OnWListItemDeselect));
	
	details_win = wxWebView::New(panel, wxID_ANY, wxWebViewDefaultURLStr, wxDefaultPosition, wxSize(-1, 200));

	// Arrange above widgets in panel using sizers.
	// Top level panel sizer will be panel_h_szr
	// Below that will be panel_v_szr
	// panel_v_szr will directly receive widgets
	
	wxBoxSizer* btns_row1_h_szr = new wxBoxSizer(wxHORIZONTAL);
	btns_row1_h_szr->Add(create_btn, 0, wxALIGN_CENTER_VERTICAL);
	btns_row1_h_szr->AddSpacer(5);
	btns_row1_h_szr->Add(load_btn, 0, wxALIGN_CENTER_VERTICAL);
	btns_row1_h_szr->AddSpacer(5);
	btns_row1_h_szr->Add(remove_btn, 0, wxALIGN_CENTER_VERTICAL);
	
    wxBoxSizer* btns_row2_h_szr = new wxBoxSizer(wxHORIZONTAL);
    btns_row2_h_szr->Add(histogram_btn, 0, wxALIGN_CENTER_VERTICAL);
    btns_row2_h_szr->AddSpacer(5);
    btns_row2_h_szr->Add(connectivity_map_btn, 0, wxALIGN_CENTER_VERTICAL);
    btns_row2_h_szr->AddSpacer(5);
 
    
	wxBoxSizer* wghts_list_h_szr = new wxBoxSizer(wxHORIZONTAL);
	wghts_list_h_szr->Add(w_list);
	
	wxBoxSizer* panel_v_szr = new wxBoxSizer(wxVERTICAL);
	panel_v_szr->Add(btns_row1_h_szr, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
    panel_v_szr->AddSpacer(15);
	panel_v_szr->Add(wghts_list_h_szr, 0, wxALIGN_CENTER_HORIZONTAL);
	panel_v_szr->Add(details_win, 1, wxEXPAND);
	panel_v_szr->Add(btns_row2_h_szr, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
	
	
	wxBoxSizer* panel_h_szr = new wxBoxSizer(wxHORIZONTAL);
	panel_h_szr->Add(panel_v_szr, 1, wxEXPAND);
	
	panel->SetSizer(panel_h_szr);
	
	
	//wxBoxSizer* right_v_szr = new wxBoxSizer(wxVERTICAL);
	//conn_hist_canvas = new ConnectivityHistCanvas(this, this, project, boost::uuids::nil_uuid());
	//right_v_szr->Add(conn_hist_canvas, 1, wxEXPAND);
	
	// We have decided not to display the ConnectivityMapCanvas.  Uncomment
	// the following 4 lines to re-enable for shape-enabled projects.
	//if (!project->IsTableOnlyProject()) {
	//	conn_map_canvas = new ConnectivityMapCanvas(this, this, project,
	//												boost::uuids::nil_uuid());
	//	right_v_szr->Add(conn_map_canvas, 1, wxEXPAND);
	//}
	
	boost::uuids::uuid default_id = w_man_int->GetDefault();
	SelectId(default_id);
	UpdateButtons();
	
	// Top Sizer for Frame
	wxBoxSizer* top_h_sizer = new wxBoxSizer(wxHORIZONTAL);
	top_h_sizer->Add(panel, 1, wxEXPAND|wxALL, 8);
	//top_h_sizer->Add(right_v_szr, 1, wxEXPAND);
	
	wxColour panel_color = panel->GetBackgroundColour();
	SetBackgroundColour(panel_color);
	//hist_canvas->SetCanvasBackgroundColor(panel_color);
	
	SetSizerAndFit(top_h_sizer);
	DisplayStatusBar(false);

	w_man_state->registerObserver(this);
	Show(true);
	LOG_MSG("Exiting WeightsManFrame::WeightsManFrame");
}
Exemple #6
0
void WeightsManFrame::OnLoadBtn(wxCommandEvent& ev)
{
	wxFileDialog dlg( this, "Choose Weights File", "", "",
					 "Weights Files (*.gal, *.gwt)|*.gal;*.gwt");
	
    if (dlg.ShowModal() != wxID_OK) return;
	wxString path  = dlg.GetPath();
	wxString ext = GenUtils::GetFileExt(path).Lower();
	
	if (ext != "gal" && ext != "gwt") {
		wxString msg("Only 'gal' and 'gwt' weights files supported.");
		wxMessageDialog dlg(this, msg, "Error", wxOK|wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	WeightsMetaInfo wmi;
	wxString id_field = WeightUtils::ReadIdField(path);
	LOG(id_field);
	wmi.SetToCustom(id_field);
	wmi.filename = path;
	
	suspend_w_man_state_updates = true;
	
	// Check if weights already loaded and simply select and set as
	// new default if already loaded.
	boost::uuids::uuid id = w_man_int->FindIdByFilename(path);
	if (id.is_nil()) {
		LOG_MSG("could not find existing weight with filename: " + path);
		//id = w_man_int->FindIdByMetaInfo(wmi);
	}
	if (!id.is_nil()) {
		HighlightId(id);
		SelectId(id);
		Refresh();
		suspend_w_man_state_updates = false;
		return;
	}
	

	
	GalElement* tempGal = 0;
	if (ext == "gal") {
		tempGal = WeightUtils::ReadGal(path, table_int);
	} else {
		tempGal = WeightUtils::ReadGwtAsGal(path, table_int);
	}
	if (tempGal == NULL) {
		// WeightsUtils read functions already reported any issues
		// to user when NULL returned.
		suspend_w_man_state_updates = false;
		return;
	}
    
    id = w_man_int->RequestWeights(wmi);
    if (id.is_nil()) {
        wxString msg("There was a problem requesting the weights file.");
        wxMessageDialog dlg(this, msg, "Error", wxOK|wxICON_ERROR);
        dlg.ShowModal();
        suspend_w_man_state_updates = false;
        return;
    }
	
	GalWeight* gw = new GalWeight();
	gw->num_obs = table_int->GetNumberRows();
	gw->wflnm = wmi.filename;
    gw->id_field = id_field;
	gw->gal = tempGal;

	if (!((WeightsNewManager*) w_man_int)->AssociateGal(id, gw)) {
		wxString msg("There was a problem associating the weights file.");
		wxMessageDialog dlg(this, msg, "Error", wxOK|wxICON_ERROR);
		dlg.ShowModal();
		delete gw;
		suspend_w_man_state_updates = false;
		return;
	}
	ids.push_back(id);
	long last = ids.size()-1;
	w_list->InsertItem(last, wxEmptyString);
	w_list->SetItem(last, TITLE_COL, w_man_int->GetTitle(id));
	w_man_int->MakeDefault(id);
	HighlightId(id);
	SelectId(id);
	Refresh();
	suspend_w_man_state_updates = false;
}