RDKit
Open-source cheminformatics and machine learning.
MolDraw2DSVG.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2015 Greg Landrum
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 // derived from Dave Cosgrove's MolDraw2D
11 //
12 // This is a concrete class derived from MolDraw2D that uses RDKit to draw a
13 // molecule into an SVG file
14 
15 #ifndef MOLDRAW2DSVG_H
16 #define MOLDRAW2DSVG_H
17 
18 #include <iostream>
19 #include <sstream>
20 #include "MolDraw2D.h"
21 
22 // ****************************************************************************
23 
24 namespace RDKit {
25 
26 class MolDraw2DSVG : public MolDraw2D {
27  public:
28  // initialize to use a particular ostream
29  MolDraw2DSVG(int width, int height, std::ostream &os)
30  : MolDraw2D(width, height), d_os(os) {
31  initDrawing();
32  };
33  // initialize to use the internal stringstream
34  MolDraw2DSVG(int width, int height) : MolDraw2D(width, height), d_os(d_ss) {
35  initDrawing();
36  };
37 
38  // set font size in molecule coordinate units. That's probably Angstrom for
39  // RDKit. It will turned into drawing units using scale_, which might be
40  // changed as a result, to make sure things still appear in the window.
41  void setFontSize(double new_size);
42  void setColour(const DrawColour &col);
43 
44  // not sure if this goes here or if we should do a dtor since initDrawing() is
45  // called in the ctor,
46  // but we'll start here
47  void finishDrawing();
48 
49  void drawLine(const Point2D &cds1, const Point2D &cds2);
50  void drawString(const std::string &str, const Point2D &cds);
51  void drawPolygon(const std::vector<Point2D> &cds);
52  void drawEllipse(const Point2D &cds1, const Point2D &cds2);
53  void clearDrawing();
54 
55  // using the current scale, work out the size of the label in molecule
56  // coordinates
57  void getStringSize(const std::string &label, double &label_width,
58  double &label_height) const;
59 
60  // this only makes sense if the object was initialized without a stream
61  std::string getDrawingText() const { return d_ss.str(); };
62 
63  void tagAtoms(const ROMol &mol);
64 
65  private:
66  std::ostream &d_os;
67  std::stringstream d_ss;
68 
69  void drawChar(char c, const Point2D &cds);
70  void initDrawing();
71 };
72 }
73 #endif // MOLDRAW2DSVG_H
virtual int height() const
Definition: MolDraw2D.h:129
void setColour(const DrawColour &col)
void tagAtoms(const ROMol &mol)
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
void drawLine(const Point2D &cds1, const Point2D &cds2)
void drawString(const std::string &str, const Point2D &cds)
void drawPolygon(const std::vector< Point2D > &cds)
MolDraw2DSVG(int width, int height, std::ostream &os)
Definition: MolDraw2DSVG.h:29
void drawEllipse(const Point2D &cds1, const Point2D &cds2)
void setFontSize(double new_size)
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
MolDraw2DSVG(int width, int height)
Definition: MolDraw2DSVG.h:34
void getStringSize(const std::string &label, double &label_width, double &label_height) const
virtual int width() const
Definition: MolDraw2D.h:128
std::string getDrawingText() const
Definition: MolDraw2DSVG.h:61
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:37