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

Go to the SVN repository for this file.

1 /* $Id: score_methods_dlg.cpp 27635 2013-03-15 19:33:00Z katargir@NCBI.NLM.NIH.GOV $
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: Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 ////@begin includes
33 ////@end includes
34 
35 #include "score_methods_dlg.hpp"
36 
40 
47 
48 #include <wx/sizer.h>
49 #include <wx/stattext.h>
50 #include <wx/choice.h>
51 #include <wx/listbox.h>
52 #include <wx/textctrl.h>
53 #include <wx/button.h>
54 #include <wx/bitmap.h>
55 #include <wx/icon.h>
56 
57 ////@begin XPM images
58 ////@end XPM images
59 
61 
62 
63 /*!
64  * CScoreMethodsDlg type definition
65  */
66 
67 IMPLEMENT_DYNAMIC_CLASS( CScoreMethodsDlg, wxDialog )
68 
69 
70 /*!
71  * CScoreMethodsDlg event table definition
72  */
73 
74 BEGIN_EVENT_TABLE( CScoreMethodsDlg, wxDialog )
75 
76 ////@begin CScoreMethodsDlg event table entries
78 
80 
82 
84 
85 ////@end CScoreMethodsDlg event table entries
86 
88 
89 
90 /*!
91  * CScoreMethodsDlg constructors
92  */
93 
95 {
96  Init();
97 }
98 
99 CScoreMethodsDlg::CScoreMethodsDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
100 {
101  Init();
102  Create(parent, id, caption, pos, size, style);
103 }
104 
105 
106 /*!
107  * CScoreMethodsDlg creator
108  */
109 
110 bool CScoreMethodsDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
111 {
112 ////@begin CScoreMethodsDlg creation
113  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
114  wxDialog::Create( parent, id, caption, pos, size, style );
115 
116  CreateControls();
117  if (GetSizer())
118  {
119  GetSizer()->SetSizeHints(this);
120  }
121  Centre();
122 ////@end CScoreMethodsDlg creation
123  return true;
124 }
125 
126 
127 /*!
128  * CScoreMethodsDlg destructor
129  */
130 
132 {
133 ////@begin CScoreMethodsDlg destruction
134 ////@end CScoreMethodsDlg destruction
135 }
136 
137 
138 /*!
139  * Member initialisation
140  */
141 
142 static const wxChar* kDefUserScoreDir = wxT("<home>/align_scores");
143 static const wxChar* kDefScoreDir = wxT("<std>/etc/align_scores");
144 static const char* kUIToolsRegKey = "GBENCH.UITools";
145 
147 {
148 public:
149  virtual bool Select(const IUITool& tool)
150  {
151  return dynamic_cast<const IScoringMethod*>(&tool) != NULL;
152  }
153 };
154 
156 {
157 ////@begin CScoreMethodsDlg member initialisation
158 ////@end CScoreMethodsDlg member initialisation
159 
160 
161 
162 // Withgout this the metods won't be registered in static build
166 
167  list<wxString> dirs;
168  dirs.push_back(kDefUserScoreDir);
169  dirs.push_back(kDefScoreDir);
170 
172  reg->LoadTemplateToolsInfo(dirs);
173 
175  reg->LoadSettings();
176 
177  vector<CConstIRef<IUITool> > tools;
179  CUIToolRegistry::GetInstance()->GetTools(tools, sel);
180 
181  for( size_t i = 0; i < tools.size(); i++ ) {
182  const IScoringMethod* method =
183  dynamic_cast<const IScoringMethod*>(tools[i].GetPointer());
184  _ASSERT(method);
185  if(method) {
186  CIRef<IUITool> tool = reg->CreateToolInstance(method->GetName());
187  if (!tool)
188  return;
189 
190  IScoringMethod* toolMethod = dynamic_cast<IScoringMethod*>(tool.GetPointer());
191  if (toolMethod)
192  m_Tools.push_back(CIRef<IScoringMethod>(toolMethod));
193  }
194  }
195 }
196 
197 /*!
198  * Control creation for CScoreMethodsDlg
199  */
200 
202 {
203 ////@begin CScoreMethodsDlg content construction
204  CScoreMethodsDlg* itemDialog1 = this;
205 
206  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
207  itemDialog1->SetSizer(itemBoxSizer2);
208 
209  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
210  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 0);
211 
212  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Methods:"), wxDefaultPosition, wxDefaultSize, 0 );
213  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
214 
215  itemBoxSizer3->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
216 
217  wxStaticText* itemStaticText6 = new wxStaticText( itemDialog1, wxID_STATIC, _("Type:"), wxDefaultPosition, wxDefaultSize, 0 );
218  itemBoxSizer3->Add(itemStaticText6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
219 
220  wxArrayString itemChoice7Strings;
221  itemChoice7Strings.Add(_("DNA"));
222  itemChoice7Strings.Add(_("Protein"));
223  itemChoice7Strings.Add(_("Mixed"));
224  itemChoice7Strings.Add(_("Homogenous"));
225  wxChoice* itemChoice7 = new wxChoice( itemDialog1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, itemChoice7Strings, 0 );
226  itemChoice7->SetStringSelection(_("DNA"));
227  itemBoxSizer3->Add(itemChoice7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
228 
229  wxArrayString itemListBox8Strings;
230  wxListBox* itemListBox8 = new wxListBox( itemDialog1, ID_LISTBOX1, wxDefaultPosition, wxSize(250, 200), itemListBox8Strings, wxLB_SINGLE );
231  itemBoxSizer2->Add(itemListBox8, 1, wxGROW|wxLEFT|wxRIGHT, 5);
232 
233  wxTextCtrl* itemTextCtrl9 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxSize(-1, 80), wxTE_MULTILINE|wxTE_READONLY );
234  itemBoxSizer2->Add(itemTextCtrl9, 0, wxGROW|wxALL, 5);
235 
236  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, ID_STATICLINE, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
237  itemBoxSizer2->Add(itemStaticLine10, 0, wxGROW|wxALL, 0);
238 
239  wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
240  itemBoxSizer2->Add(itemBoxSizer11, 0, wxALIGN_RIGHT|wxALL, 5);
241 
242  wxButton* itemButton12 = new wxButton( itemDialog1, ID_BUTTON2, _("Select Method Dlg..."), wxDefaultPosition, wxDefaultSize, 0 );
243  itemBoxSizer11->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
244 
245  wxButton* itemButton13 = new wxButton( itemDialog1, ID_BUTTON1, _("Properties"), wxDefaultPosition, wxDefaultSize, 0 );
246  itemBoxSizer11->Add(itemButton13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
247 
248  wxButton* itemButton14 = new wxButton( itemDialog1, wxID_CANCEL, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
249  itemBoxSizer11->Add(itemButton14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
250 
251 ////@end CScoreMethodsDlg content construction
252 
253  x_LoadTools();
254 }
255 
256 
257 /*!
258  * Should we show tooltips?
259  */
260 
262 {
263  return true;
264 }
265 
266 /*!
267  * Get bitmap resources
268  */
269 
270 wxBitmap CScoreMethodsDlg::GetBitmapResource( const wxString& name )
271 {
272  // Bitmap retrieval
273 ////@begin CScoreMethodsDlg bitmap retrieval
274  wxUnusedVar(name);
275  return wxNullBitmap;
276 ////@end CScoreMethodsDlg bitmap retrieval
277 }
278 
279 /*!
280  * Get icon resources
281  */
282 
283 wxIcon CScoreMethodsDlg::GetIconResource( const wxString& name )
284 {
285  // Icon retrieval
286 ////@begin CScoreMethodsDlg icon retrieval
287  wxUnusedVar(name);
288  return wxNullIcon;
289 ////@end CScoreMethodsDlg icon retrieval
290 }
291 
292 /*!
293  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
294  */
295 
296 void CScoreMethodsDlg::OnButton1Click( wxCommandEvent& WXUNUSED(event) )
297 {
298  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
299  string methodName = ToStdString(itemListBox->GetStringSelection());
300  if (methodName.empty())
301  return;
302 
305  return;
306 
307  IUIToolWithGUI* method = 0;
309  if ((*it)->GetType() & type && (*it)->GetName() == methodName) {
310  method = dynamic_cast<IUIToolWithGUI*>(it->GetPointer());
311  break;
312  }
313  }
314 
315  if (method) {
316  CPropertiesPanelDlg dlg(this, method);
317  dlg.ShowModal();
318  }
319 }
320 
322 {
323  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
324  itemListBox->Clear();
325 
326 
329  return;
330 
331  ITERATE(vector<CIRef<IScoringMethod> >, it, m_Tools) {
332  if ((*it)->GetType() & type) {
333  itemListBox->Append(ToWxString((*it)->GetName()));
334  }
335  }
336 
337  if (itemListBox->GetCount() > 0) itemListBox->SetSelection(0);
338 
340 }
341 
343 {
344  wxTextCtrl* itemTextCtrl9 = (wxTextCtrl*)FindWindow(ID_TEXTCTRL1);
345  itemTextCtrl9->Clear();
346 
347  wxListBox* itemListBox = (wxListBox*)FindWindow(ID_LISTBOX1);
348  string methodName = ToStdString(itemListBox->GetStringSelection());
349  if (methodName.empty())
350  return;
351 
352  *itemTextCtrl9 << ToWxString(CUIToolRegistry::GetInstance()->GetToolDescription(methodName));
353  itemTextCtrl9->SetInsertionPoint(0);
354 }
355 
357 {
358  wxChoice* itemChoice3 = (wxChoice*)FindWindow(ID_CHOICE1);
359  int index = itemChoice3->GetSelection();
361 
362  switch(index) {
363  case 0 :
365  break;
366  case 1 :
368  break;
369  case 2 :
371  break;
372  case 3 :
374  break;
375  }
376 
377  return type;
378 }
379 
380 /*!
381  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_CHOICE1
382  */
383 
384 void CScoreMethodsDlg::OnChoice1Selected( wxCommandEvent& WXUNUSED(event) )
385 {
386  x_LoadTools();
387 }
388 
389 /*!
390  * wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_LISTBOX1
391  */
392 
393 void CScoreMethodsDlg::OnListbox1Selected( wxCommandEvent& WXUNUSED(event) )
394 {
396 }
397 
398 /*!
399  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON2
400  */
401 
402 void CScoreMethodsDlg::OnButton2Click( wxCommandEvent& WXUNUSED(event) )
403 {
404  /// FIXME: don't use a static here!!!!
405  static string selectedMethod;
406 
409  return;
410 
411  CScoringMethodsDlg dlg;
412  dlg.Setup(selectedMethod, type);
413  dlg.Create(this);
414 
415  if (dlg.ShowModal() == wxID_OK) {
416  selectedMethod = ToStdString(dlg.GetSelectedMethod());
417  }
418 }
419 
#define ID_CHOICE1
CColorTableMethod.
CQualityScoringMethodNA - Quality scoring method for Nucleic Acids (DNA alignments).
vector< CIRef< IScoringMethod > > m_Tools
~CScoreMethodsDlg()
Destructor.
void OnButton1Click(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
void OnButton2Click(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON2
bool Create(wxWindow *parent, wxWindowID id=ID_CALIGNSCOREPROPDLG, const wxString &caption=_("Score Methods"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX)
Creation.
static bool ShowToolTips()
Should we show tooltips?
void OnChoice1Selected(wxCommandEvent &event)
wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_CHOICE1
void OnListbox1Selected(wxCommandEvent &event)
wxEVT_COMMAND_LISTBOX_SELECTED event handler for ID_LISTBOX1
IAlnExplorer::EAlignType x_GetSelectedType()
void CreateControls()
Creates the controls and sizers.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void Init()
Initialises member variables.
CScoreMethodsDlg()
Constructors.
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 Setup(const string &sel_method, IAlnExplorer::EAlignType type)
wxString GetSelectedMethod() const
CSimpleScoringMethod - trivial implementation of IScoringMethod.
CUIToolRegistry - is a registry providing access to various tools registred in the application.
static CUIToolRegistry * GetInstance()
void LoadTemplateToolsInfo(TDirList &dirs)
loads descriptors for all template methods installed in the system
CIRef< IUITool > CreateToolInstance(const string &method_name)
factory method, returns NULL if name is invalid.
virtual void LoadSettings()
virtual void SetRegistryPath(const string &path)
void GetTools(vector< CConstIRef< IUITool > > &tools, ISelector &selector) const
IScoringMethod represents an abstract algorithm for calculating alignment scores and assigning colors...
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_BUTTON2
#define ID_LISTBOX1
static void Init(void)
Definition: cursor6.c:76
static int type
Definition: getdata.c:31
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
END_EVENT_TABLE()
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static const wxChar * kDefScoreDir
static const wxChar * kDefUserScoreDir
static const char * kUIToolsRegKey
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 Wed Sep 04 15:06:49 2024 by modify_doxy.py rev. 669887