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

Go to the SVN repository for this file.

1 /* $Id: singlequal_panel.cpp 46836 2021-10-28 20:47:55Z asztalos $
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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
37 #include <wx/choice.h>
38 #include <wx/textctrl.h>
39 #include <wx/sizer.h>
40 #include <wx/button.h>
41 #include <wx/combobox.h>
42 
44 
45 /*!
46  * CSingleQualPanel type definition
47  */
48 
49 IMPLEMENT_DYNAMIC_CLASS( CSingleQualPanel, wxPanel )
50 
51 
52 /*!
53  * CSingleQualPanel event table definition
54  */
55 
56 BEGIN_EVENT_TABLE( CSingleQualPanel, wxPanel )
57 
58 ////@begin CSingleQualPanel event table entries
59 ////@end CSingleQualPanel event table entries
60 
62 
63 
64 /*!
65  * CSingleQualPanel constructors
66  */
67 
69 {
70  Init();
71 }
72 
73 CSingleQualPanel::CSingleQualPanel( wxWindow* parent, EMacroFieldType type, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
74  :m_FieldType(type), m_MatchType(type)
75 {
76  Init();
77  Create(parent, id, pos, size, style);
78 }
79 
80 
81 /*!
82  * CSingleQualPanel creator
83  */
84 
85 bool CSingleQualPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
86 {
87 ////@begin CSingleQualPanel creation
88  SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
89  wxPanel::Create( parent, id, pos, size, style );
90 
92  if (GetSizer())
93  {
94  GetSizer()->SetSizeHints(this);
95  }
96  Centre();
97 ////@end CSingleQualPanel creation
98  return true;
99 }
100 
101 
102 /*!
103  * CSingleQualPanel destructor
104  */
105 
107 {
108 ////@begin CSingleQualPanel destruction
109 ////@end CSingleQualPanel destruction
110 }
111 
112 
113 /*!
114  * Member initialisation
115  */
116 
118 {
119 ////@begin CSingleQualPanel member initialisation
120  m_FieldFirst = NULL;
121  m_Column = NULL;
122  m_MatchCheck = NULL;
123 ////@end CSingleQualPanel member initialisation
124 }
125 
126 
127 /*!
128  * Control creation for CSingleQualPanel
129  */
130 
132 {
133 ////@begin CSingleQualPanel content construction
134  CSingleQualPanel* itemPanel1 = this;
135 
136  wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
137  itemPanel1->SetSizer(itemBoxSizer1);
138 
139  wxArrayString m_FieldFirstStrings;
140  m_FieldFirst = new wxComboBox( itemPanel1, ID_SNGLQUALCH1, wxEmptyString, wxDefaultPosition, wxSize(169, -1), m_FieldFirstStrings, wxCB_DROPDOWN);
141  itemBoxSizer1->Add(m_FieldFirst, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
142  m_FieldFirst->Bind(wxEVT_COMBOBOX, &CSingleQualPanel::OnFieldSelected, this);
143  m_FieldFirst->SetToolTip("Use 'Select' to choose qualifier");
144 
145  m_Column = new wxTextCtrl(itemPanel1, ID_SNGLQUALCOL, wxEmptyString, wxDefaultPosition, wxSize(30, -1), 0);
146  itemBoxSizer1->Add(m_Column, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
147 
148  m_MatchCheck = new wxCheckBox(itemPanel1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
149  itemBoxSizer1->Add(m_MatchCheck, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
150  m_MatchCheck->SetValue(false);
151 
152  wxHyperlinkCtrl* link = new wxHyperlinkCtrl(itemPanel1, wxID_ANY, wxT("Select"), wxT("select"), wxDefaultPosition, wxDefaultSize, 0);
153  itemBoxSizer1->Add(link, 0, wxALIGN_CENTER_VERTICAL, 5);
154  link->Bind(wxEVT_HYPERLINK, &CSingleQualPanel::OnSelectClicked, this);
155 
156  x_LoadChoices();
157 ////@end CSingleQualPanel content construction
158 }
159 
160 
162 {
163  wxArrayString arraystring;
164  m_FieldFirst->AppendString(wxEmptyString);
165  m_FieldFirst->AppendString(kFieldTypeSeqId);
168  m_FieldType != EMacroFieldType::eCdsGeneProt) { // don't load fields
169 
171  ToArrayString(choices, arraystring);
172  m_FieldFirst->Append(arraystring);
173  }
174 }
175 
176 void CSingleQualPanel::SetField(const string& first_field, int col)
177 {
178  string field = first_field;
179  if (NStr::EqualNocase(field, "accession") ||
181  NStr::StartsWith(field, "sequence", NStr::eNocase) ||
182  NStr::StartsWith(field, "filename", NStr::eNocase) ||
183  NStr::StartsWith(field, "bankit", NStr::eNocase)) {
184  field = kFieldTypeSeqId;
185  }
186  else if (NStr::EqualNocase(field, "authors")) {
189  }
190 
191  int sel = m_FieldFirst->FindString(ToWxString(field));
192  if (sel > -1) {
193  m_FieldFirst->SetSelection(sel);
194  }
195 
196  m_Column->SetValue(ToWxString(NStr::IntToString(col)));
197  m_MatchCheck->SetValue(field == kFieldTypeSeqId);
198 }
199 
200 bool CSingleQualPanel::InsertField(const string& field, int col, EMacroFieldType type, bool matching_field)
201 {
202  bool ret = true;
203  int sel = m_FieldFirst->FindString(ToWxString(field));
204  if (sel > -1) {
205  m_FieldFirst->SetSelection(sel);
206  }
207  else {
209  ret = dlg.SetField(field, type);
210 
211  m_MatchType = dlg.GetMatchType();
212  auto sel_field = dlg.GetSelection();
213  m_FieldFirst->SetString(0, sel_field.m_GUIName);
214  m_FieldFirst->SetSelection(0);
215  m_AdditionalFields.push_back(sel_field);
216  }
217 
218  m_Column->SetValue(ToWxString(NStr::IntToString(col)));
219  m_MatchCheck->SetValue(field == kFieldTypeSeqId || matching_field);
220  return ret;
221 }
222 
224 {
225  auto col = m_Column->GetValue().ToStdString();
226  const string& field = m_FieldFirst->GetStringSelection().ToStdString();
227  for (auto&& it : m_AdditionalFields) {
228  if (it.m_GUIName == field) {
229  it.m_Column = col;
230  return it;
231  }
232  }
233 
234  if (field == kFieldTypeSeqId) {
236  return SFieldFromTable(col, name_in_macro, field, true);
237  }
238  return SFieldFromTable(col, field, field, false);
239 }
240 
241 void CSingleQualPanel::OnSelectClicked(wxHyperlinkEvent& event)
242 {
243  if (event.GetURL() != wxT("select")) {
244  event.Skip();
245  return;
246  }
247 
249  if (dlg.ShowModal() == wxID_OK) {
250  m_MatchType = dlg.GetMatchType();
251  auto sel_field = dlg.GetSelection();
252  m_FieldFirst->SetString(0, sel_field.m_GUIName);
253  m_FieldFirst->SetSelection(0);
254  m_AdditionalFields.push_back(sel_field);
255  }
256 
257  event.Skip();
258 }
259 
260 void CSingleQualPanel::OnFieldSelected(wxCommandEvent& event)
261 {
262  if (!m_MatchCheck->IsChecked())
263  m_MatchCheck->SetValue(ToStdString(m_FieldFirst->GetStringSelection()) == kFieldTypeSeqId);
264 }
265 
266 
267 /*!
268  * Should we show tooltips?
269  */
270 
272 {
273  return true;
274 }
275 
276 /*!
277  * Get bitmap resources
278  */
279 
280 wxBitmap CSingleQualPanel::GetBitmapResource( const wxString& name )
281 {
282  // Bitmap retrieval
283 ////@begin CSingleQualPanel bitmap retrieval
284  wxUnusedVar(name);
285  return wxNullBitmap;
286 ////@end CSingleQualPanel bitmap retrieval
287 }
288 
289 /*!
290  * Get icon resources
291  */
292 
293 wxIcon CSingleQualPanel::GetIconResource( const wxString& name )
294 {
295  // Icon retrieval
296 ////@begin CSingleQualPanel icon retrieval
297  wxUnusedVar(name);
298  return wxNullIcon;
299 ////@end CSingleQualPanel icon retrieval
300 }
301 
303 
string GetAsnPathToFieldName(const string &field, EMacroFieldType type, const string &target=kEmptyStr)
static CMacroEditorContext & GetInstance()
vector< string > GetFieldNames(EMacroFieldType type) const
static string NormalizePubFieldName(string orig_label)
static string GetLabelForType(EPubFieldType field_type)
EMacroFieldType GetMatchType() const
SFieldFromTable GetSelection() const
bool SetField(const string &field, EMacroFieldType type)
~CSingleQualPanel()
Destructor.
EMacroFieldType m_FieldType
CSingleQualPanel()
Constructors.
void OnFieldSelected(wxCommandEvent &event)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
SFieldFromTable GetField()
void OnSelectClicked(wxHyperlinkEvent &event)
bool Create(wxWindow *parent, wxWindowID id=ID_CSINGLEQUALPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
EMacroFieldType m_MatchType
void SetField(const string &first_field, int col)
wxComboBox * m_FieldFirst
wxCheckBox * m_MatchCheck
list< SFieldFromTable > m_AdditionalFields
void CreateControls()
Creates the controls and sizers.
static bool ShowToolTips()
Should we show tooltips?
bool InsertField(const string &field, int col, EMacroFieldType type, bool matching_field)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
void Init()
Initialises member variables.
static void Init(void)
Definition: cursor6.c:76
const char * kFieldTypeSeqId
#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
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
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:5412
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:5353
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
static static static wxID_ANY
Definition: type.c:6
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void ToArrayString(const vector< string > &out, wxArrayString &in)
Definition: wx_utils.cpp:353
Modified on Tue Feb 27 05:53:37 2024 by modify_doxy.py rev. 669887