NCBI C++ ToolKit
scoring_methods_dlg.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: scoring_methods_dlg.cpp 37492 2017-01-13 21:51:26Z shkeda $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrey Yazhuk, Roman Katargin
27  *
28  * File Description:
29  */
30 
31 
32 #include <ncbi_pch.hpp>
33 
34 ////@begin includes
35 ////@end includes
36 
38 
41 
45 
46 #include <wx/sizer.h>
47 #include <wx/statbox.h>
48 #include <wx/listbox.h>
49 #include <wx/textctrl.h>
50 #include <wx/button.h>
51 #include <wx/bitmap.h>
52 #include <wx/icon.h>
53 #include <wx/msgdlg.h>
54 
56 
57 
58 IMPLEMENT_DYNAMIC_CLASS( CScoringMethodsDlg, CDialog )
59 
60 BEGIN_EVENT_TABLE( CScoringMethodsDlg, CDialog )
61 
62 ////@begin CScoringMethodsDlg event table entries
65 
67 
68  EVT_BUTTON( wxID_OK, CScoringMethodsDlg::OnOkClick )
69 
70 ////@end CScoringMethodsDlg event table entries
71 
73 
74 
76 : m_Type(IAlnExplorer::fDNA)
77 {
78  Init();
79 }
80 
81 CScoringMethodsDlg::CScoringMethodsDlg(wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
82 : m_Type(IAlnExplorer::fDNA)
83 {
84 
85  Init();
86  Create(parent, id, caption, pos, size, style);
87 }
88 
89 
90 bool CScoringMethodsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
91 {
92 ////@begin CScoringMethodsDlg creation
93  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
94  CDialog::Create( parent, id, caption, pos, size, style );
95 
97  if (GetSizer())
98  {
99  GetSizer()->SetSizeHints(this);
100  }
101  Centre();
102 ////@end CScoringMethodsDlg creation
103  return true;
104 }
105 
106 
108 {
109 ////@begin CScoringMethodsDlg destruction
110 ////@end CScoringMethodsDlg destruction
111 }
112 
113 
115 {
116  m_SelMethod = ToWxString(sel_method);
117  m_Type = type;
118 }
119 
120 
122 {
123 ////@begin CScoringMethodsDlg member initialisation
124 ////@end CScoringMethodsDlg member initialisation
125 }
126 
127 
129 {
130 public:
131  virtual bool Select(const IUITool& tool)
132  {
133  return dynamic_cast<const IScoringMethod*>(&tool) != NULL;
134  }
135 };
136 
137 
139 {
140 ////@begin CScoringMethodsDlg content construction
141  CScoringMethodsDlg* itemCDialog1 = this;
142 
143  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
144  itemCDialog1->SetSizer(itemBoxSizer2);
145 
146  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
147  itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
148 
149  wxStaticBox* itemStaticBoxSizer4Static = new wxStaticBox(itemCDialog1, wxID_ANY, _("Methods List"));
150  wxStaticBoxSizer* itemStaticBoxSizer4 = new wxStaticBoxSizer(itemStaticBoxSizer4Static, wxVERTICAL);
151  itemBoxSizer3->Add(itemStaticBoxSizer4, 6, wxGROW|wxALL, 5);
152 
153  wxArrayString itemListBox5Strings;
154  wxListBox* itemListBox5 = new wxListBox( itemCDialog1, ID_LISTBOX1, wxDefaultPosition, wxSize(-1, itemCDialog1->ConvertDialogToPixels(wxSize(-1, 110)).y), itemListBox5Strings, wxLB_SINGLE );
155  itemStaticBoxSizer4->Add(itemListBox5, 1, wxGROW|wxALL, 1);
156 
157  wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxVERTICAL);
158  itemBoxSizer3->Add(itemBoxSizer6, 7, wxGROW|wxALL, 0);
159 
160  wxStaticBox* itemStaticBoxSizer7Static = new wxStaticBox(itemCDialog1, wxID_ANY, _("Method Description"));
161  wxStaticBoxSizer* itemStaticBoxSizer7 = new wxStaticBoxSizer(itemStaticBoxSizer7Static, wxVERTICAL);
162  itemBoxSizer6->Add(itemStaticBoxSizer7, 1, wxGROW|wxALL, 5);
163 
164  wxTextCtrl* itemTextCtrl8 = new wxTextCtrl( itemCDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY );
165  itemStaticBoxSizer7->Add(itemTextCtrl8, 1, wxGROW|wxALL, 1);
166 
167  // Temporary removed until coloring methods settings become persistent
168  //wxButton* itemButton9 = new wxButton( itemCDialog1, ID_BUTTON1, _("Properties"), wxDefaultPosition, wxDefaultSize, 0 );
169  //itemBoxSizer6->Add(itemButton9, 0, wxALIGN_RIGHT|wxLEFT|wxRIGHT, 5);
170 
171  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemCDialog1, ID_STATICLINE, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
172  itemBoxSizer2->Add(itemStaticLine10, 0, wxGROW|wxLEFT|wxRIGHT, 5);
173 
174  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
175  itemBoxSizer2->Add(itemBoxSizer11, 0, wxALIGN_RIGHT|wxALL, 5);
176 
177  wxButton* itemButton12 = new wxButton( itemCDialog1, wxID_OK, _("&Select"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemBoxSizer11->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  wxButton* itemButton13 = new wxButton( itemCDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
181  itemBoxSizer11->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
182 
183 ////@end CScoringMethodsDlg content construction
184 
185 
186  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
187 
188  // obtain a collection of IScoringMethod tools from the Registry
190 
191  vector<CConstIRef<IUITool> > tools;
193  reg->GetTools(tools, sel);
194 
195  // fill the List with the methods applicable to this type of alignment
196  size_t i;
197  for( i = 0; i < tools.size(); i++ ) {
198  const IScoringMethod* method =
199  dynamic_cast<const IScoringMethod*>(tools[i].GetPointer());
200  _ASSERT(method);
201 
202  if(method && method->GetType() & m_Type) {
203  wxString method_name = ToWxString(method->GetName());
204  itemListBox->Append(method_name);
205  }
206  }
207 
208  for( i = 0; i < itemListBox->GetCount(); i++ ) {
209  if (m_SelMethod == itemListBox->GetString((unsigned)i))
210  break;
211  }
212 
213  int index = (int)((i >= itemListBox->GetCount()) ? 0 : i);
214  if (itemListBox->GetCount() > 0)
215  itemListBox->SetSelection(index);
216 
218 }
219 
220 
222 {
223  return true;
224 }
225 
226 
227 wxBitmap CScoringMethodsDlg::GetBitmapResource( const wxString& name )
228 {
229  // Bitmap retrieval
230 ////@begin CScoringMethodsDlg bitmap retrieval
231  wxUnusedVar(name);
232  return wxNullBitmap;
233 ////@end CScoringMethodsDlg bitmap retrieval
234 }
235 
236 
237 wxIcon CScoringMethodsDlg::GetIconResource( const wxString& name )
238 {
239  // Icon retrieval
240 ////@begin CScoringMethodsDlg icon retrieval
241  wxUnusedVar(name);
242  return wxNullIcon;
243 ////@end CScoringMethodsDlg icon retrieval
244 }
245 
246 
248 {
249  wxTextCtrl* itemTextCtrl = (wxTextCtrl*)FindWindow(ID_TEXTCTRL1);
250  itemTextCtrl->Clear();
251 
252  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
253  wxString methodName = itemListBox->GetStringSelection();
254  if (methodName.empty())
255  return;
256 
257  *itemTextCtrl << ToWxString(CUIToolRegistry::GetInstance()->GetToolDescription(ToStdString(methodName)));
258  itemTextCtrl->SetInsertionPoint(0);
259 }
260 
261 void CScoringMethodsDlg::OnMethodSelected( wxCommandEvent& event )
262 {
263  wxUnusedVar(event);
265 }
266 
267 void CScoringMethodsDlg::OnPropertiesClick( wxCommandEvent& event )
268 {
269  wxUnusedVar(event);
270 
271  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
272  wxString methodName = itemListBox->GetStringSelection();
273  if (methodName.empty())
274  return;
275 
277  IUIToolWithGUI* method = tool ? dynamic_cast<IUIToolWithGUI*>(tool.GetPointer()) : 0;
278 
279  if (!method) {
280  wxString msg = _("Failed to create instance of tool '") + methodName + _("'.");
281  wxMessageBox(msg, _("Error"), wxOK | wxICON_ERROR);
282  return;
283  }
284 
285  CPropertiesPanelDlg dlg(this, method);
286  dlg.ShowModal();
287 }
288 
289 
290 void CScoringMethodsDlg::OnOkClick( wxCommandEvent& event )
291 {
292  wxUnusedVar(event);
293 
294  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
295  m_SelMethod = itemListBox->GetStringSelection();
296  EndModal(wxID_OK);
297 }
298 
299 
300 void CScoringMethodsDlg::OnListbox1DoubleClicked( wxCommandEvent& event )
301 {
302  wxUnusedVar(event);
303 
304  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
305  m_SelMethod = itemListBox->GetStringSelection();
306  EndModal(wxID_OK);
307 }
308 
309 
CDialog.
Definition: dialog.hpp:47
virtual void EndModal(int retCode)
Definition: dialog.cpp:142
virtual bool Select(const IUITool &tool)
CScoringMethodsDlg.
bool Create(wxWindow *parent, wxWindowID id=ID_CSCORINGMETHODSDLG, const wxString &caption=_("Alignment Scoring Methods"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX)
Creation.
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnPropertiesClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
CScoringMethodsDlg()
Constructors.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
void OnMethodSelected(wxCommandEvent &event)
wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_LISTBOX1
static bool ShowToolTips()
Should we show tooltips?
IAlnExplorer::EAlignType m_Type
void OnListbox1DoubleClicked(wxCommandEvent &event)
wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event handler for ID_LISTBOX1
void OnOkClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
void Setup(const string &sel_method, IAlnExplorer::EAlignType type)
~CScoringMethodsDlg()
Destructor.
CUIToolRegistry - is a registry providing access to various tools registred in the application.
static CUIToolRegistry * GetInstance()
CIRef< IUITool > CreateToolInstance(const string &method_name)
factory method, returns NULL if name is invalid.
void GetTools(vector< CConstIRef< IUITool > > &tools, ISelector &selector) const
Alignment explorer interface.
IScoringMethod represents an abstract algorithm for calculating alignment scores and assigning colors...
virtual int GetType() const =0
returns combination of EAlignType flags defining types of alignments that can be colored with this me...
IUIToolWithGUI - represents a method that can be integrated in GUI.
Definition: ui_tool.hpp:102
IUITool represents an abstract algorithm that is bound to a UI component.
Definition: ui_tool.hpp:59
virtual string GetName() const =0
returns unique name of the method that is used in UI to identify it
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define ID_BUTTON1
#define ID_LISTBOX1
static void Init(void)
Definition: cursor6.c:76
static int type
Definition: getdata.c:31
#define NULL
Definition: ncbistd.hpp:225
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Definition: type.c:6
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:58:01 2024 by modify_doxy.py rev. 669887