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>
11 #include <Bpp/Graphics/Point2D.h>
12 
13 
14 // From PhylLib:
15 #include "../Tree/Tree.h"
16 
17 namespace bpp
18 {
19 // Forward declarations:
20 class TreeDrawing;
21 class TreeDrawingListener;
22 
27 {
28 public:
33  unsigned int pointSize;
34  double pointArea; // this specifies the radius of the point area
35  // More options will be added in the future...
36 
37 public:
39  fontLeafNames("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 12),
40  fontBranchLengths("Courier", Font::STYLE_ITALIC, Font::WEIGHT_NORMAL, 10),
41  fontBootstrapValues("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 10),
42  fontNodesId("Courier", Font::STYLE_NORMAL, Font::WEIGHT_BOLD, 12),
43  pointSize(1),
44  pointArea(5)
45  {}
46 };
47 
48 
52 class Cursor
53 {
54 private:
55  double x_;
56  double y_;
57  double angle_;
58  short hpos_;
59  short vpos_;
60 
61 public:
62  Cursor(double x, double y, double angle = 0, short hpos = GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos = GraphicDevice::TEXT_VERTICAL_CENTER) :
63  x_(x), y_(y), angle_(angle), hpos_(hpos), vpos_(vpos) {}
64 
65 public:
66  double getX() const { return x_; }
67  double getY() const { return y_; }
68  double getAngle() const { return angle_; }
69  short getHPos() const { return hpos_; }
70  short getVPos() const { return vpos_; }
71  double addX(double increment) { return x_ += increment; }
72  double addY(double increment) { return y_ += increment; }
73 
74  Cursor getTranslation(double x, double y) const
75  {
76  Cursor c = *this;
77  c.addX(x);
78  c.addY(y);
79  return c;
80  }
81 };
82 
83 
88 {
89 private:
90  const TreeDrawing* td_;
92  int id_;
94 
95 public:
96  DrawNodeEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
97  td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
98  {}
99 
101  td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
102  {}
103 
105  {
106  td_ = dne.td_;
107  gd_ = dne.gd_;
108  id_ = dne.id_;
109  cursor_ = dne.cursor_;
110  return *this;
111  }
112 
113  virtual ~DrawNodeEvent() {}
114 
115 public:
116  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
117  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
118  virtual int getNodeId() const { return id_; }
119  virtual const Cursor& getCursor() const { return cursor_; }
120 };
121 
122 
127 {
128 private:
129  const TreeDrawing* td_;
131  int id_;
133 
134 public:
135  DrawBranchEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
136  td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
137  {}
138 
140  td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
141  {}
142 
144  {
145  td_ = dne.td_;
146  gd_ = dne.gd_;
147  id_ = dne.id_;
148  cursor_ = dne.cursor_;
149  return *this;
150  }
151 
152  virtual ~DrawBranchEvent() {}
153 
154 public:
155  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
156  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
157  virtual int getNodeId() const { return id_; }
158  virtual const Cursor& getCursor() const { return cursor_; }
163  virtual Cursor getBranchCursor(double position) const = 0;
164 };
165 
166 
171 {
172 private:
173  const TreeDrawing* td_;
175 
176 public:
178  td_(source), gd_(gd)
179  {}
180 
182  td_(dne.td_), gd_(dne.gd_)
183  {}
184 
186  {
187  td_ = dte.td_;
188  gd_ = dte.gd_;
189  return *this;
190  }
191 
192  virtual ~DrawTreeEvent() {}
193 
194 public:
195  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
196  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
197 };
198 
199 
221 class TreeDrawing :
222  public virtual Clonable
223 {
224 public:
226  virtual ~TreeDrawing() {}
227 
228  TreeDrawing* clone() const = 0;
229 
230 public:
234  virtual std::string getName() const = 0;
235 
239  virtual bool hasTree() const = 0;
240 
244  virtual const Tree* getTree() 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(const TreeDrawingSettings* tds) = 0;
333  virtual const TreeDrawingSettings& getDisplaySettings() const = 0;
344  virtual void addTreeDrawingListener(TreeDrawingListener* listener) = 0;
345 
352  virtual void removeTreeDrawingListener(TreeDrawingListener* listener) = 0;
353 };
354 } // end of namespace bpp.
355 #endif // BPP_PHYL_GRAPHICS_TREEDRAWING_H
Data structure describing a plotting direction.
Definition: TreeDrawing.h:53
Cursor getTranslation(double x, double y) const
Definition: TreeDrawing.h:74
double angle_
Definition: TreeDrawing.h:57
double addY(double increment)
Definition: TreeDrawing.h:72
double getX() const
Definition: TreeDrawing.h:66
short vpos_
Definition: TreeDrawing.h:59
short getVPos() const
Definition: TreeDrawing.h:70
double y_
Definition: TreeDrawing.h:56
short hpos_
Definition: TreeDrawing.h:58
short getHPos() const
Definition: TreeDrawing.h:69
double addX(double increment)
Definition: TreeDrawing.h:71
double getAngle() const
Definition: TreeDrawing.h:68
double x_
Definition: TreeDrawing.h:55
double getY() const
Definition: TreeDrawing.h:67
Cursor(double x, double y, double angle=0, short hpos=GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos=GraphicDevice::TEXT_VERTICAL_CENTER)
Definition: TreeDrawing.h:62
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:127
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:155
virtual Cursor getBranchCursor(double position) const =0
GraphicDevice * gd_
Definition: TreeDrawing.h:130
DrawBranchEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:135
const TreeDrawing * td_
Definition: TreeDrawing.h:129
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:158
virtual int getNodeId() const
Definition: TreeDrawing.h:157
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:156
DrawBranchEvent & operator=(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:143
DrawBranchEvent(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:139
virtual ~DrawBranchEvent()
Definition: TreeDrawing.h:152
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:88
const TreeDrawing * td_
Definition: TreeDrawing.h:90
DrawNodeEvent & operator=(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:104
virtual ~DrawNodeEvent()
Definition: TreeDrawing.h:113
GraphicDevice * gd_
Definition: TreeDrawing.h:91
DrawNodeEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:96
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:119
DrawNodeEvent(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:100
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:116
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:117
virtual int getNodeId() const
Definition: TreeDrawing.h:118
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:171
GraphicDevice * gd_
Definition: TreeDrawing.h:174
DrawTreeEvent(const DrawTreeEvent &dne)
Definition: TreeDrawing.h:181
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:196
virtual ~DrawTreeEvent()
Definition: TreeDrawing.h:192
const TreeDrawing * td_
Definition: TreeDrawing.h:173
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:195
DrawTreeEvent & operator=(const DrawTreeEvent &dte)
Definition: TreeDrawing.h:185
DrawTreeEvent(const TreeDrawing *source, GraphicDevice *gd)
Definition: TreeDrawing.h:177
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:27
unsigned int pointSize
Definition: TreeDrawing.h:33
Basal interface for tree drawing classes.
Definition: TreeDrawing.h:223
virtual bool isNodeCollapsed(int nodeId) const =0
virtual double getYUnit() const =0
virtual Point2D< double > getNodePosition(int nodeId) const =0
Get the position of a node.
virtual void collapseNode(int nodeId, bool yn)=0
Properties to draw.
virtual bool hasTree() const =0
virtual void addTreeDrawingListener(TreeDrawingListener *listener)=0
Add a drawing listener to this instance.
virtual void setTree(const Tree *tree)=0
TreeDrawing * clone() const =0
virtual int getNodeAt(const Point2D< double > &position) const =0
Get the node corresponding to a position on the device.
virtual const Tree * getTree() const =0
virtual void setDisplaySettings(const TreeDrawingSettings *tds)=0
Global drawing settings.
virtual std::string getName() 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 const TreeDrawingSettings & getDisplaySettings() const =0
virtual double getXUnit() const =0
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.