NCBI C++ ToolKit
tax_tree.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS___TAX_TREE__HPP
2 #define GUI_WIDGETS___TAX_TREE__HPP
3 
4 /* $Id: tax_tree.hpp 45992 2021-01-20 18:24:18Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <corelib/ncbi_tree.hpp>
37 
38 #include <gui/objutils/objects.hpp>
39 
41 
42 #include <gui/utils/view_event.hpp>
43 #include <gui/utils/command.hpp>
45 
46 // This header must (at least indirectly) precede any wxWidgets headers.
48 
49 #include <wx/treectrl.h>
50 
51 #include <memory>
52 
54 
55 class IReporter;
56 
57 
58 /// class CTaxTreeBrowser implements a tree-based view of a taxonomic
59 /// hierarchy. This class was designed to deal with generating common
60 /// taxonomic trees, but should be flexible enough to deal with any
61 /// sort of taxonomic tree.
62 ///
63 /// This class wraps a data source that provides an abstraction for dealing
64 /// with taxonomic trees. The data source must provide a taxonomy tree
65 /// iterator conforming to that defined in <objects/taxon1/taxon1.hpp>.
66 /// No assumption is made about how the data are derived internally. In
67 /// addition, no assumption is made about the UIDs that this data source
68 /// contains. The data source must provide a mapping between a UID of
69 /// user-specified significance and a taxonomy ID and tax tree node.
70 ///
71 
73 {
74 public:
75  /// our internal tree structure
76  struct STaxInfo {
78  : tax_node(NULL) {}
79 
81  const objects::ITaxon1Node* tax_node;
83  };
85 
86 
87  class wxTaxTreeData : public wxTreeItemData {
89  public:
90  wxTaxTreeData(TTaxTree * item) : m_Item(item){}
91  TTaxTree * GetData(){return m_Item;}
92  virtual ~wxTaxTreeData(){}
93  };
94 
95 
96  /// default ctor (for FLTK)
97  CTaxTreeBrowser(wxWindow *parent, wxWindowID id,
98  const wxPoint& pos, const wxSize& size,
99  long style, const wxValidator& validator,
100  const wxString& name);
101 
102  CTaxTreeBrowser(wxWindow *parent, wxWindowID id,
103  const wxPoint& pos, const wxSize& size,
104  long style);
105 
106 
107  /// dtor
108  ~CTaxTreeBrowser();
109 
110  /// set the abstract reporter interface
111  void SetReporter(IReporter* reporter);
112 
113  /// set the data source for this widget
114  void SetDataSource(CTaxTreeDataSource& ds);
115 
116  /// set the current display mode. This controls how many nodes in the
117  /// tax tree we show, and how deep the branches should run.
118  void SetDisplayMode(CTaxTreeDataSource::EDisplayMode mode);
119 
120  /// retrieve the selected UIDs
121  void GetSelectedUids(CTaxTreeDataSource::TUidVec& uids) const;
122 
123  /// set selected ids
124  void SetSelectedUids(const CTaxTreeDataSource::TUidVec& uids, wxTreeItemId node);
125 
126  /// Selection API
127  void GetObjectSelection(TConstObjects& objs);
128  void SetObjectSelection(const CTaxTreeDataSource::TUidVec& uids);
129 
130  /// callback function
131  // friend void OnTaxtreeNotify(Fl_Widget * widget, void * data);
132 
133  /// handler for selection changed event
134  // void OnSelChangedEvent(CEvent * evt);
135 
136 protected:
137  /// This will clear our current tree and repopulate it from our data source
138  void x_Refresh();
139 
140  /// populate a given node from a tax tree node
141  void x_PopulateTree(wxTreeItemId node, TTaxTree* tree);
142 
143  /// retrieve a name for a node
144  void x_GetName(TTaxTree& node, string& str) const;
145 
146  /// count the number of UIDs held underneath a given tree
147  size_t x_CountNodes(TTaxTree& node) const;
148 
149 protected:
150  friend class CTreeFiller;
151 
152  /// the data source we use
154 
155  unique_ptr<TTaxTree> m_TaxTree;
156 
157  /// typedef for a map of tax-id to UID vector. This is defined in
158  /// the data source; we re-typedef it here for convenience
160 
161  /// display mode
163 
164  /// our reporter interface
166 
167  wxTreeItemId m_RootId;
168 
169 private:
170  /// forbidden
173 };
174 
175 
176 
178 
179 #endif /// GUI_WIDGETS___TAX_TREE__HPP
wxTaxTreeData(TTaxTree *item)
Definition: tax_tree.hpp:90
class CTaxTreeBrowser implements a tree-based view of a taxonomic hierarchy.
Definition: tax_tree.hpp:73
CTaxTreeBrowser & operator=(const CTaxTreeBrowser &)
CTaxTreeBrowser(const CTaxTreeBrowser &)
forbidden
IReporter * m_Reporter
our reporter interface
Definition: tax_tree.hpp:165
CRef< CTaxTreeDataSource > m_DataSource
the data source we use
Definition: tax_tree.hpp:153
CTreeNode< STaxInfo > TTaxTree
Definition: tax_tree.hpp:84
unique_ptr< TTaxTree > m_TaxTree
Definition: tax_tree.hpp:155
CTaxTreeDataSource::EDisplayMode m_DispMode
display mode
Definition: tax_tree.hpp:162
CTaxTreeDataSource::TTaxMap TTaxMap
typedef for a map of tax-id to UID vector.
Definition: tax_tree.hpp:159
wxTreeItemId m_RootId
Definition: tax_tree.hpp:167
vector< TUid > TUidVec
Definition: tax_tree_ds.hpp:63
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Definition: map.hpp:338
GUI command routing and handling framework.
Workaround for wxWidgets header errors in certain configurations; MUST be included (at least indirect...
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
vector< CConstRef< CObject > > TConstObjects
Definition: objects.hpp:64
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_TAXTREE_EXPORT
Definition: gui_export.h:541
mdb_mode_t mode
Definition: lmdb++.h:38
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
our internal tree structure
Definition: tax_tree.hpp:76
CTaxTreeDataSource::TUidVec uids
Definition: tax_tree.hpp:82
const objects::ITaxon1Node * tax_node
Definition: tax_tree.hpp:81
CRef< CTaxTreeDataSource > data_source
Definition: tax_tree.hpp:80
Modified on Fri Jun 07 13:37:09 2024 by modify_doxy.py rev. 669887