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, int panelWidth = -1,
30  int panelHeight = -1)
31  : MolDraw2D(width, height, panelWidth, panelHeight), d_os(os) {
32  initDrawing();
33  };
34  // initialize to use the internal stringstream
35  MolDraw2DSVG(int width, int height, int panelWidth = -1, int panelHeight = -1)
36  : MolDraw2D(width, height, panelWidth, panelHeight), d_os(d_ss) {
37  initDrawing();
38  };
39 
40  // set font size in molecule coordinate units. That's probably Angstrom for
41  // RDKit. It will turned into drawing units using scale_, which might be
42  // changed as a result, to make sure things still appear in the window.
43  void setFontSize(double new_size);
44  void setColour(const DrawColour &col);
45 
46  // not sure if this goes here or if we should do a dtor since initDrawing() is
47  // called in the ctor,
48  // but we'll start here
49  void finishDrawing();
50 
51  void drawLine(const Point2D &cds1, const Point2D &cds2);
52  void drawString(const std::string &str, const Point2D &cds);
53  void drawPolygon(const std::vector<Point2D> &cds);
54  void drawEllipse(const Point2D &cds1, const Point2D &cds2);
55  void clearDrawing();
56 
57  void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
58  const DrawColour &col1, const DrawColour &col2,
59  unsigned int nSegments = 16, double vertOffset = 0.05);
60 
61  // using the current scale, work out the size of the label in molecule
62  // coordinates
63  void getStringSize(const std::string &label, double &label_width,
64  double &label_height) const;
65 
66  // this only makes sense if the object was initialized without a stream
67  std::string getDrawingText() const { return d_ss.str(); };
68 
69  void tagAtoms(const ROMol &mol);
70 
71  private:
72  std::ostream &d_os;
73  std::stringstream d_ss;
74 
75  void drawChar(char c, const Point2D &cds);
76  void initDrawing();
77 };
78 }
79 #endif // MOLDRAW2DSVG_H
virtual int height() const
Definition: MolDraw2D.h:148
void setColour(const DrawColour &col)
void getStringSize(const std::string &label, double &label_width, double &label_height) const
virtual int panelHeight() const
Definition: MolDraw2D.h:150
void tagAtoms(const ROMol &mol)
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
void drawLine(const Point2D &cds1, const Point2D &cds2)
MolDraw2DSVG(int width, int height, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DSVG.h:35
void drawString(const std::string &str, const Point2D &cds)
void drawPolygon(const std::vector< Point2D > &cds)
std::string getDrawingText() const
Definition: MolDraw2DSVG.h:67
void drawEllipse(const Point2D &cds1, const Point2D &cds2)
void setFontSize(double new_size)
void drawWavyLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, unsigned int nSegments=16, double vertOffset=0.05)
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
virtual int width() const
Definition: MolDraw2D.h:147
virtual int panelWidth() const
Definition: MolDraw2D.h:149
MolDraw2DSVG(int width, int height, std::ostream &os, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DSVG.h:29
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:37