RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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, 4.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, double lineWidth = 2.0,
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
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_;
56 double lineWidth_;
59 bool fill_;
61};
62
63class DrawShapeArrow : public DrawShape {
64 public:
65 DrawShapeArrow(const std::vector<Point2D> &points, double lineWidth = 2.0,
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 should be size 2 - the first entry is the centre, the second
85 // gives the x and y radii of the ellipse.
86 DrawShapeEllipse(const std::vector<Point2D> &points, double lineWidth = 2,
87 bool scaleLineWidth = false,
89 bool fill = false, int atom1 = -1);
92 ~DrawShapeEllipse() = default;
95 void myDraw(MolDraw2D &drawer) const override;
96 void findExtremes(double &xmin, double &xmax, double &ymin,
97 double &ymax) const override;
98 void move(const Point2D &trans) override;
99 bool doesRectClash(const StringRect &rect, double padding) const override;
100};
101
103 public:
104 DrawShapeSimpleLine(const std::vector<Point2D> &points,
105 double lineWidth = 2.0, bool scaleLineWidth = false,
107 int atom1 = -1, int atom2 = -1, int bond = -1,
114 void myDraw(MolDraw2D &drawer) const override;
115 bool doesRectClash(const StringRect &rect, double padding) const override;
116
118};
119
121 public:
122 DrawShapePolyLine(const std::vector<Point2D> &points, double lineWidth = 2.0,
123 bool scaleLineWidth = false,
125 bool fill = false, int atom1 = -1, int atom2 = -1,
126 int bond = -1, DashPattern dashPattern = noDash);
132 void myDraw(MolDraw2D &drawer) const override;
133 bool doesRectClash(const StringRect &rect, double padding) const override;
134
136};
137
139 public:
140 DrawShapeSolidWedge(const std::vector<Point2D> points, const DrawColour &col1,
141 const DrawColour &col2, bool splitBonds,
142 std::vector<Point2D> &otherBondVecs,
143 double lineWidth = 1.0, int atom1 = -1, int atom2 = -1,
144 int bond = -1);
153 void myDraw(MolDraw2D &drawer) const override;
154 bool doesRectClash(const StringRect &rect, double padding) const override;
155 // if otherBondVecs_.size() > 2, then we only want the two vecs with the
156 // widest angle between them.
158 // if there are 2 otherBondVecs_ (assuming we've already trimmed down to 2 if
159 // necessary) make sure the first is on the points_[1] side, the second on
160 // the points_[2] side, so that the merging of the triangles to the bond
161 // lines is correct.
163
166 std::vector<Point2D> otherBondVecs_;
167};
168
170 public:
171 // oneLessDash means that the last dash at the fat end of the wedge
172 // isn't drawn. The wedge will be as fat as it would have been with
173 // the extra dash. This is so that bonds coming out of the fat end
174 // of the wedge aren't directly incident on a dash.
175 DrawShapeDashedWedge(const std::vector<Point2D> points,
176 const DrawColour &col1, const DrawColour &col2,
177 bool oneLessDash = true, double lineWidth = 1.0,
178 int atom1 = -1, int atom2 = -1, int bond = -1);
185 void myDraw(MolDraw2D &drawer) const override;
186 void scale(const Point2D &scale_factor) override;
187 void move(const Point2D &trans) override;
188 void findExtremes(double &xmin, double &xmax, double &ymin,
189 double &ymax) const override;
190 bool doesRectClash(const StringRect &rect, double padding) const override;
191
194 std::vector<DrawColour> lineColours_;
195 // for when we re-create the lines, such as after scaling, this is
196 // the initial points[0-2] from the c'tor.
198};
199
201 public:
202 DrawShapeWavyLine(const std::vector<Point2D> points, double lineWidth = 2.0,
203 bool scaleLineWidth = false,
204 const DrawColour &col1 = DrawColour(0, 0, 0),
205 const DrawColour &col2 = DrawColour(0, 0, 0),
206 double offset = 0.05, int atom1 = -1, int atom2 = -1,
207 int bond = -1);
213 void myDraw(MolDraw2D &drawer) const override;
214 void scale(const Point2D &scaleFactor) override;
215 bool doesRectClash(const StringRect &rect, double padding) const override;
216
218 double offset_;
219};
220
221class DrawShapeArc : public DrawShape {
222 public:
223 // draw the arc of an ellipse between ang1 and ang2. Note that 0 is
224 // at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
225 // BUT because y increases down the screen, the angles go anticlockwise, such
226 // that 90 is actually at 6 o'clock on the screen.
227 // ang2 must be > ang1 - it won't draw backwards. Angles in degrees,
228 // between 0 and 360.0.
229 // Points should be size 2 - the first entry is the centre, the second
230 // gives the x and y radii of the ellipse.
231 DrawShapeArc(const std::vector<Point2D> points, double ang1, double ang2,
232 double lineWidth = 2.0, bool scaleLineWidth = false,
233 const DrawColour &col1 = DrawColour(0, 0, 0), bool fill = false,
234 int atom1 = -1);
235 DrawShapeArc(const DrawShapeArc &) = delete;
237 ~DrawShapeArc() = default;
240
241 void myDraw(MolDraw2D &drawer) const override;
242 void findExtremes(double &xmin, double &xmax, double &ymin,
243 double &ymax) const override;
244 void move(const Point2D &trans) override;
245 bool doesRectClash(const StringRect &rect, double padding) const override;
246
247 double ang1_, ang2_;
248};
249
250} // namespace MolDraw2D_detail
251} // namespace RDKit
252
253#endif // RDKIT_DRAWSHAPE_H
#define M_PI
Definition MMFF/Params.h:27
DrawShapeArc(DrawShapeArc &&)=delete
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
DrawShapeArc(const std::vector< Point2D > points, double ang1, double ang2, double lineWidth=2.0, bool scaleLineWidth=false, const DrawColour &col1=DrawColour(0, 0, 0), bool fill=false, int atom1=-1)
void myDraw(MolDraw2D &drawer) const override
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
DrawShapeArrow(const DrawShapeArrow &)=delete
DrawShapeArrow(const std::vector< Point2D > &points, double lineWidth=2.0, 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)
DrawShapeArrow(DrawShapeArrow &&)=delete
DrawShapeArrow & operator=(DrawShapeArrow &&)=delete
DrawShapeArrow & operator=(const DrawShapeArrow &)=delete
void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const override
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 & operator=(DrawShapeDashedWedge &&)=delete
DrawShapeDashedWedge(const DrawShapeDashedWedge &)=delete
DrawShapeDashedWedge(DrawShapeDashedWedge &&)=delete
DrawShapeDashedWedge(const std::vector< Point2D > points, const DrawColour &col1, const DrawColour &col2, bool oneLessDash=true, double lineWidth=1.0, int atom1=-1, int atom2=-1, int bond=-1)
DrawShapeEllipse(const std::vector< Point2D > &points, double lineWidth=2, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1)
DrawShapeEllipse(DrawShapeEllipse &&)=delete
void move(const Point2D &trans) override
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapeEllipse(const DrawShapeEllipse &)=delete
DrawShapeEllipse & operator=(DrawShapeEllipse &&)=delete
DrawShapeEllipse & operator=(const DrawShapeEllipse &)=delete
void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const override
DrawShapePolyLine(const std::vector< Point2D > &points, double lineWidth=2.0, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1, int atom2=-1, int bond=-1, DashPattern dashPattern=noDash)
bool doesRectClash(const StringRect &rect, double padding) const override
void myDraw(MolDraw2D &drawer) const override
DrawShapePolyLine(const DrawShapePolyLine &)=delete
DrawShapePolyLine(DrawShapePolyLine &&)=delete
DrawShapePolyLine & operator=(DrawShapePolyLine &&)=delete
DrawShapePolyLine & operator=(const DrawShapePolyLine &)=delete
DrawShapeSimpleLine(const std::vector< Point2D > &points, double lineWidth=2.0, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), int atom1=-1, int atom2=-1, int bond=-1, DashPattern dashPattern=noDash)
bool doesRectClash(const StringRect &rect, double padding) const override
DrawShapeSimpleLine & operator=(DrawShapeSimpleLine &&)=delete
DrawShapeSimpleLine(DrawShapeSimpleLine &&)=delete
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(const std::vector< Point2D > points, const DrawColour &col1, const DrawColour &col2, bool splitBonds, std::vector< Point2D > &otherBondVecs, double lineWidth=1.0, int atom1=-1, int atom2=-1, int bond=-1)
DrawShapeSolidWedge & operator=(DrawShapeSolidWedge &&)=delete
DrawShapeSolidWedge(DrawShapeSolidWedge &&)=delete
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, double lineWidth=2.0, 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
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
DrawShape(const std::vector< Point2D > &points, double lineWidth=2.0, bool scaleLineWidth=false, DrawColour lineColour=DrawColour(0, 0, 0), bool fill=false, int atom1=-1, int atom2=-1, int bond=-1)
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.
const DashPattern dots
Definition DrawShape.h:27
std::vector< double > DashPattern
bool rdvalue_is(const RDValue_cast_t)
const DashPattern dashes
Definition DrawShape.h:28
const DashPattern noDash
Definition DrawShape.h:26
const DashPattern shortDashes
Definition DrawShape.h:29