File: rdMolDraw2DQt.cpp

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (51 lines) | stat: -rw-r--r-- 1,896 bytes parent folder | download | duplicates (3)
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
//
//  Copyright (C) 2015-2019 Greg Landrum
//
//   @@ 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.
//
#include <RDBoost/python.h>
#include <RDBoost/Wrap.h>

#include <GraphMol/ROMol.h>
#include <GraphMol/MolDraw2D/MolDraw2D.h>

#include <GraphMol/MolDraw2D/Qt/MolDraw2DQt.h>
#include <QPainter>

namespace python = boost::python;

namespace RDKit {
MolDraw2DQt *moldrawFromQPainter(int width, int height, size_t ptr,
                                 int panelWidth, int panelHeight) {
  if (!ptr) {
    throw_value_error("QPainter pointer is null");
  }
  QPainter *qptr = reinterpret_cast<QPainter *>(ptr);
  return new MolDraw2DQt(width, height, qptr, panelWidth, panelHeight);
}

}  // namespace RDKit

BOOST_PYTHON_MODULE(rdMolDraw2DQt) {
  python::scope().attr("__doc__") =
      "Module containing a C++ implementation of 2D molecule drawing using Qt";

  python::scope().attr("rdkitQtVersion") = RDKit::rdkitQtVersion;

  std::string docString = "Qt molecule drawer";
  python::class_<RDKit::MolDraw2DQt, python::bases<RDKit::MolDraw2D>,
                 boost::noncopyable>("MolDraw2DQt", docString.c_str(),
                                     python::no_init);
  python::def("MolDraw2DFromQPainter_", RDKit::moldrawFromQPainter,
              (python::arg("width"), python::arg("height"),
               python::arg("pointer_to_QPainter"),
               python::arg("panelWidth") = -1, python::arg("panelHeight") = -1),
              "Returns a MolDraw2DQt instance set to use a QPainter.\nUse "
              "sip.unwrapinstance(qptr) to get the required pointer "
              "information. Please note that this is somewhat fragile.",
              python::return_value_policy<python::manage_new_object>());
}