RDKit: MolDraw2DCairo.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MolDraw2DCairo.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 a cairo drawing context
14
15 #ifndef MOLDRAW2DCAIRO_H
16 #define MOLDRAW2DCAIRO_H
17
18 #include <GraphMol/MolDraw2D/MolDraw2D.h>
19 #include <cairo.h>
20
21 // ****************************************************************************
22
23 namespace RDKit {
24
25 class MolDraw2DCairo : public MolDraw2D {
26 public:
27 // does not take ownership of the drawing context
28 MolDraw2DCairo(int width, int height, cairo_t *cr, int panelWidth = -1,
29 int panelHeight = -1)
30 : MolDraw2D(width, height, panelWidth, panelHeight), dp_cr(cr) {
31 cairo_reference(dp_cr);
32 initDrawing();
33 };
34 MolDraw2DCairo(int width, int height, int panelWidth = -1,
35 int panelHeight = -1)
36 : MolDraw2D(width, height, panelWidth, panelHeight) {
37 cairo_surface_t *surf =
38 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
39 dp_cr = cairo_create(surf);
40 cairo_surface_destroy(surf); // dp_cr has a reference to this now;
41 initDrawing();
42 };
43 ~MolDraw2DCairo() {
44 if (dp_cr) {
45 if (cairo_get_reference_count(dp_cr) > 0) {
46 cairo_destroy(dp_cr);
47 }
48 dp_cr = NULL;
49 }
50 }
51
52 // set font size in molecule coordinate units. That's probably Angstrom for
53 // RDKit. It will turned into drawing units using scale_, which might be
54 // changed as a result, to make sure things still appear in the window.
55 void setFontSize(double new_size);
56 void setColour(const DrawColour &col);
57
58 // not sure if this goes here or if we should do a dtor since initDrawing() is
59 // called in the ctor,
60 // but we'll start here
61 void finishDrawing();
62
63 void drawLine(const Point2D &cds1, const Point2D &cds2);
64 void drawChar(char c, const Point2D &cds);
65 // void drawString( const std::string &str, const Point2D &cds );
66 void drawPolygon(const std::vector<Point2D> &cds);
67 void clearDrawing();
68
69 void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
70 const DrawColour &col1, const DrawColour &col2,
71 unsigned int nSegments = 16, double vertOffset = 0.05);
72
73 // using the current scale, work out the size of the label in molecule
74 // coordinates
75 void getStringSize(const std::string &label, double &label_width,
76 double &label_height) const;
77
78 // returns the PNG data in a string
79 std::string getDrawingText() const;
80 // writes the PNG data to a file
81 void writeDrawingText(const std::string &fName) const;
82
83 private:
84 cairo_t *dp_cr;
85
86 void initDrawing();
87 };
88 }
89 #endif // MOLDRAW2DCAIRO_H
RDKit::MolDraw2DCairo::drawWavyLine
void drawWavyLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, unsigned int nSegments=16, double vertOffset=0.05)
draw a wavy line like that used to indicate unknown stereochemistry
RDKit::MolDraw2DCairo::drawChar
void drawChar(char c, const Point2D &cds)
RDKit::MolDraw2D::height
virtual int height() const
return the height of the drawing area.
Definition: MolDraw2D.h:284
RDKit::MolDraw2DCairo::getDrawingText
std::string getDrawingText() const
RDKit::MolDraw2DCairo
Definition: MolDraw2DCairo.h:25
RDKit::MolDraw2DCairo::clearDrawing
void clearDrawing()
clears the contes of the drawingd]
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DCairo.h:34
RDGeom::Point2D
Definition: point.h:254
RDKit::MolDraw2D::panelHeight
virtual int panelHeight() const
return the height of the drawing panels.
Definition: MolDraw2D.h:288
RDKit::MolDraw2DCairo::setFontSize
void setFontSize(double new_size)
MolDraw2D.h
RDKit::MolDraw2DCairo::getStringSize
void getStringSize(const std::string &label, double &label_width, double &label_height) const
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height, cairo_t *cr, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DCairo.h:28
RDKit::MolDraw2DCairo::~MolDraw2DCairo
~MolDraw2DCairo()
Definition: MolDraw2DCairo.h:43
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::MolDraw2D::width
virtual int width() const
return the width of the drawing area.
Definition: MolDraw2D.h:282
RDKit::MolDraw2DCairo::finishDrawing
void finishDrawing()
RDKit::MolDraw2DCairo::drawPolygon
void drawPolygon(const std::vector< Point2D > &cds)
draw a polygon
RDKit::MolDraw2D::panelWidth
virtual int panelWidth() const
return the width of the drawing panels.
Definition: MolDraw2D.h:286
RDKit::MolDraw2DCairo::setColour
void setColour(const DrawColour &col)
sets the current draw color
RDKit::MolDraw2D
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:132
RDKit::MolDraw2DCairo::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2)
draws a line from cds1 to cds2 using the current drawing style
RDKit::MolDraw2DCairo::writeDrawingText
void writeDrawingText(const std::string &fName) const
RDKit::DrawColour
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:38