bpp-phyl  2.2.0
TreeDrawing.h
Go to the documentation of this file.
1 //
2 // File: TreeDrawing.h
3 // Created by: Julien Dutheil
4 // Created on: Sun Oct 8 11:57 2006
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10 This software is a computer program whose purpose is to provide
11 graphic components to develop bioinformatics applications.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _TREEDRAWING_H_
41 #define _TREEDRAWING_H_
42 
43 #include <Bpp/Clonable.h>
44 #include <Bpp/Graphics/GraphicDevice.h>
45 #include <Bpp/Graphics/Point2D.h>
46 #include <Bpp/Graphics/Font/Font.h>
47 
48 // From PhylLib:
49 #include "../Tree.h"
50 
51 namespace bpp
52 {
53 
54 //Forward declarations:
55 class TreeDrawing;
56 class TreeDrawingListener;
57 
62 {
63  public:
68  unsigned int pointSize;
69  double pointArea; //this specifies the radius of the point area
70  //More options will be added in the future...
71 
72  public:
74  fontLeafNames("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 12),
75  fontBranchLengths("Courier", Font::STYLE_ITALIC, Font::WEIGHT_NORMAL, 10),
76  fontBootstrapValues("Courier", Font::STYLE_NORMAL, Font::WEIGHT_NORMAL, 10),
77  fontNodesId("Courier", Font::STYLE_NORMAL, Font::WEIGHT_BOLD, 12),
78  pointSize(1),
79  pointArea(5)
80  {}
81 };
82 
83 
87 class Cursor
88 {
89 private:
90  double x_;
91  double y_;
92  double angle_;
93  short hpos_;
94  short vpos_;
95 
96 public:
97  Cursor(double x, double y, double angle = 0, short hpos = GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos = GraphicDevice::TEXT_VERTICAL_CENTER) :
98  x_(x), y_(y), angle_(angle), hpos_(hpos), vpos_(vpos) {}
99 
100 public:
101  double getX() const { return x_; }
102  double getY() const { return y_; }
103  double getAngle() const { return angle_; }
104  short getHPos() const { return hpos_; }
105  short getVPos() const { return vpos_; }
106  double addX(double increment) { return x_ += increment; }
107  double addY(double increment) { return y_ += increment; }
108 
109  Cursor getTranslation(double x, double y) const
110  {
111  Cursor c = *this;
112  c.addX(x);
113  c.addY(y);
114  return c;
115  }
116 
117 };
118 
119 
120 
125 {
126  private:
127  const TreeDrawing* td_;
128  GraphicDevice* gd_;
129  int id_;
131 
132  public:
133  DrawNodeEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
134  td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
135  {}
136 
138  td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
139  {}
140 
142  {
143  td_ = dne.td_;
144  gd_ = dne.gd_;
145  id_ = dne.id_;
146  cursor_ = dne.cursor_;
147  return *this;
148  }
149 
150  virtual ~DrawNodeEvent() {}
151 
152  public:
153  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
154  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
155  virtual int getNodeId() const { return id_; }
156  virtual const Cursor& getCursor() const { return cursor_; }
157 
158 };
159 
160 
161 
166 {
167  private:
168  const TreeDrawing* td_;
169  GraphicDevice* gd_;
170  int id_;
172 
173  public:
174  DrawBranchEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
175  td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
176  {}
177 
179  td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
180  {}
181 
183  {
184  td_ = dne.td_;
185  gd_ = dne.gd_;
186  id_ = dne.id_;
187  cursor_ = dne.cursor_;
188  return *this;
189  }
190 
191  virtual ~DrawBranchEvent() {}
192 
193  public:
194  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
195  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
196  virtual int getNodeId() const { return id_; }
197  virtual const Cursor& getCursor() const { return cursor_; }
202  virtual Cursor getBranchCursor(double position) const = 0;
203 
204 };
205 
206 
207 
212 {
213  private:
214  const TreeDrawing* td_;
215  GraphicDevice* gd_;
216 
217  public:
218  DrawTreeEvent(const TreeDrawing* source, GraphicDevice* gd) :
219  td_(source), gd_(gd)
220  {}
221 
223  td_(dne.td_), gd_(dne.gd_)
224  {}
225 
227  {
228  td_ = dte.td_;
229  gd_ = dte.gd_;
230  return *this;
231  }
232 
233  virtual ~DrawTreeEvent() {}
234 
235  public:
236  virtual const TreeDrawing* getTreeDrawing() const { return td_; }
237  virtual GraphicDevice* getGraphicDevice() const { return gd_; }
238 
239 };
240 
241 
242 
265  public virtual Clonable
266 {
267  public:
269  virtual ~TreeDrawing() {}
270 
271 #ifndef NO_VIRTUAL_COV
272  TreeDrawing* clone() const = 0;
273 #endif
274 
275  public:
279  virtual std::string getName() const = 0;
280 
284  virtual bool hasTree() const = 0;
285 
289  virtual const Tree* getTree() const = 0;
290 
294  virtual void setTree(const Tree* tree) = 0;
295 
302  virtual void setXUnit(double xu) = 0;
303 
310  virtual void setYUnit(double yu) = 0;
311 
315  virtual double getXUnit() const = 0;
316 
320  virtual double getYUnit() const = 0;
321 
325  virtual double getWidth() const = 0;
326 
330  virtual double getHeight() const = 0;
331 
337  virtual void plot(GraphicDevice& gDevice) const throw (Exception) = 0;
338 
346  virtual Point2D<double> getNodePosition(int nodeId) const throw (NodeNotFoundException) = 0;
347 
355  virtual int getNodeAt(const Point2D<double>& position) const throw (NodeNotFoundException) = 0;
356 
368  virtual void collapseNode(int nodeId, bool yn) throw (NodeNotFoundException, Exception) = 0;
369  virtual bool isNodeCollapsed(int nodeId) const throw (NodeNotFoundException, Exception) = 0;
377  virtual void setDisplaySettings(const TreeDrawingSettings* tds) = 0;
378  virtual const TreeDrawingSettings& getDisplaySettings() const = 0;
389  virtual void addTreeDrawingListener(TreeDrawingListener* listener) = 0;
390 
397  virtual void removeTreeDrawingListener(TreeDrawingListener* listener) = 0;
398  };
399 
400 } //end of namespace bpp.
401 
402 #endif //_TREEDRAWING_H_
403 
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:195
Basal interface for tree drawing classes.
Definition: TreeDrawing.h:264
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:156
DrawBranchEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:174
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:153
double getY() const
Definition: TreeDrawing.h:102
virtual int getNodeId() const
Definition: TreeDrawing.h:196
virtual void removeTreeDrawingListener(TreeDrawingListener *listener)=0
Remove a drawing listener from this instance.
Cursor(double x, double y, double angle=0, short hpos=GraphicDevice::TEXT_HORIZONTAL_CENTER, short vpos=GraphicDevice::TEXT_VERTICAL_CENTER)
Definition: TreeDrawing.h:97
virtual int getNodeAt(const Point2D< double > &position) const =0
Get the node corresponding to a position on the device.
DrawBranchEvent & operator=(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:182
virtual bool hasTree() const =0
DrawTreeEvent & operator=(const DrawTreeEvent &dte)
Definition: TreeDrawing.h:226
virtual std::string getName() const =0
virtual void setDisplaySettings(const TreeDrawingSettings *tds)=0
Global drawing settings.
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:237
TreeDrawing * clone() const =0
Cursor getTranslation(double x, double y) const
Definition: TreeDrawing.h:109
virtual Cursor getBranchCursor(double position) const =0
double addX(double increment)
Definition: TreeDrawing.h:106
GraphicDevice * gd_
Definition: TreeDrawing.h:128
double getAngle() const
Definition: TreeDrawing.h:103
DrawTreeEvent(const TreeDrawing *source, GraphicDevice *gd)
Definition: TreeDrawing.h:218
virtual void setXUnit(double xu)=0
Set the &#39;horizontal&#39; expansion unit.
virtual double getYUnit() const =0
Interface for phylogenetic tree objects.
Definition: Tree.h:148
virtual ~DrawTreeEvent()
Definition: TreeDrawing.h:233
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:194
virtual ~TreeDrawing()
Definition: TreeDrawing.h:269
virtual double getWidth() const =0
DrawNodeEvent(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:137
virtual const Cursor & getCursor() const
Definition: TreeDrawing.h:197
short hpos_
Definition: TreeDrawing.h:93
virtual ~DrawBranchEvent()
Definition: TreeDrawing.h:191
virtual bool isNodeCollapsed(int nodeId) const =0
virtual void setTree(const Tree *tree)=0
double angle_
Definition: TreeDrawing.h:92
A set of options to tune the display of a TreeDrawing object.
Definition: TreeDrawing.h:61
double x_
Definition: TreeDrawing.h:90
const TreeDrawing * td_
Definition: TreeDrawing.h:168
Exception thrown when something is wrong with a particular node.
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:124
virtual Point2D< double > getNodePosition(int nodeId) const =0
Get the position of a node.
virtual double getHeight() const =0
Interface allowing to capture drawing events.
virtual const TreeDrawing * getTreeDrawing() const
Definition: TreeDrawing.h:236
virtual double getXUnit() const =0
short getHPos() const
Definition: TreeDrawing.h:104
DrawNodeEvent(const TreeDrawing *source, GraphicDevice *gd, int nodeId, const Cursor &cursor)
Definition: TreeDrawing.h:133
DrawNodeEvent & operator=(const DrawNodeEvent &dne)
Definition: TreeDrawing.h:141
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:165
virtual ~DrawNodeEvent()
Definition: TreeDrawing.h:150
const TreeDrawing * td_
Definition: TreeDrawing.h:127
virtual void addTreeDrawingListener(TreeDrawingListener *listener)=0
Add a drawing listener to this instance.
virtual GraphicDevice * getGraphicDevice() const
Definition: TreeDrawing.h:154
virtual void plot(GraphicDevice &gDevice) const =0
Plot the tree onto the specified device.
DrawBranchEvent(const DrawBranchEvent &dne)
Definition: TreeDrawing.h:178
double getX() const
Definition: TreeDrawing.h:101
virtual void setYUnit(double yu)=0
Set the &#39;vertical&#39; expansion unit.
virtual const Tree * getTree() const =0
GraphicDevice * gd_
Definition: TreeDrawing.h:215
double addY(double increment)
Definition: TreeDrawing.h:107
virtual const TreeDrawingSettings & getDisplaySettings() const =0
const TreeDrawing * td_
Definition: TreeDrawing.h:214
short vpos_
Definition: TreeDrawing.h:94
GraphicDevice * gd_
Definition: TreeDrawing.h:169
double y_
Definition: TreeDrawing.h:91
virtual int getNodeId() const
Definition: TreeDrawing.h:155
virtual void collapseNode(int nodeId, bool yn)=0
Properties to draw.
short getVPos() const
Definition: TreeDrawing.h:105
Data structure describing a plotting direction.
Definition: TreeDrawing.h:87
DrawTreeEvent(const DrawTreeEvent &dne)
Definition: TreeDrawing.h:222
unsigned int pointSize
Definition: TreeDrawing.h:68
Event class used by TreeDrawing classes.
Definition: TreeDrawing.h:211