bpp-phyl3 3.0.0
TreeDrawingDisplayControler.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
6#define BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
7
8
10
11// From the STL:
12#include <string>
13#include <vector>
14#include <map>
15#include <algorithm>
16
17namespace bpp
18{
28{
29private:
30 std::map<std::string, TreeDrawingListener*> listeners_;
31 std::vector<std::shared_ptr<TreeDrawing>> registeredTreeDrawings_;
32
33public:
36 {}
37
38private:
41 {
42 for (auto it = tddc.listeners_.begin();
43 it != tddc.listeners_.end(); ++it)
44 {
45 listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
46 }
47 }
49 {
50 listeners_.clear();
52 for (std::map<std::string, TreeDrawingListener*>::const_iterator it = tddc.listeners_.begin();
53 it != tddc.listeners_.end(); ++it)
54 {
55 listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
56 }
57 return *this;
58 }
59
60public:
62
63public:
68 void addListener(const std::string& propertyName, TreeDrawingListener* listener);
69
70 bool hasListenerFor(const std::string& propertyName) const
71 {
72 return listeners_.find(propertyName) != listeners_.end();
73 }
74
75 void enableListener(const std::string& propertyName, bool tf)
76 {
77 if (!hasListenerFor(propertyName))
78 throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
79 listeners_[propertyName]->enable(tf);
80 }
81
82 bool isListenerEnabled(const std::string& propertyName) const
83 {
84 if (!hasListenerFor(propertyName))
85 throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
86 return listeners_.find(propertyName)->second->isEnabled();
87 }
88
89 void registerTreeDrawing(std::shared_ptr<TreeDrawing> td)
90 {
91 if (std::find(registeredTreeDrawings_.begin(), registeredTreeDrawings_.end(), td) != registeredTreeDrawings_.end())
92 throw Exception("TreeDrawingDisplayControler::registerTreeDrawing. TreeDrawing is already associated to this controller.");
93 for (std::map<std::string, TreeDrawingListener*>::iterator it = listeners_.begin();
94 it != listeners_.end(); ++it)
95 {
96 td->addTreeDrawingListener(it->second);
97 }
98 registeredTreeDrawings_.push_back(td);
99 }
100};
101
102
117{
118public:
119 static const std::string PROPERTY_NODE_IDS;
120 static const std::string PROPERTY_LEAF_NAMES;
121 static const std::string PROPERTY_BRANCH_LENGTHS;
122 static const std::string PROPERTY_BOOTSTRAP_VALUES;
123
124private:
125 std::shared_ptr<const TreeDrawingSettings> settings_;
126
127public:
128 BasicTreeDrawingDisplayControler(std::shared_ptr<const TreeDrawingSettings> settings) :
129 settings_(settings)
130 {
131 if (!settings)
132 throw NullPointerException("BasicTreeDrawingDisplayControler::constructor. Trying to use NULL settings.");
137 }
138
139private:
142};
143} // end of namespace bpp.
144#endif // BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
Easy tune of tree drawings display, a basic implementation:
BasicTreeDrawingDisplayControler(const BasicTreeDrawingDisplayControler &)
BasicTreeDrawingDisplayControler & operator=(const BasicTreeDrawingDisplayControler &)
std::shared_ptr< const TreeDrawingSettings > settings_
BasicTreeDrawingDisplayControler(std::shared_ptr< const TreeDrawingSettings > settings)
A TreeDrawingListener implementation that write the bootstrap values of inner nodes.
A TreeDrawingListener implementation that write the branch lengths of inner nodes.
A TreeDrawingListener implementation that write leaf names.
A TreeDrawingListener implementation that writes nodes id.
Easy tune of tree drawings display.
void enableListener(const std::string &propertyName, bool tf)
TreeDrawingDisplayControler(const TreeDrawingDisplayControler &tddc)
void registerTreeDrawing(std::shared_ptr< TreeDrawing > td)
bool isListenerEnabled(const std::string &propertyName) const
std::vector< std::shared_ptr< TreeDrawing > > registeredTreeDrawings_
std::map< std::string, TreeDrawingListener * > listeners_
bool hasListenerFor(const std::string &propertyName) const
void addListener(const std::string &propertyName, TreeDrawingListener *listener)
Add a listener to the controller. The controller then owns the object, and will copy or delete it whe...
TreeDrawingDisplayControler & operator=(const TreeDrawingDisplayControler &tddc)
Interface allowing to capture drawing events.
Defines the basic types of data flow nodes.