RDKit
Open-source cheminformatics and machine learning.
DrawShape.h
Go to the documentation of this file.
1//
2// Copyright (C) 2021-2022 David Cosgrove and other RDKit contributors
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// Original author: David Cosgrove (CozChemIx Limited)
11//
12
13// A set of shapes used in 2D drawing.d Not part of the public API.
14
15#ifndef RDKIT_DRAWSHAPE_H
16#define RDKIT_DRAWSHAPE_H
17
18#include <vector>
19
20#include <Geometry/point.h>
22
23namespace RDKit {
24
25class MolDraw2D;
27const DashPattern dots{2.0, 6.0};
28const DashPattern dashes{6, 0, 6.0};
29const DashPattern shortDashes{2.0, 2.0};
30
31namespace MolDraw2D_detail {
32
33struct StringRect;
34
35class DrawShape {
36 public:
37 DrawShape(const std::vector<Point2D> &points, int lineWidth = 2,
38 bool scaleLineWidth = false,
39 DrawColour lineColour = DrawColour(0, 0, 0), bool fill = false,
40 int atom1 = -1, int atom2 = -1, int bond = -1);
41 DrawShape(const DrawShape &) = delete;
42 DrawShape(DrawShape &&) = delete;
43 virtual ~DrawShape() = default;
44 DrawShape &operator=(const DrawShape &) = delete;
46
47 void draw(MolDraw2D &drawer);
48 virtual void myDraw(MolDraw2D &drawer) const = 0;
49 virtual void findExtremes(double &xmin, double &xmax, double &ymin,
50 double &ymax) const;
51 virtual void scale(const Point2D &scale_factor);
52 virtual void move(const Point2D &trans);
53 virtual bool doesRectClash(const StringRect &rect, double padding) const;
54
55 std::vector<Point2D> points_;
59 bool fill_;
61};
62
63class DrawShapeArrow : public DrawShape {
64 public:
65 DrawShapeArrow(const std::vector<Point2D> &points, int lineWidth = 2,
66 bool scaleLineWidth = false,
67 DrawColour lineColour = DrawColour(0, 0, 0), bool fill = false,
68 int atom1 = -1, int atom2 = -1, int bond = -1,
69 double frac = 0.2, double angle = M_PI / 6);
70 DrawShapeArrow(const DrawShapeArrow &) = delete;
72 ~DrawShapeArrow() = default;
75 void myDraw(MolDraw2D &drawer) const override;
76 bool doesRectClash(const StringRect &rect, double padding) const override;
77
78 double frac_;
79 double angle_;
80};
81
83 public:
84 // points are the 2 foci of the ellipse
85 DrawShapeEllipse(const std::vector<Point2D> &points, int lineWidth = 2,
86 bool scaleLineWidth = false,
87 DrawColour lineColour = DrawColour(0, 0, 0),
88 bool fill = false, int atom1 = -1);
91 ~DrawShapeEllipse() = default;
94 void myDraw(MolDraw2D &drawer) const override;
95 void findExtremes(double &xmin, double &xmax, double &ymin,
96 double &ymax) const override;
97 bool doesRectClash(const StringRect &rect, double padding) const override;
98};
99
101 public:
102 DrawShapeSimpleLine(const std::vector<Point2D> &points, int lineWidth = 2,
103 bool scaleLineWidth = false,
104 DrawColour lineColour = DrawColour(0, 0, 0),
105 int atom1 = -1, int atom2 = -1, int bond = -1,
106 DashPattern dashPattern = noDash);
112 void myDraw(MolDraw2D &drawer) const override;
113 bool doesRectClash(const StringRect &rect, double padding) const override;
114
116};
117
119 public:
120 DrawShapePolyLine(const std::vector<Point2D> &points, int lineWidth = 2,
121 bool scaleLineWidth = false,
122 DrawColour lineColour = DrawColour(0, 0, 0),
123 bool fill = false, int atom1 = -1, int atom2 = -1,
124 int bond = -1, DashPattern dashPattern = noDash);
130 void myDraw(MolDraw2D &drawer) const override;
131 bool doesRectClash(const StringRect &rect, double padding) const override;
132
134};
135
137 public:
138 DrawShapeSolidWedge(const std::vector<Point2D> points, const DrawColour &col1,
139 const DrawColour &col2, bool splitBonds, int atom1 = -1,
140 int atom2 = -1, int bond = -1);
147 void myDraw(MolDraw2D &drawer) const override;
148 bool doesRectClash(const StringRect &rect, double padding) const override;
149
152};
153
155 public:
156 DrawShapeDashedWedge(const std::vector<Point2D> points,
157 const DrawColour &col1, const DrawColour &col2,
158 int atom1 = -1, int atom2 = -1, int bond = -1);
165 void myDraw(MolDraw2D &drawer) const override;
166 void scale(const Point2D &scale_factor) override;
167 void move(const Point2D &trans) override;
168 bool doesRectClash(const StringRect &rect, double padding) const override;
169
171 std::vector<DrawColour> lineColours_;
172 // for when we re-create the lines when it gets too wide, this is
173 // the initial points[0] from the c'tor.
175};
176
178 public:
179 DrawShapeWavyLine(const std::vector<Point2D> points, int lineWidth = 2,
180 bool scaleLineWidth = false,
181 const DrawColour &col1 = DrawColour(0, 0, 0),
182 const DrawColour &col2 = DrawColour(0, 0, 0),
183 double offset = 0.05, int atom1 = -1, int atom2 = -1,
184 int bond = -1);
190 void myDraw(MolDraw2D &drawer) const override;
191 void scale(const Point2D &scaleFactor) override;
192 bool doesRectClash(const StringRect &rect, double padding) const override;
193
195 double offset_;
196};
197
198class DrawShapeArc : public DrawShape {
199 public:
200 // draw the arc of an ellipse between ang1 and ang2. Note that 0 is
201 // at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
202 // ang2 must be > ang1 - it won't draw backwards. Angles in degrees,
203 // between 0 and 360.0.
204 // Points should be size 2 - the first entry is the centre, the second
205 // gives the x and y radii of the ellipse.
206 DrawShapeArc(const std::vector<Point2D> points, double ang1, double ang2,
207 int lineWidth = 2, bool scaleLineWidth = false,
208 const DrawColour &col1 = DrawColour(0, 0, 0), bool fill = false,
209 int atom1 = -1);
210 DrawShapeArc(const DrawShapeArc &) = delete;
212 ~DrawShapeArc() = default;
215
216 void myDraw(MolDraw2D &drawer) const override;
217 void findExtremes(double &xmin, double &xmax, double &ymin,
218 double &ymax) const override;
219 void move(const Point2D &trans) override;
220 bool doesRectClash(const StringRect &rect, double padding) const override;
221
222 double ang1_, ang2_;
223};
224
225} // namespace MolDraw2D_detail
226} // namespace RDKit
227
228#endif // RDKIT_DRAWSHAPE_H
#define M_PI
Definition: MMFF/Params.h:27
DrawShapeArc(DrawShapeArc &&)=delete
DrawShapeArc(const std::vector< Point2D > points, double ang1, double ang2, int lineWidth=2, bool scaleLineWidth=false, const DrawColour &col1=DrawColour(0, 0, 0), bool fill=false, int atom1=-1)
bool doesRectClash(const StringRect &rect, double padding) const override
DrawShapeArc & operator=(DrawShapeArc &&)=delete
void move(const Point2D &trans) override
DrawShapeArc & operator=(const DrawShapeArc &)=delete
DrawShapeArc(const DrawShapeArc &)=delete
void myDraw(MolDraw2D &drawer) const override
void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const override
DrawShapeArrow(const std::vector< Point2D > &points, int lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1, int atom2=-1, int bond=-1, double frac=0.2, double angle=M_PI/6)
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapeArrow(const DrawShapeArrow &)=delete
DrawShapeArrow(DrawShapeArrow &&)=delete
DrawShapeArrow & operator=(DrawShapeArrow &&)=delete
DrawShapeArrow & operator=(const DrawShapeArrow &)=delete
void myDraw(MolDraw2D &drawer) const override
void scale(const Point2D &scale_factor) override
void move(const Point2D &trans) override
DrawShapeDashedWedge & operator=(const DrawShapeDashedWedge &)=delete
bool doesRectClash(const StringRect &rect, double padding) const override
DrawShapeDashedWedge(const std::vector< Point2D > points, const DrawColour &col1, const DrawColour &col2, int atom1=-1, int atom2=-1, int bond=-1)
std::vector< DrawColour > lineColours_
Definition: DrawShape.h:171
DrawShapeDashedWedge & operator=(DrawShapeDashedWedge &&)=delete
DrawShapeDashedWedge(const DrawShapeDashedWedge &)=delete
DrawShapeDashedWedge(DrawShapeDashedWedge &&)=delete
DrawShapeEllipse(DrawShapeEllipse &&)=delete
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapeEllipse(const DrawShapeEllipse &)=delete
DrawShapeEllipse & operator=(DrawShapeEllipse &&)=delete
DrawShapeEllipse(const std::vector< Point2D > &points, int lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1)
DrawShapeEllipse & operator=(const DrawShapeEllipse &)=delete
void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const override
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapePolyLine(const DrawShapePolyLine &)=delete
DrawShapePolyLine(DrawShapePolyLine &&)=delete
DrawShapePolyLine(const std::vector< Point2D > &points, int lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1, int atom2=-1, int bond=-1, DashPattern dashPattern=noDash)
DrawShapePolyLine & operator=(DrawShapePolyLine &&)=delete
DrawShapePolyLine & operator=(const DrawShapePolyLine &)=delete
bool doesRectClash(const StringRect &rect, double padding) const override
DrawShapeSimpleLine & operator=(DrawShapeSimpleLine &&)=delete
DrawShapeSimpleLine(DrawShapeSimpleLine &&)=delete
DrawShapeSimpleLine(const std::vector< Point2D > &points, int lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), int atom1=-1, int atom2=-1, int bond=-1, DashPattern dashPattern=noDash)
DrawShapeSimpleLine(const DrawShapeSimpleLine &)=delete
void myDraw(MolDraw2D &drawer) const override
DrawShapeSimpleLine & operator=(const DrawShapeSimpleLine &)=delete
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapeSolidWedge & operator=(DrawShapeSolidWedge &&)=delete
DrawShapeSolidWedge(DrawShapeSolidWedge &&)=delete
DrawShapeSolidWedge(const std::vector< Point2D > points, const DrawColour &col1, const DrawColour &col2, bool splitBonds, int atom1=-1, int atom2=-1, int bond=-1)
DrawShapeSolidWedge & operator=(const DrawShapeSolidWedge &)=delete
DrawShapeSolidWedge(const DrawShapeSolidWedge &)=delete
bool doesRectClash(const StringRect &rect, double padding) const override
DrawShapeWavyLine & operator=(const DrawShapeWavyLine &)=delete
DrawShapeWavyLine(const DrawShapeWavyLine &)=delete
DrawShapeWavyLine & operator=(DrawShapeWavyLine &&)=delete
void myDraw(MolDraw2D &drawer) const override
DrawShapeWavyLine(DrawShapeWavyLine &&)=delete
void scale(const Point2D &scaleFactor) override
DrawShapeWavyLine(const std::vector< Point2D > points, int lineWidth=2, bool scaleLineWidth=false, const DrawColour &col1=DrawColour(0, 0, 0), const DrawColour &col2=DrawColour(0, 0, 0), double offset=0.05, int atom1=-1, int atom2=-1, int bond=-1)
virtual void myDraw(MolDraw2D &drawer) const =0
DrawShape(const std::vector< Point2D > &points, int lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1, int atom2=-1, int bond=-1)
virtual void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const
virtual bool doesRectClash(const StringRect &rect, double padding) const
void draw(MolDraw2D &drawer)
std::vector< Point2D > points_
Definition: DrawShape.h:55
DrawShape & operator=(DrawShape &&)=delete
DrawShape & operator=(const DrawShape &)=delete
virtual void scale(const Point2D &scale_factor)
virtual void move(const Point2D &trans)
DrawShape(const DrawShape &)=delete
DrawShape(DrawShape &&)=delete
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:47
Std stuff.
Definition: Abbreviations.h:18
const DashPattern dots
Definition: DrawShape.h:27
std::vector< double > DashPattern
const DashPattern dashes
Definition: DrawShape.h:28
const DashPattern noDash
Definition: DrawShape.h:26
const DashPattern shortDashes
Definition: DrawShape.h:29