src/gui/widgets/data/scoring_methods_dlg.cpp

Go to the documentation of this file.
00001 /*  $Id: scoring_methods_dlg.cpp 17877 2008-09-24 13:03:09Z dicuccio $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Authors:  Andrey Yazhuk, Roman Katargin
00027  *
00028  * File Description:
00029  */
00030 
00031 
00032 #include <ncbi_pch.hpp>
00033 
00034 ////@begin includes
00035 ////@end includes
00036 
00037 #include <gui/widgets/data/scoring_method.hpp>
00038 #include <gui/objutils/ui_tool_registry.hpp>
00039 #include <gui/widgets/data/ui_tool_with_gui.hpp>
00040 #include <gui/widgets/data/properties_panel_dlg.hpp>
00041 #include <gui/widgets/wx/wx_utils.hpp>
00042 
00043 #include <gui/widgets/data/scoring_methods_dlg.hpp>
00044 
00045 #include <wx/sizer.h>
00046 #include <wx/statbox.h>
00047 #include <wx/listbox.h>
00048 #include <wx/textctrl.h>
00049 #include <wx/button.h>
00050 #include <wx/bitmap.h>
00051 #include <wx/icon.h>
00052 #include <wx/msgdlg.h>
00053 
00054 BEGIN_NCBI_SCOPE
00055 
00056 
00057 IMPLEMENT_DYNAMIC_CLASS( CScoringMethodsDlg, CDialog )
00058 
00059 BEGIN_EVENT_TABLE( CScoringMethodsDlg, CDialog )
00060 
00061 ////@begin CScoringMethodsDlg event table entries
00062     EVT_LISTBOX( ID_LISTBOX1, CScoringMethodsDlg::OnMethodSelected )
00063     EVT_LISTBOX_DCLICK( ID_LISTBOX1, CScoringMethodsDlg::OnListbox1DoubleClicked )
00064 
00065     EVT_BUTTON( ID_BUTTON1, CScoringMethodsDlg::OnPropertiesClick )
00066 
00067     EVT_BUTTON( wxID_OK, CScoringMethodsDlg::OnOkClick )
00068 
00069 ////@end CScoringMethodsDlg event table entries
00070 
00071 END_EVENT_TABLE()
00072 
00073 
00074 CScoringMethodsDlg::CScoringMethodsDlg()
00075 :  m_Type(IAlnExplorer::fDNA)
00076 {
00077     Init();
00078 }
00079 
00080 CScoringMethodsDlg::CScoringMethodsDlg(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00081 :   m_Type(IAlnExplorer::fDNA)
00082 {
00083 
00084     Init();
00085     Create(parent, id, caption, pos, size, style);
00086 }
00087 
00088 
00089 bool CScoringMethodsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00090 {
00091 ////@begin CScoringMethodsDlg creation
00092     SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
00093     CDialog::Create( parent, id, caption, pos, size, style );
00094 
00095     CreateControls();
00096     if (GetSizer())
00097     {
00098         GetSizer()->SetSizeHints(this);
00099     }
00100     Centre();
00101 ////@end CScoringMethodsDlg creation
00102     return true;
00103 }
00104 
00105 
00106 CScoringMethodsDlg::~CScoringMethodsDlg()
00107 {
00108 ////@begin CScoringMethodsDlg destruction
00109 ////@end CScoringMethodsDlg destruction
00110 }
00111 
00112 
00113 void CScoringMethodsDlg::Setup( const string& sel_method, IAlnExplorer::EAlignType type)
00114 {
00115     m_SelMethod = ToWxString(sel_method);
00116     m_Type = type;
00117 }
00118 
00119 
00120 void CScoringMethodsDlg::Init()
00121 {
00122 ////@begin CScoringMethodsDlg member initialisation
00123 ////@end CScoringMethodsDlg member initialisation
00124 }
00125 
00126 
00127 class CScoringMethodSelector : public CUIToolRegistry::ISelector
00128 {
00129 public:
00130     virtual bool Select(const IUITool& tool)
00131     {
00132         return dynamic_cast<const IScoringMethod*>(&tool) != NULL;
00133     }
00134 };
00135 
00136 
00137 void CScoringMethodsDlg::CreateControls()
00138 {
00139 ////@begin CScoringMethodsDlg content construction
00140     CScoringMethodsDlg* itemCDialog1 = this;
00141 
00142     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00143     itemCDialog1->SetSizer(itemBoxSizer2);
00144 
00145     wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
00146     itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
00147 
00148     wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox(itemCDialog1, wxID_ANY, _T("Methods List"));
00149     wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxVERTICAL);
00150     itemBoxSizer3->Add(itemStaticBoxSizer4, 6, wxGROW|wxALL, 5);
00151 
00152     wxArrayString itemListBox5Strings;
00153     wxListBox* itemListBox5 = new wxListBox( itemCDialog1, ID_LISTBOX1, wxDefaultPosition, wxSize(-1, itemCDialog1->ConvertDialogToPixels(wxSize(-1, 110)).y), itemListBox5Strings, wxLB_SINGLE );
00154     itemStaticBoxSizer4->Add(itemListBox5, 1, wxGROW|wxALL, 1);
00155 
00156     wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
00157     itemBoxSizer3->Add(itemBoxSizer6, 7, wxGROW|wxALL, 0);
00158 
00159     wxStaticBox* itemStaticBoxSizer7Static = new wxStaticBox(itemCDialog1, wxID_ANY, _T("Method Description"));
00160     wxStaticBoxSizer* itemStaticBoxSizer7 = new wxStaticBoxSizer(itemStaticBoxSizer7Static, wxVERTICAL);
00161     itemBoxSizer6->Add(itemStaticBoxSizer7, 1, wxGROW|wxALL, 5);
00162 
00163     wxTextCtrl* itemTextCtrl8 = new wxTextCtrl( itemCDialog1, ID_TEXTCTRL1, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
00164     itemStaticBoxSizer7->Add(itemTextCtrl8, 1, wxGROW|wxALL, 1);
00165 
00166     wxButton* itemButton9 = new wxButton( itemCDialog1, ID_BUTTON1, _T("Properties"), wxDefaultPosition, wxDefaultSize, 0 );
00167     itemBoxSizer6->Add(itemButton9, 0, wxALIGN_RIGHT|wxLEFT|wxRIGHT, 5);
00168 
00169     wxStaticLine* itemStaticLine10 = new wxStaticLine( itemCDialog1, ID_STATICLINE, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
00170     itemBoxSizer2->Add(itemStaticLine10, 0, wxGROW|wxLEFT|wxRIGHT, 5);
00171 
00172     wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
00173     itemBoxSizer2->Add(itemBoxSizer11, 0, wxALIGN_RIGHT|wxALL, 5);
00174 
00175     wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_OK, _T("&Select"), wxDefaultPosition, wxDefaultSize, 0 );
00176     itemBoxSizer11->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00177 
00178     wxButton* itemButton13 = new wxButton( itemCDialog1, wxID_CANCEL, _T("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00179     itemBoxSizer11->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00180 
00181 ////@end CScoringMethodsDlg content construction
00182 
00183 
00184     wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
00185 
00186     // obtain a collection of IScoringMethod tools from the Registry
00187     CUIToolRegistry* reg = CUIToolRegistry::GetInstance();
00188 
00189     vector<CConstIRef<IUITool> > tools;
00190     CScoringMethodSelector sel;
00191     reg->GetTools(tools, sel);
00192 
00193     // fill the List with the methods applicable to this type of alignment
00194     size_t i;
00195     for( i = 0; i < tools.size(); i++ )  {
00196         const IScoringMethod* method =
00197             dynamic_cast<const IScoringMethod*>(tools[i].GetPointer());
00198         _ASSERT(method);
00199 
00200         if(method  &&  method->GetType() & m_Type)  {
00201             wxString method_name = ToWxString(method->GetName());
00202             itemListBox->Append(method_name);
00203         }
00204     }
00205 
00206     for( i = 0; i < itemListBox->GetCount(); i++ )  {
00207         if (m_SelMethod == itemListBox->GetString(i))
00208             break;
00209     }
00210 
00211     int index = (i >= itemListBox->GetCount()) ? 0 : i;
00212     if (itemListBox->GetCount() > 0)
00213         itemListBox->SetSelection(index);
00214 
00215     x_UpdateDescription();
00216 }
00217 
00218 
00219 bool CScoringMethodsDlg::ShowToolTips()
00220 {
00221     return true;
00222 }
00223 
00224 
00225 wxBitmap CScoringMethodsDlg::GetBitmapResource( const wxString& name )
00226 {
00227     // Bitmap retrieval
00228 ////@begin CScoringMethodsDlg bitmap retrieval
00229     wxUnusedVar(name);
00230     return wxNullBitmap;
00231 ////@end CScoringMethodsDlg bitmap retrieval
00232 }
00233 
00234 
00235 wxIcon CScoringMethodsDlg::GetIconResource( const wxString& name )
00236 {
00237     // Icon retrieval
00238 ////@begin CScoringMethodsDlg icon retrieval
00239     wxUnusedVar(name);
00240     return wxNullIcon;
00241 ////@end CScoringMethodsDlg icon retrieval
00242 }
00243 
00244 
00245 void CScoringMethodsDlg::x_UpdateDescription()
00246 {
00247     wxTextCtrl* itemTextCtrl = (wxTextCtrl*)FindWindow(ID_TEXTCTRL1);
00248     itemTextCtrl->Clear();
00249 
00250     wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
00251     wxString methodName = itemListBox->GetStringSelection();
00252     if (methodName.empty())
00253         return;
00254 
00255     *itemTextCtrl << ToWxString(CUIToolRegistry::GetInstance()->GetToolDescription(ToStdString(methodName)));
00256     itemTextCtrl->SetInsertionPoint(0);
00257 }
00258 
00259 void CScoringMethodsDlg::OnMethodSelected( wxCommandEvent& event )
00260 {
00261     x_UpdateDescription();
00262 }
00263 
00264 void CScoringMethodsDlg::OnPropertiesClick( wxCommandEvent& event )
00265 {
00266     wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
00267     wxString methodName = itemListBox->GetStringSelection();
00268     if (methodName.empty())
00269         return;
00270 
00271     CIRef<IUITool> tool = CUIToolRegistry::GetInstance()->CreateToolInstance(ToStdString(methodName));
00272     IUIToolWithGUI* method = tool ? dynamic_cast<IUIToolWithGUI*>(tool.GetPointer()) : 0;
00273 
00274     if (!method) {
00275         wxString msg = _T("Failed to create instance of tool '") + methodName + _T("'.");
00276         wxMessageBox(msg, _T("Error"), wxOK | wxICON_ERROR);
00277         return;
00278     }
00279 
00280     CPropertiesPanelDlg dlg(this, method);
00281     dlg.ShowModal();
00282 }
00283 
00284 
00285 void CScoringMethodsDlg::OnOkClick( wxCommandEvent& event )
00286 {
00287     wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
00288     m_SelMethod = itemListBox->GetStringSelection();
00289     EndModal(wxID_OK);
00290 }
00291 
00292 
00293 void CScoringMethodsDlg::OnListbox1DoubleClicked( wxCommandEvent& event )
00294 {
00295     wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
00296     m_SelMethod = itemListBox->GetStringSelection();
00297     EndModal(wxID_OK);
00298 }
00299 
00300 
00301 END_NCBI_SCOPE
00302 
00303 

Generated on Wed Dec 9 04:35:57 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Wed Dec 09 08:18:02 2009 by modify_doxy.py rev. 173732