/** 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(); }
// List item Enter key or double click void SelectWeightsDlg::OnWListItemDblClick(wxListEvent& ev) { LOG_MSG("In SelectWeightsDlg::OnWListItemDblClick"); long item = ev.GetIndex(); LOG(item); if (item < 0 || item >= ids.size()) return; LOG(w_man_int->GetShortDispName(ids[item])); HighlightId(ids[item]); EndDialog(wxID_OK); }
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; }