Open Babel  3.0
asciipainter.h
Go to the documentation of this file.
1 /**********************************************************************
2 asciipainter.h - Render molecule as ASCII
3 
4 Copyright (C) 2012 by Noel O'Boyle
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 #ifndef OB_ASCIIPAINTER_H
19 #define OB_ASCIIPAINTER_H
20 
22 
23 namespace OpenBabel
24 {
25  class ASCIIPainter : public OBPainter
26  {
27  public:
28  ASCIIPainter(int width, int height, double aspect);
29  ~ASCIIPainter();
31 
32  void NewCanvas(double width, double height);
33  bool IsGood() const;
34  void SetFontFamily(const std::string &fontFamily) {}
35  void SetFontSize(int pointSize);
36  void SetFillColor(const OBColor &color);
37  void SetFillRadial(const OBColor &start, const OBColor &end);
38  void SetPenColor(const OBColor &color);
39  void SetPenWidth(double width);
40  double GetPenWidth();
41  void DrawLine(double x1, double y1, double x2, double y2, const std::vector<double> & dashes=std::vector<double>());
42  void DrawPolygon(const std::vector<std::pair<double,double> > &points);
43  void DrawCircle(double x, double y, double r);
44  void DrawBall(double x, double y, double r, double opacity = 1.0);
45  void DrawText(double x, double y, const std::string &text);
46  OBFontMetrics GetFontMetrics(const std::string &text);
48 
50 
51  void Write(std::ostream &ofs);
52  int round(double r);
53  std::string Bresenham(int x, int y, int x2, int y2, std::vector<std::pair<int, int> > &coords);
55 
56  private:
57  std::vector<std::vector<char> > m_buf;
58  int m_width, m_height; // Width and height of output canvas in characters
59  double m_aspect; // Ratio of height:width for a single character
60  double m_scale; // Conversion from Depiction coords to m_buf coords
61  };
62 
63 }
64 
65 #endif
void SetFillColor(const OBColor &color)
Definition: asciipainter.cpp:58
Abstract painter base class used by OBDepict.
Definition: painter.h:128
void DrawBall(double x, double y, double r, double opacity=1.0)
Definition: asciipainter.cpp:110
bool IsGood() const
Definition: asciipainter.cpp:49
void SetFontSize(int pointSize)
Definition: asciipainter.cpp:54
void SetPenColor(const OBColor &color)
Definition: asciipainter.cpp:67
OBFontMetrics GetFontMetrics(const std::string &text)
Definition: asciipainter.cpp:124
void DrawCircle(double x, double y, double r)
Definition: asciipainter.cpp:106
void DrawText(double x, double y, const std::string &text)
Definition: asciipainter.cpp:114
void NewCanvas(double width, double height)
Definition: asciipainter.cpp:42
void DrawLine(double x1, double y1, double x2, double y2, const std::vector< double > &dashes=std::vector< double >())
Definition: asciipainter.cpp:80
~ASCIIPainter()
Definition: asciipainter.cpp:38
void SetFillRadial(const OBColor &start, const OBColor &end)
Definition: asciipainter.cpp:62
void DrawPolygon(const std::vector< std::pair< double, double > > &points)
Definition: asciipainter.cpp:95
Color class used by OBDepict.
Definition: painter.h:37
Font metrics class used by OBDepict.
Definition: painter.h:116
double GetPenWidth()
Definition: asciipainter.cpp:75
void SetPenWidth(double width)
Definition: asciipainter.cpp:71
Definition: asciipainter.h:25
int round(double r)
Definition: asciipainter.cpp:148
void Write(std::ostream &ofs)
Definition: asciipainter.cpp:136
std::string Bresenham(int x, int y, int x2, int y2, std::vector< std::pair< int, int > > &coords)
Definition: asciipainter.cpp:191
Base class for graphical 2D depiction classes (e.g., "paint" to SVG)
ASCIIPainter(int width, int height, double aspect)
Definition: asciipainter.cpp:28
void SetFontFamily(const std::string &fontFamily)
Definition: asciipainter.h:34
Global namespace for all Open Babel code.
Definition: alias.h:22