RDKit: MolDraw2Dwx.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
MolDraw2Dwx.h
Go to the documentation of this file.
1//
2// @@ All Rights Reserved @@
3// This file is part of the RDKit.
4// The contents are covered by the terms of the BSD license
5// which is included in the file license.txt, found at the root
6// of the RDKit source tree.
7//
8// Author: Igor Filippov based on the work of David Cosgrove (AstraZeneca)
9//
10// This is a concrete class derived from MolDraw2D that uses RDKit to draw a
11// molecule into a wxDC
12
13#include <RDGeneral/export.h>
14#ifndef MOLDRAW2DWX_H
15#define MOLDRAW2DWX_H
16
17#include <GraphMol/MolDraw2D/MolDraw2D.h>
18#include <wx/dc.h>
19#include <wx/font.h>
20#include <wx/pen.h>
21#include <wx/colour.h>
22#include <wx/brush.h>
23
24// ****************************************************************************
25
26namespace RDKit {
27
28 class RDKIT_MOLDRAW2D_EXPORT MolDraw2Dwx : public MolDraw2D {
29 public:
30 MolDraw2Dwx(int width, int height, wxDC &dc, int panelWidth = -1,
31 int panelHeight = -1)
32 : MolDraw2D(width, height, panelWidth, panelHeight), m_dc(dc) {
33 // m_dc.SetFont(wxFont(10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL,
34 // wxFONTWEIGHT_NORMAL));
35 }
36
37 // set font size in molecule coordinate units. That's probably Angstrom for
38 // RDKit. It will turned into drawing units using scale_, which might be
39 // changed as a result, to make sure things still appear in the window.
40
41 void setFontSize(double new_size) {
42 MolDraw2D::setFontSize(new_size);
43 double font_size_in_points = fontSize() * scale();
44 wxFont font = m_dc.GetFont();
45 // font.SetPointSize(font_size_in_points);
46 font.SetPixelSize(wxSize(0, font_size_in_points));
47 m_dc.SetFont(font);
48 }
49
50 void setColour(const DrawColour &col) {
51 MolDraw2D::setColour(col);
52 double r = col.get<0>();
53 double g = col.get<1>();
54 double b = col.get<2>();
55 wxColour colour(r * 255, g * 255, b * 255);
56 m_dc.SetTextForeground(colour);
57 m_dc.SetPen(wxPen(colour));
58 m_dc.SetBrush(wxBrush(colour));
59 }
60
61 void drawLine(const Point2D &cds1, const Point2D &cds2) {
62 Point2D c1 = getDrawCoords(cds1);
63 Point2D c2 = getDrawCoords(cds2);
64 m_dc.DrawLine(c1.x, c1.y, c2.x, c2.y);
65 }
66
67 void drawChar(char c, const Point2D &cds) {
68 m_dc.DrawText(wxString(c), cds.x, cds.y);
69 }
70
71 void drawPolygon(const std::vector<Point2D> &cds) {
72 PRECONDITION(cds.size() >= 3, "must have at least three points");
73 wxPoint lines[cds.size()];
74 for (unsigned int i = 0; i < cds.size(); ++i) {
75 Point2D c1 = getDrawCoords(cds[i]);
76 lines[i] = wxPoint(c1.x, c1.y);
77 }
78 // FIX: deal with toggling fills
79 m_dc.DrawPolygon(cds.size(), lines);
80 }
81
82 void clearDrawing() {
83 const wxBrush &brush = m_dc.GetBrush();
84 const wxPen &pen = m_dc.GetPen();
85 setColour(drawOptions.backgroundColour);
86 m_dc.DrawRectangle(0, 0, width(), height());
87 m_dc.SetBrush(brush);
88 m_dc.SetPen(pen);
89 }
90
91 // using the current scale, work out the size of the label in molecule
92 // coordinates
93 void getStringSize(const std::string &label, double &label_width,
94 double &label_height) const {
95 if (m_dc.CanGetTextExtent()) {
96 wxCoord width, height;
97 m_dc.GetTextExtent(wxString(label), &width, &height);
98 label_width = double(width) / scale();
99 label_height = double(height) / scale();
100 }
101 }
102
103 private:
104 wxDC &m_dc;
105};
106} // namespace RDKit
107#endif // MOLDRAW2DWX_H
PRECONDITION
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
MolDraw2D.h
RDGeom::Point2D
Definition point.h:284
RDGeom::Point2D::y
double y
Definition point.h:287
RDGeom::Point2D::x
double x
Definition point.h:286
RDKit::MolDraw2D::panelHeight
int panelHeight() const
return the height of the drawing panels.
Definition MolDraw2D.h:338
RDKit::MolDraw2D::setFontSize
virtual void setFontSize(double new_size)
RDKit::MolDraw2D::MolDraw2D
MolDraw2D(int width, int height, int panelWidth, int panelHeight)
constructor for a particular size
RDKit::MolDraw2D::height
int height() const
return the height of the drawing area.
Definition MolDraw2D.h:334
RDKit::MolDraw2D::colour
virtual DrawColour colour() const
returns the current draw color
Definition MolDraw2D.h:382
RDKit::MolDraw2D::setColour
virtual void setColour(const DrawColour &col)
sets the current draw color
Definition MolDraw2D.h:380
RDKit::MolDraw2D::getDrawCoords
virtual Point2D getDrawCoords(const Point2D &mol_cds) const
RDKit::MolDraw2D::panelWidth
int panelWidth() const
return the width of the drawing panels.
Definition MolDraw2D.h:336
RDKit::MolDraw2D::width
int width() const
return the width of the drawing area.
Definition MolDraw2D.h:332
RDKit::MolDraw2D::fontSize
virtual double fontSize() const
font size in drawing coordinate units. That's probably pixels.
RDKit::MolDraw2D::scale
double scale() const
RDKit::MolDraw2D::drawOptions
MolDrawOptions & drawOptions()
returns our current drawing options
Definition MolDraw2D.h:424
RDKit::MolDraw2Dwx::getStringSize
void getStringSize(const std::string &label, double &label_width, double &label_height) const
Definition MolDraw2Dwx.h:93
RDKit::MolDraw2Dwx::setColour
void setColour(const DrawColour &col)
sets the current draw color
Definition MolDraw2Dwx.h:50
RDKit::MolDraw2Dwx::drawPolygon
void drawPolygon(const std::vector< Point2D > &cds)
Definition MolDraw2Dwx.h:71
RDKit::MolDraw2Dwx::drawChar
void drawChar(char c, const Point2D &cds)
Definition MolDraw2Dwx.h:67
RDKit::MolDraw2Dwx::clearDrawing
void clearDrawing()
clears the contents of the drawing
Definition MolDraw2Dwx.h:82
RDKit::MolDraw2Dwx::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2)
Definition MolDraw2Dwx.h:61
RDKit::MolDraw2Dwx::setFontSize
void setFontSize(double new_size)
Definition MolDraw2Dwx.h:41
RDKit::MolDraw2Dwx::MolDraw2Dwx
MolDraw2Dwx(int width, int height, wxDC &dc, int panelWidth=-1, int panelHeight=-1)
Definition MolDraw2Dwx.h:30
export.h
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition export.h:313
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::DrawColour
Definition MolDraw2DHelpers.h:40