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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_PHY_TREE___PHYLO_SELECTION_SET__HPP
2 #define GUI_WIDGETS_PHY_TREE___PHYLO_SELECTION_SET__HPP
3 
4 /* $Id: phylo_selection_set.hpp 36928 2016-11-15 14:28:10Z falkrb $
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: Bob Falk
30 *
31 * File Description:
32 *
33 */
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiobj.hpp>
36 
37 #include <gui/utils/rgba_color.hpp>
38 #include <objects/biotree/Node.hpp>
41 
42 
44 
45 class CPhyloTree;
46 
47 /*******************************************************************************
48 * CPhyloSelectionSet
49 *
50 * A named set of selected nodes. Allows user to save a selection
51 * set for later viewing without having to re-create it through a query
52 * or hand-slection.
53 ******************************************************************************/
55 public:
56  CPhyloSelectionSet(const vector<objects::CNode::TId>& sel, const string& name, int cluster_id = 0)
57  : m_SelectedIDs(sel)
58  , m_SelectionName(name)
59  , m_SelectionColor(0.0f, 0.0f, 0.0f, 1.0f)
60  , m_Selected(false)
61  , m_ClusterID(cluster_id) {}
62 
64  : m_Selected(false)
65  , m_ClusterID(-1) {}
66 
67  /// call RemoveDuplicateIDs first which sorts and removes dups
68  bool operator==(const CPhyloSelectionSet& rhs) const;
69 
70  /// remove duplicates form m_SelectedIDs. should be called before operator==
71  void RemoveDuplicateIDs();
72 
73  void InitFromUserObject(CRef< objects::CUser_object > sel_set);
74  CRef< objects::CUser_object > SaveToUserObject() const;
75 
76  vector<objects::CNode::TId>& GetSelectionSet() { return m_SelectedIDs; }
77  const vector<objects::CNode::TId>& GetSelectionSet() const { return m_SelectedIDs; }
78  void UpdateSelectionSet(const vector<objects::CNode::TId>& sel) { m_SelectedIDs = sel; }
79 
80  string GetName() const { return m_SelectionName; }
81  void SetName(const string& n) { m_SelectionName = n; }
82 
83  CRgbaColor GetColor() const { return m_SelectionColor; }
84  void SetColor(const CRgbaColor& c) { m_SelectionColor = c; }
85 
86  bool GetSelected() const { return m_Selected; }
87  void SetSelected(bool b) { m_Selected = b; }
88 
89  int GetClusterID() const { return m_ClusterID; }
90  void SetClusterID(int cid) { m_ClusterID = cid; }
91 
92 
93 protected:
94  vector<objects::CNode::TId> m_SelectedIDs;
97  bool m_Selected;
99 };
100 
101 
102 /*******************************************************************************
103 * CPhyloSelectionSetMgr
104 *
105 * Manages a set of CPhyloSelectionSet objects
106 ******************************************************************************/
108 public:
109  typedef std::map<int, size_t> TClusterToColorMap;
110 
111 public:
113 
114  bool operator==(const CPhyloSelectionSetMgr& rhs) const;
115 
116  void Clear() { m_SelectionSets.clear(); }
117  void InitFromUserObject(CPhyloTree* tree_model,
118  const objects::CBioTreeContainer_Base::TUser& uo);
119  void SaveToUserObject(objects::CBioTreeContainer_Base::TUser& uo);
120 
121  /// Remove duplicate IDs from individual sets
122  void RemoveDuplicateIDs();
123 
124  vector<CPhyloSelectionSet>& GetSets() { return m_SelectionSets; }
125  const vector<CPhyloSelectionSet>& GetSets() const { return m_SelectionSets; }
126 
127  void SetSelectionSetProperty(CPhyloTree* tree_model);
128 
129  /// Returns size_t(-1) if the name set_name is not an existing selection set
130  size_t GetSelectionSet(const string& set_name);
131 
132  /// Add the new set set_name and return it. If it already exists, just return it.
133  CPhyloSelectionSet& AddSet(const string& set_name);
134  CPhyloSelectionSet& AddSet(const string& set_name, const CRgbaColor& c);
135 
136  // Get cluster ids from selection sets
137  map<int, size_t> GetClusterToSelectionMap();
138 
139  CRgbaColor PickBestColor(const vector<CRgbaColor>& current_colors);
140 
141  /// Update all cluster ids using the starting-id as the lowest value
142  void RenumberClusterIDs(int start_id);
143 
144 protected:
145 
146  void x_SyncSelectionSets(CPhyloTree* tree_model);
147 
148  vector<CPhyloSelectionSet> m_SelectionSets;
149 };
150 
152 
153 #endif //GUI_WIDGETS_PHY_TREE___PHYLO_SELECTION_SET__HPP
154 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
vector< CPhyloSelectionSet > & GetSets()
std::map< int, size_t > TClusterToColorMap
vector< CPhyloSelectionSet > m_SelectionSets
const vector< CPhyloSelectionSet > & GetSets() const
void SetColor(const CRgbaColor &c)
void SetName(const string &n)
const vector< objects::CNode::TId > & GetSelectionSet() const
vector< objects::CNode::TId > & GetSelectionSet()
vector< objects::CNode::TId > m_SelectedIDs
void UpdateSelectionSet(const vector< objects::CNode::TId > &sel)
CRgbaColor GetColor() const
CPhyloSelectionSet(const vector< objects::CNode::TId > &sel, const string &name, int cluster_id=0)
Tree subclass also has functions and data needed for rendering and selection.
Definition: phylo_tree.hpp:52
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
bool operator==(const CEquivRange &A, const CEquivRange &B)
#define false
Definition: bool.h:36
#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_PHYLO_TREE_EXPORT
Definition: gui_export.h:535
yy_size_t n
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Wed Jun 12 11:18:05 2024 by modify_doxy.py rev. 669887