5#ifndef BPP_PHYL_GRAPHICS_ABSTRACTTREEDRAWING_H
6#define BPP_PHYL_GRAPHICS_ABSTRACTTREEDRAWING_H
9#include "../Tree/NodeTemplate.h"
10#include "../Tree/TreeTemplate.h"
118 std::unique_ptr<TreeTemplate<INode>>
tree_;
134 for (
unsigned int i = 0; i <
listeners_.size(); ++i)
152 for (
unsigned int i = 0; i <
listeners_.size(); ++i)
164 for (
unsigned int i = 0; i <
listeners_.size(); i++)
174 if (
tree_)
return true;
186 throw Exception(
"AbstractTreeDrawing::tree(). No tree is associated.");
198 throw Exception(
"AbstractTreeDrawing::treeTemplate(). No tree is associated.");
236 double xOffset = 0,
double yOffset = 0,
271 if (!
tree_.get())
throw Exception(
"AbstractTreeDrawing::collapseNode. No tree is associated to the drawing.");
272 tree_->getNode(nodeId)->getInfos().collapse(yn);
277 if (!
tree_.get())
throw Exception(
"AbstractTreeDrawing::isNodeCollapsed. No tree is associated to the drawing.");
278 return tree_->getNode(nodeId)->getInfos().isCollapsed();
284 throw Exception(
"AbstractTreeDrawing::addTreeDrawingListener. Listener is already associated to this drawing.");
290 std::vector<TreeDrawingListener*>::iterator it = std::find(
listeners_.begin(),
listeners_.end(), listener);
292 throw Exception(
"AbstractTreeDrawing::addTreeDrawingListener. Listener is not associated to this drawing, and therefore can't be removed.");
306 for (
unsigned int i = 0; i <
listeners_.size(); i++)
315 for (
unsigned int i = 0; i <
listeners_.size(); i++)
324 for (
unsigned int i = 0; i <
listeners_.size(); i++)
333 for (
unsigned int i = 0; i <
listeners_.size(); i++)
342 for (
unsigned int i = 0; i <
listeners_.size(); i++)
351 for (
unsigned int i = 0; i <
listeners_.size(); i++)
Partial implementation of the TreeDrawing interface.
void setDisplaySettings(std::shared_ptr< const TreeDrawingSettings > tds) override
Global drawing settings.
const TreeTemplate< INode > & treeTemplate() const
void fireBeforeBranchEvent_(const DrawIBranchEvent &event) const
int getNodeAt(const Point2D< double > &position) const override
Get the node corresponding to a position on the device.
void addTreeDrawingListener(TreeDrawingListener *listener) override
Add a drawing listener to this instance.
bool isNodeCollapsed(int nodeId) const override
std::vector< TreeDrawingListener * > listeners_
Point2D< double > getNodePosition(int nodeId) const override
Get the position of a node.
AbstractTreeDrawing(const AbstractTreeDrawing &atd)
void removeTreeDrawingListener(TreeDrawingListener *listener) override
Remove a drawing listener from this instance.
static std::shared_ptr< const TreeDrawingSettings > DEFAULT_SETTINGS
const Tree & tree() const override
double getXUnit() const override
void collapseNode(int nodeId, bool yn) override
Properties to draw.
double getYUnit() const override
void setTree(const Tree &tree) override
bool belongsTo(const Point2D< double > &p1, const Point2D< double > &p2) const
Utilitary function, telling if a point belongs to a specified area.
std::unique_ptr< TreeTemplate< INode > > tree_
virtual void drawAtBranch(GraphicDevice &gDevice, const INode &node, const std::string &text, double xOffset=0, double yOffset=0, short hpos=GraphicDevice::TEXT_HORIZONTAL_LEFT, short vpos=GraphicDevice::TEXT_VERTICAL_CENTER, double angle=0) const
Draw some text at a particular branch position.
void fireAfterTreeEvent_(const DrawTreeEvent &event) const
void fireBeforeNodeEvent_(const DrawINodeEvent &event) const
void setXUnit(double xu) override
Set the 'horizontal' expansion unit.
virtual void drawAtNode(GraphicDevice &gDevice, const INode &node, const std::string &text, double xOffset=0, double yOffset=0, short hpos=GraphicDevice::TEXT_HORIZONTAL_LEFT, short vpos=GraphicDevice::TEXT_VERTICAL_CENTER, double angle=0) const
Draw some text at a particular node position.
AbstractTreeDrawing & operator=(const AbstractTreeDrawing &atd)
const TreeDrawingSettings & displaySettings() const override
virtual void treeHasChanged()=0
Method to implement to deal with redrawing when the underlying tree has been modified.
void fireAfterNodeEvent_(const DrawINodeEvent &event) const
bool hasTree() const override
virtual ~AbstractTreeDrawing()
std::shared_ptr< const TreeDrawingSettings > settings_
void fireBeforeTreeEvent_(const DrawTreeEvent &event) const
void fireAfterBranchEvent_(const DrawIBranchEvent &event) const
void setYUnit(double yu) override
Set the 'vertical' expansion unit.
Data structure describing a plotting direction.
Event class used by TreeDrawing classes.
DrawBranchEvent & operator=(const DrawBranchEvent &dne)
Event class that uses INode object (more efficient than relying on nodes id, but less generic).
const INode * getINode() const
DrawIBranchEvent(const TreeDrawing *source, GraphicDevice *gd, const INode *node, const Cursor &cursor)
DrawIBranchEvent & operator=(const DrawIBranchEvent &dne)
DrawIBranchEvent(const DrawIBranchEvent &dne)
Event class that uses INode object (more efficient than relying on nodes id, but less generic).
const INode * getINode() const
DrawINodeEvent(const TreeDrawing *source, GraphicDevice *gd, const INode *node, const Cursor &cursor)
DrawINodeEvent(const DrawINodeEvent &dne)
DrawINodeEvent & operator=(const DrawINodeEvent &dne)
Event class used by TreeDrawing classes.
DrawNodeEvent & operator=(const DrawNodeEvent &dne)
Event class used by TreeDrawing classes.
static short TEXT_HORIZONTAL_LEFT
static short TEXT_VERTICAL_CENTER
Interface allowing to capture drawing events.
virtual bool isAutonomous() const =0
Tells if the listener is autonomous. If so, it will never be hard-copied or deleted.
virtual ~TreeDrawingNodeInfo()
Point2D< double > & getPosition()
const Point2D< double > & getPosition() const
void setPosition(const Point2D< double > &position)
A set of options to tune the display of a TreeDrawing object.
Basal interface for tree drawing classes.
TreeDrawing * clone() const =0
The phylogenetic tree class.
Interface for phylogenetic tree objects.
Defines the basic types of data flow nodes.
NodeTemplate< TreeDrawingNodeInfo > INode