bpp-phyl3 3.0.0
AbstractTreeDrawing.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
7
8#include "../Tree/TreeTemplateTools.h"
9#include "../Tree/TreeTools.h"
10#include "AbstractTreeDrawing.h"
11
12// From the STL:
13#include <algorithm>
14
15using namespace bpp;
16using namespace std;
17
18shared_ptr<const TreeDrawingSettings> AbstractTreeDrawing::DEFAULT_SETTINGS = std::make_shared<const TreeDrawingSettings>();
19
20Point2D<double> AbstractTreeDrawing::getNodePosition(int nodeId) const
21{
22 vector<INode*> nodes = tree_->getNodes();
23 for (INode* node : nodes)
24 {
25 if (node->getId() == nodeId)
26 {
27 return node->getInfos().getPosition();
28 }
29 }
30 throw NodeNotFoundException("AbstractTreeDrawing::getNodePosition.", TextTools::toString(nodeId));
31}
32
34{
35 vector<INode*> nodes = tree_->getNodes();
36 for (INode* node : nodes)
37 {
38 Point2D<double> nodePos = node->getInfos().getPosition();
39 if (belongsTo(position, nodePos))
40 {
41 return node->getId();
42 }
43 }
44 throw NodeNotFoundException("AbstractTreeDrawing::getNode.", "");
45}
46
48{
49 return p1.getX() >= p2.getX() - settings_->pointArea && p1.getX() <= p2.getX() + settings_->pointArea
50 && p1.getY() >= p2.getY() - settings_->pointArea && p1.getY() <= p2.getY() + settings_->pointArea;
51}
52
53void AbstractTreeDrawing::drawAtNode(GraphicDevice& gDevice, const INode& node, const string& text, double xOffset, double yOffset, short hpos, short vpos, double angle) const
54{
55 gDevice.drawText(node.getInfos().getX() + xOffset * xUnit_, node.getInfos().getY() + yOffset * yUnit_, text, hpos, vpos, angle);
56}
57
58void AbstractTreeDrawing::drawAtBranch(GraphicDevice& gDevice, const INode& node, const string& text, double xOffset, double yOffset, short hpos, short vpos, double angle) const
59{
60 if (node.hasFather())
61 {
62 gDevice.drawText((node.getInfos().getX() + node.getFather()->getInfos().getX()) / 2. + xOffset * xUnit_, node.getInfos().getY() + yOffset * yUnit_, text, hpos, vpos, angle);
63 }
64}
int getNodeAt(const Point2D< double > &position) const override
Get the node corresponding to a position on the device.
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.
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.
std::shared_ptr< const TreeDrawingSettings > settings_
virtual void drawText(double x, double y, const std::string &text, short hpos=TEXT_HORIZONTAL_LEFT, short vpos=TEXT_VERTICAL_BOTTOM, double angle=0)=0
Exception thrown when something is wrong with a particular node.
The NodeTemplate class.
Definition: NodeTemplate.h:39
const NodeTemplate< NodeInfos > * getFather() const
Get the father of this node is there is one.
Definition: NodeTemplate.h:102
virtual const NodeInfos & getInfos() const
Definition: NodeTemplate.h:144
virtual bool hasFather() const
Tell if this node has a father node.
Definition: Node.h:346
const T & getY() const
const T & getX() const
std::string toString(T t)
Defines the basic types of data flow nodes.