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

Go to the SVN repository for this file.

1 /* $Id: sequence_goto_dlg.cpp 36594 2016-10-12 20:17:36Z evgeniev $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 
35 #include <wx/sizer.h>
36 #include <wx/stattext.h>
37 #include <wx/textctrl.h>
38 #include <wx/button.h>
39 #include <wx/bitmap.h>
40 #include <wx/icon.h>
41 #include <wx/frame.h>
42 
43 ////@begin includes
44 ////@end includes
45 
49 #include <gui/objutils/utils.hpp>
50 ////@begin XPM images
51 ////@end XPM images
52 
54 
55 /*!
56  * CSequenceGotoEvent type definition
57  */
58 
59 IMPLEMENT_DYNAMIC_CLASS(CSequenceGotoEvent, wxCommandEvent)
60 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SEQ_GOTO)
61 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SEQ_GOTO_CLOSE)
62 
63 /*!
64  * CSequenceGotoDlg type definition
65  */
66 
67 IMPLEMENT_DYNAMIC_CLASS( CSequenceGotoDlg, wxDialog )
68 
69 /*!
70  * CSequenceGotoDlg event table definition
71  */
72 
73 BEGIN_EVENT_TABLE( CSequenceGotoDlg, wxDialog )
74 
75 ////@begin CSequenceGotoDlg event table entries
77 
79 
80  EVT_BUTTON( wxID_OK, CSequenceGotoDlg::OnOkClick )
81 
82  EVT_BUTTON( wxID_CANCEL, CSequenceGotoDlg::OnCancelClick )
83 
84 ////@end CSequenceGotoDlg event table entries
85 
87 
88 
89 /*!
90  * CSequenceGotoDlg constructors
91  */
92 
94 {
95  Init();
96 }
97 
100  wxEvtHandler* eventHandler,
101  wxWindowID id, const wxString& caption,
102  const wxPoint& pos, const wxSize& size, long style )
103 {
104  m_Data = data;
105  m_EventHandler = eventHandler ? eventHandler : parent;
106  Init();
107  Create(parent, id, caption, pos, size, style);
108 }
109 
110 
111 /*!
112  * CSequenceGotoDlg creator
113  */
114 
115 bool CSequenceGotoDlg::Create( wxWindow* parent, wxWindowID id,
116  const wxString& caption, const wxPoint& pos,
117  const wxSize& size, long style )
118 {
119 ////@begin CSequenceGotoDlg creation
120  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
121  wxDialog::Create( parent, id, caption, pos, size, style );
122 
123  CreateControls();
124  if (GetSizer())
125  {
126  GetSizer()->SetSizeHints(this);
127  }
128  Centre();
129 ////@end CSequenceGotoDlg creation
130 
131  wxSize maxSize = this->GetSize();
132  maxSize.SetWidth(-1);
133  this->SetMaxSize(maxSize);
134 
135  return true;
136 }
137 
138 
139 /*!
140  * CSequenceGotoDlg destructor
141  */
142 
144 {
145 ////@begin CSequenceGotoDlg destruction
146 ////@end CSequenceGotoDlg destruction
147 }
148 
149 
150 /*!
151  * Member initialisation
152  */
153 
155 {
156 ////@begin CSequenceGotoDlg member initialisation
157  m_InputBox = NULL;
158 ////@end CSequenceGotoDlg member initialisation
159 
160  if (m_Data)
162 }
163 
164 
165 /*!
166  * Control creation for CSequenceGotoDlg
167  */
168 
170 {
171 ////@begin CSequenceGotoDlg content construction
172  CSequenceGotoDlg* itemDialog1 = this;
173 
174  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
175  itemDialog1->SetSizer(itemBoxSizer2);
176 
177  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
178  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);
179 
180  wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Sequence Position/Range:"), wxDefaultPosition, wxDefaultSize, 0 );
181  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
182 
183  m_InputBox = new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
184  itemBoxSizer3->Add(m_InputBox, 1, wxGROW|wxALL, 5);
185 
186  wxButton* itemButton6 = new wxButton( itemDialog1, wxID_OK, _("Go!"), wxDefaultPosition, wxDefaultSize, 0 );
187  itemButton6->SetDefault();
188  itemBoxSizer3->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
189 
190  wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
191  itemBoxSizer2->Add(itemBoxSizer7, 0, wxGROW|wxALL, 5);
192 
193  wxStaticText* itemStaticText8 = new wxStaticText( itemDialog1, wxID_STATIC, _("Range examples: 1000; 1000-2000; 1000..2000;\n 10,000:2,000,000; 100k:1m;\n 1000 2000; 1000[tab]2000"), wxDefaultPosition, wxDefaultSize, 0 );
194  itemBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
195 
196  itemBoxSizer7->Add(7, 8, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
197 
198  wxButton* itemButton10 = new wxButton( itemDialog1, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
199  itemBoxSizer7->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
200 
201  // Set validators
202  m_InputBox->SetValidator( CRegexpValidator("^[ \t]*[1-9][0-9,]*[ \t]*[kKmM]?((([ \t]*([-:]|\\.\\.)[ \t]*)|([ \t]+))[1-9][0-9,]*[ \t]*[kKmM]?)?[ \t]*$","1000\n1000-2000\n1000..2000\n10,000:2,000,000\n100k:1m\n1000 2000\n1000 2000" , & m_SeqPos) );
203 ////@end CSequenceGotoDlg content construction
204 }
205 
206 
207 /*!
208  * Should we show tooltips?
209  */
210 
212 {
213  return true;
214 }
215 
216 /*!
217  * Get bitmap resources
218  */
219 
220 wxBitmap CSequenceGotoDlg::GetBitmapResource( const wxString& name )
221 {
222  // Bitmap retrieval
223 ////@begin CSequenceGotoDlg bitmap retrieval
224  wxUnusedVar(name);
225  return wxNullBitmap;
226 ////@end CSequenceGotoDlg bitmap retrieval
227 }
228 
229 /*!
230  * Get icon resources
231  */
232 
233 wxIcon CSequenceGotoDlg::GetIconResource( const wxString& name )
234 {
235  // Icon retrieval
236 ////@begin CSequenceGotoDlg icon retrieval
237  wxUnusedVar(name);
238  return wxNullIcon;
239 ////@end CSequenceGotoDlg icon retrieval
240 }
241 
242 
244 {
245  m_InputBox->SetFocus();
246 }
247 
248 
249 bool CSequenceGotoDlg::Show(bool show)
250 {
251 #ifdef __WXOSX_COCOA__
252  wxFrame* f = NULL;
253  wxWindow* pp = GetParent();
254  while (f==NULL && pp !=NULL) {
255  f = dynamic_cast<wxFrame*>(pp);
256  pp = pp->GetParent();
257  }
258 
259  if (f != NULL) {
260  if (show) {
262  } else {
263  ncbi::RemoveChildWindow(f, this);
264  }
265  }
266 #endif
267  return wxWindow::Show(show);
268 }
269 
270 
271 /*!
272  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
273  */
274 
275 
276 
277 void CSequenceGotoDlg::OnOkClick( wxCommandEvent& WXUNUSED(event) )
278 {
279  if (Validate() && TransferDataFromWindow()) {
280  CSequenceGotoEvent dlgEvent(wxEVT_COMMAND_SEQ_GOTO, GetId());
281  dlgEvent.SetPositionString(m_SeqPos);
282  if (m_Data)
284  Send(dlgEvent);
285  }
286  m_InputBox->SetFocus();
287 }
288 
289 /*!
290  * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
291  */
292 
293 void CSequenceGotoDlg::OnCancelClick( wxCommandEvent& WXUNUSED(event) )
294 {
295  CSequenceGotoEvent dlgEvent(wxEVT_COMMAND_SEQ_GOTO_CLOSE, GetId());
296  Send(dlgEvent);
297 }
298 
300 {
301  m_EventHandler->ProcessEvent(event);
302 }
303 
304 
305 /*!
306  * wxEVT_CLOSE_WINDOW event handler for ID_CSEQUENCEGOTODLG
307  */
308 
309 void CSequenceGotoDlg::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
310 {
311  CSequenceGotoEvent dlgEvent(wxEVT_COMMAND_SEQ_GOTO_CLOSE, GetId());
312  Send(dlgEvent);
313 }
314 
315 
316 /*!
317  * wxEVT_COMMAND_TEXT_ENTER event handler for ID_TEXTCTRL1
318  */
319 
320 void CSequenceGotoDlg::OnTextctrl1Enter( wxCommandEvent& event )
321 {
322  OnOkClick(event);
323 }
324 
325 
326 bool CSequenceGotoData::GetRange(long& from, long& to) const
327 {
328  string pos_str = ToStdString(m_PositionStr);
329  return CSeqUtils::StringToRange(pos_str, from, to);
330 }
331 
332 
333 //bool CSequenceGotoData::GetRange(long& from, long& to) const
334 //{
335 // bool valid = false;
336 // from = to = -1;
337 // m_PositionStr.Trim(false); // trim white spaces on left side
338 // m_PositionStr.Trim(true); // trim white spaces on right side
339 // size_t len = m_PositionStr.length();
340 //
341 // if (len == 0) return valid;
342 //
343 // string pos_str;
344 // bool space = false;
345 // for (size_t i = 0; i < len; ++i) {
346 // if (m_PositionStr[i
347 // NStr::ReplaceInPlace(pos_str, ",", "");
348 // NStr::ReplaceInPlace(pos_str, "k", "000");
349 // NStr::ReplaceInPlace(pos_str, "K", "000");
350 // NStr::ReplaceInPlace(pos_str, "m", "000000");
351 // NStr::ReplaceInPlace(pos_str, "M", "000000");
352 // }
353 //
354 // typedef vector<string> TPositions;
355 // TPositions pos;
356 // NStr::Split(pos_str, "-:.", pos);
357 // if (pos.size() < 2) {
358 // // maybe space or tab is used as a separator
359 // NStr::Split(pos_str, " \t", pos);
360 // } else {
361 // NStr::ReplaceInPlace(pos_str, " ", "");
362 // NStr::ReplaceInPlace(pos_str, "\t", "");
363 // }
364 // try {
365 // bool is_from = true;
366 // ITERATE (TPositions, iter, pos) {
367 // if (iter->empty()) continue;
368 // if (is_from) {
369 // to = from = NStr::StringToLong(*iter);
370 // is_from = false;
371 // } else {
372 // to = NStr::StringToLong(*iter);
373 // }
374 // }
375 // } catch (CException&) {
376 // LOG_POST(Warning
377 // << "can't convert the input position string to integer: "
378 // << pos_str) ;
379 // }
380 //}
381 //
382 
384 
385 
void SetPositionString(const wxString &str)
const wxString & GetPositionString()
bool GetRange(long &from, long &to) const
void CreateControls()
Creates the controls and sizers.
void OnCancelClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
static bool ShowToolTips()
Should we show tooltips?
void Init()
Initialises member variables.
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnOkClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
wxEvtHandler * m_EventHandler
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
~CSequenceGotoDlg()
Destructor.
void OnCloseWindow(wxCloseEvent &event)
wxEVT_CLOSE_WINDOW event handler for ID_CSEQUENCEGOTODLG
virtual bool Show(bool show=true)
CSequenceGotoData * m_Data
void OnTextctrl1Enter(wxCommandEvent &event)
wxEVT_COMMAND_TEXT_ENTER event handler for ID_TEXTCTRL1
CSequenceGotoDlg()
Constructors.
bool Create(wxWindow *parent, wxWindowID id=ID_CSEQUENCEGOTODLG, const wxString &caption=_("Go to sequence"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
void Send(CSequenceGotoEvent &event)
void SetPositionString(const wxString &str)
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
static FILE * f
Definition: readconf.c:23
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
static bool StringToRange(const string &range_str, long &from, long &to)
Convert a range string to a range.
Definition: utils.cpp:1254
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
END_EVENT_TABLE()
const struct ncbi::grid::netcache::search::fields::SIZE size
#define ID_TEXTCTRL1
void RemoveChildWindow(wxFrame *parent, wxWindow *child)
For OSX Cocoa, removes child window connection (for layering) to parent.
Definition: wx_utils.cpp:1224
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
void AddChildWindowAbove(wxFrame *parent, wxWindow *child)
For OSX Cocoa, puts child window in front of (visually) parent.
Definition: wx_utils.cpp:1194
Modified on Fri Sep 20 14:57:29 2024 by modify_doxy.py rev. 669887