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

Go to the SVN repository for this file.

1 /* $Id: single_ref_gene_track_loc_panel.cpp 40132 2017-12-22 15:45:12Z bollin $
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>
31 ////@begin includes
32 ////@end includes
33 
38 
39 ////@begin XPM images
40 ////@end XPM images
41 
44 
45 /*!
46  * CSingleRefGeneTrackLocPanel type definition
47  */
48 
49 IMPLEMENT_DYNAMIC_CLASS( CSingleRefGeneTrackLocPanel, wxPanel )
50 
51 
52 /*!
53  * CSingleRefGeneTrackLocPanel event table definition
54  */
55 
56 BEGIN_EVENT_TABLE( CSingleRefGeneTrackLocPanel, wxPanel )
57 
58 ////@begin CSingleRefGeneTrackLocPanel event table entries
59  EVT_TEXT( ID_ACCESSION_TXT, CSingleRefGeneTrackLocPanel::OnAccessionTxtTextUpdated )
60 
62 
64 
66 
68 
69 ////@end CSingleRefGeneTrackLocPanel event table entries
70 
72 
73 
74 /*!
75  * CSingleRefGeneTrackLocPanel constructors
76  */
77 
79 {
80  Init();
81 }
82 
83 CSingleRefGeneTrackLocPanel::CSingleRefGeneTrackLocPanel( wxWindow* parent, CUser_field& field, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
84 {
85  Init();
86  m_Field = new CUser_field();
87  m_Field->Assign(field);
88  Create(parent, id, pos, size, style);
89 }
90 
91 
92 /*!
93  * CSingleRefGeneTrackLocPanel creator
94  */
95 
96 bool CSingleRefGeneTrackLocPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
97 {
98 ////@begin CSingleRefGeneTrackLocPanel creation
99  wxPanel::Create( parent, id, pos, size, style );
100 
101  CreateControls();
102  if (GetSizer())
103  {
104  GetSizer()->SetSizeHints(this);
105  }
106  Centre();
107 ////@end CSingleRefGeneTrackLocPanel creation
108  return true;
109 }
110 
111 
112 /*!
113  * CSingleRefGeneTrackLocPanel destructor
114  */
115 
117 {
118 ////@begin CSingleRefGeneTrackLocPanel destruction
119 ////@end CSingleRefGeneTrackLocPanel destruction
120 }
121 
122 
123 /*!
124  * Member initialisation
125  */
126 
128 {
129 ////@begin CSingleRefGeneTrackLocPanel member initialisation
130  m_Accession = NULL;
131  m_GI = NULL;
132  m_Start = NULL;
133  m_Stop = NULL;
134  m_Comment = NULL;
135 ////@end CSingleRefGeneTrackLocPanel member initialisation
136 }
137 
138 
139 /*!
140  * Control creation for CSingleRefGeneTrackLocPanel
141  */
142 
144 {
145 ////@begin CSingleRefGeneTrackLocPanel content construction
146  CSingleRefGeneTrackLocPanel* itemPanel1 = this;
147 
148  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
149  itemPanel1->SetSizer(itemBoxSizer2);
150 
151  m_Accession = new wxTextCtrl( itemPanel1, ID_ACCESSION_TXT, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
152  itemBoxSizer2->Add(m_Accession, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
153 
154  m_GI = new wxTextCtrl( itemPanel1, ID_GI_TXT, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
155  itemBoxSizer2->Add(m_GI, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
156 
157  m_Start = new wxTextCtrl( itemPanel1, ID_START_TXT, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
158  itemBoxSizer2->Add(m_Start, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
159 
160  m_Stop = new wxTextCtrl( itemPanel1, ID_STOP_TXT, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
161  itemBoxSizer2->Add(m_Stop, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
162 
163  m_Comment = new wxTextCtrl( itemPanel1, ID_COMMENT_TXT, wxEmptyString, wxDefaultPosition, wxSize(100, -1), 0 );
164  itemBoxSizer2->Add(m_Comment, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
165 
166 ////@end CSingleRefGeneTrackLocPanel content construction
167 }
168 
169 
171 {
172  if (!wxPanel::TransferDataToWindow())
173  return false;
174 
175  string accession = "";
176  int gi = 0;
177  int from = 0;
178  int to = 0;
179  string comment = "";
180 
181  if (m_Field->GetData().IsFields()) {
182  ITERATE(CUser_field::TData::TFields, it, m_Field->GetData().GetFields()) {
183  if ((*it)->IsSetLabel() && (*it)->GetLabel().IsStr()) {
184  const string& label = (*it)->GetLabel().GetStr();
185  if (NStr::EqualNocase(label, "accession")) {
186  if ((*it)->GetData().IsStr()) {
187  accession = (*it)->GetData().GetStr();
188  }
189  } else if (NStr::EqualNocase(label, "name")) {
190  if ((*it)->GetData().IsStr()) {
191  comment = (*it)->GetData().GetStr();
192  }
193  } else if (NStr::EqualNocase(label, "gi")) {
194  if ((*it)->GetData().IsInt()) {
195  gi = (*it)->GetData().GetInt();
196  }
197  } else if (NStr::EqualNocase(label, "from")) {
198  if ((*it)->GetData().IsInt()) {
199  from = (*it)->GetData().GetInt();
200  }
201  } else if (NStr::EqualNocase(label, "to")) {
202  if ((*it)->GetData().IsInt()) {
203  to = (*it)->GetData().GetInt();
204  }
205  }
206  }
207  }
208  }
209 
210  m_Accession->SetValue(ToWxString(accession));
211  if (gi > 0) {
212  m_GI->SetValue(ToWxString(NStr::NumericToString(gi)));
213  } else {
214  m_GI->SetValue(wxEmptyString);
215  }
216  if (from > 0) {
217  m_Start->SetValue(ToWxString(NStr::NumericToString(from)));
218  } else {
219  m_Start->SetValue(wxEmptyString);
220  }
221  if (to > 0) {
222  m_Stop->SetValue(ToWxString(NStr::NumericToString(to)));
223  } else {
224  m_Stop->SetValue(wxEmptyString);
225  }
226 
227  m_Comment->SetValue(ToWxString(comment));
228 
229  return true;
230 }
231 
232 
234 {
235  if (NStr::EqualNocase(field, "accession")
236  || NStr::EqualNocase(field, "name")
237  || NStr::EqualNocase(field, "to")
238  || NStr::EqualNocase(field, "from")
239  || NStr::EqualNocase(field, "gi")) {
240  return true;
241  } else {
242  return false;
243  }
244 }
245 
246 
248 {
249  if (!wxPanel::TransferDataFromWindow())
250  return false;
251 
252  string accession = ToStdString(m_Accession->GetValue());
253  string comment = ToStdString(m_Comment->GetValue());
254  int gi = 0;
255  int from = 0;
256  int to = 0;
257  try {
258  gi = NStr::StringToInt (ToStdString(m_GI->GetValue()));
259  } catch(CException &e) {} catch (exception &e) {}
260 
261 
262  try {
263  from = NStr::StringToInt(ToStdString(m_Start->GetValue()));
264  } catch(CException &e) {} catch (exception &e) {}
265 
266  try {
267  to = NStr::StringToInt(ToStdString(m_Stop->GetValue()));
268  } catch(CException &e) {} catch (exception &e) {}
269 
270  m_Field->SetLabel().SetId(0);
271 
272  CUser_field::TData::TFields::iterator it = m_Field->SetData().SetFields().begin();
273  while (it != m_Field->SetData().SetFields().end()) {
274  if ((*it)->IsSetLabel() && (*it)->GetLabel().IsStr() && x_IsControlled((*it)->GetLabel().GetStr())) {
275  it = m_Field->SetData().SetFields().erase(it);
276  } else {
277  ++it;
278  }
279  }
280 
281  if (!NStr::IsBlank(accession)) {
282  CRef<CUser_field> acc_field(new CUser_field());
283  acc_field->SetLabel().SetStr("accession");
284  acc_field->SetData().SetStr(accession);
285  m_Field->SetData().SetFields().push_back(acc_field);
286  }
287  if (!NStr::IsBlank(comment)) {
288  CRef<CUser_field> comment_field(new CUser_field());
289  comment_field->SetLabel().SetStr("name");
290  comment_field->SetData().SetStr(comment);
291  m_Field->SetData().SetFields().push_back(comment_field);
292  }
293  if (to > 0 && from > 0) {
294  CRef<CUser_field> from_field(new CUser_field());
295  from_field->SetLabel().SetStr("from");
296  from_field->SetData().SetInt(from);
297  m_Field->SetData().SetFields().push_back(from_field);
298  CRef<CUser_field> to_field(new CUser_field());
299  to_field->SetLabel().SetStr("to");
300  to_field->SetData().SetInt(to);
301  m_Field->SetData().SetFields().push_back(to_field);
302  }
303  if (gi > 0) {
304  CRef<CUser_field> gi_field(new CUser_field());
305  gi_field->SetLabel().SetStr("gi");
306  gi_field->SetData().SetInt(gi);
307  m_Field->SetData().SetFields().push_back(gi_field);
308  }
309 
310  return true;
311 }
312 
313 
315 {
316  CRef<CUser_field> new_field;
317  if (m_Field) {
318  new_field.Reset(new CUser_field());
319  new_field->Assign(*m_Field);
320  }
321 
322  return new_field;
323 }
324 
325 
326 /*!
327  * Should we show tooltips?
328  */
329 
331 {
332  return true;
333 }
334 
335 /*!
336  * Get bitmap resources
337  */
338 
339 wxBitmap CSingleRefGeneTrackLocPanel::GetBitmapResource( const wxString& name )
340 {
341  // Bitmap retrieval
342 ////@begin CSingleRefGeneTrackLocPanel bitmap retrieval
343  wxUnusedVar(name);
344  return wxNullBitmap;
345 ////@end CSingleRefGeneTrackLocPanel bitmap retrieval
346 }
347 
348 /*!
349  * Get icon resources
350  */
351 
352 wxIcon CSingleRefGeneTrackLocPanel::GetIconResource( const wxString& name )
353 {
354  // Icon retrieval
355 ////@begin CSingleRefGeneTrackLocPanel icon retrieval
356  wxUnusedVar(name);
357  return wxNullIcon;
358 ////@end CSingleRefGeneTrackLocPanel icon retrieval
359 }
360 
361 
362 /*!
363  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_ACCESSION_TXT
364  */
365 
367 {
368  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
369  if (NStr::IsBlank(ToStdString(item->GetValue()))) {
370  return;
371  }
372  x_OnChange();
373 }
374 
375 
376 /*!
377  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_GI_TXT
378  */
379 
381 {
382  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
383  if (NStr::IsBlank(ToStdString(item->GetValue()))) {
384  return;
385  }
386  x_OnChange();
387 }
388 
389 
390 /*!
391  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_START_TXT
392  */
393 
395 {
396  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
397  if (NStr::IsBlank(ToStdString(item->GetValue()))) {
398  return;
399  }
400  x_OnChange();
401 }
402 
403 
404 /*!
405  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_STOP_TXT
406  */
407 
409 {
410  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
411  if (NStr::IsBlank(ToStdString(item->GetValue()))) {
412  return;
413  }
414  x_OnChange();
415 }
416 
417 
418 /*!
419  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_COMMENT_TXT
420  */
421 
423 {
424  wxTextCtrl* item = (wxTextCtrl*)event.GetEventObject();
425  if (NStr::IsBlank(ToStdString(item->GetValue()))) {
426  return;
427  }
428  x_OnChange();
429 }
430 
431 
void Init()
Initialises member variables.
bool Create(wxWindow *parent, wxWindowID id=ID_CSINGLEREFGENETRACKLOCPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
static bool ShowToolTips()
Should we show tooltips?
void OnAccessionTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_ACCESSION_TXT
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void CreateControls()
Creates the controls and sizers.
void OnStopTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_STOP_TXT
void OnStartTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_START_TXT
void OnGiTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_GI_TXT
CRef< objects::CUser_field > GetUser_field()
void OnCommentTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_COMMENT_TXT
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
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
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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 int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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:5347
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
static const char label[]
vector< CRef< CUser_field > > TFields
void SetLabel(TLabel &value)
Assign a value to Label data member.
void SetData(TData &value)
Assign a value to Data data member.
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
USING_SCOPE(objects)
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Fri Sep 20 14:57:12 2024 by modify_doxy.py rev. 669887