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  initTextDrawer(noFreetype);
41  }
42  MolDraw2DJS(const MolDraw2DJS &) = delete;
43  MolDraw2DJS(MolDraw2DJS &&) = delete;
44  MolDraw2DJS &operator=(const MolDraw2DJS &) = delete;
46 
47  void drawLine(const Point2D &cds1, const Point2D &cds2,
48  bool rawCoords = false) override;
49  void drawPolygon(const std::vector<Point2D> &cds,
50  bool rawCoords = false) override;
51  void drawEllipse(const Point2D &cds1, const Point2D &cds2,
52  bool rawCoords = false) override;
53  void clearDrawing() override;
54  void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
55  const DrawColour &col1, const DrawColour &col2,
56  unsigned int nSegments = 16, double vertOffset = 0.05,
57  bool rawCoords = false) override;
58 
59  private:
60  emscripten::val &d_context;
61  void initDrawing() override;
62  void initTextDrawer(bool noFreetype) override;
63 };
64 
65 } // namespace RDKit
66 #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