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

Go to the SVN repository for this file.

1 /* $Id: search_form_base.cpp 39745 2017-10-31 21:21:36Z katargir $
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 
37 
40 
42 
45 
46 #include <wx/sizer.h>
47 #include <wx/srchctrl.h>
48 #include <wx/choice.h>
49 
52 
53 ///////////////////////////////////////////////////////////////////////////////
54 /// CSearchFormBase
55 
56 #define DICTIONARY_MAX_SIZE 50
57 
58 CSearchControl::CSearchControl (wxWindow* parent, wxWindowID id, const wxString& value,
59  const wxPoint& pos, const wxSize& size,
60  long style, const wxValidator& validator,
61  const wxString& name)
62  : CAutoCompleteCombo(parent, id, value, pos, size, wxArrayString(), style, validator, name)
63  , m_MaxSize(DICTIONARY_MAX_SIZE)
64  , m_bDoSelectAll(false)
65  , m_bIgnoreNextTextEdit(false)
66  , m_pDict(NULL)
67 {
68 }
69 
70 CSearchControl::CSearchControl(wxWindow *parent, wxWindowID id,
71  const wxPoint& pos,
72  const wxSize& size,
73  long style,
74  const wxValidator& validator,
75  const wxString& name)
76  : CAutoCompleteCombo(parent, id, wxT(""), pos, size, wxArrayString(), style, validator, name)
77  , m_MaxSize(DICTIONARY_MAX_SIZE)
78  , m_bDoSelectAll(false)
79  , m_bIgnoreNextTextEdit(false)
80  , m_pDict(NULL)
81 {
82 }
83 
84 class StringCmp
85 {
86 public:
87  string m_Str;
88 
89  StringCmp(string str) {m_Str = str;}
90 
91  bool operator()(string str)
92  {
93  return str.find(m_Str) == 0;
94  }
95 };
96 
97 void CSearchControl::SetDictionary(list<string> * dict)
98 {
99  m_pDict = dict;
100 
101  wxArrayString items;
102  ITERATE (list<string>, str, *m_pDict) {
103  items.Add(ToWxString(*str));
104  }
105  SetBaseItems(items);
106 }
107 
109 {
110  if (m_pDict) {
111  while (m_pDict->size() >= m_MaxSize) {
112  m_pDict->pop_back();
113  if (GetCount()) Delete(0);
114  }
115  string value = ToStdString(GetValue());
116  if (value.size() && (find(m_pDict->begin(), m_pDict->end(), value)==m_pDict->end())) {
117  m_pDict->push_front(value);
118  Append(GetValue());
119  }
120  //m_pDict->unique();
121  }
122 }
123 
124 ///////////////////////////////////////////////////////////////////////////////
125 /// CSearchFormBase
127 : m_ActiveContext(NULL),
128  m_Controller(NULL),
129  m_Sizer(NULL),
130  m_Text(NULL),
131  m_bRange(false)
132 {
133 
134  const CFeatList* feat_list = CSeqFeatData::GetFeatList();
135  ITERATE(CFeatList, ft_it, *feat_list) {
136  const CFeatListItem& item = *ft_it;
137  string desc = item.GetDescription();
138  int feat_type = item.GetType();
139 
140  if (feat_type == CSeqFeatData::e_Rna ||
141  feat_type == CSeqFeatData::e_Gene ||
142  feat_type == CSeqFeatData::e_Cdregion) {
143  m_FeatTypesSet.insert(item);
144  }
145  }
146 }
147 
148 
150 {
151 }
152 
153 
155 {
156  m_Controller = controller;
157 }
158 
160 {
161  if (m_Text) {
162  m_Text->Push();
163  }
164 }
165 
167 {
168  m_bRange = bLimit;
169 }
170 
171 
172 wxSizer* CSearchFormBase::GetWidget(wxWindow * parent)
173 {
174  return NULL;
175 }
176 
177 
179 {
181  return ref;
182 }
183 
184 
185 /// updates m_ContextCombo
187 {
188  m_ActiveContext = 0;
189 
190  m_Contexts.clear();
191 
193  if(srv) {
194  /// create a list of compatible contexts
195  vector<string> context_names;
196 
197  /// Add "Active" Context
198  IDataMiningContext* act_context = srv->GetLastActiveContext();
199  bool ok = false;
200 
201  if (act_context) {
202  ok = x_GetTool()->IsCompatible(act_context);
203  if (ok) {
204  m_ActiveContext = act_context;
205  }
206  }
207 
208  /// now add all the compatible contexts
209  vector<IDataMiningContext*> all_contexts;
210  srv->GetContexts(all_contexts);
211 
212  for( size_t i = 0; i < all_contexts.size(); i++ ) {
213  IDataMiningContext* ctx = all_contexts[i];
215  if(ok) {
216  m_Contexts.push_back(ctx);
217  //string name = ctx->GetDMContextName();
218  //context_names.push_back(name);
219  }
220  }
221 
222  /// initilize the ComboBox with the list of context names
223  // DDX_ComboBox(m_ContextCombo, context_names, eDDX_Set);
224  }
225 
226  bool bEnable = false;
227 
228  ITERATE(TContexts, cont, m_Contexts) {
229  ISeqLocSearchContext* seq_ctx =
230  dynamic_cast<ISeqLocSearchContext*>(*cont);
231  if (seq_ctx && !seq_ctx->GetSearchLoc().Empty()){
232  bEnable=true;
233  break;
234  }
235  }
236  if (m_Controller) {
237  m_Controller->OnSearchEnabled(bEnable);
238  }
239 }
240 
242 {
243  combo->Clear();
244 
245  combo->Append(wxT("All Searchable Contexts (") +
247  wxT(" available)"));
248  combo->Select(0);
249 
250  for( size_t i = 0; i < m_Contexts.size(); i++ ) {
251  if (m_Contexts[i]) {
252  string cname = m_Contexts[i]->GetDMContextName();
253  if (cname.length() > 40) {
254  cname = cname.substr(0, 40) + "...";
255  }
256  combo->Append(ToWxString(cname));
257 
258  if (m_ActiveContext && (m_ActiveContext->GetDMContextName() == m_Contexts[i]->GetDMContextName())) {
259  combo->Select((int)(i+1));
260  }
261  }
262  }
263 }
264 
265 /// TODO this function should be here - it should be move the the form
266 /// that needs this dialog
267 
268 /// popup a dialog for additional info
270 {
271  switch (dt) {
275  dlg.SetSelected(m_FeatTypesSet); //default values
276  dlg.ShowModal();
278  break;
279  }
280 }
281 
282 
283 void CSearchFormBase::SetDictionary(list<string> * ddd)
284 {
285  if (m_Text) {
286  m_Text->SetDictionary(ddd);
287  }
288 }
289 
290 
291 void CSearchFormBase::SetRegistryPath(const string& reg_path)
292 {
293  m_RegPath = reg_path;
294 }
295 
296 
298 {
299  if (!m_RegPath.empty())
301 }
302 
303 
305 {
306  if (!m_RegPath.empty())
308 }
309 
310 
312 {
313  return m_Text ? ToStdString(m_Text->GetValue()) : string("#empty#");
314 }
315 
317 {
318  if (m_Text) {
319  wxString wVal = ToWxString(val);
320  if (wVal != m_Text->GetValue())
321  m_Text->SetValue(wVal);
322  }
323 }
324 
325 
CAutoCompleteComboBox.
void SetBaseItems(const wxArrayString &choices)
CDataMiningService.
virtual IDataMiningContext * GetLastActiveContext()
virtual void GetContexts(TContexts &contexts)
CFeatListItem - basic configuration data for one "feature" type.
string GetDescription() const
int GetType() const
CConfigurableItems - a static list of items that can be configured.
void SetRegistryPath(const string &rpath)
void GetSelected(TFeatTypeItemSet &feat_types)
void SetSelected(TFeatTypeItemSet &feat_types)
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
void SetDictionary(list< string > *dict)
list< string > * m_pDict
CSearchControl(wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxSearchCtrlNameStr)
virtual CIRef< IDMSearchQuery > ConstructQuery()
virtual void Push()
virtual wxSizer * GetWidget(wxWindow *parent)
return a widget associated with the form; the form controls the lifetime of the widget (do not delete...
virtual IDMSearchTool * x_GetTool()=0
virtual void x_SaveSettings(CRegistryWriteView) const =0
virtual void x_LoadSettings(const CRegistryReadView &)=0
virtual void SetController(IDMSearchFormController *controller)
virtual void SaveSettings() const
IDMSearchFormController * m_Controller
virtual void UpdateContexts()
updates m_ContextCombo
CSearchControl * m_Text
virtual void SetDictionary(list< string > *ddd)
virtual void SetRegistryPath(const string &reg_path)
IDataMiningContext * m_ActiveContext
void UpdateContextCombo(wxChoice *combo)
TFeatTypeItemSet m_FeatTypesSet
virtual string GetMainValue()
get/set main search value, this is separate from settings
virtual ~CSearchFormBase()
vector< IDataMiningContext * > TContexts
virtual void SetRangeLimit(bool bLimit)
virtual void SetMainValue(string val)
virtual void PopupADialog(TDialogType dt)
TODO this function should be here - it should be move the the form that needs this dialog.
virtual void LoadSettings()
CSearchFormBase()
CSearchFormBase.
A variant of IDMSearchQuery with a dummy search string (not advised for real use)
static const CFeatList * GetFeatList()
IDMSearchFormController - interface representing an entity that controls the lifecycle of search Form...
virtual CDataMiningService * GetDataMiningService()=0
virtual void OnSearchEnabled(bool)
virtual bool IsCompatible(IDataMiningContext *context)=0
retuns true if the tool is compatible with the provided Search Context
IDataMiningContext IDataMiningContext represents an abstract context for a Search.
virtual string GetDMContextName()=0
returns Name of the context to be used in UI
ISeqlocSearchContext.
virtual CRef< objects::CSeq_loc > GetSearchLoc()=0
bool operator()(string str)
StringCmp(string str)
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
CS_CONTEXT * ctx
Definition: t0006.c:12
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
#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 string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
Definition: ncbistr.cpp:2751
int i
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
USING_SCOPE(objects)
#define DICTIONARY_MAX_SIZE
CSearchFormBase.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sun Apr 14 05:28:40 2024 by modify_doxy.py rev. 669887