Open Babel  3.0
painter.h
Go to the documentation of this file.
1 /**********************************************************************
2 painter.h - Abstract base class for rendering
3 
4 Copyright (C) 2009 by Tim Vandermeersch
5 Some portions Copyright (C) 2009 by Chris Morley
6 
7 This file is part of the Open Babel project.
8 For more information, see <http://openbabel.org/>
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 ***********************************************************************/
19 #ifndef OB_PAINTER_H
20 #define OB_PAINTER_H
21 
22 #include <openbabel/babelconfig.h>
23 #include <string>
24 #include <vector>
25 #include <sstream>
26 #ifndef OBDEPICT
27  #define OBDEPICT
28 #endif
29 
30 namespace OpenBabel
31 {
37  struct OBDEPICT OBColor
38  {
39  public:
41  {
42  *this = OBColor(0.0, 0.0, 0.0);
43  }
44  OBColor(double _red, double _green, double _blue, double _alpha = 1.0) :
45  red(_red), green(_green), blue(_blue), alpha(_alpha)
46  {
47  }
48  OBColor(const std::string &color)
49  {
50  if (color[0]=='#')
51  {
52  std::stringstream ss(color.substr(1));
53  unsigned c;
54  ss >> std::hex >> c;
55  *this = OBColor((c/0x10000)/256.0, ((c%0x10000)/0x100/256.0), (c%0x100)/256.0);
56  return;
57  }
58  if (color == "black")
59  *this = OBColor(0.0, 0.0, 0.0);
60  else if (color == "white")
61  *this = OBColor(1.0, 1.0, 1.0);
62  else if (color == "red")
63  *this = OBColor(1.0, 0.0, 0.0);
64  else if (color == "green")
65  *this = OBColor(0.0, 1.0, 0.0);
66  else if (color == "blue")
67  *this = OBColor(0.0, 0.0, 1.0);
68  else if (color == "yellow")
69  *this = OBColor(1.0, 1.0, 0.0);
70  else if (color == "gray")
71  *this = OBColor(0.3, 0.3, 0.3);
72  else if (color == "cyan")
73  *this = OBColor(1.0, 0.0, 1.0);
74  else if (color == "purple")
75  *this = OBColor(0.5, 0.0, 0.5);
76  else if (color == "teal")
77  *this = OBColor(0.0, 0.5, 0.5);
78  else if (color == "olive")
79  *this = OBColor(0.5, 0.5, 0.0);
80  else if (color == "none")
81  *this = OBColor(0.0, 0.0, 0.0, 0.0);
82  else
83  *this = OBColor(0.5, 0.5, 0.5);
84  }
85 
86  OBColor(std::vector<double> vec) : red(vec[0]), green(vec[1]), blue(vec[2]), alpha(1.0){}
87 
88  bool operator !=(const OBColor& other)
89  {
90  return red!=other.red || green!=other.green || blue!=other.blue;
91  }
92 
93  bool operator <(const OBColor& other) const
94  {
95  if (red < other.red)
96  return true;
97  else if (red > other.red)
98  return false;
99  else if (green < other.green)
100  return true;
101  else if (green > other.green)
102  return false;
103  else if (blue<other.blue)
104  return true;
105  return false;
106  }
107 
108  double red, green, blue, alpha;
109  };
110 
116  struct OBDEPICT OBFontMetrics
117  {
118  int fontSize;
119  double ascent, descent;
120  double width, height;
121  };
122 
128  class OBDEPICT OBPainter
129  {
130  public:
134  virtual ~OBPainter() {}
135 
142  virtual void NewCanvas(double width, double height) = 0;
148  virtual bool IsGood() const = 0;
152  virtual void SetFontFamily(const std::string &fontFamily) = 0;
156  virtual void SetFontSize(int pointSize) = 0;
160  virtual void SetFillColor(const OBColor &color) = 0;
164  virtual void SetFillRadial(const OBColor &start, const OBColor &end) = 0;
168  virtual void SetPenColor(const OBColor &color) = 0;
172  virtual void SetPenWidth(double width) = 0;
176  virtual double GetPenWidth() = 0;
181  virtual void DrawLine(double x1, double y1, double x2, double y2, const std::vector<double> & dashes=std::vector<double>()) = 0;
182  virtual void DrawCircle(double x, double y, double r) = 0;
189  virtual void DrawPolygon(const std::vector<std::pair<double,double> > &points) = 0;
190 
195  virtual void DrawBall(double x, double y, double r, double opacity = 1.0) = 0;
196 
197  virtual void DrawText(double x, double y, const std::string &text) = 0;
198  virtual OBFontMetrics GetFontMetrics(const std::string &text) = 0;
199  };
200 
201 }
202 
203 #endif
204 
Abstract painter base class used by OBDepict.
Definition: painter.h:128
double width
Definition: painter.h:120
bool operator<(const OBBitVec &bv1, const OBBitVec &bv2)
Definition: bitvec.cpp:556
double red
Definition: painter.h:108
double descent
Definition: painter.h:119
virtual ~OBPainter()
Definition: painter.h:134
static const char * blue
Definition: isomorphism.cpp:33
OBColor()
Definition: painter.h:40
static const char * green
Definition: isomorphism.cpp:31
static const char * red
Definition: isomorphism.cpp:30
Color class used by OBDepict.
Definition: painter.h:37
Font metrics class used by OBDepict.
Definition: painter.h:116
double green
Definition: painter.h:108
double blue
Definition: painter.h:108
OBColor(double _red, double _green, double _blue, double _alpha=1.0)
Definition: painter.h:44
OBColor(const std::string &color)
Definition: painter.h:48
int fontSize
Definition: painter.h:118
OBColor(std::vector< double > vec)
Definition: painter.h:86
Global namespace for all Open Babel code.
Definition: alias.h:22