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

Go to the SVN repository for this file.

1 /* $Id: field_choice_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 // Generated by DialogBlocks (unregistered), 12/06/2013 14:35:26
31 
32 #include <ncbi_pch.hpp>
36 
49 
56 
59 
60 /*!
61  * CFieldChoicePanel type definition
62  */
63 
64 IMPLEMENT_DYNAMIC_CLASS( CFieldChoicePanel, CFieldNamePanel )
65 
66 wxDEFINE_EVENT(wxEVT_COMMAND_UPDATE_CONSTRAINT_FIELD, wxCommandEvent);
67 /*!
68  * CFieldChoicePanel event table definition
69  */
70 
71 BEGIN_EVENT_TABLE( CFieldChoicePanel, CFieldNamePanel )
72 
73 ////@begin CFieldChoicePanel event table entries
74 ////@end CFieldChoicePanel event table entries
75  EVT_CHOICE( ID_CFIELD_TYPE_CHOICE, CFieldChoicePanel::OnFieldTypeChoiceSelected )
76 
78 
79 
80 /*!
81  * CFieldChoicePanel constructors
82  */
83 
85 {
86  Init();
87 }
88 
89 CFieldChoicePanel::CFieldChoicePanel( wxWindow* parent, const vector<CFieldNamePanel::EFieldType>& field_types, bool horizontal, bool is_pair, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90  : m_IsPair (is_pair), m_IsHorizontal(horizontal), m_Composed(false), m_FieldTypes(field_types), m_Field1(NULL), m_Field2(NULL)
91 {
92  Init();
93  Create(parent, field_types, horizontal, id, pos, size, style);
94 }
95 
96 
97 /*!
98  * CFieldChoicePanel creator
99  */
100 
101 bool CFieldChoicePanel::Create( wxWindow* parent, const vector<CFieldNamePanel::EFieldType>& field_types, bool horizontal, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
102 {
103 ////@begin CFieldChoicePanel creation
104  CFieldNamePanel::Create( parent, id, pos, size, style );
105 
106  CreateControls();
107  if (GetSizer())
108  {
109  GetSizer()->SetSizeHints(this);
110  }
111  Centre();
112 ////@end CFieldChoicePanel creation
113  return true;
114 }
115 
116 
117 /*!
118  * CFieldChoicePanel destructor
119  */
120 
122 {
123 ////@begin CFieldChoicePanel destruction
124 ////@end CFieldChoicePanel destruction
125 }
126 
127 
128 /*!
129  * Member initialisation
130  */
131 
133 {
134 ////@begin CFieldChoicePanel member initialisation
138  m_show_legal_only = false;
139 ////@end CFieldChoicePanel member initialisation
140 }
141 
142 
143 /*!
144  * Control creation for CFieldChoicePanel
145  */
146 
148 {
149 ////@begin CFieldChoicePanel content construction
150  CFieldChoicePanel* itemCFieldNamePanel1 = this;
151 
152  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
153  itemCFieldNamePanel1->SetSizer(itemBoxSizer2);
154 
155  m_TopFieldTypeSizer = new wxBoxSizer(wxHORIZONTAL);
156  itemBoxSizer2->Add(m_TopFieldTypeSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxRIGHT, 5);
157 
158  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
159  itemBoxSizer2->Add(itemBoxSizer4, 0, wxALIGN_LEFT|wxALL, 5);
160 
161  m_SideFieldTypeSizer = new wxBoxSizer(wxVERTICAL);
162  itemBoxSizer4->Add(m_SideFieldTypeSizer, 0, wxALIGN_TOP|wxLEFT|wxRIGHT, 5);
163 
164  m_FieldPicker = new wxBoxSizer(wxHORIZONTAL);
165  itemBoxSizer4->Add(m_FieldPicker, 0, wxALIGN_TOP|wxLEFT|wxRIGHT, 5);
166 
167 ////@end CFieldChoicePanel content construction
168  wxArrayString field_type_strings;
169  ITERATE(vector<CFieldNamePanel::EFieldType>, it, m_FieldTypes) {
170  field_type_strings.Add(ToWxString(CFieldNamePanel::GetFieldTypeName(*it)));
171  }
172  m_FieldType = new wxChoice( this, ID_CFIELD_TYPE_CHOICE, wxDefaultPosition, wxDefaultSize, field_type_strings, 0 );
173  if (m_IsHorizontal) {
175  } else {
177  }
178 }
179 
180 
181 /*!
182  * Should we show tooltips?
183  */
184 
186 {
187  return true;
188 }
189 
190 /*!
191  * Get bitmap resources
192  */
193 
194 wxBitmap CFieldChoicePanel::GetBitmapResource( const wxString& name )
195 {
196  // Bitmap retrieval
197 ////@begin CFieldChoicePanel bitmap retrieval
198  wxUnusedVar(name);
199  return wxNullBitmap;
200 ////@end CFieldChoicePanel bitmap retrieval
201 }
202 
203 /*!
204  * Get icon resources
205  */
206 
207 wxIcon CFieldChoicePanel::GetIconResource( const wxString& name )
208 {
209  // Icon retrieval
210 ////@begin CFieldChoicePanel icon retrieval
211  wxUnusedVar(name);
212  return wxNullIcon;
213 ////@end CFieldChoicePanel icon retrieval
214 }
215 
217 {
218  m_Composed = show;
219 }
220 
221 void CFieldChoicePanel::OnFieldTypeChoiceSelected( wxCommandEvent& event )
222 {
223  string val = ToStdString(m_FieldType->GetStringSelection());
224 
226  SetFieldType(field_type, m_IsPair);
227 
228  wxCommandEvent fieldTypeEvent(wxEVT_COMMAND_UPDATE_CONSTRAINT_FIELD, GetId());
229  fieldTypeEvent.SetEventObject(this);
230  GetEventHandler()->ProcessEvent(fieldTypeEvent);
231 
232  x_UpdateParent();
233  event.Skip();
234 }
235 
237 {
238  bool rval = false;
239  while (m_FieldPicker->GetItemCount() > 0) {
240  int pos = 0;
241  m_FieldPicker->GetItem(pos)->DeleteWindows();
242  m_FieldPicker->Remove(pos);
243  }
244  m_Field1 = NULL;
245  m_Field2 = NULL;
246 
247  if (m_FieldType->SetStringSelection(CFieldNamePanel::GetFieldTypeName(field_type))) {
248  m_IsPair = is_pair;
249 
250  switch (field_type) {
252  m_Field1 = new CSourceFieldNamePanel(this, m_Composed, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
253  m_FieldPicker->Add(m_Field1);
254  if (x_IsParentAECRDlg()) {
255  CSourceFieldNamePanel* src_panel = dynamic_cast<CSourceFieldNamePanel*>(m_Field1);
256  src_panel->DoNotShowSubList(true);
257  }
258  if (m_IsPair) {
260  m_Field2 = new CSourceFieldNamePanel(this, m_Composed, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
261  m_FieldPicker->Add(m_Field2);
262  if (x_IsParentAECRDlg()) {
263  CSourceFieldNamePanel* src_panel = dynamic_cast<CSourceFieldNamePanel*>(m_Field2);
264  src_panel->HideSourceType();
265  src_panel->DoNotShowSubList(true);
266  }
267  }
268 
269  rval = true;
270  break;
272  m_Field1 = new CSourceFieldNamePanel(this, m_Composed, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
273  m_FieldPicker->Add(m_Field1);
274  if (x_IsParentAECRDlg()) {
275  CSourceFieldNamePanel* src_panel = dynamic_cast<CSourceFieldNamePanel*>(m_Field1);
276  src_panel->DoNotShowSubList(true);
277  }
278  if (m_IsPair) {
280  m_Field2 = new CSourceFieldNamePanel(this, m_Composed, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
281  m_FieldPicker->Add(m_Field2);
282  if (x_IsParentAECRDlg()) {
283  CSourceFieldNamePanel* src_panel = dynamic_cast<CSourceFieldNamePanel*>(m_Field2);
284  src_panel->HideSourceType();
285  src_panel->DoNotShowSubList(true);
286  }
287  }
288  SetOneFieldName("taxname");
289  rval = true;
290  break;
292  m_Field1 = new CFeatureFieldNamePanel(this, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
293  m_FieldPicker->Add(m_Field1);
294  if (m_IsPair) {
295  m_Field2 = new CFeatureFieldNamePanel(this, dynamic_cast<CFeatureFieldNamePanel*>(m_Field1), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
296  m_FieldPicker->Add(m_Field2);
297  }
298  if (m_Field1) {
299  CFeatureFieldNamePanel* featfield_panel = dynamic_cast<CFeatureFieldNamePanel*>(m_Field1);
300  if (featfield_panel) {
301  featfield_panel->PopulateFeatureListbox();
302  }
303  }
304  rval = true;
305  break;
308  m_FieldPicker->Add(m_Field1);
309  m_Field1->SetFieldName("protein name");
310  if (m_IsPair) {
312  m_FieldPicker->Add(m_Field2);
313  }
314  rval = true;
315  break;
317  m_Field1 = new CRNAFieldNamePanel(this, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
318  m_FieldPicker->Add(m_Field1);
319  m_Field1->SetFieldName("product");
320  if (m_IsPair) {
321  CRNAFieldNamePanel* field_panel = dynamic_cast<CRNAFieldNamePanel*>(m_Field1);
322  m_Field2 = new CRNAFieldNamePanel(this, dynamic_cast<CRNAFieldNamePanel*>(m_Field1), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
323  m_FieldPicker->Add(m_Field2);
324  }
325  rval = true;
326  break;
328  m_Field1 = new CGeneFieldPanel(this);
329  m_Field1->SetFieldName("locus");
330  m_FieldPicker->Add(m_Field1);
331  if (m_IsPair) {
332  m_Field2 = new CGeneFieldPanel(this);
333  m_FieldPicker->Add(m_Field2);
334  m_Field2->SetFieldName("locus");
335  }
336  rval = true;
337  break;
339  m_Field1 = new CProteinFieldPanel(this);
340  m_Field1->SetFieldName("name");
341  m_FieldPicker->Add(m_Field1);
342  if (m_IsPair) {
343  m_Field2 = new CProteinFieldPanel(this);
344  m_FieldPicker->Add(m_Field2);
345  m_Field2->SetFieldName("name");
346  }
347  rval = true;
348  break;
350  {{
352  a->SetFieldNames(CMolInfoFieldType::GetFieldNames());
353  m_Field1 = a;
354 
355  m_FieldPicker->Add(m_Field1);
356  m_Field1->SetFieldName("molecule");
357  if (m_IsPair) {
359  b->SetFieldNames(CMolInfoFieldType::GetFieldNames());
360  m_Field2 = b;
361  m_FieldPicker->Add(m_Field2);
362  }
363  }}
364  rval = true;
365  break;
367  {{
369  a->SetFieldNames(CPubFieldType::GetFieldNames());
370  m_Field1 = a;
371 
372  m_FieldPicker->Add(m_Field1);
373  m_Field1->SetFieldName("title");
374  if (m_IsPair) {
376  b->SetFieldNames(CPubFieldType::GetFieldNames());
377  m_Field2 = b;
378  m_FieldPicker->Add(m_Field2);
379  }
380  }}
381  rval = true;
382  break;
384  {{
385 // if (x_IsParentAECRDlg()) {
387  m_FieldPicker->Add(m_Field1);
388  if (m_IsPair) {
390  m_FieldPicker->Add(m_Field2);
391  }
392 // } else {
393 // m_Field1 = new CStructFieldValuePanel(this);
394 // m_FieldPicker->Add(m_Field1);
395 // }
396  wxCommandEvent fieldTypeEvent(wxEVT_COMMAND_UPDATE_STRUCTCOMMENT_FIELD);
397  fieldTypeEvent.SetEventObject(this);
398  GetEventHandler()->ProcessEvent(fieldTypeEvent);
399  }}
400  rval = true;
401  break;
403  {{
405  a->SetFieldNames(CDBLinkFieldType::GetFieldNames());
406  m_Field1 = a;
407 
408  m_FieldPicker->Add(m_Field1);
409  m_Field1->SetFieldName("title");
410  if (m_IsPair) {
412  b->SetFieldNames(CDBLinkFieldType::GetFieldNames());
413  m_Field2 = b;
414  m_FieldPicker->Add(m_Field2);
415  }
416  }}
417  rval = true;
418  break;
420  m_Field1 = new CDbxrefNamePanel(this);
421  m_FieldPicker->Add(m_Field1);
422  rval = true;
423  break;
425  {{
427  a->SetFieldNames(CMiscFieldType::GetStrings());
428  m_Field1 = a;
429  m_FieldPicker->Add(m_Field1);
431  if (m_IsPair) {
433  b->SetFieldNames(CMiscFieldType::GetStrings());
434  m_Field2 = b;
435  m_FieldPicker->Add(m_Field2);
436  }
437  }}
438  rval = true;
439  break;
441  m_Field1 = new CGeneralIDPanel(this);
442  m_FieldPicker->Add(m_Field1);
443  rval = true;
444  break;
451  rval = true;
452  break;
453  default:
454  break;
455  }
456  }
457 
458  if (m_Field1) {
460  m_Field1->Layout();
461  m_Field1->Fit();
462  m_Field1->Refresh();
463  }
464  if (m_Field2) {
466  m_Field2->Layout();
467  m_Field2->Fit();
468  m_Field2->Refresh();
469  }
470 
471  int min_width = 0;
472  int min_height = 0;
473  int borders = 5;
474 
475  m_FieldType->GetSize(&min_width, &min_height);
476  min_width += borders;
477  min_height += borders;
478 
479  int this_width, this_height;
480  if (m_IsHorizontal) {
481  if (m_Field1) {
482  m_Field1->GetSize(&this_width, &this_height);
483  min_width += this_width + borders;
484  this_height += borders;
485  if (this_height > min_height) {
486  min_height = this_height;
487  }
488  }
489  if (m_Field2) {
490  m_Field2->GetSize(&this_width, &this_height);
491  min_width += this_width + borders;
492  this_height += borders;
493  if (this_height > min_height) {
494  min_height = this_height;
495  }
496  }
497  } else {
498  if (m_Field1) {
499  m_Field1->GetSize(&this_width, &this_height);
500  min_height += this_height + borders;
501  this_width += borders;
502  if (this_width > min_width) {
503  min_width = this_width;
504  }
505  }
506  if (m_Field2) {
507  m_Field2->GetSize(&this_width, &this_height);
508  min_width += this_width + borders;
509  }
510  }
511 
512  if (m_IsHorizontal && min_width < 400) {
513  min_width = 400;
514  } else if (min_width < 380) {
515  min_width = 380;
516  }
517  if (m_IsHorizontal && min_height < 150) {
518  min_height = 150;
519  } else if (min_height < 185) {
520  min_height = 185;
521  }
522 
523  wxSize min_size(min_width, min_height);
524  this->SetMinClientSize(min_size);
525  Layout();
526  Fit();
527  Refresh();
528 
529  return rval;
530 }
531 
533 {
534  if (!m_Field1)
535  return;
536  CSourceFieldNamePanel *field = dynamic_cast<CSourceFieldNamePanel*>( m_Field1);
537  if (!field)
538  return;
539  field->SetSourceSubpanelSelection(sel);
540 }
541 
542 string CFieldChoicePanel::GetField1(const bool subfield)
543 {
544  string val = "";
545  if (m_Field1) {
546  val = m_Field1->GetFieldName(subfield);
547  }
548  return val;
549 }
550 
551 
552 string CFieldChoicePanel::GetField2(const bool subfield)
553 {
554  string val = "";
555  if (m_Field2) {
556  val = m_Field2->GetFieldName(subfield);
557  }
558  return val;
559 }
560 
562 {
564  if (NStr::EqualNocase(GetField1(), "protein name") || (m_IsPair && NStr::EqualNocase(GetField2(), "protein name"))) {
565  return true;
566  }
567  }
568  return false;
569 }
570 
571 const vector<CFieldNamePanel::EFieldType> CFieldChoicePanel::GetFieldTypes()
572 {
573  vector<CFieldNamePanel::EFieldType> field_types;
574  wxArrayString strings = m_FieldType->GetStrings();
575  for (size_t i = 0; i < strings.size(); i++) {
577  if (field_type != CFieldNamePanel::eFieldType_Unknown) {
578  field_types.push_back(field_type);
579  }
580  }
581  return field_types;
582 }
583 
584 
586 {
587  return GetFieldTypeFromName(ToStdString(m_FieldType->GetStringSelection()));
588 }
589 
590 
591 vector<string> CFieldChoicePanel::GetChoices(bool& allow_other)
592 {
593  vector<string> choices;
594  if (m_Field1) {
595  choices = m_Field1->GetChoices(allow_other);
596  }
597  return choices;
598 }
599 
600 
601 string CFieldChoicePanel::GetFieldName(const bool subfield)
602 {
603  string field = GetField1();
604  if (NStr::IsBlank(field)) {
605  field = ToStdString(m_FieldType->GetStringSelection());
606  if (!NStr::EqualNocase(field, kFieldTypeSeqId) &&
607  !NStr::EqualNocase(field, kLocalId) &&
608  !NStr::EqualNocase(field, kFileSeqId) &&
612  !NStr::EqualNocase(field, kComment) &&
613  !NStr::EqualNocase(field, kFlatFile)) {
614  field = kEmptyStr;
615  }
616  } else {
617  // When this changes, please update NMItemData::GetRNASpecificFieldsForTableReader and its unit test
618  string field_type = ToStdString(m_FieldType->GetStringSelection());
619  if (NStr::StartsWith(field_type, "RNA") && NStr::Find(field, "RNA") == string::npos && !subfield) {
620  field = "RNA " + field;
621  }
622  }
623  return field;
624 }
625 
626 bool CFieldChoicePanel::SetOneFieldName(const string& field)
627 {
628  bool rval = false;
629  if (m_Field1) {
630  rval = m_Field1->SetFieldName(field);
631  }
632  return rval;
633 }
634 
635 
636 bool CFieldChoicePanel::SetFieldName(const string& field)
637 {
638  bool rval = false;
639 
640  size_t pos = NStr::Find(field, " ");
641  if (pos == string::npos) {
642  if (m_Field1) {
643  rval = m_Field1->SetFieldName(field);
644  }
645  } else {
646  CFieldNamePanel::EFieldType field_type = CFieldNamePanel::GetFieldTypeFromName(field.substr(0, pos));
647  if (field_type != CFieldNamePanel::eFieldType_Unknown) {
648  string field_name_str = CFieldNamePanel::GetFieldTypeName(field_type);
649  string tmp = field;
650  if (NStr::StartsWith(tmp, field_name_str)) {
651  tmp = tmp.substr(field_name_str.length());
652  } else {
653  tmp = tmp.substr(pos);
654  }
656  SetFieldType(field_type, m_IsPair);
657  if (m_Field1 != NULL) {
658  rval = m_Field1->SetFieldName(tmp);
659  }
660  x_UpdateParent();
661  }
662  }
663  return rval;
664 }
665 
666 
667 string CFieldChoicePanel::AutoMatch(string field_name)
668 {
669  string answer = "";
670  // the first part may tell us what kind of field this is.
671  CFieldNamePanel::EFieldType field_type = GetFieldTypeFromName(field_name);
672  /* if (field_type != CFieldNamePanel::eFieldType_Unknown && field_type != CFieldNamePanel::eFieldType_SeqId) {
673  string prefix = CFieldNamePanel::GetFieldTypeName(field_type);
674  field_name = field_name.substr(0, prefix.length()); // what is this? why is it here? This seems to limit the input string to the length of field type name, such as "source qualifier" or "feature qualifier". Makes no sense.
675  NStr::TruncateSpacesInPlace(field_name);
676  } */
677  answer = AutoMatch(field_name, field_type);
678  return answer;
679 }
680 
681 
682 bool CFieldChoicePanel::LooksLikeHeader(const vector<string>& field_names)
683 {
684  if (field_names.empty()) {
685  return false;
686  }
687 
688  unsigned int unmatched = 0;
689  ITERATE(vector<string>, it, field_names) {
690  string guess = AutoMatch(*it);
691  if (NStr::IsBlank(guess)) {
692  ++unmatched;
693  }
694  }
695 
696  return (unmatched <= (2*field_names.size())/3);
697 }
698 
699 
700 string CFieldChoicePanel::AutoMatch(string field_name, CFieldNamePanel::EFieldType field_type)
701 {
702  string answer;
703 
704  switch (field_type) {
706  {
707  vector<CFieldNamePanel::EFieldType> guess_preference;
708  guess_preference.push_back(CFieldNamePanel::eFieldType_Source);
709  guess_preference.push_back(CFieldNamePanel::eFieldType_CDSGeneProt);
710  guess_preference.push_back(CFieldNamePanel::eFieldType_RNA);
711  guess_preference.push_back(CFieldNamePanel::eFieldType_Feature);
712  guess_preference.push_back(CFieldNamePanel::eFieldType_Misc);
713  ITERATE(vector<CFieldNamePanel::EFieldType>, it, guess_preference) {
714  answer = AutoMatch(field_name, *it);
715  if (!NStr::IsBlank(answer)) {
716  break;
717  }
718  }
719  }
720  break;
722  answer = AutoMatchSrc(field_name);
723  break;
725  answer = AutoMatchSrc(field_name);
726  break;
728  answer = AutoMatchFeat(field_name);
729  break;
731  answer = AutoMatchCGP(field_name);
732  break;
734  answer = AutoMatchRNA(field_name);
735  break;
737  break;
739  answer = AutoMatchPub(field_name);
740  break;
742  break;
744  answer = AutoMatchDBLink(field_name);
745  break;
747  answer = AutoMatchMisc(field_name);
748  break;
750  answer = kFieldTypeSeqId;
751  break;
752  default:
753  break;
754 
755  }
756  if (!answer.empty() && (field_type != CFieldNamePanel::eFieldType_Unknown)) {
757  answer = GetFieldTypeName(field_type) + " " + answer;
758  }
759  return answer;
760 }
761 
762 static const string kInst_suffix("-inst");
763 static const string kColl_suffix("-coll");
764 static const string kSpecid_suffix("-specid");
765 
766 string CFieldChoicePanel::AutoMatchSrc(string field_name)
767 {
768  string answer = "";
769  if (NStr::EqualNocase(field_name, "genome")) {
770  answer = "genome";
771  } else if (NStr::EqualNocase(field_name, "origin")) {
772  answer = "origin";
773  } else if (IsOrgColumnName(field_name)) {
774  answer = "taxname";
775  } else if (IsSubSourceNoteName(field_name)) {
776  answer = kSubSourceNote;
777  } else if (IsOrgModNoteName(field_name)) {
778  answer = kOrgModNote;
779  } else if (NStr::EqualNocase(field_name, "voucher")) {
780  answer = "specimen-voucher";
781  } else if (NStr::EqualNocase(field_name, kDbXref)) {
782  answer = kDbXref;
783  } else if (NStr::EndsWith(field_name, kInst_suffix)
784  || NStr::EndsWith(field_name, kColl_suffix)
785  || NStr::EndsWith(field_name, kSpecid_suffix)) {
786  return field_name;
787  }
788  else if (NStr::EqualNocase(field_name, kFwdPrimerName) || NStr::EqualNocase(field_name, kFwdPrimerSeq)
789  || NStr::EqualNocase(field_name, kRevPrimerName) || NStr::EqualNocase(field_name, kRevPrimerSeq)) {
790  return field_name;
791  }
792  else {
793  NStr::ToLower(field_name);
796  answer = CSubSource::GetSubtypeName(st);
797  }
800  answer = COrgMod::GetSubtypeName(st);
801  }
802  }
803 
804  return answer;
805 }
806 
807 
808 string CFieldChoicePanel::AutoMatchCGP(string field_name)
809 {
810  string answer = "";
811  vector<string> options = CCDSGeneProtFieldNamePanel::GetStrings();
812  ITERATE(vector<string>, it, options) {
813  if (QualifierNamesAreEquivalent(field_name, *it)) {
814  answer = *it;
815  break;
816  }
817  }
818  return answer;
819 }
820 
821 
822 string CFieldChoicePanel::AutoMatchMisc(string field_name)
823 {
824  string answer = "";
825  vector<string> options = CMiscFieldType::GetStrings();
826  ITERATE(vector<string>, it, options) {
827  if (QualifierNamesAreEquivalent(field_name, *it)) {
828  answer = *it;
829  break;
830  }
831  }
832  return answer;
833 }
834 
835 
836 string CFieldChoicePanel::AutoMatchFeat(string field_name)
837 {
838  string answer = "";
839 
840  size_t pos = NStr::Find(field_name, " ", NStr::eCase, NStr::eReverseSearch);
841  if (pos != string::npos) {
842  string feat = field_name.substr(0, pos);
843  string qual = field_name.substr(pos + 1);
844  const CFeatList* feat_list = CSeqFeatData::GetFeatList();
845  vector<string> features;
846  feat_list->GetDescriptions(features, false);
847  string answer_feat = "";
848  ITERATE(vector<string>, it, features) {
849  if (QualifierNamesAreEquivalent(*it, feat)) {
850  answer_feat = *it;
851  break;
852  }
853  }
854  if (!NStr::IsBlank(answer_feat)) {
855  string answer_qual = "";
856  int qual_num = CSeqFeatData::eQual_allele;
857  while (qual_num <= CSeqFeatData::eQual_whole_replicon) {
858  string check_qual = CSeqFeatData::GetQualifierAsString((CSeqFeatData::EQualifier)qual_num);
859  if (QualifierNamesAreEquivalent(qual, check_qual)) {
860  answer_qual = check_qual;
861  break;
862  }
863  qual_num++;
864  }
865 
866  if (NStr::EqualNocase(qual, "locus")
867  || NStr::EqualNocase(qual, "satellite_type") || (NStr::EqualNocase(qual, "satellite_name"))
868  || (NStr::EqualNocase(qual, "mobile_element_type")) || (NStr::EqualNocase(qual, "mobile_element_name"))
869  || (NStr::EqualNocase(qual, "mobile_element_type_type")) || (NStr::EqualNocase(qual, "mobile_element_type_name")) )
870  {
871  answer_qual = qual;
872  }
873  if (!NStr::IsBlank(answer_qual)) {
874  answer = answer_feat + " " + answer_qual;
875  }
876  }
877  }
878  return answer;
879 }
880 
881 
882 string CFieldChoicePanel::AutoMatchRNA(string field_name)
883 {
884  string answer = "";
885  vector<string> rna_types = CRNAFieldNamePanel::GetRNATypes();
886  string answer_rna_type = "";
887  string remainder = field_name;
888  size_t pos = NStr::Find(field_name, " ");
889  if (pos != string::npos) {
890  string check_rna_type = field_name.substr(0, pos);
891  ITERATE(vector<string>, it, rna_types) {
892  if (QualifierNamesAreEquivalent(check_rna_type, *it)) {
893  answer_rna_type = *it;
894  remainder = field_name.substr(pos);
895  }
896  break;
897  }
898  }
899  if (NStr::IsBlank(answer_rna_type)) {
900  answer_rna_type = rna_types[0];
901  }
902 
903  vector<string> rna_fields = CRNAFieldNamePanel::GetRNAFields();
904  string ncrna_class = "";
905  string answer_field = "";
906  if (NStr::Equal(answer_rna_type, "ncRNA")) {
907  ITERATE(vector<string>, it, rna_fields) {
908  if (NStr::EndsWith(remainder, *it, NStr::eNocase)) {
909  if (remainder.length() > (*it).length()) {
910  ncrna_class = remainder.substr(0, remainder.length() - (*it).length());
911  }
912  answer_field = *it;
913  break;
914  }
915  }
916  } else {
917  ITERATE(vector<string>, it, rna_fields) {
918  if (QualifierNamesAreEquivalent(remainder, *it)) {
919  answer_field = *it;
920  break;
921  }
922  }
923  }
924  if (!NStr::IsBlank(answer_field)) {
925  answer = answer_rna_type;
926  if (!NStr::IsBlank(ncrna_class)) {
927  answer += " " + ncrna_class;
928  }
929  answer += " " + answer_field;
930  }
931 
932  return answer;
933 }
934 
935 
936 string CFieldChoicePanel::AutoMatchPub(string field_name)
937 {
938  string answer;
939  field_name = CPubFieldType::NormalizePubFieldName(field_name);
940  vector<string> field_names = CPubFieldType::GetFieldNames();
941  ITERATE(vector<string>, it, field_names) {
942  if (QualifierNamesAreEquivalent(field_name, *it)) {
943  answer = *it;
944  break;
945  }
946  }
947 
948  return answer;
949 }
950 
951 
952 string CFieldChoicePanel::AutoMatchDBLink(string field_name)
953 {
954  string answer = "";
955  vector<string> field_names = CDBLinkFieldType::GetFieldNames();
956  ITERATE(vector<string>, it, field_names) {
957  if (QualifierNamesAreEquivalent(field_name, *it)) {
958  answer = *it;
959  break;
960  }
961  }
962 
963  return answer;
964 }
965 
966 string CFieldChoicePanel::AutoMatchMolInfo(string field_name)
967 {
968  string answer;
969  vector<string> field_names = CMolInfoFieldType::GetFieldNames();
970  ITERATE(vector<string>, it, field_names) {
971  if (QualifierNamesAreEquivalent(field_name, *it)) {
972  answer = *it;
973  break;
974  }
975  }
976 
977  return answer;
978 }
979 
static vector< string > GetFieldNames()
CConfigurableItems - a static list of items that can be configured.
void GetDescriptions(vector< string > &descs, bool hierarchical=false) const
return a list of all the feature descriptions for a menu or other control.
static string AutoMatchRNA(string field_name)
string GetField2(const bool subfield=false)
static string AutoMatchFeat(string field_name)
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
bool SetFieldType(CFieldNamePanel::EFieldType field_type, bool is_pair=false)
bool IsOneFieldProteinName(void)
static bool LooksLikeHeader(const vector< string > &field_names)
~CFieldChoicePanel()
Destructor.
const vector< CFieldNamePanel::EFieldType > GetFieldTypes()
static string AutoMatch(string field_name)
bool SetOneFieldName(const string &field)
void SetSubpanelSelection(const string &sel)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
static bool ShowToolTips()
Should we show tooltips?
static string AutoMatchSrc(string field_name)
CFieldChoicePanel()
Constructors.
void OnFieldTypeChoiceSelected(wxCommandEvent &event)
static string AutoMatchMolInfo(string field_name)
static string AutoMatchMisc(string field_name)
virtual vector< string > GetChoices(bool &allow_other)
void CreateControls()
Creates the controls and sizers.
wxBoxSizer * m_TopFieldTypeSizer
virtual bool SetFieldName(const string &field)
void Init()
Initialises member variables.
string GetField1(const bool subfield=false)
static string AutoMatchPub(string field_name)
void IncludeComposedItems(bool show)
static string AutoMatchDBLink(string field_name)
wxBoxSizer * m_SideFieldTypeSizer
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CFieldNamePanel * m_Field1
bool Create(wxWindow *parent, const vector< CFieldNamePanel::EFieldType > &field_types, bool horizontal, wxWindowID id=ID_CFIELDCHOICEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSIMPLE_BORDER|wxTAB_TRAVERSAL)
Creation.
CFieldNamePanel::EFieldType GetFieldType()
CFieldNamePanel * m_Field2
static string AutoMatchCGP(string field_name)
vector< CFieldNamePanel::EFieldType > m_FieldTypes
virtual string GetFieldName(const bool subfield=false)=0
Returns the name of the field as selected in the panel.
bool x_IsParentAECRDlg(void)
virtual void SetShowLegalOnly(bool show)
virtual vector< string > GetChoices(bool &allow_other)
virtual bool SetFieldName(const string &field)=0
static string GetFieldTypeName(EFieldType field_type)
void x_UpdateParent(void)
static EFieldType GetFieldTypeFromName(const string &field_type_name)
static vector< string > GetStrings()
static vector< string > GetFieldNames()
@ eVocabulary_insdc
Definition: OrgMod.hpp:69
static bool IsValidSubtypeName(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: OrgMod.cpp:86
static string GetSubtypeName(TSubtype stype, EVocabulary vocabulary=eVocabulary_raw)
Definition: OrgMod.cpp:108
static TSubtype GetSubtypeValue(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: OrgMod.cpp:62
static string NormalizePubFieldName(string orig_label)
static vector< string > GetFieldNames(bool extended=false)
static vector< string > GetRNAFields()
static vector< string > GetRNATypes()
EQualifier
List of available qualifiers for feature keys.
static const CFeatList * GetFeatList()
static CTempString GetQualifierAsString(EQualifier qual)
Convert a qualifier from an enumerated value to a string representation or empty if not found.
void SetSourceSubpanelSelection(const string &sel)
static TSubtype GetSubtypeValue(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: SubSource.cpp:129
static bool IsValidSubtypeName(const string &str, EVocabulary vocabulary=eVocabulary_raw)
Definition: SubSource.cpp:158
@ eVocabulary_insdc
Definition: SubSource.hpp:83
static string GetSubtypeName(CSubSource::TSubtype stype, EVocabulary vocabulary=eVocabulary_raw)
Definition: SubSource.cpp:186
USING_SCOPE(objects)
static const string kSpecid_suffix("-specid")
wxDEFINE_EVENT(wxEVT_COMMAND_UPDATE_CONSTRAINT_FIELD, wxCommandEvent)
static const string kColl_suffix("-coll")
static const string kInst_suffix("-inst")
const char * kDefinitionLineLabel
const char * kFileSeqId
const char * kOrgModNote
const char * kFwdPrimerSeq
const char * kFieldTypeSeqId
const char * kFwdPrimerName
const char * kComment
const char * kDbXref
const char * kLocalId
const char * kSubSourceNote
const char * kTaxnameAfterBinomial
const char * kRevPrimerName
const char * kFlatFile
const char * kBankITComment
const char * kRevPrimerSeq
#define false
Definition: bool.h:36
static void Init(void)
Definition: cursor6.c:76
static const char *const strings[]
Definition: utf8.c:21
static char tmp[3200]
Definition: utf8.c:42
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
#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
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string (in-place)
Definition: ncbistr.cpp:3192
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2882
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
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5386
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
@ eReverseSearch
Search in a backward direction.
Definition: ncbistr.hpp:1947
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
unsigned int a
Definition: ncbi_localip.c:102
static static static wxID_ANY
bool IsOrgColumnName(string name)
bool QualifierNamesAreEquivalent(string name1, string name2)
bool IsOrgModNoteName(const string &name)
bool IsSubSourceNoteName(const string &name)
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat Jul 13 13:39:45 2024 by modify_doxy.py rev. 669887