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

Go to the SVN repository for this file.

1 /* $Id: rna_field_name_panel.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: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
36 #include <wx/sizer.h>
37 
38 
40 
41 /*!
42  * CRNAFieldNamePanel type definition
43  */
44 
45 IMPLEMENT_DYNAMIC_CLASS( CRNAFieldNamePanel, CFieldNamePanel )
46 
47 
48 /*!
49  * CRNAFieldNamePanel event table definition
50  */
51 
52 BEGIN_EVENT_TABLE( CRNAFieldNamePanel, CFieldNamePanel )
53 
54 ////@begin CRNAFieldNamePanel event table entries
55  EVT_CHOICE( ID_CRNAFIELDNAME_RNA_TYPE, CRNAFieldNamePanel::OnRnaTypeSelected)
56  EVT_LISTBOX( ID_CRNAFIELDNAME_RNA_FIELD, CRNAFieldNamePanel::OnRnaFieldSelected)
57  EVT_COMBOBOX( ID_CRNAFIELDNAME_NCRNA_CLASS, CRNAFieldNamePanel::OnncRNAClassSelected)
58 
59 ////@end CRNAFieldNamePanel event table entries
60 
62 
63 
64 /*!
65  * CRNAFieldNamePanel constructors
66  */
67 
69 {
70  Init();
71 }
72 
73 CRNAFieldNamePanel::CRNAFieldNamePanel( wxWindow* parent, CRNAFieldNamePanel* sibling, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
74  : m_Sibling(sibling)
75 {
76  Init();
77  Create(parent, id, pos, size, style);
78 }
79 
80 
81 /*!
82  * CRNAFieldNamePanel creator
83  */
84 
85 bool CRNAFieldNamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin CRNAFieldNamePanel creation
88  CFieldNamePanel::Create( parent, id, pos, size, style );
89 
91  if (GetSizer())
92  {
93  GetSizer()->SetSizeHints(this);
94  }
95  Centre();
96 ////@end CRNAFieldNamePanel creation
97  return true;
98 }
99 
100 
101 /*!
102  * CRNAFieldNamePanel destructor
103  */
104 
106 {
107 ////@begin CRNAFieldNamePanel destruction
108 ////@end CRNAFieldNamePanel destruction
109 }
110 
111 
112 /*!
113  * Member initialisation
114  */
115 
117 {
118 ////@begin CRNAFieldNamePanel member initialisation
120  m_RNAType = NULL;
121  m_NcrnaClass = NULL;
122  m_RnaField = NULL;
123 ////@end CRNAFieldNamePanel member initialisation
124 }
125 
126 
127 /*!
128  * Control creation for CRNAFieldNamePanel
129  */
130 
132 {
133 ////@begin CRNAFieldNamePanel content construction
134  CRNAFieldNamePanel* itemCFieldNamePanel1 = this;
135 
136  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
137  itemCFieldNamePanel1->SetSizer(itemBoxSizer1);
138 
139  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
140  itemBoxSizer1->Add(itemBoxSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxBOTTOM,0);
141 
142  m_RnaTypeLabel = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("RNA Type"), wxDefaultPosition, wxDefaultSize, 0 );
143  itemBoxSizer2->Add(m_RnaTypeLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
144 
145  wxArrayString m_RNATypeStrings;
146  m_RNAType = new wxChoice(itemCFieldNamePanel1, ID_CRNAFIELDNAME_RNA_TYPE, wxDefaultPosition, wxDefaultSize, m_RNATypeStrings, 0);
147  itemBoxSizer2->Add(m_RNAType, 0, wxALIGN_CENTER_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN| wxLEFT|wxRIGHT|wxBOTTOM, 5);
148 
149  wxArrayString m_NcrnaClassStrings;
150  m_NcrnaClassStrings.Add(_("any"));
151  m_NcrnaClass = new wxComboBox(itemCFieldNamePanel1, ID_CRNAFIELDNAME_NCRNA_CLASS, _("any"), wxDefaultPosition, wxDefaultSize, m_NcrnaClassStrings, wxCB_DROPDOWN);
152  m_NcrnaClass->SetStringSelection(_("any"));
153  m_NcrnaClass->Enable(false);
154  itemBoxSizer2->Add(m_NcrnaClass, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxBOTTOM, 5);
155 
156  wxArrayString m_RnaFieldStrings;
157  m_RnaField = new wxListBox(itemCFieldNamePanel1, ID_CRNAFIELDNAME_RNA_FIELD, wxDefaultPosition, wxSize(220, 109), m_RnaFieldStrings, wxLB_SINGLE);
158  itemBoxSizer1->Add(m_RnaField, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT, 5);
159 
160  vector<string> rna_types = GetRNATypes();
161  ITERATE(vector<string>, it, rna_types) {
162  m_RNAType->AppendString(ToWxString(*it));
163  }
164  m_RNAType->SetStringSelection(rna_types[0]);
165 
166  vector<string> rna_fields = GetRNAFields();
167  ITERATE(vector<string>, it, rna_fields) {
168  m_RnaField->AppendString(ToWxString(*it));
169  }
170 
171  vector<string> class_vals = objects::CRNA_gen::GetncRNAClassList();
172  ITERATE(vector<string>, it, class_vals) {
173  m_NcrnaClass->AppendString(ToWxString(*it));
174  }
175 
176  if (m_Sibling) {
177  m_RnaTypeLabel->Show(false);
178  m_RNAType->Show(false);
179  m_NcrnaClass->Show(false);
180  }
182 ////@end CRNAFieldNamePanel content construction
183 }
184 
186 {
187  m_RNAType->SetSelection(0);
188  m_NcrnaClass->SetStringSelection(_("any"));
189  m_NcrnaClass->Enable(false);
190  m_RnaField->SetSelection(0);
191  m_RnaField->SetFirstItem(0);
192 }
193 
194 
195 /*!
196  * Should we show tooltips?
197  */
198 
200 {
201  return true;
202 }
203 
204 /*!
205  * Get bitmap resources
206  */
207 
208 wxBitmap CRNAFieldNamePanel::GetBitmapResource( const wxString& name )
209 {
210  // Bitmap retrieval
211 ////@begin CRNAFieldNamePanel bitmap retrieval
212  wxUnusedVar(name);
213  return wxNullBitmap;
214 ////@end CRNAFieldNamePanel bitmap retrieval
215 }
216 
217 /*!
218  * Get icon resources
219  */
220 
221 wxIcon CRNAFieldNamePanel::GetIconResource( const wxString& name )
222 {
223  // Icon retrieval
224 ////@begin CRNAFieldNamePanel icon retrieval
225  wxUnusedVar(name);
226  return wxNullIcon;
227 ////@end CRNAFieldNamePanel icon retrieval
228 }
229 
230 
232 {
233  if (m_Sibling) {
234  return m_Sibling->GetRnaType();
235  }
236  string rna_type = "";
237  int val = m_RNAType->GetSelection();
238  if (val > -1) {
239  rna_type = m_RNAType->GetString(val);
240  if (NStr::EqualNocase(rna_type, "any")) {
241  rna_type = "";
242  } else if (NStr::StartsWith(rna_type, "misc", NStr::eNocase)) {
243  rna_type.insert(4, "_");
244  } else if (NStr::StartsWith(rna_type, "pre", NStr::eNocase)) {
245  rna_type.insert(3, "_");
246  } else if (NStr::EqualNocase(rna_type, "ncRNA")) {
247  string ncrna_class = ToStdString(m_NcrnaClass->GetValue());
248  if (!NStr::EqualNocase (ncrna_class, "any")) {
249  rna_type += " " + ncrna_class;
250  }
251  }
252  }
253  return rna_type;
254 }
255 
257 {
258  if (m_Sibling)
259  {
260  return m_Sibling->GetRnaTypeOnly();
261  }
262  int i = m_RNAType->GetSelection();
263  if (i != wxNOT_FOUND)
264  {
265  return m_RNAType->GetString(i).ToStdString();
266  }
267  return kEmptyStr;
268 }
269 
271 {
272  return m_NcrnaClass->GetValue().ToStdString();
273 }
274 
276 {
277  return GetFieldName(true);
278 }
279 
280 string CRNAFieldNamePanel::GetFieldName(const bool subfield)
281 {
282  string field = "";
283  int val = m_RnaField->GetSelection();
284  if (val < 0) {
285  return field;
286  }
287  field = m_RnaField->GetString(val);
288  if (subfield) {
289  return field;
290  }
291  string rna_type = GetRnaType();
292  if (!NStr::IsBlank(rna_type)) {
293  field = rna_type + " " + field;
294  }
295 
296  return field;
297 }
298 
299 
300 bool CRNAFieldNamePanel::SetRnaType (const string& rna_type)
301 {
302  if (m_Sibling) {
303  return m_Sibling->SetRnaType(rna_type);
304  }
305  bool rval = false;
306  if (NStr::IsBlank (rna_type)) {
307  // choose any
308  m_RNAType->SetSelection(0);
309  } else {
310  string remainder = rna_type;
311  if (NStr::EqualNocase(rna_type, "misc_RNA")) {
312  m_RNAType->SetStringSelection(ToWxString("miscRNA"));
313  } else if (NStr::EqualNocase(rna_type, "pre_RNA")) {
314  m_RNAType->SetStringSelection(ToWxString("preRNA"));
315  } else {
316  for (size_t i = 0; i < m_RNAType->GetStrings().size(); i++) {
317  string major_type = ToStdString(m_RNAType->GetString(static_cast<unsigned int>(i)));
318  if (NStr::StartsWith (rna_type, major_type)) {
319  m_RNAType->SetSelection(static_cast<int>(i));
320  string remainder = rna_type.substr(major_type.length());
321  NStr::TruncateSpacesInPlace(remainder);
322  if (NStr::EqualNocase (major_type, "ncRNA")) {
323  m_NcrnaClass->SetValue(remainder);
324  remainder = "";
325  }
326  break;
327  }
328  }
329  if (!NStr::IsBlank(remainder)) {
330  rval = false;
331  }
332  }
333  }
335  return rval;
336 }
337 
338 
339 bool CRNAFieldNamePanel::SetFieldName(const string& field)
340 {
341  bool rval = false;
342  m_NcrnaClass->Enable(false);
343  string rna_type = field;
344  for (size_t i = 0; i < m_RnaField->GetCount(); i++) {
345  string rna_field = ToStdString(m_RnaField->GetString(static_cast<unsigned int>(i)));
346  if (NStr::EndsWith (field, rna_field)) {
347  m_RnaField->SetSelection(static_cast<int>(i));
348  m_RnaField->SetFirstItem(static_cast<int>(i));
349  if (rna_field.length() < field.length()) {
350  rna_type = field.substr(0, field.length() - rna_field.length());
351  NStr::TruncateSpacesInPlace(rna_type);
352  }
353  rval = true;
354  break;
355  }
356  }
357 
358  if (rval) {
359  rval = SetRnaType(rna_type);
360  }
361  x_UpdateParent();
362  return rval;
363 }
364 
365 
367 {
368  string rna_type = ToStdString(m_RNAType->GetStringSelection());
369  if (NStr::EqualNocase(rna_type, "ncRNA")) {
370  m_NcrnaClass->Enable(true);
371  } else {
372  m_NcrnaClass->Enable(false);
373  }
374 }
375 
376 
377 /*!
378  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RNA_TYPE
379  */
380 
381 void CRNAFieldNamePanel::OnRnaTypeSelected( wxCommandEvent& event )
382 {
384  x_UpdateParent();
385  event.Skip();
386 }
387 
388 void CRNAFieldNamePanel::OnRnaFieldSelected( wxCommandEvent& event )
389 {
390  x_UpdateParent();
391  event.Skip();
392 }
393 
394 void CRNAFieldNamePanel::OnncRNAClassSelected(wxCommandEvent& event)
395 {
396  x_UpdateParent();
397  event.Skip();
398 }
399 
401 {
402  vector<string> options;
403  options.push_back("any");
404  options.push_back("preRNA");
405  options.push_back("mRNA");
406  options.push_back("tRNA");
407  options.push_back("rRNA");
408  options.push_back("ncRNA");
409  options.push_back("tmRNA");
410  options.push_back("miscRNA");
411  return options;
412 }
413 
414 
416 {
417  vector<string> options;
418  options.push_back("product");
419  options.push_back("comment");
420  options.push_back("ncRNA class");
421  options.push_back("codons recognized");
422  options.push_back("tag-peptide");
423  options.push_back("anticodon");
424  options.push_back("gene locus");
425  options.push_back("gene description");
426  options.push_back("gene maploc");
427  options.push_back("gene locus tag");
428  options.push_back("gene synonym");
429  options.push_back("gene comment");
430  return options;
431 }
432 
433 string CRNAFieldNamePanel::GetMacroFieldName(const string &target, const string& selected_field)
434 {
435  string rna_type = ToStdString(m_RNAType->GetStringSelection());
436 
437  string qual_field;
438  int val = m_RnaField->GetSelection();
439  if (val >= 0) {
440  qual_field = m_RnaField->GetString(val);
441  }
442  return s_GetMacroFieldName(rna_type, qual_field, target, selected_field);
443 }
444 
445 string CRNAFieldNamePanel::s_GetMacroFieldName(const string& rna_type, const string& qual_field, const string &target, const string& selected_field)
446 {
447  string str;
448  if (NStr::StartsWith(qual_field, "gene")) {
450  str = "\"" + str + "\"";
451  if (CFieldNamePanel::IsFeature(target)) {
452  str = "RELATED_FEATURE(\"gene\", " + str + ")";
453  }
454  else {
455  str = "FEATURES(\"gene\"," + str + ")";
456  }
457  }
458  else {
460  str = "\"" + str + "\"";
461  if (str.find("::product") != NPOS) {
462  str = macro::CMacroFunction_GetRnaProduct::GetFuncName() + "()";
463  }
464  if (rna_type != "any") {
465  if (rna_type != target && rna_type != selected_field) {
466  if (CFieldNamePanel::IsFeature(target)) {
467  str = "RELATED_FEATURE(\"" + rna_type + "\", " + str + ")";
468  }
469  else {
470  str = "FEATURES(\"" + rna_type + "\"," + str + ")";
471  }
472  }
473  //
474  }
475  }
476  return str;
477 }
478 
479 
480 
481 
482 /// Dual panel
483 /*!
484  * CDualRNAFieldNamePanel type definition
485  */
486 
487 IMPLEMENT_DYNAMIC_CLASS( CDualRNAFieldNamePanel, CFieldNamePanel )
488 
489 
490 /*!
491  * CDualRNAFieldNamePanel event table definition
492  */
493 
494 BEGIN_EVENT_TABLE( CDualRNAFieldNamePanel, CFieldNamePanel )
495 
496 ////@begin CDualRNAFieldNamePanel event table entries
497  EVT_CHOICE( ID_CRNAFIELDNAME_RNA_TYPE, CDualRNAFieldNamePanel::OnRnaTypeSelected)
498  EVT_LISTBOX( ID_CRNAFIELDNAME_RNA_FIELD, CDualRNAFieldNamePanel::OnRnaFieldSelected)
499  EVT_LISTBOX( ID_CRNAFIELDNAME_RNA_FIELD2, CDualRNAFieldNamePanel::OnRnaFieldSelected)
500 ////@end CDualRNAFieldNamePanel event table entries
501 
503 
504 
505 /*!
506  * CDualRNAFieldNamePanel constructors
507  */
508 
510 {
511  Init();
512 }
513 
514 CDualRNAFieldNamePanel::CDualRNAFieldNamePanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
515 {
516  Init();
517  Create(parent, id, pos, size, style);
518 }
519 
520 
521 /*!
522  * CDualRNAFieldNamePanel creator
523  */
524 
525 bool CDualRNAFieldNamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
526 {
527 ////@begin CDualRNAFieldNamePanel creation
528  CFieldNamePanel::Create( parent, id, pos, size, style );
529 
530  CreateControls();
531  if (GetSizer())
532  {
533  GetSizer()->SetSizeHints(this);
534  }
535  Centre();
536 ////@end CDualRNAFieldNamePanel creation
537  return true;
538 }
539 
540 
541 /*!
542  * CDualRNAFieldNamePanel destructor
543  */
544 
546 {
547 ////@begin CDualRNAFieldNamePanel destruction
548 ////@end CDualRNAFieldNamePanel destruction
549 }
550 
551 
552 /*!
553  * Member initialisation
554  */
555 
557 {
558 ////@begin CDualRNAFieldNamePanel member initialisation
560  m_RNAType = NULL;
561  m_NcrnaClass = NULL;
562  m_RnaField = NULL;
563  m_RnaField2 = NULL;
564 ////@end CDualRNAFieldNamePanel member initialisation
565 }
566 
567 
568 /*!
569  * Control creation for CDualRNAFieldNamePanel
570  */
571 
573 {
574 ////@begin CDualRNAFieldNamePanel content construction
575  CDualRNAFieldNamePanel* itemCFieldNamePanel1 = this;
576 
577  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxVERTICAL);
578  itemCFieldNamePanel1->SetSizer(itemBoxSizer1);
579 
580  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
581  itemBoxSizer1->Add(itemBoxSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP,5);
582 
583  m_RnaTypeLabel = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("RNA Type"), wxDefaultPosition, wxDefaultSize, 0 );
584  itemBoxSizer2->Add(m_RnaTypeLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxTOP, 5);
585 
586  wxArrayString m_RNATypeStrings;
587  m_RNAType = new wxChoice(itemCFieldNamePanel1, ID_CRNAFIELDNAME_RNA_TYPE, wxDefaultPosition, wxDefaultSize, m_RNATypeStrings, 0);
588  itemBoxSizer2->Add(m_RNAType, 0, wxALIGN_CENTER_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN| wxALL, 5);
589 
590  wxArrayString m_NcrnaClassStrings;
591  m_NcrnaClassStrings.Add(_("any"));
592  m_NcrnaClass = new wxComboBox(itemCFieldNamePanel1, ID_CRNAFIELDNAME_NCRNA_CLASS, _("any"), wxDefaultPosition, wxDefaultSize, m_NcrnaClassStrings, wxCB_DROPDOWN);
593  m_NcrnaClass->SetStringSelection(_("any"));
594  m_NcrnaClass->Enable(false);
595  itemBoxSizer2->Add(m_NcrnaClass, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxBOTTOM|wxTOP, 5);
596 
597  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
598  itemBoxSizer1->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxBOTTOM,0);
599 
600  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
601  itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_TOP|wxTOP|wxBOTTOM,0);
602 
603  wxStaticText* fromLabel = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("From"), wxDefaultPosition, wxDefaultSize, 0 );
604  itemBoxSizer4->Add(fromLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP, 5);
605 
606  wxArrayString m_RnaFieldStrings;
607  m_RnaField = new wxListBox(itemCFieldNamePanel1, ID_CRNAFIELDNAME_RNA_FIELD, wxDefaultPosition, wxSize(220, 109), m_RnaFieldStrings, wxLB_SINGLE);
608  itemBoxSizer4->Add(m_RnaField, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP, 5);
609 
610  wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
611  itemBoxSizer3->Add(itemBoxSizer5, 0, wxALIGN_TOP|wxTOP|wxBOTTOM,0);
612 
613  wxStaticText* toLabel = new wxStaticText( itemCFieldNamePanel1, wxID_STATIC, _("To"), wxDefaultPosition, wxDefaultSize, 0 );
614  itemBoxSizer5->Add(toLabel, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP, 5);
615 
616  m_RnaField2 = new wxListBox(itemCFieldNamePanel1, ID_CRNAFIELDNAME_RNA_FIELD2, wxDefaultPosition, wxSize(220, 109), m_RnaFieldStrings, wxLB_SINGLE);
617  itemBoxSizer5->Add(m_RnaField2, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP, 5);
618 
619 ////@end CDualRNAFieldNamePanel content construction
620  vector<string> rna_types = CRNAFieldNamePanel::GetRNATypes();
621  ITERATE(vector<string>, it, rna_types) {
622  m_RNAType->AppendString(ToWxString(*it));
623  }
624  m_RNAType->SetStringSelection(rna_types[0]);
625 
626  vector<string> rna_fields = CRNAFieldNamePanel::GetRNAFields();
627  ITERATE(vector<string>, it, rna_fields) {
628  m_RnaField->AppendString(ToWxString(*it));
629  m_RnaField2->AppendString(ToWxString(*it));
630  }
631 
632  vector<string> class_vals = objects::CRNA_gen::GetncRNAClassList();
633  ITERATE(vector<string>, it, class_vals) {
634  m_NcrnaClass->AppendString(ToWxString(*it));
635  }
636 
638 }
639 
641 {
642  m_RNAType->SetSelection(0);
643  m_NcrnaClass->SetStringSelection(_("any"));
644  m_NcrnaClass->Enable(false);
645  m_RnaField->SetSelection(0);
646  m_RnaField2->SetSelection(0);
647  m_RnaField->SetFirstItem(0);
648  m_RnaField2->SetFirstItem(0);
649 }
650 
651 
652 /*!
653  * Should we show tooltips?
654  */
655 
657 {
658  return true;
659 }
660 
661 /*!
662  * Get bitmap resources
663  */
664 
665 wxBitmap CDualRNAFieldNamePanel::GetBitmapResource( const wxString& name )
666 {
667  // Bitmap retrieval
668 ////@begin CDualRNAFieldNamePanel bitmap retrieval
669  wxUnusedVar(name);
670  return wxNullBitmap;
671 ////@end CDualRNAFieldNamePanel bitmap retrieval
672 }
673 
674 /*!
675  * Get icon resources
676  */
677 
678 wxIcon CDualRNAFieldNamePanel::GetIconResource( const wxString& name )
679 {
680  // Icon retrieval
681 ////@begin CDualRNAFieldNamePanel icon retrieval
682  wxUnusedVar(name);
683  return wxNullIcon;
684 ////@end CDualRNAFieldNamePanel icon retrieval
685 }
686 
687 
689 {
690  string rna_type = "";
691  int val = m_RNAType->GetSelection();
692  if (val > -1) {
693  rna_type = m_RNAType->GetString(val);
694  if (NStr::EqualNocase(rna_type, "any")) {
695  rna_type = "";
696  } else if (NStr::StartsWith(rna_type, "misc", NStr::eNocase)) {
697  rna_type.insert(4, "_");
698  } else if (NStr::StartsWith(rna_type, "pre", NStr::eNocase)) {
699  rna_type.insert(3, "_");
700  } else if (NStr::EqualNocase(rna_type, "ncRNA")) {
701  string ncrna_class = ToStdString(m_NcrnaClass->GetValue());
702  if (!NStr::EqualNocase (ncrna_class, "any")) {
703  rna_type += " " + ncrna_class;
704  }
705  }
706  }
707  return rna_type;
708 }
709 
711 {
712  int i = m_RNAType->GetSelection();
713  if (i != wxNOT_FOUND)
714  {
715  return m_RNAType->GetString(i).ToStdString();
716  }
717  return kEmptyStr;
718 }
719 
721 {
722  return m_NcrnaClass->GetValue().ToStdString();
723 }
724 
726 {
727  return GetFieldName(true);
728 }
729 
731 {
732  return GetFieldName2(true);
733 }
734 
735 
736 string CDualRNAFieldNamePanel::GetFieldName(const bool subfield)
737 {
738  string field = "";
739  int val = m_RnaField->GetSelection();
740  if (val < 0) {
741  return field;
742  }
743  field = m_RnaField->GetString(val);
744  if (subfield) {
745  return field;
746  }
747  string rna_type = GetRnaType();
748  if (!NStr::IsBlank(rna_type)) {
749  field = rna_type + " " + field;
750  }
751 
752  return field;
753 }
754 
755 string CDualRNAFieldNamePanel::GetFieldName2(const bool subfield)
756 {
757  string field = "";
758  int val = m_RnaField2->GetSelection();
759  if (val < 0) {
760  return field;
761  }
762  field = m_RnaField2->GetString(val);
763  if (subfield) {
764  return field;
765  }
766  string rna_type = GetRnaType();
767  if (!NStr::IsBlank(rna_type)) {
768  field = rna_type + " " + field;
769  }
770 
771  return field;
772 }
773 
774 
775 bool CDualRNAFieldNamePanel::SetRnaType (const string& rna_type)
776 {
777  bool rval = false;
778  if (NStr::IsBlank (rna_type)) {
779  // choose any
780  m_RNAType->SetSelection(0);
781  } else {
782  string remainder = rna_type;
783  if (NStr::EqualNocase(rna_type, "misc_RNA")) {
784  m_RNAType->SetStringSelection(ToWxString("miscRNA"));
785  } else if (NStr::EqualNocase(rna_type, "pre_RNA")) {
786  m_RNAType->SetStringSelection(ToWxString("preRNA"));
787  } else {
788  for (size_t i = 0; i < m_RNAType->GetStrings().size(); i++) {
789  string major_type = ToStdString(m_RNAType->GetString(static_cast<unsigned int>(i)));
790  if (NStr::StartsWith (rna_type, major_type)) {
791  m_RNAType->SetSelection(static_cast<int>(i));
792  string remainder = rna_type.substr(major_type.length());
793  NStr::TruncateSpacesInPlace(remainder);
794  if (NStr::EqualNocase (major_type, "ncRNA")) {
795  m_NcrnaClass->SetValue(remainder);
796  remainder = "";
797  }
798  break;
799  }
800  }
801  if (!NStr::IsBlank(remainder)) {
802  rval = false;
803  }
804  }
805  }
807  return rval;
808 }
809 
810 
811 bool CDualRNAFieldNamePanel::SetFieldName(const string& field)
812 {
813  bool rval = false;
814  m_NcrnaClass->Enable(false);
815  string rna_type = field;
816  for (size_t i = 0; i < m_RnaField->GetCount(); i++) {
817  string rna_field = ToStdString(m_RnaField->GetString(static_cast<unsigned int>(i)));
818  if (NStr::EndsWith (field, rna_field)) {
819  m_RnaField->SetSelection(static_cast<int>(i));
820  m_RnaField->SetFirstItem(static_cast<int>(i));
821  if (rna_field.length() < field.length()) {
822  rna_type = field.substr(0, field.length() - rna_field.length());
823  NStr::TruncateSpacesInPlace(rna_type);
824  }
825  rval = true;
826  break;
827  }
828  }
829 
830  if (rval) {
831  rval = SetRnaType(rna_type);
832  }
833  x_UpdateParent();
834  return rval;
835 }
836 
837 bool CDualRNAFieldNamePanel::SetFieldName2(const string& field)
838 {
839  bool rval = false;
840  m_NcrnaClass->Enable(false);
841  string rna_type = field;
842  for (size_t i = 0; i < m_RnaField2->GetCount(); i++) {
843  string rna_field = ToStdString(m_RnaField2->GetString(static_cast<unsigned int>(i)));
844  if (NStr::EndsWith (field, rna_field)) {
845  m_RnaField2->SetSelection(static_cast<int>(i));
846  m_RnaField2->SetFirstItem(static_cast<int>(i));
847  if (rna_field.length() < field.length()) {
848  rna_type = field.substr(0, field.length() - rna_field.length());
849  NStr::TruncateSpacesInPlace(rna_type);
850  }
851  rval = true;
852  break;
853  }
854  }
855 
856  if (rval) {
857  rval = SetRnaType(rna_type);
858  }
859  x_UpdateParent();
860  return rval;
861 }
862 
863 
865 {
866  string rna_type = ToStdString(m_RNAType->GetStringSelection());
867  if (NStr::EqualNocase(rna_type, "ncRNA")) {
868  m_NcrnaClass->Enable(true);
869  } else {
870  m_NcrnaClass->Enable(false);
871  }
872 }
873 
874 
875 /*!
876  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RNA_TYPE
877  */
878 
879 void CDualRNAFieldNamePanel::OnRnaTypeSelected( wxCommandEvent& event )
880 {
882  x_UpdateParent();
883  event.Skip();
884 }
885 
886 void CDualRNAFieldNamePanel::OnRnaFieldSelected( wxCommandEvent& event )
887 {
888  x_UpdateParent();
889  event.Skip();
890 }
891 
892 
User-defined methods of the data storage class.
void Init()
Initialises member variables.
void OnRnaFieldSelected(wxCommandEvent &event)
virtual bool SetFieldName(const string &field)
static bool ShowToolTips()
Should we show tooltips?
void OnRnaTypeSelected(wxCommandEvent &event)
wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RNA_TYPE
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
bool Create(wxWindow *parent, wxWindowID id=ID_CDUALRNAFIELDNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void CreateControls()
Creates the controls and sizers.
string GetFieldName2(const bool subfield=false)
bool SetRnaType(const string &rna_type)
bool SetFieldName2(const string &field)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
virtual void ClearValues(void)
void x_UpdateParent(void)
static bool IsFeature(const string &target)
string GetAsnPathToFieldName(const string &field, EMacroFieldType type, const string &target=kEmptyStr)
static CMacroEditorContext & GetInstance()
virtual void ClearValues(void)
static vector< string > GetRNAFields()
virtual string GetMacroFieldName(const string &target, const string &selected_field=kEmptyStr)
void Init()
Initialises member variables.
void OnncRNAClassSelected(wxCommandEvent &event)
void OnRnaTypeSelected(wxCommandEvent &event)
wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_RNA_TYPE
virtual bool SetFieldName(const string &field)
CRNAFieldNamePanel * m_Sibling
bool SetRnaType(const string &rna_type)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
static string s_GetMacroFieldName(const string &rna_type, const string &qual_field, const string &target, const string &selected_field=kEmptyStr)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CRNAFIELDNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
void OnRnaFieldSelected(wxCommandEvent &event)
static vector< string > GetRNATypes()
static bool ShowToolTips()
Should we show tooltips?
CRNAFieldNamePanel()
Constructors.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#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
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5432
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
#define NPOS
Definition: ncbistr.hpp:133
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
Definition: ncbistr.cpp:3192
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5414
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5355
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sun Jul 14 04:59:55 2024 by modify_doxy.py rev. 669887