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 #include <RDGeneral/export.h>
16 #ifndef MOLDRAW2DSVG_H
17 #define MOLDRAW2DSVG_H
18 
19 #include <iostream>
20 #include <sstream>
21 #include "MolDraw2D.h"
22 
23 // ****************************************************************************
24 
25 namespace RDKit {
26 
28  public:
29  // initialize to use a particular ostream
30  MolDraw2DSVG(int width, int height, std::ostream &os, int panelWidth = -1,
31  int panelHeight = -1)
32  : MolDraw2D(width, height, panelWidth, panelHeight), d_os(os) {
33  initDrawing();
34  };
35  // initialize to use the internal stringstream
36  MolDraw2DSVG(int width, int height, int panelWidth = -1, int panelHeight = -1)
37  : MolDraw2D(width, height, panelWidth, panelHeight), d_os(d_ss) {
38  initDrawing();
39  };
40 
41  // set font size in molecule coordinate units. That's probably Angstrom for
42  // RDKit. It will turned into drawing units using scale_, which might be
43  // changed as a result, to make sure things still appear in the window.
44  void setFontSize(double new_size);
45  void setColour(const DrawColour &col);
46 
47  // not sure if this goes here or if we should do a dtor since initDrawing() is
48  // called in the ctor,
49  // but we'll start here
50  void finishDrawing();
51 
52  void drawLine(const Point2D &cds1, const Point2D &cds2);
53  void drawString(const std::string &str, const Point2D &cds);
54  void drawPolygon(const std::vector<Point2D> &cds);
55  void drawEllipse(const Point2D &cds1, const Point2D &cds2);
56  void clearDrawing();
57 
58  void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
59  const DrawColour &col1, const DrawColour &col2,
60  unsigned int nSegments = 16, double vertOffset = 0.05);
61 
62  // using the current scale, work out the size of the label in molecule
63  // coordinates
64  void getStringSize(const std::string &label, double &label_width,
65  double &label_height) const;
66 
67  // this only makes sense if the object was initialized without a stream
68  std::string getDrawingText() const { return d_ss.str(); };
69 
70  void tagAtoms(const ROMol &mol);
71 
72  void addMoleculeMetadata(const ROMol &mol, int confId = -1) const;
73  void addMoleculeMetadata(const std::vector<ROMol *> &mols,
74  const std::vector<int> confIds = {}) const;
75 
76  private:
77  std::ostream &d_os;
78  std::stringstream d_ss;
79 
80  void drawChar(char c, const Point2D &cds);
81  void initDrawing();
82 };
83 } // namespace RDKit
84 #endif // MOLDRAW2DSVG_H
MolDraw2DSVG(int width, int height, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DSVG.h:36
Std stuff.
Definition: Atom.h:30
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:133
std::string getDrawingText() const
Definition: MolDraw2DSVG.h:68
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:385
MolDraw2DSVG(int width, int height, std::ostream &os, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DSVG.h:30
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:39