3
// Created by: Julien Dutheil
4
// Created on: Sun Oct 8 11:57 2006
8
Copyright or Ā© or Copr. Bio++ Development Team, (November 16, 2004)
10
This software is a computer program whose purpose is to provide
11
graphic components to develop bioinformatics applications.
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".
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
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.
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.
40
#ifndef _TREEDRAWING_H_
41
#define _TREEDRAWING_H_
43
#include <Bpp/Clonable.h>
44
#include <Bpp/Graphics/GraphicDevice.h>
45
#include <Bpp/Graphics/Point2D.h>
46
#include <Bpp/Graphics/Font/Font.h>
54
//Forward declarations:
56
class TreeDrawingListener;
59
* @brief A set of options to tune the display of a TreeDrawing object.
61
class TreeDrawingSettings
65
Font fontBranchLengths;
66
Font fontBootstrapValues;
68
unsigned int pointSize;
69
double pointArea; //this specifies the radius of the point area
70
//More options will be added in the future...
73
TreeDrawingSettings() :
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),
85
* @brief Data structure describing a plotting direction.
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) {}
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; }
109
Cursor getTranslation(double x, double y) const
122
* @brief Event class used by TreeDrawing classes.
127
const TreeDrawing* td_;
133
DrawNodeEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
134
td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
137
DrawNodeEvent(const DrawNodeEvent& dne) :
138
td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
141
DrawNodeEvent& operator=(const DrawNodeEvent& dne)
146
cursor_ = dne.cursor_;
150
virtual ~DrawNodeEvent() {}
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_; }
163
* @brief Event class used by TreeDrawing classes.
165
class DrawBranchEvent
168
const TreeDrawing* td_;
174
DrawBranchEvent(const TreeDrawing* source, GraphicDevice* gd, int nodeId, const Cursor& cursor) :
175
td_(source), gd_(gd), id_(nodeId), cursor_(cursor)
178
DrawBranchEvent(const DrawBranchEvent& dne) :
179
td_(dne.td_), gd_(dne.gd_), id_(dne.id_), cursor_(dne.cursor_)
182
DrawBranchEvent& operator=(const DrawBranchEvent& dne)
187
cursor_ = dne.cursor_;
191
virtual ~DrawBranchEvent() {}
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_; }
199
* @return The coordinate of a point on the branch.
200
* @param position The position of the point on the branch, as a proportion of the total branch length.
202
virtual Cursor getBranchCursor(double position) const = 0;
209
* @brief Event class used by TreeDrawing classes.
214
const TreeDrawing* td_;
218
DrawTreeEvent(const TreeDrawing* source, GraphicDevice* gd) :
222
DrawTreeEvent(const DrawTreeEvent& dne) :
223
td_(dne.td_), gd_(dne.gd_)
226
DrawTreeEvent& operator=(const DrawTreeEvent& dte)
233
virtual ~DrawTreeEvent() {}
236
virtual const TreeDrawing* getTreeDrawing() const { return td_; }
237
virtual GraphicDevice* getGraphicDevice() const { return gd_; }
244
* @brief Basal interface for tree drawing classes.
246
* Basicly, a TreeDrawing object draw a graph of the tree and compute the coordinates
247
* of each node on the graph. These coordinates may be retrieved by dedicated functions.
248
* The drawing is performed on a GraphicDevice object.
250
* The TreeDrwing class is in charge of the tree reprensentation, and offer tools to retireve
251
* the coordinates of nodes. Using these functions to plot annotation may turn to be unefficient
252
* however, particularly for large trees, as they involve a search on the whole tree. For easier
253
* tuning of the drawing extensions, the interface defines the drawProperty,
254
* getSupportedDrawableProperties and isDrawable methods. These methods can be used to add features
255
* to the plot. Adding new features can then be performed by subclassing an existing algorithm
256
* and adding support for more properties.
258
* The TreeDrawing interface do not implies that the implementation works on a copy of the tree.
259
* It takes a constant pointer toward the tree to plot. Depending on the implementation however,
260
* the inheriting class may chose to store a copy of the tree for convenience. Refer to the
261
* documentation of the specific implementation you are using for details.
265
public virtual Clonable
269
virtual ~TreeDrawing() {}
271
#ifndef NO_VIRTUAL_COV
272
TreeDrawing* clone() const = 0;
277
* @return A string describing this drawing algorithm.
279
virtual std::string getName() const = 0;
282
* @return 'True' if a tree is attached to this instance.
284
virtual bool hasTree() const = 0;
287
* @return A pointer toward the tree associated to this drawing.
289
virtual const Tree* getTree() const = 0;
292
* @param tree A pointer toward the tree to associate with this drawing.
294
virtual void setTree(const Tree* tree) = 0;
297
* @brief Set the 'horizontal' expansion unit.
299
* The effect of this expansion factor depends on the implementation of the interface.
300
* @param xu The horizontal unit length.
302
virtual void setXUnit(double xu) = 0;
305
* @brief Set the 'vertical' expansion unit.
307
* The effect of this expansion factor depends on the implementation of the interface.
308
* @param yu The vertical unit length.
310
virtual void setYUnit(double yu) = 0;
313
* @return The horizontal unit length.
315
virtual double getXUnit() const = 0;
318
* @return The vertical unit length.
320
virtual double getYUnit() const = 0;
323
* @return The total width of the drawing, in X units.
325
virtual double getWidth() const = 0;
328
* @return The total height of the drawing, in Y units.
330
virtual double getHeight() const = 0;
333
* @brief Plot the tree onto the specified device.
335
* @param gDevice An object implementing the GraphicDevice interface.
337
virtual void plot(GraphicDevice& gDevice) const throw (Exception) = 0;
340
* @brief Get the position of a node.
342
* @param nodeId The identifier of the node.
343
* @return The localization of the node using the coordinate system of the last GraphicDevice used.
344
* @throw NodeNotFoundException If the node does not correspond to a node in the tree.
346
virtual Point2D<double> getNodePosition(int nodeId) const throw (NodeNotFoundException) = 0;
349
* @brief Get the node corresponding to a position on the device.
351
* @param position A position in the coordinates system of the last GraphicDevice used.
352
* @return The corresponding node identifier if available.
353
* @throw NodeNotFoundException If the node does not correspond to a node in the tree.
355
virtual int getNodeAt(const Point2D<double>& position) const throw (NodeNotFoundException) = 0;
358
* @brief Properties to draw.
364
* @brief Collapsing nodes
368
virtual void collapseNode(int nodeId, bool yn) throw (NodeNotFoundException, Exception) = 0;
369
virtual bool isNodeCollapsed(int nodeId) const throw (NodeNotFoundException, Exception) = 0;
373
* @brief Global drawing settings.
377
virtual void setDisplaySettings(const TreeDrawingSettings* tds) = 0;
378
virtual const TreeDrawingSettings& getDisplaySettings() const = 0;
382
* @brief Add a drawing listener to this instance.
384
* @param listener a pointer toward an object implementing the TreeDrawingListener interface.
385
* This object will then be owned by the class and copied and deleted if/when needed, unless
387
* @see TreeDrawingListener
389
virtual void addTreeDrawingListener(TreeDrawingListener* listener) = 0;
392
* @brief Remove a drawing listener from this instance.
394
* @param listener a pointer toward an object implementing the TreeDrawingListener interface.
395
* If the listener is autonomous, it will be deleted.
397
virtual void removeTreeDrawingListener(TreeDrawingListener* listener) = 0;
400
} //end of namespace bpp.
402
#endif //_TREEDRAWING_H_