1 #ifndef GUI_WIDGETS_PHY_TREE___PHYLO_RENDER_MODEL__HPP
2 #define GUI_WIDGETS_PHY_TREE___PHYLO_RENDER_MODEL__HPP
89 void SortSubtreeDist(
TTreeIdx idx,
const vector<float>& distances,
bool order);
96 void SortLabel(
TTreeIdx idx,
bool order);
105 const vector<pair<string,string> >& subtree_labels,
118 bool sel_children =
true,
119 bool sel_parents =
true);
130 void GetSelState(TSelState& sel_state,
132 bool sel_children =
true,
133 bool sel_parents =
true)
const;
136 void ClearSelection();
141 void GetSelected(vector<TTreeIdx>& sel)
const;
146 void GetSelectedIDs(vector<TID>& sel)
const;
157 void GetExplicitlySelected(vector<TTreeIdx>& esel)
const;
163 void GetExplicitlySelectedAndNotCollapsed(vector<TTreeIdx>& esel)
const;
169 void GetExplicitlySelectedIDs(vector<TID>& esel)
const;
177 void SetExplicitlySelected(
const vector<TID>& esel);
183 void SetLeavesExplicitlySelected();
190 void SetSelection(
const vector<TTreeIdx>& sel,
191 bool sel_children =
true,
192 bool sel_parents =
true);
199 void SetSelectionIDs(
const vector<TID>& ids,
bool sel=
true,
bool sel_children=
true);
201 bool HasSelection()
const {
return (m_Selected.size() > 0 ?
true :
false); }
222 bool SelectByPoint(
const CVect2<float>& pt,
bool sel,
bool toggle,
223 bool labels_visible,
bool rotated_labels=
false);
239 vector<TTreeIdx> GetAllCollapsed()
const;
256 void SetCurrentNode(
TTreeIdx node_idx);
264 bool SetCurrentNode(
const CVect2<float>& pt,
bool labels_visible,
bool rotated_labels,
284 bool HasCurrentEdge()
const;
310 return (itNode != m_NodesMap.end()) ? itNode->second :
Null();
329 void UpdateNodesMapping();
335 bool override_explicit=
true);
340 void x_SelectParents(
CPhyloTreeNode& node,
bool sel,
bool children_selected =
true);
348 void x_GetParentState(TSelState& sel_state,
351 void x_GetChildState(TSelState& sel_state,
428 template<
class TTreeModel,
class Fun>
431 typedef typename TTreeModel::TNodeType TNodeType;
436 stop_scan = func(tree_model, node_idx, delta_level);
446 TNodeType* tr = &tree_model[node_idx];
448 typedef typename TNodeType::TNodeList_I TTreeNodeIterator;
450 TTreeNodeIterator it = tr->SubNodeBeginEx();
451 TTreeNodeIterator it_end = tr->SubNodeEndEx();
456 stack<TTreeNodeIterator> tree_stack;
459 tr = &tree_model[*it];
460 stop_scan = func(tree_model, *it, delta_level);
469 (delta_level >= 0) &&
472 it = tr->SubNodeBeginEx();
473 it_end = tr->SubNodeEndEx();
479 if (tree_stack.empty()) {
482 it = tree_stack.top();
484 tr = &tree_model[*it];
485 it_end = tree_model[tr->GetParent()].SubNodeEndEx();
494 func(tree_model, node_idx, -1);
499 template<
class TTreeModel,
class Fun>
524 template<
class TTreeModel,
class Fun>
527 typedef typename TTreeModel::TNodeType TNodeType;
533 stop_scan = func(tree_model, node_idx, delta_level);
542 typedef typename TNodeType::TNodeList_I TTreeNodeIterator;
544 queue<TTreeIdx> node_queue;
545 node_queue.push(node_idx);
549 while (!node_queue.empty()) {
550 TTreeIdx node_idx = node_queue.front();
553 TNodeType* tr = &tree_model[node_idx];
555 TTreeNodeIterator it = tr->SubNodeBeginEx();
556 TTreeNodeIterator it_end = tr->SubNodeEndEx();
557 for (; it != it_end; ++it) {
558 stop_scan = func(tree_model, *it, delta_level);
568 node_queue.push(*it);
575 if (--level_count == 0) {
576 level_count =
static_cast<int>(node_queue.size());
582 func(tree_model, node_idx, -1);
587 template<
class TTreeModel,
class Fun>
Tree subclass also has functions and data needed for rendering and selection.
CRef< CTreeGraphicsModel > m_GraphicsModel
Model for rendering (updated from current tree state)
bool IsUnused(TTreeIdx idx) const
Return true if the given position in the array is not currently included as a node in the tree.
TTIDPhyloTreeNodeMap m_NodesMap
CRef< CTreeGraphicsModel > GetGraphicsModelRef()
CPhyloTree & operator=(const CPhyloTree &)
TTreeIdx m_CurrentEdgeChild
Currently active edge (to allow re-rooting by edge).
map< TID, TTreeIdx > TTIDPhyloTreeNodeMap
Node ID to tree index map.
TTreeIdx m_CurrentNode
Currently active node (for operations like edit), or Null()
TTreeIdxSet m_ExplicitlySelected
Often when you select a node, it's children or parents may also join the selection set.
CPhyloNodeData::TClusterID TClusterID
bool HasSelection() const
CPhyloSelectionSetMgr & GetSelectionSets()
const CBioTreeFeatureDictionary & GetFeatureDict() const
TTreeIdx GetCurrentNodeIdx() const
Return the index of the currently active node (may be Null()).
CRef< CRgbaGradColorTable > m_ColorTable
Color table to store colors by index.
vector< TSelStateValue > TSelState
CPhyloTree(const CPhyloTree &)
Disable copy.
TTreeIdx m_CurrentEdgeParent
CPhyloSelectionSetMgr m_SelectionSets
Selection sets - sets of selected nodes, which are saved in the biotreecontainer in user data (visual...
const CPhyloSelectionSetMgr & GetSelectionSets() const
bool HasCurrentNode() const
Return true if the currently active node is not Null()
TTreeIdx FindNodeById(TID id) const
Return index of the node with the given id or Null().
set< TTreeIdx > TTreeIdxSet
Indices of all the nodes with selection state eSelected.
CBioTreeFeatureDictionary & GetFeatureDict()
Return feature dictionary.
pair< TTreeIdx, CPhyloNodeData::TSelectedState > TSelStateValue
size_t GetNumSelected() const
Returns the number of selected nodes.
CBioTreeFeatureDictionary m_FeatureDict
Feature dictionary.
void SetGraphicsModelRef(CRef< CTreeGraphicsModel > gm)
Set graphics model - may be needed if we want to render to different graphics contexts since graphics...
CRgbaGradColorTable Provides a storage for colors (to eliminate color creation overhead) and Function...
class CTreeGraphicsModel Model for rendering tree graphics data.
virtual void x_ConvertUpstream(TTreeIdx node_idx)
Convert parents of node_idx to be its children.
static TTreeIdx Null()
Return the index value that represents a NULL node.
void Clear()
Remove all nodes (empty array) and set root index to Null.
container_type::const_iterator const_iterator
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
@ eTreeTraverseStop
Stop traversal (return form algorithm)
@ eTreeTraverse
Keep traversal.
@ eTreeTraverseStepOver
Do not traverse current node (pick the next one)
#define NCBI_GUIWIDGETS_PHYLO_TREE_EXPORT
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
void TreeBreadthFirstEx(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun &func)
Breadth-first tree traversal that skips collapsed nodes.
void TreeDepthFirstEx(TTreeModel &tree_model, typename TTreeModel::TTreeIdx node_idx, Fun &func)
Depth-first tree traversal that skips collapsed nodes.
size_t TTreeIdx
Bi-directionaly linked N way tree allocated in a contiguous memory block.