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