File: MolDraw2Dwx.h

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (107 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
// Author: Igor Filippov based on the work of David Cosgrove (AstraZeneca)
//
// This is a concrete class derived from MolDraw2D that uses RDKit to draw a
// molecule into a wxDC

#include <RDGeneral/export.h>
#ifndef MOLDRAW2DWX_H
#define MOLDRAW2DWX_H

#include <GraphMol/MolDraw2D/MolDraw2D.h>
#include <wx/dc.h>
#include <wx/font.h>
#include <wx/pen.h>
#include <wx/colour.h>
#include <wx/brush.h>

// ****************************************************************************

namespace RDKit {

class RDKIT_MOLDRAW2D_EXPORT MolDraw2Dwx : public MolDraw2D {
 public:
  MolDraw2Dwx(int width, int height, wxDC &dc, int panelWidth = -1,
              int panelHeight = -1)
      : MolDraw2D(width, height, panelWidth, panelHeight), m_dc(dc) {
    // m_dc.SetFont(wxFont(10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL,
    // wxFONTWEIGHT_NORMAL));
  }

  // set font size in molecule coordinate units. That's probably Angstrom for
  // RDKit. It will turned into drawing units using scale_, which might be
  // changed as a result, to make sure things still appear in the window.

  void setFontSize(double new_size) {
    MolDraw2D::setFontSize(new_size);
    double font_size_in_points = fontSize() * scale();
    wxFont font = m_dc.GetFont();
    // font.SetPointSize(font_size_in_points);
    font.SetPixelSize(wxSize(0, font_size_in_points));
    m_dc.SetFont(font);
  }

  void setColour(const DrawColour &col) {
    MolDraw2D::setColour(col);
    double r = col.get<0>();
    double g = col.get<1>();
    double b = col.get<2>();
    wxColour colour(r * 255, g * 255, b * 255);
    m_dc.SetTextForeground(colour);
    m_dc.SetPen(wxPen(colour));
    m_dc.SetBrush(wxBrush(colour));
  }

  void drawLine(const Point2D &cds1, const Point2D &cds2) {
    Point2D c1 = getDrawCoords(cds1);
    Point2D c2 = getDrawCoords(cds2);
    m_dc.DrawLine(c1.x, c1.y, c2.x, c2.y);
  }

  void drawChar(char c, const Point2D &cds) {
    m_dc.DrawText(wxString(c), cds.x, cds.y);
  }

  void drawPolygon(const std::vector<Point2D> &cds) {
    PRECONDITION(cds.size() >= 3, "must have at least three points");
    wxPoint lines[cds.size()];
    for (unsigned int i = 0; i < cds.size(); ++i) {
      Point2D c1 = getDrawCoords(cds[i]);
      lines[i] = wxPoint(c1.x, c1.y);
    }
    // FIX: deal with toggling fills
    m_dc.DrawPolygon(cds.size(), lines);
  };

  void clearDrawing() {
    const wxBrush &brush = m_dc.GetBrush();
    const wxPen &pen = m_dc.GetPen();
    setColour(drawOptions.backgroundColour);
    m_dc.DrawRectangle(0, 0, width(), height());
    m_dc.SetBrush(brush);
    m_dc.SetPen(pen);
  }

  // using the current scale, work out the size of the label in molecule
  // coordinates
  void getStringSize(const std::string &label, double &label_width,
                     double &label_height) const {
    if (m_dc.CanGetTextExtent()) {
      wxCoord width, height;
      m_dc.GetTextExtent(wxString(label), &width, &height);
      label_width = double(width) / scale();
      label_height = double(height) / scale();
    }
  }

 private:
  wxDC &m_dc;
};
}
#endif  // MOLDRAW2DWX_H