RDKit
Open-source cheminformatics and machine learning.
MolDraw2DJS.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2020 Greg Landrum and T5 informatics GmbH
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 using
13 // the JS canvas. This requires emscripten and is only intended for the RDKit
14 // Javascript builds
15 
16 #include <RDGeneral/export.h>
17 #ifndef MOLDRAW2DJS_H
18 #define MOLDRAW2DJS_H
19 
20 #include <iostream>
21 #include <sstream>
22 #include <emscripten.h>
23 #include <emscripten/val.h>
24 
26 
27 // ****************************************************************************
28 
29 namespace RDKit {
30 
32  public:
33  // initialize to use a particular ostream
34  MolDraw2DJS(int width, int height, emscripten::val &context,
35  int panelWidth = -1, int panelHeight = -1,
36  bool noFreetype = false)
37  : MolDraw2D(width, height, panelWidth, panelHeight), d_context(context) {
38  PRECONDITION(width > 0, "bad width");
39  PRECONDITION(height > 0, "bad height");
40  initDrawing();
41  needs_init_ = false;
42  initTextDrawer(noFreetype);
43  }
44  MolDraw2DJS(const MolDraw2DJS &) = delete;
45  MolDraw2DJS(MolDraw2DJS &&) = delete;
46  MolDraw2DJS &operator=(const MolDraw2DJS &) = delete;
48 
49  void drawLine(const Point2D &cds1, const Point2D &cds2,
50  bool rawCoords = false) override;
51  void drawPolygon(const std::vector<Point2D> &cds,
52  bool rawCoords = false) override;
53  void drawEllipse(const Point2D &cds1, const Point2D &cds2,
54  bool rawCoords = false) override;
55  void clearDrawing() override;
56  void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
57  const DrawColour &col1, const DrawColour &col2,
58  unsigned int nSegments = 16, double vertOffset = 0.05,
59  bool rawCoords = false) override;
60 
61  private:
62  emscripten::val &d_context;
63  void initDrawing() override;
64  void initTextDrawer(bool noFreetype) override;
65 };
66 
67 } // namespace RDKit
68 #endif // MOLDRAW2DSVG_H
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
void drawPolygon(const std::vector< Point2D > &cds, bool rawCoords=false) override
void drawWavyLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, unsigned int nSegments=16, double vertOffset=0.05, bool rawCoords=false) override
draw a wavy line like that used to indicate unknown stereochemistry
MolDraw2DJS & operator=(MolDraw2DJS &&)=delete
MolDraw2DJS(int width, int height, emscripten::val &context, int panelWidth=-1, int panelHeight=-1, bool noFreetype=false)
Definition: MolDraw2DJS.h:34
void drawEllipse(const Point2D &cds1, const Point2D &cds2, bool rawCoords=false) override
draw an ellipse
void drawLine(const Point2D &cds1, const Point2D &cds2, bool rawCoords=false) override
MolDraw2DJS(const MolDraw2DJS &)=delete
MolDraw2DJS & operator=(const MolDraw2DJS &)=delete
MolDraw2DJS(MolDraw2DJS &&)=delete
void clearDrawing() override
clears the contents of the drawing
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:47
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:281
Std stuff.
Definition: Abbreviations.h:19