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

Go to the SVN repository for this file.

1 /* $Id: wx_choose_seq_dlg.cpp 47479 2023-05-02 13:24:02Z ucko $
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:
27  *
28  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>////@begin includes
32 ////@end includes
33 
34 
37 
38 #include <wx/sizer.h>
39 #include <wx/stattext.h>
40 #include <wx/button.h>
41 #include <wx/checkbox.h>
42 #include <wx/statbox.h>
43 #include <wx/radiobut.h>
44 
45 #include <wx/msgdlg.h>
46 
47 
49 
50 
51 IMPLEMENT_DYNAMIC_CLASS( CwxChooseSeqDlg, wxDialog )
52 
53 BEGIN_EVENT_TABLE( CwxChooseSeqDlg, wxDialog )
54 
55 ////@begin CwxChooseSeqDlg event table entries
57 
59 
61 
63 
64  EVT_LIST_ITEM_SELECTED( ID_SUBJECT_TABLE, CwxChooseSeqDlg::OnSubjectSelected )
66 
67  EVT_BUTTON( wxID_OK, CwxChooseSeqDlg::OnOkClick )
68 
69  EVT_BUTTON( wxID_CANCEL, CwxChooseSeqDlg::OnCancelClick )
70 
71 ////@end CwxChooseSeqDlg event table entries
73 
74 
76 {
77  Init();
78 }
79 
80 
81 CwxChooseSeqDlg::CwxChooseSeqDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
82 {
83  Init();
84  Create(parent, id, caption, pos, size, style);
85 }
86 
87 
88 bool CwxChooseSeqDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
89 {
90 ////@begin CwxChooseSeqDlg creation
91  SetExtraStyle(wxWS_EX_BLOCK_EVENTS|wxDIALOG_EX_CONTEXTHELP);
92  wxDialog::Create( parent, id, caption, pos, size, style );
93 
95  if (GetSizer())
96  {
97  GetSizer()->SetSizeHints(this);
98  }
99  Centre();
100 ////@end CwxChooseSeqDlg creation
101  return true;
102 }
103 
104 
105 void sDeleteIds(vector<IHitSeqId*>& ids)
106 {
107  for( size_t i =0; i < ids.size(); i++) {
108  delete ids[i];
109  }
110 }
111 
112 
114 {
115  Disable(); // to indicate that we do not need notifications
116 
119 
121 ////@begin CwxChooseSeqDlg destruction
122 ////@end CwxChooseSeqDlg destruction
123 }
124 
125 
127 {
128 ////@begin CwxChooseSeqDlg member initialisation
129  m_SepCheck = NULL;
130  m_ShowRadios = NULL;
133  m_QueryTable = NULL;
134 ////@end CwxChooseSeqDlg member initialisation
135 }
136 
137 
139 {
140 ////@begin CwxChooseSeqDlg content construction
141  // Generated by DialogBlocks, Sat 16 Feb 2008 11:40:36 AM EST (unregistered)
142 
143  CwxChooseSeqDlg* itemDialog1 = this;
144 
145  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
146  itemDialog1->SetSizer(itemBoxSizer2);
147 
148  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
149  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5);
150 
151  m_SepCheck = new wxCheckBox( itemDialog1, ID_SEP_CHECK, wxT("Separate Alignments"), wxDefaultPosition, wxDefaultSize, 0 );
152  m_SepCheck->SetValue(false);
153  itemBoxSizer3->Add(m_SepCheck, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
154 
155  m_ShowRadios = new wxStaticBox(itemDialog1, wxID_ANY, wxT("Show Alignments"));
156  wxStaticBoxSizer* itemStaticBoxSizer5 = new wxStaticBoxSizer(m_ShowRadios, wxHORIZONTAL);
157  itemBoxSizer3->Add(itemStaticBoxSizer5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
158 
159  m_OrientRadios = new wxRadioButton( itemDialog1, ID_POS_NEG_RADIO, wxT("Positive and Negative"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
160  m_OrientRadios->SetValue(false);
161  itemStaticBoxSizer5->Add(m_OrientRadios, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
162 
163  wxRadioButton* itemRadioButton7 = new wxRadioButton( itemDialog1, ID_POS_RADIO, wxT("Positive"), wxDefaultPosition, wxDefaultSize, 0 );
164  itemRadioButton7->SetValue(false);
165  itemStaticBoxSizer5->Add(itemRadioButton7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
166 
167  wxRadioButton* itemRadioButton8 = new wxRadioButton( itemDialog1, ID_NEG_RADIO, wxT("Negative"), wxDefaultPosition, wxDefaultSize, 0 );
168  itemRadioButton8->SetValue(false);
169  itemStaticBoxSizer5->Add(itemRadioButton8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
170 
171  wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxVERTICAL);
172  itemBoxSizer2->Add(itemBoxSizer9, 1, wxGROW|wxALL, 5);
173 
174  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
175  itemBoxSizer9->Add(itemStaticLine10, 0, wxGROW|wxLEFT|wxRIGHT, 5);
176 
177  wxStaticText* itemStaticText11 = new wxStaticText( itemDialog1, wxID_STATIC, wxT("Subject:"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemBoxSizer9->Add(itemStaticText11, 0, wxALIGN_LEFT|wxALL, 5);
179 
180  m_SubjectTable = new CwxTableListCtrl( itemDialog1, ID_SUBJECT_TABLE, wxDefaultPosition, wxSize(600, 140), wxLC_REPORT );
181  itemBoxSizer9->Add(m_SubjectTable, 1, wxGROW|wxALL, 5);
182 
183  wxStaticText* itemStaticText13 = new wxStaticText( itemDialog1, wxID_STATIC, wxT("Query : [ only available alignments are displayed ]"), wxDefaultPosition, wxDefaultSize, 0 );
184  itemBoxSizer9->Add(itemStaticText13, 0, wxALIGN_LEFT|wxALL, 5);
185 
186  m_QueryTable = new CwxTableListCtrl( itemDialog1, ID_QUERY_TABLE, wxDefaultPosition, wxSize(600, 140), wxLC_REPORT );
187  itemBoxSizer9->Add(m_QueryTable, 1, wxGROW|wxALL, 5);
188 
189  wxStdDialogButtonSizer* itemStdDialogButtonSizer15 = new wxStdDialogButtonSizer;
190 
191  itemBoxSizer9->Add(itemStdDialogButtonSizer15, 0, wxALIGN_RIGHT|wxALL, 5);
192  wxButton* itemButton16 = new wxButton( itemDialog1, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
193  itemStdDialogButtonSizer15->AddButton(itemButton16);
194 
195  wxButton* itemButton17 = new wxButton( itemDialog1, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemStdDialogButtonSizer15->AddButton(itemButton17);
197 
198  itemStdDialogButtonSizer15->Realize();
199 
200  // Set validators
201  m_SepCheck->SetValidator( wxGenericValidator(& m_SeparateAligns) );
202  m_OrientRadios->SetValidator( wxGenericValidator(& m_PosAndNeg) );
203  itemRadioButton7->SetValidator( wxGenericValidator(& m_Pos) );
204  itemRadioButton8->SetValidator( wxGenericValidator(& m_Neg) );
205 ////@end CwxChooseSeqDlg content construction
206 
209 }
210 
211 
213 {
214  return true;
215 }
216 
217 
218 wxBitmap CwxChooseSeqDlg::GetBitmapResource( const wxString& name )
219 {
220  // Bitmap retrieval
221 ////@begin CwxChooseSeqDlg bitmap retrieval
222  wxUnusedVar(name);
223  return wxNullBitmap;
224 ////@end CwxChooseSeqDlg bitmap retrieval
225 }
226 
227 
228 wxIcon CwxChooseSeqDlg::GetIconResource( const wxString& name )
229 {
230  // Icon retrieval
231 ////@begin CwxChooseSeqDlg icon retrieval
232  wxUnusedVar(name);
233  return wxNullIcon;
234 ////@end CwxChooseSeqDlg icon retrieval
235 }
236 
237 
238 void CwxChooseSeqDlg::OnSepCheckClick( wxCommandEvent& event )
239 {
241 
243  x_ReloadIDLists();
245 }
246 
247 
248 static const char* kSubjectTag = "GBENCH.ChooseSeqDlg.Subject";
249 static const char* kQueryTag = "GBENCH.ChooseSeqDlg.Query";
250 
251 
253 {
254  m_DataSource = ds;
255 
256  /// initilize data members based on the Data Source state
258  m_DataSource->GetParams(params);
259 
260  m_SeparateAligns = params.m_RowBased;
261  m_Orient = params.m_Direction;
262 
263  /// load UI settings
264  x_LoadSettings();
265 
266  // initialize identifiers
267  x_SetSelectedIds(&m_DataSource->GetSubjectId(), &m_DataSource->GetQueryId());
268 
269  // fill the tables
270  x_ReloadIDLists();
271 }
272 
273 
275  const TIdVector& ids, int sel_index)
276 {
279 
280  model->Init(ds, ids);
281 
282  // select row
283  if(sel_index >= 0 && sel_index < model->GetNumRows()) {
284  control->Select(sel_index, true);
285  }
286 }
287 
288 
290 {
293  auto i_vis = control->GetFirstSelected();
294  auto i_row = control->RowVisibleToData(static_cast<int>(i_vis));
295 
296  return model->GetId(static_cast<int>(i_row));
297 }
298 
299 
301 {
302  if(m_SeparateAligns) {
303  m_SepSubjectId.reset(s_id ? s_id->Clone() : NULL);
304  m_SepQueryId.reset(q_id ? q_id->Clone() : NULL);
305  } else {
306  m_SubjectId.reset(s_id ? s_id->Clone() : NULL);
307  m_QueryId.reset(q_id ? q_id->Clone() : NULL);
308  }
309 }
310 
311 
312 // fill tables with ids
314 {
315  //m_IgnoreSelEvents = true;
316 
317  /// delete exisiting Ids
319  m_AllIds.clear();
320 
322  GetParams(params);
323 
324  m_DataSource->GetHitSeqIdsForParams(m_AllIds, params);
325 
326  // init Subject Table
327  IHitSeqId* s_id = m_SeparateAligns ? m_SepSubjectId.get() : m_SubjectId.get();
328  int s_index = x_GetIdIndex(s_id, m_AllIds);
329 
330  x_InitTable(true, *m_DataSource, m_AllIds, s_index);
331 
332  // init Query Table
334  int q_index = -1;
335  if(s_id) {
336  m_DataSource->GetAlignedIdsForParams(*s_id, m_AllIds, ids, params);
337 
338  IHitSeqId* q_id = m_SeparateAligns ? m_SepQueryId.get() : m_QueryId.get();
339  q_index = x_GetIdIndex(q_id, ids);
340 
341  }
342 
343  x_InitTable(false, *m_DataSource, ids, q_index);
344 
345  //m_IgnoreSelEvents = false;
346 }
347 
348 
349 static const wxChar* kSpecifySubject = wxT("Please select a subject sequence.");
350 static const wxChar* kSpecifyQuery = wxT("Please select a query sequence.");
351 
352 
354 {
355  if(GetSubjectId() == NULL) {
356  wxMessageBox(kSpecifySubject, wxT(""), wxOK | wxICON_EXCLAMATION);
357  return false;
358  }
359  if(GetQueryId() == NULL) {
360  wxMessageBox(kSpecifyQuery, wxT(""), wxOK | wxICON_EXCLAMATION);
361  return false;
362  }
363  return true;
364 }
365 
366 
368 {
370 
373 
376 }
377 
378 
380 {
381  // Load table settings
383 
386 
389 }
390 
391 
393 {
394  return x_GetSelectedId(true);
395 }
396 
397 
399 {
400  return x_GetSelectedId(false);
401 }
402 
403 
405 {
406  params.m_RowBased = m_SeparateAligns;
408 }
409 
410 
413 {
414  if(id) {
415  for( int i = 0; i < (int) ids.size(); i++ ) {
416  if(ids[i]->Equals(*id))
417  return i;
418  }
419  }
420  return -1;
421 }
422 
423 
424 void CwxChooseSeqDlg::OnOkClick( wxCommandEvent& event )
425 {
427  x_SaveSettings();
428  EndModal(wxID_OK);
429  }
430 }
431 
432 
433 void CwxChooseSeqDlg::OnCancelClick( wxCommandEvent& event )
434 {
435  x_SaveSettings();
436  EndModal(wxID_CANCEL);
437 }
438 
439 
440 void CwxChooseSeqDlg::OnPosNegRadioSelected( wxCommandEvent& event )
441 {
444 }
445 
446 
447 void CwxChooseSeqDlg::OnPosRadioSelected( wxCommandEvent& event )
448 {
451 }
452 
453 
454 void CwxChooseSeqDlg::OnNegRadioSelected( wxCommandEvent& event )
455 {
458 }
459 
460 
462 {
463  m_SepCheck->Enable(m_DataSource->CanCreateRowBased());
464 
465  m_ShowRadios->Enable( ! m_SeparateAligns);
467  : m_Orient;
468  m_PosAndNeg = orient == 0;
469  m_Pos = orient == 1;
470  m_Neg = orient == 2;
471 
472  return wxDialog::TransferDataToWindow();
473 }
474 
475 
477 {
478  if(wxDialog::TransferDataFromWindow()) {
479  int orient = m_PosAndNeg ? 0 : (m_Pos ? 1 : 2);
481  return true;
482  }
483  return false;
484 }
485 
486 
487 void CwxChooseSeqDlg::OnSubjectSelected( wxListEvent& event )
488 {
490 }
491 
492 
494 {
496 }
497 
498 
500 {
501  if(IsEnabled()) {
502  const IHitSeqId* s_id = GetSubjectId();
503  _ASSERT(s_id);
504 
507  GetParams(params);
508 
509  m_DataSource->GetAlignedIdsForParams(*s_id, m_AllIds, ids, params);
510 
511  // get Query id if possible
512  const IHitSeqId* q_id = GetQueryId();
513  int index = x_GetIdIndex(q_id, ids);
514  x_InitTable(false, *m_DataSource, ids, index);
515  }
516 }
517 
518 
520 
EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX, CAdjustFeaturesForGaps::OnKnownUnknownSelected) EVT_CHECKBOX(ID_CADJUSTFEATURES_CHECKBOX1
CAlignSeqTableModel.
const IHitSeqId * GetId(int row) const
void Init(IHitMatrixDataSource &ds, const TIdVector &ids)
@ eBothDirections
No filtering: use both direct and reverse sequences.
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
void OnOkClick(wxCommandEvent &event)
const IHitSeqId * x_GetSelectedId(bool subject) const
wxStaticBox * m_ShowRadios
unique_ptr< IHitSeqId > m_SubjectId
wxIcon GetIconResource(const wxString &name)
bool Create(wxWindow *parent, wxWindowID id=10013, const wxString &caption=wxT("Choose Sequences"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
const IHitSeqId * GetSubjectId()
void OnPosRadioSelected(wxCommandEvent &event)
void OnSubjectTableDeselected(wxListEvent &event)
const IHitSeqId * GetQueryId()
static bool ShowToolTips()
void OnSepCheckClick(wxCommandEvent &event)
unique_ptr< IHitSeqId > m_QueryId
CIRef< IHitMatrixDataSource > m_DataSource
void SetSeqs(CIRef< IHitMatrixDataSource > ds)
IHitMatrixDataSource::TIdVector m_AllIds
void x_InitTable(bool subject, IHitMatrixDataSource &ds, const TIdVector &ids, int sel_index)
void OnCancelClick(wxCommandEvent &event)
CwxTableListCtrl * m_SubjectTable
wxCheckBox * m_SepCheck
CAlignSeqTableModel m_SubjectModel
void OnNegRadioSelected(wxCommandEvent &event)
void GetParams(IHitMatrixDataSource::SParams &params) const
wxRadioButton * m_OrientRadios
int x_GetIdIndex(const IHitSeqId *id, const IHitMatrixDataSource::TIdVector &ids)
CwxTableListCtrl * m_QueryTable
unique_ptr< IHitSeqId > m_SepSubjectId
wxBitmap GetBitmapResource(const wxString &name)
void OnSubjectSelected(wxListEvent &event)
IHitMatrixDataSource::TIdVector TIdVector
unique_ptr< IHitSeqId > m_SepQueryId
void x_SetSelectedIds(const IHitSeqId *s_id, const IHitSeqId *q_id)
void OnPosNegRadioSelected(wxCommandEvent &event)
CAlignSeqTableModel m_QueryModel
CwxTableListCtrl - generic wxListCtrl-based Table Control.
int RowVisibleToData(int aRow) const
/////////// Row staff /////////////////
void LoadTableSettings(const CRegistryReadView &view, bool byName=false)
void SaveTableSettings(CRegistryWriteView &view, bool saveSorting=true) const
void SetModel(IwxTableModel *data_model, bool own=false)
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
vector< IHitSeqId * > TIdVector
IHit::TDirection TDirection
IHitSeqId - abstract identifier of a sequence in an alignment.
virtual IHitSeqId * Clone() const =0
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
#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
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static bool Equals(const CVariation::TPlacements &p1, const CVariation::TPlacements &p2)
static static static wxID_ANY
static string subject
#define _ASSERT
static const wxChar * kSpecifySubject
void sDeleteIds(vector< IHitSeqId * > &ids)
static const char * kQueryTag
static const wxChar * kSpecifyQuery
static const char * kSubjectTag
#define ID_POS_RADIO
#define ID_SUBJECT_TABLE
#define ID_POS_NEG_RADIO
#define ID_SEP_CHECK
#define ID_NEG_RADIO
#define ID_QUERY_TABLE
Modified on Sat Dec 09 04:48:16 2023 by modify_doxy.py rev. 669887