bpp-phyl3 3.0.0
TreeDrawing.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_TREEDRAWING_H
6#define BPP_PHYL_GRAPHICS_TREEDRAWING_H
7
8#include <Bpp/Clonable.h>
12
13#include <memory>
14
15// From bpp-phyl:
16#include "../Tree/Tree.h"
17
18namespace bpp
19{
20// Forward declarations:
21class TreeDrawing;
22class TreeDrawingListener;
23
28{
29public:
34 unsigned int pointSize;
35 double pointArea; // this specifies the radius of the point area
36 // More options will be added in the future...
37
38public:
40 fontLeafNames("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 12),
41 fontBranchLengths("Courier", Font::STYLE_ITALIC, Font::WEIGHT_NORMAL, 10),
42 fontBootstrapValues("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 10),
43 fontNodesId("Courier", Font::STYLE_NORMAL, Font::WEIGHT_BOLD, 12),
44 pointSize(1),
45 pointArea(5)
46 {}
47};
48
49
53class Cursor
54{
55private:
56 double x_;
57 double y_;
58 double angle_;
59 short hpos_;
60 short vpos_;
61
62public:
63 Cursor(double x, double y, double angle = 0, short hpos = GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos = GraphicDevice::TEXT_VERTICAL_CENTER) :
64 x_(x), y_(y), angle_(angle), hpos_(hpos), vpos_(vpos) {}
65
66public:
67 double getX() const { return x_; }
68 double getY() const { return y_; }
69 double getAngle() const { return angle_; }
70 short getHPos() const { return hpos_; }
71 short getVPos() const { return vpos_; }
72 double addX(double increment) { return x_ += increment; }
73 double addY(double increment) { return y_ += increment; }
74
75 Cursor getTranslation(double x, double y) const
76 {
77 Cursor c = *this;
78 c.addX(x);
79 c.addY(y);
80 return c;
81 }
82};
83
84
89{
90private:
93 int id_;
95
96public:
97 DrawNodeEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
98 td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
99 {}
100
102 td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
103 {}
104
106 {
107 td_ = dne.td_;
108 gd_ = dne.gd_;
109 id_ = dne.id_;
110 cursor_ = dne.cursor_;
111 return *this;
112 }
113
114 virtual ~DrawNodeEvent() {}
115
116public:
117 virtual const TreeDrawing* getTreeDrawing() const { return td_; }
118 virtual GraphicDevice* getGraphicDevice() const { return gd_; }
119 virtual int getNodeId() const { return id_; }
120 virtual const Cursor& getCursor() const { return cursor_; }
121};
122
123
128{
129private:
132 int id_;
134
135public:
136 DrawBranchEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
137 td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
138 {}
139
141 td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
142 {}
143
145 {
146 td_ = dne.td_;
147 gd_ = dne.gd_;
148 id_ = dne.id_;
149 cursor_ = dne.cursor_;
150 return *this;
151 }
152
153 virtual ~DrawBranchEvent() {}
154
155public:
156 virtual const TreeDrawing* getTreeDrawing() const { return td_; }
157 virtual GraphicDevice* getGraphicDevice() const { return gd_; }
158 virtual int getNodeId() const { return id_; }
159 virtual const Cursor& getCursor() const { return cursor_; }
164 virtual Cursor getBranchCursor(double position) const = 0;
165};
166
167
172{
173private:
176
177public:
179 td_(source), gd_(gd)
180 {}
181
183 td_(dne.td_), gd_(dne.gd_)
184 {}
185
187 {
188 td_ = dte.td_;
189 gd_ = dte.gd_;
190 return *this;
191 }
192
193 virtual ~DrawTreeEvent() {}
194
195public:
196 virtual const TreeDrawing* getTreeDrawing() const { return td_; }
197 virtual GraphicDevice* getGraphicDevice() const { return gd_; }
198};
199
200
222 public virtual Clonable
223{
224public:
226 virtual ~TreeDrawing() {}
227
228 TreeDrawing* clone() const = 0;
229
230public:
234 virtual std::string getName() const = 0;
235
239 virtual bool hasTree() const = 0;
240
244 virtual const Tree& tree() const = 0;
245
249 virtual void setTree(const Tree& tree) = 0;
250
257 virtual void setXUnit(double xu) = 0;
258
265 virtual void setYUnit(double yu) = 0;
266
270 virtual double getXUnit() const = 0;
271
275 virtual double getYUnit() const = 0;
276
280 virtual double getWidth() const = 0;
281
285 virtual double getHeight() const = 0;
286
292 virtual void plot(GraphicDevice& gDevice) const = 0;
293
301 virtual Point2D<double> getNodePosition(int nodeId) const = 0;
302
310 virtual int getNodeAt(const Point2D<double>& position) const = 0;
311
323 virtual void collapseNode(int nodeId, bool yn) = 0;
324 virtual bool isNodeCollapsed(int nodeId) const = 0;
332 virtual void setDisplaySettings(std::shared_ptr<const TreeDrawingSettings> tds) = 0;
333 virtual const TreeDrawingSettings& displaySettings() const = 0;
344 virtual void addTreeDrawingListener(TreeDrawingListener* listener) = 0;
345
353};
354} // end of namespace bpp.
355#endif // BPP_PHYL_GRAPHICS_TREEDRAWING_H
Data structure describing a plotting direction.
Definition: TreeDrawing.h:54
Cursor getTranslation(double x, double y) const
Definition: TreeDrawing.h:75
double angle_
Definition: TreeDrawing.h:58
double addY(double increment)
Definition: TreeDrawing.h:73
double getX() const
Definition: TreeDrawing.h:67
short vpos_
Definition: TreeDrawing.h:60
short getVPos() const
Definition: TreeDrawing.h:71
double y_
Definition: TreeDrawing.h:57
short hpos_
Definition: TreeDrawing.h:59
short getHPos() const
Definition: TreeDrawing.h:70
double addX(double increment)
Definition: TreeDrawing.h:72
double getAngle() const
Definition: TreeDrawing.h:69
double x_
Definition: TreeDrawing.h:56
double getY() const
Definition: TreeDrawing.h:68
Cursor(double x, double y, double angle=0, short hpos=GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos=GraphicDevice::TEXT_VERTICAL_CENTER)
Definition: TreeDrawing.h:63
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:128
virtual Cursor getBranchCursor(double position) const =0
GraphicDevice * gd_
Definition: TreeDrawing.h:131
DrawBranchEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:136
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:157
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:159
const TreeDrawing * td_
Definition: TreeDrawing.h:130
virtual int getNodeId() const
Definition: TreeDrawing.h:158
DrawBranchEvent(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:140
DrawBranchEvent & operator=(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:144
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:156
virtual ~DrawBranchEvent()
Definition: TreeDrawing.h:153
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:89
const TreeDrawing * td_
Definition: TreeDrawing.h:91
virtual ~DrawNodeEvent()
Definition: TreeDrawing.h:114
GraphicDevice * gd_
Definition: TreeDrawing.h:92
DrawNodeEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:97
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:120
DrawNodeEvent(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:101
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:118
DrawNodeEvent & operator=(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:105
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:117
virtual int getNodeId() const
Definition: TreeDrawing.h:119
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:172
GraphicDevice * gd_
Definition: TreeDrawing.h:175
DrawTreeEvent(const DrawTreeEvent &dne)
Definition: TreeDrawing.h:182
virtual ~DrawTreeEvent()
Definition: TreeDrawing.h:193
DrawTreeEvent & operator=(const DrawTreeEvent &dte)
Definition: TreeDrawing.h:186
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:196
const TreeDrawing * td_
Definition: TreeDrawing.h:174
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:197
DrawTreeEvent(const TreeDrawing *source, GraphicDevice *gd)
Definition: TreeDrawing.h:178
static short TEXT_HORIZONTAL_CENTER
static short TEXT_VERTICAL_CENTER
Interface allowing to capture drawing events.
A set of options to tune the display of a TreeDrawing object.
Definition: TreeDrawing.h:28
unsigned int pointSize
Definition: TreeDrawing.h:34
Basal interface for tree drawing classes.
Definition: TreeDrawing.h:223
virtual bool isNodeCollapsed(int nodeId) const =0
virtual double getYUnit() const =0
virtual void collapseNode(int nodeId, bool yn)=0
Properties to draw.
virtual bool hasTree() const =0
TreeDrawing * clone() const =0
virtual void addTreeDrawingListener(TreeDrawingListener *listener)=0
Add a drawing listener to this instance.
virtual int getNodeAt(const Point2D< double > &position) const =0
Get the node corresponding to a position on the device.
virtual std::string getName() const =0
virtual void setTree(const Tree &tree)=0
virtual const TreeDrawingSettings & displaySettings() const =0
virtual void setDisplaySettings(std::shared_ptr< const TreeDrawingSettings > tds)=0
Global drawing settings.
virtual Point2D< double > getNodePosition(int nodeId) const =0
Get the position of a node.
virtual const Tree & tree() const =0
virtual void setYUnit(double yu)=0
Set the 'vertical' expansion unit.
virtual void setXUnit(double xu)=0
Set the 'horizontal' expansion unit.
virtual double getHeight() const =0
virtual void plot(GraphicDevice &gDevice) const =0
Plot the tree onto the specified device.
virtual void removeTreeDrawingListener(TreeDrawingListener *listener)=0
Remove a drawing listener from this instance.
virtual double getWidth() const =0
virtual ~TreeDrawing()
Definition: TreeDrawing.h:226
virtual double getXUnit() const =0
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.