00001 #include <wx/filedlg.h> 00002 #include <wx/msgdlg.h> 00003 00004 #include "trafu_dialog.h" 00005 #include "flowvis_frame.h" 00006 00007 #include <string> 00008 #include <stdexcept> 00009 00010 BEGIN_EVENT_TABLE( TraFuDialog, wxDialog ) 00011 EVT_TRANSFERFUNCTION_CHANGED(wxID_ANY, TraFuDialog::OnTraFuChanged) 00012 END_EVENT_TABLE() 00013 00014 namespace 00015 { 00016 void ShowError(wxWindow* parent, const wxString &source, const wxString* info) 00017 { 00018 wxString message(source); 00019 if (info) message += _("\n\nReason:\n") + *info; 00020 wxMessageBox(message, _("Error"), wxOK | wxCENTER | wxICON_ERROR, parent); 00021 } 00022 } 00023 00024 void TraFuDialog::OnSaveTF(wxCommandEvent& event) 00025 { 00026 wxString caption = _("Save Transfer Function"); 00027 wxString wildcard = _("Transfer Function Files (*.tf)|*.tf|All Files (*.*)|*.*"); 00028 wxFileDialog dlg(this, caption, wxEmptyString, wxEmptyString, wildcard, wxSAVE); 00029 00030 if (dlg.ShowModal() == wxID_OK) { 00031 00032 try{ 00033 this->m_data->save_file(dlg.GetPath().fn_str()); 00034 } catch (const std::exception &e) { 00035 wxString info = wxString::FromAscii(e.what()); 00036 ShowError(this, _("Failed to save transfer function."), &info); 00037 } catch (...) { 00038 ShowError(this, _("Failed to save transfer function."), 0); 00039 } 00040 } 00041 } 00042 00043 void TraFuDialog::OnLoadTF(wxCommandEvent& event) 00044 { 00045 wxString caption = _("Open Transfer Function File"); 00046 wxString wildcard = _("Transfer Function Files (*.tf)|*.tf|All Files (*.*)|*.*"); 00047 wxFileDialog dlg(this, caption, wxEmptyString, wxEmptyString, wildcard, wxOPEN | wxFILE_MUST_EXIST); 00048 00049 if (dlg.ShowModal() == wxID_OK) { 00050 00051 try { 00052 this->m_data->load_file(dlg.GetPath().fn_str()); 00053 } catch (const std::exception &e) { 00054 wxString info = wxString::FromAscii(e.what()); 00055 ShowError(this, _("Failed to load transfer function."), &info); 00056 } catch (...) { 00057 ShowError(this, _("Failed to load transfer function."), 0); 00058 } 00059 } 00060 m_trafu_canvas->Refresh(); 00061 } 00062 00063 void TraFuDialog::OnTFReset( wxCommandEvent& event ) 00064 { 00065 m_data->Init(); 00066 m_trafu_canvas->Refresh(); 00067 UpdateVolumeCanvas(); 00068 } 00069 00070 void TraFuDialog::OnTraFuChanged(const wxTransferFunctionEvent& event) 00071 { 00072 UpdateVolumeCanvas(); 00073 } 00074 00075 void TraFuDialog::UpdateVolumeCanvas() 00076 { 00077 FlowVisFrame *big_daddy = static_cast<FlowVisFrame *>(this->GetParent()); 00078 big_daddy->OnTraFuChanged(); 00079 }