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

Go to the SVN repository for this file.

1 /* $Id: feature_check_panel.cpp 26513 2012-09-28 20:22:30Z wuliangs $
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 
29 
30 #include <ncbi_pch.hpp>
31 
32 
33 #include <wx/bitmap.h>
34 #include <wx/icon.h>
35 #include <wx/sizer.h>
36 #include <wx/stattext.h>
37 #include <wx/statbox.h>
38 #include <wx/button.h>
39 
40 ////@begin includes
41 ////@end includes
42 
44 
45 ////@begin XPM images
46 ////@end XPM images
47 
52 #include <util/xregexp/regexp.hpp>
53 
54 #include <wx/sizer.h>
55 #include <wx/bitmap.h>
56 #include <wx/icon.h>
57 
60 
61 /*!
62  * CFeatureCheckPanel type definition
63  */
64 
65 IMPLEMENT_DYNAMIC_CLASS( CFeatureCheckPanel, wxPanel )
66 
67 
68 /*!
69  * CFeatureCheckPanel event table definition
70  */
71 
72 BEGIN_EVENT_TABLE( CFeatureCheckPanel, wxPanel )
73 
74 ////@begin CFeatureCheckPanel event table entries
75 ////@end CFeatureCheckPanel event table entries
76 
78 
79 
80 /*!
81  * CFeatureCheckPanel constructors
82  */
83 
85 {
86  Init();
87 }
88 
89 CFeatureCheckPanel::CFeatureCheckPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90 {
91  Init();
92  Create(parent, id, pos, size, style);
93 }
94 
95 
96 /*!
97  * CFeatureCheckPanel creator
98  */
99 
100 bool CFeatureCheckPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
101 {
102 ////@begin CFeatureCheckPanel creation
103  wxPanel::Create( parent, id, pos, size, style );
104 
105  CreateControls();
106  if (GetSizer())
107  {
108  GetSizer()->SetSizeHints(this);
109  }
110  Centre();
111 ////@end CFeatureCheckPanel creation
112  return true;
113 }
114 
115 
116 /*!
117  * CFeatureCheckPanel destructor
118  */
119 
121 {
122 ////@begin CFeatureCheckPanel destruction
123 ////@end CFeatureCheckPanel destruction
124 }
125 
126 
127 /*!
128  * Member initialisation
129  */
130 
132 {
133 ////@begin CFeatureCheckPanel member initialisation
134  m_Tree = NULL;
135 ////@end CFeatureCheckPanel member initialisation
136  m_Filter = "";
137 }
138 
139 
140 /*!
141  * Control creation for CFeatureCheckPanel
142  */
143 
145 {
146 ////@begin CFeatureCheckPanel content construction
147  CFeatureCheckPanel* itemPanel1 = this;
148 
149  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
150  itemPanel1->SetSizer(itemBoxSizer2);
151 
152  m_Tree = new CwxTreeCtrlEx( itemPanel1, ID_TREECTRL1, wxDefaultPosition, wxSize(250, 250), wxTR_HAS_BUTTONS |wxTR_SINGLE );
153  itemBoxSizer2->Add(m_Tree, 1, wxGROW|wxALL, 5);
154 
155 ////@end CFeatureCheckPanel content construction
156  x_InitTree();
157 }
158 
159 
161 {
162  wxTreeItemId root_id = m_Tree->AddRoot(wxT("All Feature Types"));
163 
164  wxTreeItemId prt_id = m_Tree->AppendItem(root_id, wxT("All Protein"));
165  wxTreeItemId rna_id = m_Tree->AppendItem(root_id, wxT("All Rna"));
166  wxTreeItemId imp_id = m_Tree->AppendItem(root_id, wxT("All Import"));
167 
168  CRegexp * rxp = NULL;
169  if (!m_Filter.empty()) {
170  string pattern = CRegexp::WildcardToRegexp(m_Filter);
171  rxp = new CRegexp(pattern, CRegexp::fCompile_ignore_case);
172  }
173 
174  const CFeatList* feat_list = CSeqFeatData::GetFeatList();
175  ITERATE(CFeatList, ft_it, *feat_list) {
176  const CFeatListItem& item = *ft_it;
177  string desc = item.GetDescription();
178  int feat_type = item.GetType();
179 
180  // if filter set, skip mismatches
181  if (rxp && !rxp->IsMatch(desc)) {
182  continue;
183  }
184 
185  // indent subordinate types
186  if (item.GetSubtype() != CSeqFeatData::eSubtype_any) {
187  switch (feat_type){
189  {{
190  m_Tree->AppendItem(prt_id, ToWxString(desc), -1, -1, new wxFeatItemData(item));
191  break;
192  }}
193  case CSeqFeatData::e_Rna:
194  {{
195  m_Tree->AppendItem(rna_id, ToWxString(desc), -1, -1, new wxFeatItemData(item));
196  break;
197  }}
198  case CSeqFeatData::e_Imp:
199  {{
200  m_Tree->AppendItem(imp_id, ToWxString(desc), -1, -1, new wxFeatItemData(item));
201  break;
202  }}
203  default:
204  {{
205  m_Tree->AppendItem(root_id, ToWxString(desc), -1, -1, new wxFeatItemData(item));
206  break;
207  }}
208  }
209  }
210  else {
211  //m_Tree->AppendItem(root_id, desc.c_str());
212  }
213  }
214  m_Tree->SetItemText(prt_id,
215  m_Tree->GetItemText(prt_id) +
216  wxT(" (") +
217  ToWxString(NStr::NumericToString(m_Tree->GetChildrenCount(prt_id))) +
218  wxT(" items)"));
219 
220  m_Tree->SetItemText(rna_id,
221  m_Tree->GetItemText(rna_id) +
222  wxT(" (") +
223  ToWxString(NStr::NumericToString(m_Tree->GetChildrenCount(rna_id))) +
224  wxT(" items)"));
225 
226  m_Tree->SetItemText(imp_id,
227  m_Tree->GetItemText(imp_id) +
228  wxT(" (") +
229  ToWxString(NStr::NumericToString(m_Tree->GetChildrenCount(imp_id))) +
230  wxT(" items)"));
231 
232  m_Tree->Expand(root_id);
233  m_Tree->CheckAll(false);
234 
235 }
236 
238 {
239  if (m_Tree->GetChildrenCount(id, false)==0 && m_Tree->GetCheck(id)) {
240  set.insert(*(dynamic_cast<wxFeatItemData*>(m_Tree->GetItemData(id))));
241  }
242  else {
243  wxTreeItemIdValue cookie;
244  for (wxTreeItemId cid = m_Tree->GetFirstChild(id, cookie); cid.IsOk(); cid=m_Tree->GetNextChild(id, cookie)){
245  x_GetSelections(cid, set);
246  }
247  }
248 }
249 
250 void CFeatureCheckPanel::x_SetSelections(const wxTreeItemId &id, TFeatTypeItemSet & dset)
251 {
252  if (m_Tree->GetChildrenCount(id, false)==0) {
253  const wxTreeItemData* p0 = m_Tree->GetItemData(id);
254  const wxFeatItemData* p1 = dynamic_cast<const wxFeatItemData*>(p0);
255  if (!p1) return;
256  const TFeatTypeItem & fi = *dynamic_cast<wxFeatItemData*>(m_Tree->GetItemData(id));
257  bool bCheck = false;
258  ITERATE(TFeatTypeItemSet, item, dset) {
259  if ((item->GetType() == fi.GetType()) &&
260  (item->GetSubtype() == fi.GetSubtype())){
261  bCheck = true;
262  break;
263  }
264  }
265  m_Tree->SetCheck(id, bCheck);
266  }
267  else {
268  wxTreeItemIdValue cookie;
269  for (wxTreeItemId cid = m_Tree->GetFirstChild(id, cookie); cid.IsOk(); cid=m_Tree->GetNextChild(id, cookie)){
270  x_SetSelections(cid, dset);
271  }
272  }
273 }
274 
275 
277 {
278  feat_types.clear();
279  x_GetSelections(m_Tree->GetRootItem(), feat_types);
280 }
281 
283 {
284  x_SetSelections(m_Tree->GetRootItem(), feat_types);
285 }
286 
287 
288 
289 /*!
290  * Should we show tooltips?
291  */
292 
294 {
295  return true;
296 }
297 
298 /*!
299  * Get bitmap resources
300  */
301 
302 wxBitmap CFeatureCheckPanel::GetBitmapResource( const wxString& name )
303 {
304  // Bitmap retrieval
305 ////@begin CFeatureCheckPanel bitmap retrieval
306  wxUnusedVar(name);
307  return wxNullBitmap;
308 ////@end CFeatureCheckPanel bitmap retrieval
309 }
310 
311 /*!
312  * Get icon resources
313  */
314 
315 wxIcon CFeatureCheckPanel::GetIconResource( const wxString& name )
316 {
317  // Icon retrieval
318 ////@begin CFeatureCheckPanel icon retrieval
319  wxUnusedVar(name);
320  return wxNullIcon;
321 ////@end CFeatureCheckPanel icon retrieval
322 }
323 
324 
325 void CFeatureCheckPanel::x_AccessState(const wxTreeItemId &id, TStateVector & check, TStateVector & expand, bool bRead)
326 {
327  string tid = ToStdString(m_Tree->GetItemText(id));
328  if (m_Tree->GetChildrenCount(id, false)==0) {
329  if (!bRead) {
330  if (m_Tree->GetCheck(id)) {
331  check.push_back(tid);
332  }
333  }
334  else {
335  if (find(check.begin(), check.end(), tid)!=check.end()) {
336  m_Tree->SetCheck(id);
337  }
338  }
339  }
340  else {
341  if (!bRead) {
342  if (m_Tree->IsExpanded(id)) {
343  expand.push_back(tid);
344  }
345  }
346  else {
347  if (find(expand.begin(), expand.end(), tid)!=expand.end()) {
348  m_Tree->Expand(id);
349  }
350  }
351  wxTreeItemIdValue cookie;
352  for (wxTreeItemId cid = m_Tree->GetFirstChild(id, cookie); cid.IsOk(); cid=m_Tree->GetNextChild(id, cookie)){
353  x_AccessState(cid, check, expand, bRead);
354  }
355  }
356 }
357 
359 {
360  if (!bRead) {
361  check.clear();
362  expand.clear();
363  } else {
364  m_Check = check;
365  m_Expand = expand;
366  }
367  x_AccessState(m_Tree->GetRootItem(), check, expand, bRead);
368 }
369 
371 {
372  m_Filter = str;
373  x_AccessState(m_Tree->GetRootItem(), m_Check, m_Expand, false);
374  m_Tree->Freeze();
375  m_Tree->DeleteAllItems();
376  x_InitTree();
377  x_AccessState(m_Tree->GetRootItem(), m_Check, m_Expand, true);
378  m_Tree->Thaw();
379 }
380 
CFeatListItem - basic configuration data for one "feature" type.
int GetSubtype() const
string GetDescription() const
int GetType() const
CConfigurableItems - a static list of items that can be configured.
void AccessState(TStateVector &check, TStateVector &expand, bool bRead=true)
void x_SetSelections(const wxTreeItemId &id, TFeatTypeItemSet &set)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
objects::CFeatListItem TFeatTypeItem
void GetSelected(TFeatTypeItemSet &feat_types)
~CFeatureCheckPanel()
Destructor.
void SetSelected(TFeatTypeItemSet &feat_types)
CFeatureCheckPanel()
Constructors.
void CreateControls()
Creates the controls and sizers.
bool Create(wxWindow *parent, wxWindowID id=ID_CTREECHECKPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(300, 300), long style=wxTAB_TRAVERSAL)
Creation.
void x_AccessState(const wxTreeItemId &id, TStateVector &check, TStateVector &expand, bool bRead)
void Init()
Initialises member variables.
static bool ShowToolTips()
Should we show tooltips?
vector< string > TStateVector
void x_GetSelections(const wxTreeItemId &id, TFeatTypeItemSet &set)
CRegexp –.
Definition: regexp.hpp:70
static const CFeatList * GetFeatList()
bool GetCheck(const wxTreeItemId &item)
void SetCheck(const wxTreeItemId &item, bool bcheck=true)
void CheckAll(bool bcheck=true)
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
void clear()
Definition: set.hpp:153
USING_SCOPE(objects)
static void Init(void)
Definition: cursor6.c:76
#define check(s)
Definition: describecol2.c:21
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
#define NULL
Definition: ncbistd.hpp:225
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
Definition: regexp.cpp:193
static string WildcardToRegexp(CTempString mask)
Convert wildcard mask to regular expression.
Definition: regexp.cpp:228
@ fCompile_ignore_case
Definition: regexp.hpp:103
#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
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
#define fi
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Wed Apr 24 14:19:41 2024 by modify_doxy.py rev. 669887