RDKit
Open-source cheminformatics and machine learning.
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 #include <RDGeneral/export.h>
16 #ifndef MOLDRAW2DCAIRO_H
17 #define MOLDRAW2DCAIRO_H
18 
20 #include <cairo.h>
21 
22 // ****************************************************************************
23 
24 namespace RDKit {
25 
27  public:
28  // does not take ownership of the drawing context
29  MolDraw2DCairo(int width, int height, cairo_t *cr, int panelWidth = -1,
30  int panelHeight = -1)
31  : MolDraw2D(width, height, panelWidth, panelHeight), dp_cr(cr) {
32  cairo_reference(dp_cr);
33  initDrawing();
34  };
35  MolDraw2DCairo(int width, int height, int panelWidth = -1,
36  int panelHeight = -1)
37  : MolDraw2D(width, height, panelWidth, panelHeight) {
38  cairo_surface_t *surf =
39  cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
40  dp_cr = cairo_create(surf);
41  cairo_surface_destroy(surf); // dp_cr has a reference to this now;
42  initDrawing();
43  };
45  if (dp_cr) {
46  if (cairo_get_reference_count(dp_cr) > 0) {
47  cairo_destroy(dp_cr);
48  }
49  dp_cr = NULL;
50  }
51  }
52 
53  void setColour(const DrawColour &col) override;
54 
55  // not sure if this goes here or if we should do a dtor since initDrawing() is
56  // called in the ctor,
57  // but we'll start here
58  void finishDrawing();
59 
60  void drawLine(const Point2D &cds1, const Point2D &cds2) override;
61  void drawChar(char c, const Point2D &cds) override;
62  // void drawString( const std::string &str, const Point2D &cds );
63  void drawPolygon(const std::vector<Point2D> &cds) override;
64  void clearDrawing() override;
65 
66  void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
67  const DrawColour &col1, const DrawColour &col2,
68  unsigned int nSegments = 16, double vertOffset = 0.05) override;
69 
70  // using the current scale, work out the size of the label in molecule
71  // coordinates
72  void getStringSize(const std::string &label, double &label_width,
73  double &label_height) const override;
74 
75  // returns the PNG data in a string
76  std::string getDrawingText() const;
77  // writes the PNG data to a file
78  void writeDrawingText(const std::string &fName) const;
79 
80 #ifdef WIN32
81  bool supportsAnnotations() override {
82  return false;
83  }
84 #endif
85 
86 
87  private:
88  cairo_t *dp_cr;
89 
90  void initDrawing();
91 };
92 } // namespace RDKit
93 #endif // MOLDRAW2DCAIRO_H
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:398
RDKit::MolDraw2DCairo::drawChar
void drawChar(char c, const Point2D &cds) override
RDKit::MolDraw2DCairo::~MolDraw2DCairo
~MolDraw2DCairo()
Definition: MolDraw2DCairo.h:44
RDKit::MolDraw2DCairo::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2) override
draws a line from cds1 to cds2 using the current drawing style
MolDraw2D.h
RDKit::MolDraw2DCairo::clearDrawing
void clearDrawing() override
clears the contents of the drawing
RDKit::DrawColour
Definition: MolDraw2D.h:37
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DCairo.h:35
RDKit::MolDraw2DCairo::MolDraw2DCairo
MolDraw2DCairo(int width, int height, cairo_t *cr, int panelWidth=-1, int panelHeight=-1)
Definition: MolDraw2DCairo.h:29
RDKit::MolDraw2DCairo::setColour
void setColour(const DrawColour &col) override
sets the current draw color
RDKit::MolDraw2DCairo::drawPolygon
void drawPolygon(const std::vector< Point2D > &cds) override
RDKit::MolDraw2DCairo::getStringSize
void getStringSize(const std::string &label, double &label_width, double &label_height) const override
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::MolDraw2D
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:214
RDKit::MolDraw2DCairo::finishDrawing
void finishDrawing()
RDGeom::Point2D
Definition: point.h:258
RDKit::MolDraw2DCairo
Definition: MolDraw2DCairo.h:26
RDKit::MolDraw2DCairo::writeDrawingText
void writeDrawingText(const std::string &fName) const
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) override
draw a wavy line like that used to indicate unknown stereochemistry
RDKit::MolDraw2DCairo::getDrawingText
std::string getDrawingText() const
export.h