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

Go to the SVN repository for this file.

1 /* $Id: altitude_panel.cpp 33304 2015-07-06 13:41:18Z 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: Colleen Bollin
27  */
28 
29 
30 
31 #include <ncbi_pch.hpp>
32 
33 
34 
35 ////@begin includes
36 ////@end includes
37 
40 
41 #include <wx/stattext.h>
42 #include <wx/sizer.h>
43 
44 ////@begin XPM images
45 ////@end XPM images
46 
48 
49 /*
50  * CAltitudePanel type definition
51  */
52 
53 IMPLEMENT_DYNAMIC_CLASS( CAltitudePanel, CSrcModEditPanel )
54 
55 
56 /*
57  * CAltitudePanel event table definition
58  */
59 
60 BEGIN_EVENT_TABLE( CAltitudePanel, CSrcModEditPanel )
61 
62 ////@begin CAltitudePanel event table entries
64 
65 ////@end CAltitudePanel event table entries
66 
68 
69 
70 /*
71  * CAltitudePanel constructors
72  */
73 
75 {
76  Init();
77 }
78 
79 CAltitudePanel::CAltitudePanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
81 {
82  Init();
83  Create(parent, id, pos, size, style);
84 }
85 
86 
87 /*
88  * CAltitudePanel creator
89  */
90 
91 bool CAltitudePanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
92 {
93 ////@begin CAltitudePanel creation
94  CSrcModEditPanel::Create( parent, id, pos, size, style );
95 
97  if (GetSizer())
98  {
99  GetSizer()->SetSizeHints(this);
100  }
101  Centre();
102 ////@end CAltitudePanel creation
103  return true;
104 }
105 
106 
107 /*
108  * CAltitudePanel destructor
109  */
110 
112 {
113 ////@begin CAltitudePanel destruction
114 ////@end CAltitudePanel destruction
115 }
116 
117 
118 /*
119  * Member initialisation
120  */
121 
123 {
124 ////@begin CAltitudePanel member initialisation
125  m_Text = NULL;
126 ////@end CAltitudePanel member initialisation
127 }
128 
129 
130 /*
131  * Control creation for CAltitudePanel
132  */
133 
135 {
136 ////@begin CAltitudePanel content construction
137  CAltitudePanel* itemCSrcModEditPanel1 = this;
138 
139  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
140  itemCSrcModEditPanel1->SetSizer(itemBoxSizer2);
141 
142  m_Text = new wxTextCtrl( itemCSrcModEditPanel1, ID_ALTITUDE_TXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
143  itemBoxSizer2->Add(m_Text, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
144 
145  wxStaticText* itemStaticText4 = new wxStaticText( itemCSrcModEditPanel1, wxID_STATIC, _("meters"), wxDefaultPosition, wxDefaultSize, 0 );
146  itemBoxSizer2->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0);
147 
148 ////@end CAltitudePanel content construction
149 }
150 
151 
152 /*
153  * Should we show tooltips?
154  */
155 
157 {
158  return true;
159 }
160 
161 /*
162  * Get bitmap resources
163  */
164 
165 wxBitmap CAltitudePanel::GetBitmapResource( const wxString& name )
166 {
167  // Bitmap retrieval
168 ////@begin CAltitudePanel bitmap retrieval
169  wxUnusedVar(name);
170  return wxNullBitmap;
171 ////@end CAltitudePanel bitmap retrieval
172 }
173 
174 /*
175  * Get icon resources
176  */
177 
178 wxIcon CAltitudePanel::GetIconResource( const wxString& name )
179 {
180  // Icon retrieval
181 ////@begin CAltitudePanel icon retrieval
182  wxUnusedVar(name);
183  return wxNullIcon;
184 ////@end CAltitudePanel icon retrieval
185 }
186 
187 
189 {
190  string val = ToStdString(m_Text->GetValue());
191  if (NStr::IsBlank(val)) {
192  return val;
193  }
194  string check = val + " m.";
195  string number = "";
196  if (x_GetNumber(check, number)) {
197  return check;
198  } else if (x_GetNumber(val, number)) {
199  check = number + " m.";
200  return check;
201  } else {
202  return val;
203  }
204 }
205 
206 
207 void CAltitudePanel::SetValue(const string& val)
208 {
209  string number = "";
210  if (x_GetNumber(val, number)) {
211  m_Text->SetValue(number);
212  } else {
213  m_Text->SetValue(val);
214  }
215 
216 }
217 
218 
219 bool CAltitudePanel::IsWellFormatted(const string& val)
220 {
221  string number = "";
222  return x_GetNumber (val, number);
223 }
224 
225 
226 /*
227  * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_ALTITUDE_TXT
228  */
229 
230 void CAltitudePanel::OnAltitudeTxtTextUpdated( wxCommandEvent& event )
231 {
232  x_NotifyParent();
233 }
234 
235 
236 bool CAltitudePanel::x_GetNumber(const string& input, string& number)
237 {
238  number = "";
239  if (NStr::IsBlank(input)) {
240  return true;
241  }
242 
243  string cpy = input;
244  size_t pos = 0;
245  if (NStr::StartsWith(input, "-")) {
246  cpy = input.substr(1);
247  pos++;
248  }
249  bool any_digit = false;
250  string::iterator sit = cpy.begin();
251  while (sit != cpy.end() && isdigit(*sit)) {
252  any_digit = true;
253  ++sit;
254  pos++;
255  }
256 
257  if (sit != cpy.end() && *sit == '.') {
258  ++sit;
259  pos++;
260  while (sit != cpy.end() && isdigit(*sit)) {
261  any_digit = true;
262  ++sit;
263  pos++;
264  }
265  }
266 
267  if (!any_digit) {
268  return false;
269  }
270  while (sit != cpy.end() && isspace(*sit)) {
271  ++sit;
272  pos++;
273  }
274 
275  if (sit == cpy.end()) {
276  return false;
277  }
278  string units = input.substr(pos);
279  if (NStr::Equal(units, "m")
280  || NStr::Equal(units, "m.")
281  || NStr::Equal(units, "meters")
282  || NStr::Equal(units, "metres")) {
283  number = input.substr(0, pos - 1);
284  return true;
285  } else {
286  return false;
287  }
288 }
289 
290 
292 
293 
#define ID_ALTITUDE_TXT
wxTextCtrl * m_Text
static bool ShowToolTips()
Should we show tooltips?
void Init()
Initialises member variables.
bool x_GetNumber(const string &input, string &number)
~CAltitudePanel()
Destructor.
virtual bool IsWellFormatted(const string &val)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CAltitudePanel()
Constructors.
virtual string GetValue()
void CreateControls()
Creates the controls and sizers.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
bool Create(wxWindow *parent, wxWindowID id=10014, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
virtual void SetValue(const string &val)
void OnAltitudeTxtTextUpdated(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_UPDATED event handler for ID_ALTITUDE_TXT
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define check(s)
Definition: describecol2.c:21
#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 bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
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 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:5384
END_EVENT_TABLE()
static int input()
const struct ncbi::grid::netcache::search::fields::SIZE size
int isspace(Uchar c)
Definition: ncbictype.hpp:69
int isdigit(Uchar c)
Definition: ncbictype.hpp:64
static BOOL number
Definition: pcregrep.c:193
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Mon Feb 26 04:02:43 2024 by modify_doxy.py rev. 669887