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 
5 #include <Bpp/Numeric/Number.h>
6 #include <Bpp/Text/TextTools.h>
7 
8 #include "../Tree/TreeTemplateTools.h"
9 #include "../Tree/TreeTools.h"
10 #include "AbstractTreeDrawing.h"
11 
12 // From the STL:
13 #include <algorithm>
14 
15 using namespace bpp;
16 using namespace std;
17 
19 
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 
53 void 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 
58 void 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 }
Point2D< double > getNodePosition(int nodeId) const
Get the position of a node.
bool belongsTo(const Point2D< double > &p1, const Point2D< double > &p2) const
Utilitary function, telling if a point belongs to a specified area.
int getNodeAt(const Point2D< double > &position) const
Get the node corresponding to a position on the device.
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.
static const TreeDrawingSettings DEFAULT_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
A set of options to tune the display of a TreeDrawing object.
Definition: TreeDrawing.h:27
std::string toString(T t)
Defines the basic types of data flow nodes.