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

Go to the SVN repository for this file.

1 /* $Id: seq_text_demo_dlg.cpp 38348 2017-04-27 14:54:37Z ivanov $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbistd.hpp>
34 #include <corelib/ncbitime.hpp>
35 
36 #include "seq_text_demo_dlg.hpp"
37 
40 
41 // Register commands
45 
47 
49 
50 #include <serial/objistr.hpp>
51 #include <serial/serial.hpp>
52 
53 
54 #include <wx/msgdlg.h>
55 #include <wx/statline.h>
56 #include <wx/sizer.h>
57 #include <wx/textctrl.h>
58 #include <wx/button.h>
59 #include <wx/bitmap.h>
60 #include <wx/icon.h>
61 
62 
65 
66 IMPLEMENT_DYNAMIC_CLASS( CSeqTextDemoDlg, wxDialog )
67 
68 BEGIN_EVENT_TABLE( CSeqTextDemoDlg, wxDialog )
69 
70 ////@begin CSeqTextDemoDlg event table entries
71  EVT_CLOSE( CSeqTextDemoDlg::OnCloseWindow )
72  EVT_BUTTON( ID_ACC, CSeqTextDemoDlg::OnAccClick )
73  EVT_BUTTON( ID_FILE, CSeqTextDemoDlg::OnFileClick )
74  EVT_BUTTON( wxID_CLOSE, CSeqTextDemoDlg::OnCloseClick )
75 ////@end CSeqTextDemoDlg event table entries
77 
78 
79 CSeqTextDemoDlg::CSeqTextDemoDlg()
80 {
81  Init();
82 }
83 
84 
85 CSeqTextDemoDlg::CSeqTextDemoDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
86 {
87  Init();
88  Create(parent, id, caption, pos, size, style);
89 }
90 
91 
92 bool CSeqTextDemoDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
93 {
94 ////@begin CSeqTextDemoDlg creation
95  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
96  wxDialog::Create( parent, id, caption, pos, size, style );
97 
99  Centre();
100 ////@end CSeqTextDemoDlg creation
101  return true;
102 }
103 
104 
106 {
107 ////@begin CSeqTextDemoDlg destruction
108 ////@end CSeqTextDemoDlg destruction
109 }
110 
111 
113 {
114 ////@begin CSeqTextDemoDlg member initialisation
116  m_AccInput = NULL;
117  m_FileInput = NULL;
118 ////@end CSeqTextDemoDlg member initialisation
119 
120  if ( !m_ObjMgr ) {
123 
124  m_Scope.Reset(new CScope(*m_ObjMgr));
125  m_Scope->AddDefaults();
126  }
127 
128  // configure our GBench registry
129  {{
131 
132  string gbench_cfg = reg.GetString("filesystem",
133  "GBenchRegistry",
134  "plugin_config.asn");
135  CNcbiIfstream istr(gbench_cfg.c_str());
136  if (istr) {
138  }
139  }}
140 
143  WidgetsWx_RegisterCommands(cmd_reg, *provider);
144 }
145 
146 
148 {
149 ////@begin CSeqTextDemoDlg content construction
150  CSeqTextDemoDlg* itemDialog1 = this;
151 
152  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
153  itemDialog1->SetSizer(itemBoxSizer2);
154 
155  m_SeqTextWidget = new CSeqTextWidget( itemDialog1, ID_WIDGET, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
156  itemBoxSizer2->Add(m_SeqTextWidget, 1, wxGROW|wxALL, 5);
157 
158  wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
159  itemBoxSizer2->Add(itemBoxSizer4, 0, wxGROW|wxALL, 5);
160 
161  wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(2, 2, 0, 0);
162  itemFlexGridSizer5->AddGrowableCol(0);
163  itemBoxSizer4->Add(itemFlexGridSizer5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 0);
164 
165  m_AccInput = new wxTextCtrl( itemDialog1, ID_ACC_TEXT, _(""), wxDefaultPosition, wxDefaultSize, 0 );
166  m_AccInput->SetMaxLength(20);
167  m_AccInput->SetHelpText(_("Enter Accession"));
169  m_AccInput->SetToolTip(_("Enter Accession"));
170  itemFlexGridSizer5->Add(m_AccInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
171 
172  wxButton* itemButton7 = new wxButton( itemDialog1, ID_ACC, _("Load Accession"), wxDefaultPosition, wxDefaultSize, 0 );
173  itemFlexGridSizer5->Add(itemButton7, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
174 
175  m_FileInput = new wxTextCtrl( itemDialog1, ID_FILE_TEXT, _(""), wxDefaultPosition, wxDefaultSize, 0 );
176  m_FileInput->SetMaxLength(256);
177  m_FileInput->SetHelpText(_("Enter asn file name"));
179  m_FileInput->SetToolTip(_("Enter asn file name"));
180  itemFlexGridSizer5->Add(m_FileInput, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
181 
182  wxButton* itemButton9 = new wxButton( itemDialog1, ID_FILE, _("Load File"), wxDefaultPosition, wxDefaultSize, 0 );
183  itemFlexGridSizer5->Add(itemButton9, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
184 
185  wxStaticLine* itemStaticLine10 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
186  itemBoxSizer4->Add(itemStaticLine10, 0, wxGROW|wxALL, 5);
187 
188  wxButton* itemButton11 = new wxButton( itemDialog1, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
189  itemBoxSizer4->Add(itemButton11, 0, wxALIGN_BOTTOM|wxALL, 5);
190 
191 ////@end CSeqTextDemoDlg content construction
192 
193  wxString path = CSysPath::ResolvePathExisting(wxT("<std>/gbench/etc/plugin_config.asn"));
194  if (!path.empty()) {
195  CNcbiIfstream istr(path.fn_str());
196  if (istr)
198  }
199 
201 }
202 
203 
205 {
206  return true;
207 }
208 
209 
210 wxBitmap CSeqTextDemoDlg::GetBitmapResource( const wxString& name )
211 {
212  // Bitmap retrieval
213 ////@begin CSeqTextDemoDlg bitmap retrieval
214  wxUnusedVar(name);
215  return wxNullBitmap;
216 ////@end CSeqTextDemoDlg bitmap retrieval
217 }
218 
219 
220 wxIcon CSeqTextDemoDlg::GetIconResource( const wxString& name )
221 {
222  // Icon retrieval
223 ////@begin CSeqTextDemoDlg icon retrieval
224  wxUnusedVar(name);
225  return wxNullIcon;
226 ////@end CSeqTextDemoDlg icon retrieval
227 }
228 
229 
230 
231 void CSeqTextDemoDlg::OnCloseWindow(wxCloseEvent& /*event*/)
232 {
233  Destroy();
234 }
235 
236 
237 
238 void CSeqTextDemoDlg::OnCloseClick( wxCommandEvent& /*event*/ )
239 {
240  Close();
241 }
242 
243 
244 
245 void CSeqTextDemoDlg::OnAccClick( wxCommandEvent& /*event*/ )
246 {
247  CSeq_id id;
248 
249  string acc = ToStdString(m_AccInput->GetValue());
250  try {
251  id.Set(acc);
252  }
253  catch (CSeqIdException&) {
254  wxString msg(_("Accession '"));
255  msg += ToWxString(acc) + _(" not recognized as a valid accession");
256  wxMessageBox(msg, _("Cannot load accesion"),
257  wxOK | wxICON_ERROR);
258  return;
259  }
260 
261  // retrieve our sequence
262  CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
263  if(handle) {
266 
267  } else {
268  wxString msg = _("Can't find sequence for accession '");
269  msg += ToWxString(acc) + _("'");
270  wxMessageBox(msg, _("Cannot load accesion"),
271  wxOK | wxICON_ERROR);
272  return;
273  }
274 }
275 
276 
277 void CSeqTextDemoDlg::OnFileClick( wxCommandEvent& /*event*/ )
278 {
279  wxString filename = m_FileInput->GetValue();
280  CNcbiIfstream istr(filename.fn_str());
281  auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_AsnText, istr));
282 
283  CRef<CSeq_entry> sep(new CSeq_entry());
284  *is >> *sep;
285 
286  if ( !m_ObjMgr ) {
289 
290  m_Scope.Reset(new CScope(*m_ObjMgr));
291  m_Scope->AddDefaults();
292  }
293 
295 
297 
298 }
299 
300 
CBioseq_Handle –.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
static const unsigned char msg[]
Definition: ccm.c:378
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:1124
#define ID_WIDGET
void Init()
Initialises member variables.
END_EVENT_TABLE()
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxString ToWxString(const char *s)
Definition: wx_utils.hpp:157
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:461
ASN.1 text.
Definition: serialdef.hpp:73
virtual void SetDataSource(CSeqTextDataSource &ds)
string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
CRef< CSeqTextDataSource > m_DataSource
void OnCloseClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CLOSE
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:99
#define NULL
Definition: ncbistd.hpp:225
~CSeqTextDemoDlg()
Destructor.
class CSeqTextWidget
wxTextCtrl * m_AccInput
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:185
Defines: CTimeFormat - storage class for time format.
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:243
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:192
bool Create(wxWindow *parent, wxWindowID id=10000, const wxString &caption=_("CSeqTextDemoDlg"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(600, 600), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|0x1000)
Creation.
CSeqTextDataSource implements Adapter design pattern.
CRef< CRegistryFile > AddSite(CNcbiIstream &istr, int priority)
Add a site-specific repository.
Definition: registry.cpp:98
CSeqTextWidget * m_SeqTextWidget
CRef< CScope > m_Scope
static bool ShowToolTips()
Should we show tooltips?
void WidgetsWx_RegisterCommands(CUICommandRegistry &cmd_reg, wxFileArtProvider &provider)
Register standard commands defined in this file and wxWidgets headers.
Definition: commands.cpp:46
#define ID_FILE_TEXT
CSeqTextDemoDlg()
Constructors.
int size
#define ID_ACC
wxTextCtrl * m_FileInput
void CreateControls()
Creates the controls and sizers.
CScope –.
Definition: scope.hpp:90
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
Definition: ncbiapp.hpp:696
static CUICommandRegistry & GetInstance()
the main instance associated with the application
Definition: ui_command.cpp:176
Definition: Seq_entry.hpp:55
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void OnAccClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ACC
static void Init(void)
Definition: cursor6.c:79
CRef< CObjectManager > m_ObjMgr
#define wxT(x)
Definition: muParser.cpp:41
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CNcbiRegistry –.
Definition: ncbireg.hpp:904
CSeqIdException –.
Definition: Seq_id.hpp:714
void OnFileClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FILE
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:245
USING_SCOPE(objects)
static wxString ResolvePathExisting(const wxString &path, const wxString &delim=wxT(","))
Utility function to hide the platform specifics of locating our standard directories.
Definition: sys_path.cpp:142
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:145
CUICommandRegistry is a centralized registry where all application commands should be registered...
Definition: ui_command.hpp:145
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void OnCloseWindow(wxCloseEvent &event)
wxEVT_CLOSE_WINDOW event handler for ID_HIT_MATRIX_DEMO_DLG
virtual void Create()
creates controls and performs basic initialization
#define ID_FILE
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:756
#define ID_ACC_TEXT
Modified on Tue Jul 25 19:56:43 2017 by modify_doxy.py rev. 533848