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

Go to the SVN repository for this file.

1 /* $Id: taxtree_testdlg.cpp 47107 2022-08-09 14:20:12Z 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:
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <wx/bitmap.h>
33 #include <wx/icon.h>
34 #include <wx/sizer.h>
35 #include <wx/stattext.h>
36 #include <wx/button.h>
37 #include <wx/dialog.h>
38 #include <wx/textctrl.h>
39 
40 
41 
48 
50 #include <objmgr/scope.hpp>
52 
55 
57 #include <algorithm>
58 #include <stack>
59 
60 
61 ////@begin includes
62 #include "wx/imaglist.h"
63 ////@end includes
64 
65 #include "taxtree_testdlg.hpp"
66 
67 ////@begin XPM images
68 ////@end XPM images
69 
70 
73 
74 
75 /*!
76  * CTaxTreeTestDlg type definition
77  */
78 
79 IMPLEMENT_DYNAMIC_CLASS( CTaxTreeTestDlg, wxDialog )
80 
81 
82 /*!
83  * CTaxTreeTestDlg event table definition
84  */
85 
86 BEGIN_EVENT_TABLE( CTaxTreeTestDlg, wxDialog )
87 
88 ////@begin CTaxTreeTestDlg event table entries
90 
92 
93 ////@end CTaxTreeTestDlg event table entries
94 
96 
97 
98 /*!
99  * CTaxTreeTestDlg constructors
100  */
101 
103 {
104  Init();
105 }
106 
107 CTaxTreeTestDlg::CTaxTreeTestDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
108 {
109  Init();
110  Create(parent, id, caption, pos, size, style);
111 }
112 
113 
114 /*!
115  * CTaxTreeTestDlg creator
116  */
117 
118 bool CTaxTreeTestDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
119 {
120 ////@begin CTaxTreeTestDlg creation
121  SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
122  wxDialog::Create( parent, id, caption, pos, size, style );
123 
124  CreateControls();
125  if (GetSizer())
126  {
127  GetSizer()->SetSizeHints(this);
128  }
129  Centre();
130 ////@end CTaxTreeTestDlg creation
131  return true;
132 }
133 
134 
135 /*!
136  * CTaxTreeTestDlg destructor
137  */
138 
140 {
141 ////@begin CTaxTreeTestDlg destruction
142 ////@end CTaxTreeTestDlg destruction
143 }
144 
145 
146 /*!
147  * Member initialisation
148  */
149 
151 {
152 ////@begin CTaxTreeTestDlg member initialisation
153  m_Input = NULL;
154  m_Tree = NULL;
155 ////@end CTaxTreeTestDlg member initialisation
156 }
157 
158 
159 /*!
160  * Control creation for CTaxTreeTestDlg
161  */
162 
164 {
165 ////@begin CTaxTreeTestDlg content construction
166  CTaxTreeTestDlg* itemDialog1 = this;
167 
168  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
169  itemDialog1->SetSizer(itemBoxSizer2);
170 
171  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
172  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 5);
173 
174  m_Input = new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
175  itemBoxSizer3->Add(m_Input, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
176 
177  wxButton* itemButton5 = new wxButton( itemDialog1, ID_BUTTON1, _("Submit Query"), wxDefaultPosition, wxDefaultSize, 0 );
178  itemBoxSizer3->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
179 
180  wxButton* itemButton6 = new wxButton( itemDialog1, ID_BUTTON2, _("Show Related"), wxDefaultPosition, wxDefaultSize, 0 );
181  itemBoxSizer3->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
182 
183  m_Tree = new CTaxTreeBrowser( itemDialog1, ID_TREECTRL, wxDefaultPosition, wxSize(-1, 200), wxTR_SINGLE );
184  itemBoxSizer2->Add(m_Tree, 1, wxGROW|wxALL, 5);
185 
186  wxStaticLine* itemStaticLine8 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
187  itemBoxSizer2->Add(itemStaticLine8, 0, wxGROW|wxALL, 5);
188 
189  wxStdDialogButtonSizer* itemStdDialogButtonSizer9 = new wxStdDialogButtonSizer;
190 
191  itemBoxSizer2->Add(itemStdDialogButtonSizer9, 0, wxALIGN_RIGHT|wxALL, 5);
192  wxButton* itemButton10 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
193  itemStdDialogButtonSizer9->AddButton(itemButton10);
194 
195  wxButton* itemButton11 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
196  itemStdDialogButtonSizer9->AddButton(itemButton11);
197 
198  itemStdDialogButtonSizer9->Realize();
199 
200 ////@end CTaxTreeTestDlg content construction
201 }
202 
203 
204 /*!
205  * Should we show tooltips?
206  */
207 
209 {
210  return true;
211 }
212 
213 /*!
214  * Get bitmap resources
215  */
216 
217 wxBitmap CTaxTreeTestDlg::GetBitmapResource( const wxString& name )
218 {
219  // Bitmap retrieval
220 ////@begin CTaxTreeTestDlg bitmap retrieval
221  wxUnusedVar(name);
222  return wxNullBitmap;
223 ////@end CTaxTreeTestDlg bitmap retrieval
224 }
225 
226 /*!
227  * Get icon resources
228  */
229 
230 wxIcon CTaxTreeTestDlg::GetIconResource( const wxString& name )
231 {
232  // Icon retrieval
233 ////@begin CTaxTreeTestDlg icon retrieval
234  wxUnusedVar(name);
235  return wxNullIcon;
236 ////@end CTaxTreeTestDlg icon retrieval
237 }
238 
239 
240 
241 /*!
242  * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
243  */
244 
245 void CTaxTreeTestDlg::OnSubmitClick( wxCommandEvent& event )
246 {
247  string query = m_Input->GetValue().ToStdString();
248  if (query.empty()) {
249  return;
250  }
251 
252  //
253  // prepare the Entrez query
254  //
256  req.SetReturn_UIDs(true);
257  CEntrez2_boolean_exp& exp = req.SetQuery();
258 
259  // set the database we're querying
260  exp.SetDb().Set("nucleotide");
261 
262  // set the query
264  elem->SetStr(query);
265  exp.SetExp().push_back(elem);
266 
267  // set some limits - if num > 0, we assume it's correct
269  try {
270  // now, submit our query. this gets us the UIDs we want
271  query_res = x_GetClient().AskEval_boolean(req);
272 
273  const CEntrez2_id_list& ids = query_res->GetUids();
274  vector<int> uids;
275  uids.reserve(ids.GetNum());
276 
277  _TRACE("query: " << query << " UIDs: " << ids.GetNum());
279  seq_ids.reserve(uids.size());
280 
282  for (size_t i = 0; i < ids.GetNum(); ++i, ++iter) {
283  uids.push_back(*iter);
284 
285  CRef<CSeq_id> id(new CSeq_id());
286  id->SetGi(GI_FROM(CEntrez2_id_list::TUid, *iter));
287  seq_ids.push_back(id);
288  }
289 
290  if ( !m_ObjMgr ) {
293  m_Scope.Reset(new CScope(*m_ObjMgr));
294  m_Scope->AddDefaults();
295  }
296 
298 
299  // m_DataSource.Reset(new CTaxTreeDS_Entrez2(uids));
300 
302  m_Tree->ExpandAll();
303  // m_Tree->SetGis(uids);
304  }
305  catch (const CException& e) {
306  LOG_POST(Info << "exception: " << e.what());
307  LOG_POST(Info << "query failed; reconnecting...");
308  }
309 
310 // event.Skip();
311 }
312 
313 
314 void CTaxTreeTestDlg::OnRelatedClick( wxCommandEvent& event )
315 {
317  m_Tree->GetSelectedUids(gis);
318  if (gis.size() != 1) {
319  NcbiMessageBox("Please select one and only one sequence");
320  return;
321  }
322 
323  //CStatusBarGuard LOCK(*m_StatusBar, "Submitting query...");
324 
325  auto gi = gis.front()->GetGi();
326  vector <CEntrez2Client::TUid> gis_n;
327  x_GetClient().GetNeighbors(GI_TO(CEntrez2_id_list::TUid, gi), "nucleotide", "nucleotide_nucleotide",
328  gis_n);
329 
330  NcbiMessageBox("Found " +
331  NStr::NumericToString(gis_n.size()) +
332  " related sequences");
333 
334  }
335 
337 {
338  if ( !m_Client ) {
340  }
341  return *m_Client;
342 }
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CEntrez2_boolean_element –.
CEntrez2_boolean_exp –.
CEntrez2_eval_boolean –.
TConstUidIterator GetConstUidIterator() const
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
CRef –.
Definition: ncbiobj.hpp:618
CScope –.
Definition: scope.hpp:92
class CTaxTreeBrowser implements a tree-based view of a taxonomic hierarchy.
Definition: tax_tree.hpp:73
void SetDataSource(CTaxTreeDataSource &ds)
set the data source for this widget
Definition: tax_tree.cpp:176
void GetSelectedUids(CTaxTreeDataSource::TUidVec &uids) const
retrieve the selected UIDs
Definition: tax_tree.cpp:245
vector< TUid > TUidVec
Definition: tax_tree_ds.hpp:63
void OnSubmitClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON1
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
CRef< objects::CEntrez2Client > m_Client
CTaxTreeTestDlg()
Constructors.
void Init()
Initialises member variables.
CTaxTreeBrowser * m_Tree
CRef< objects::CScope > m_Scope
void OnRelatedClick(wxCommandEvent &event)
wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON2
CRef< CTaxTreeDataSource > m_DataSource
void CreateControls()
Creates the controls and sizers.
static bool ShowToolTips()
Should we show tooltips?
bool Create(wxWindow *parent, wxWindowID id=ID_CTAXTREETESTDLG, const wxString &caption=_("Taxonomy Tree Test Dialog"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX|wxTAB_TRAVERSAL)
Creation.
objects::CEntrez2Client & x_GetClient()
wxTextCtrl * m_Input
CRef< objects::CObjectManager > m_ObjMgr
~CTaxTreeTestDlg()
Destructor.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
#define _(proto)
Definition: ct_nlmzip_i.h:78
#define ID_BUTTON1
#define ID_BUTTON2
static void Init(void)
Definition: cursor6.c:76
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
#define NULL
Definition: ncbistd.hpp:225
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
Definition: message_box.cpp:48
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create 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 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
void SetDb(const TDb &value)
Assign a value to Db data member.
TNum GetNum(void) const
Get the Num member data.
void SetReturn_UIDs(TReturn_UIDs value)
Assign a value to Return_UIDs data member.
TExp & SetExp(void)
Assign a value to Exp data member.
void SetQuery(TQuery &value)
Assign a value to Query data member.
END_EVENT_TABLE()
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
The Object manager core.
static string query
USING_SCOPE(ncbi::objects)
Modified on Mon May 13 04:38:44 2024 by modify_doxy.py rev. 669887