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

Go to the SVN repository for this file.

1 /* $Id: pub_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>
39 #include <wx/sizer.h>
40 
41 
44 
45 /*!
46  * CFieldHandlerNamePanel type definition
47  */
48 
49 IMPLEMENT_DYNAMIC_CLASS( CFieldHandlerNamePanel, CFieldNamePanel )
50 
51 
52 /*!
53  * CFieldHandlerNamePanel event table definition
54  */
55 
56 BEGIN_EVENT_TABLE( CFieldHandlerNamePanel, CFieldNamePanel )
57 
58 ////@begin CFieldHandlerNamePanel event table entries
59  EVT_LISTBOX( ID_PUBFIELDNAME_FIELD, CFieldHandlerNamePanel::OnFieldSelected)
60 
61 ////@end CFieldHandlerNamePanel event table entries
62 
64 
65 
66 /*!
67  * CFieldHandlerNamePanel constructors
68  */
69 
71 {
72  Init();
73 }
74 
75 CFieldHandlerNamePanel::CFieldHandlerNamePanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
76 {
77  Init();
78  Create(parent, id, pos, size, style);
79 }
80 
81 
82 /*!
83  * CPubFieldNamePanel creator
84  */
85 
86 bool CFieldHandlerNamePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
87 {
88 ////@begin CFieldHandlerNamePanel creation
89  CFieldNamePanel::Create( parent, id, pos, size, style );
90 
92  if (GetSizer())
93  {
94  GetSizer()->SetSizeHints(this);
95  }
96  Centre();
97 ////@end CFieldHandlerNamePanel creation
98  return true;
99 }
100 
101 
102 /*!
103  * CFieldHandlerNamePanel destructor
104  */
105 
107 {
108 ////@begin CFieldHandlerNamePanel destruction
109 ////@end CFieldHandlerNamePanel destruction
110 }
111 
112 
113 /*!
114  * Member initialisation
115  */
116 
118 {
119 ////@begin CFieldHandlerNamePanel member initialisation
120  m_Field = NULL;
121 ////@end CFieldHandlerNamePanel member initialisation
122 }
123 
124 
125 /*!
126  * Control creation for CPubFieldNamePanel
127  */
128 
130 {
131 ////@begin CFieldHandlerNamePanel content construction
132  CFieldHandlerNamePanel* itemCFieldNamePanel1 = this;
133 
134  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
135  itemCFieldNamePanel1->SetSizer(itemBoxSizer2);
136 
137  wxArrayString m_FieldStrings;
138  m_Field = new wxListBox(itemCFieldNamePanel1, ID_PUBFIELDNAME_FIELD, wxDefaultPosition, wxSize(220,109), m_FieldStrings, wxLB_SINGLE);
139  itemBoxSizer2->Add(m_Field, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
140 
141 ////@end CFieldHandlerNamePanel content construction
142 }
143 
145 {
146  m_Field->SetSelection(0);
147  m_Field->SetFirstItem(0);
148 }
149 
150 /*!
151  * wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_PUBFIELDNAME_FIELD
152  */
153 
154 void CFieldHandlerNamePanel::OnFieldSelected( wxCommandEvent& event )
155 {
156  x_UpdateParent();
157  event.Skip();
158 }
159 
160 
161 /*!
162  * Should we show tooltips?
163  */
164 
166 {
167  return true;
168 }
169 
170 /*!
171  * Get bitmap resources
172  */
173 
174 wxBitmap CFieldHandlerNamePanel::GetBitmapResource( const wxString& name )
175 {
176  // Bitmap retrieval
177 ////@begin CFieldHandlerNamePanel bitmap retrieval
178  wxUnusedVar(name);
179  return wxNullBitmap;
180 ////@end CFieldHandlerNamePanel bitmap retrieval
181 }
182 
183 /*!
184  * Get icon resources
185  */
186 
187 wxIcon CFieldHandlerNamePanel::GetIconResource( const wxString& name )
188 {
189  // Icon retrieval
190 ////@begin CFieldHandlerNamePanel icon retrieval
191  wxUnusedVar(name);
192  return wxNullIcon;
193 ////@end CFieldHandlerNamePanel icon retrieval
194 }
195 
196 
197 string CFieldHandlerNamePanel::GetFieldName(const bool subfield)
198 {
199  string field = "";
200  int val = m_Field->GetSelection();
201  if (val > -1) {
202  field = ToStdString(m_Field->GetString(val));
204  if (CPubFieldType::IsAffilField(field_type) && !subfield) {
205  field = "affiliation " + field;
206  }
207  }
208  return field;
209 }
210 
211 static string s_GetMolinfoMember(const string& field)
212 {
213  _ASSERT(field.front() == '\"');
214  size_t end_dot = NStr::Find(field, ".", NStr::eNocase, NStr::eReverseSearch);
215  if (end_dot != NPOS) {
216  return "\"" + field.substr(end_dot + 1, NPOS);
217  }
218  return kEmptyStr;
219 }
220 
221 string CFieldHandlerNamePanel::GetMacroFieldName(const string& target, const string& selected_field)
222 {
223  string field;
224  int val = m_Field->GetSelection();
225  if (val > -1)
226  {
227  field = m_MacroField[val];
228  }
229 
230  bool is_inst_field = NStr::StartsWith(field, "\"inst.");
231  if (m_self == macro::CMacroBioData::sm_MolInfo)
232  {
233  if (target == macro::CMacroBioData::sm_MolInfo) {
234  if (is_inst_field) {
235  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) + "(" + field + ")";
236  }
237  else {
238  return s_GetMolinfoMember(field);
239  }
240  }
241 
242  if (target == macro::CMacroBioData::sm_BioSource) {
243  if (is_inst_field) {
244  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) + "(" + field + ")";
245  }
246  else {
247  return CTempString(macro::CMacroFunction_GetSeqdesc::sm_MolinfoForBsrc) + "(" + s_GetMolinfoMember(field) + ")";
248  }
249  }
250 
251  if (target == macro::CMacroBioData::sm_Seqdesc) {
252  if (is_inst_field) {
253  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) + "(" + field + ")";
254  }
255  }
256 
257  if (target == macro::CMacroBioData::sm_Seq ||
258  target == macro::CMacroBioData::sm_SeqNa ||
259  target == macro::CMacroBioData::sm_SeqAa) {
260  // strip off the " characters from beginning and from the end
261  if (field[0] == '\"' && field.back() == field[0]) {
262  field = field.substr(1, field.length() - 2);
263  }
264  return field;
265  }
266 
267  if (CFieldNamePanel::IsFeature(target))
268  {
269  if (is_inst_field) {
270  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForFeat) + "(" + field + ")";
271  }
272  else {
273  return CTempString(macro::CMacroFunction_GetSeqdesc::sm_MolinfoForFeat) + "(" + s_GetMolinfoMember(field) + ")";
274  }
275  }
276  return kEmptyStr;
277  }
278 
279  if (m_self == macro::CMacroBioData::sm_DBLink) {
280  if (target == m_self) {
281  return "data_obj";
282  }
283  else {
284  return macro::CMacroFunction_GetDBLink::GetFuncName() + "(\"" + field + "\")";
285  }
286  }
287 
288  if (m_self == "Misc") {
289  if (target == macro::CMacroBioData::sm_Seqdesc) {
290  size_t pos = field.find("..");
291  field = field.substr(pos + 2, NPOS);
292  field = "\"" + field;
293  }
294  else if (CFieldNamePanel::IsFeature(target)) {
295  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForFeat) + "(" + field + ")";
296  }
297  else if ((target != macro::CMacroBioData::sm_SeqNa) && (target != macro::CMacroBioData::sm_SeqAa)){
298  return CTempString(macro::CMacroFunction_GetSequence::sm_SeqForDescr) + "(" + field + ")";
299  }
300  }
301  return field;
302 }
303 
304 string CFieldHandlerNamePanel::GetMacroFieldLabel(const string& target, const string& selected_field)
305 {
306  string field;
307  int val = m_Field->GetSelection();
308  if (val > -1)
309  {
310  field = ToStdString(m_Field->GetString(val));
311  }
312  if (m_self == "Misc")
313  {
314  if (field == kGenomeProjectID)
315  return "obj.label.str = \"ProjectID\"";
316  }
317  if (m_self == "DBLink" && target == m_self)
318  {
319  return "obj.label.str = \"" + field + "\"";
320  }
321  return kEmptyStr;
322 }
323 
324 void CFieldHandlerNamePanel::SetMacroFieldNames(const vector<string>& field_names)
325 {
326  m_MacroField = field_names;
327 }
328 
329 bool CFieldHandlerNamePanel::SetFieldName(const string& field)
330 {
331  bool rval = false;
332  for (size_t i = 0; i < m_Field->GetStrings().size(); i++) {
333  string misc_field = ToStdString(m_Field->GetString(static_cast<unsigned int>(i)));
336  misc_field == field ||
337  (CPubFieldType::IsAffilField(field_type) && "affiliation " + misc_field == field)) {
338  m_Field->SetSelection(static_cast<int>(i));
339  m_Field->SetFirstItem(static_cast<int>(i));
340  rval = true;
341  break;
342  }
343  }
344  x_UpdateParent();
345  return rval;
346 }
347 
348 
349 void CFieldHandlerNamePanel::SetFieldNames(const vector<string>& field_names)
350 {
351  wxArrayString field_strings;
352  ITERATE(vector<string>, it, field_names) {
353  field_strings.push_back(ToWxString(*it));
354  }
355  m_Field->Clear();
356  m_Field->Append(field_strings);
357  m_Field->SetSelection(0);
358  m_Field->SetFirstItem(0);
359 }
360 
361 
362 vector<string> CFieldHandlerNamePanel::GetChoices(bool& allow_other)
363 {
364  vector<string> choices;
365 
366  string field_name = GetFieldName();
367 
369  if (field_type != CMolInfoFieldType::e_Unknown) {
370  choices = CMolInfoFieldType::GetChoicesForField(field_type, allow_other);
371  }
372  else {
374  if (pub_field_type != CPubFieldType::ePubFieldType_Unknown) {
375  choices = CPubFieldType::GetChoicesForField(pub_field_type, allow_other);
376  }
377  }
378  return choices;
379 }
380 
382 {
383  vector<string> values;
384 
385  string field_name = GetFieldName();
386 
388  if (field_type != CMolInfoFieldType::e_Unknown) {
389  values = CMolInfoFieldType::GetValuesForField(field_type);
390  }
391  else {
393  if (pub_field_type != CPubFieldType::ePubFieldType_Unknown) {
394  bool allow_other = false;
395  values = CPubFieldType::GetChoicesForField(pub_field_type, allow_other);
396  }
397  }
398 
399  return values;
400 }
401 
403 
CFieldHandlerNamePanel()
Constructors.
void SetMacroFieldNames(const vector< string > &field_names)
static bool ShowToolTips()
Should we show tooltips?
bool Create(wxWindow *parent, wxWindowID id=ID_PUBFIELDNAMEPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
virtual vector< string > GetChoices(bool &allow_other)
virtual bool SetFieldName(const string &field)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void SetFieldNames(const vector< string > &field_names)
virtual void ClearValues(void)
void Init()
Initialises member variables.
virtual vector< string > GetMacroValues()
virtual string GetMacroFieldName(const string &target, const string &selected_field=kEmptyStr)
void OnFieldSelected(wxCommandEvent &event)
wxEVT_COMMAND_CHOICE_SELECTED event handler for ID_PUBFIELDNAME_FIELD
virtual string GetMacroFieldLabel(const string &target, const string &selected_field=kEmptyStr)
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void x_UpdateParent(void)
static bool IsFeature(const string &target)
static EMolInfoFieldType GetFieldType(const string &field_name)
static vector< string > GetChoicesForField(CMolInfoFieldType::EMolInfoFieldType field_type, bool &allow_other)
static vector< string > GetValuesForField(EMolInfoFieldType field_type)
static bool IsAffilField(EPubFieldType field_type)
static EPubFieldType GetTypeForLabel(string label)
static vector< string > GetChoicesForField(EPubFieldType field_type, bool &allow_other)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
const char * kGenomeProjectID
static void Init(void)
Definition: cursor6.c:76
#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
#define NPOS
Definition: ncbistr.hpp:133
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
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
Definition: tempstr.hpp:776
@ eReverseSearch
Search in a backward direction.
Definition: ncbistr.hpp:1947
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(objects)
static string s_GetMolinfoMember(const string &field)
bool QualifierNamesAreEquivalent(string name1, string name2)
#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:05:30 2024 by modify_doxy.py rev. 669887