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() override = default;
75 void myDraw(MolDraw2D &drawer) const override;
76 void findExtremes(double &xmin, double &xmax, double &ymin,
77 double &ymax) const override;
78 void scale(const Point2D &scale_factor) override;
79 void move(const Point2D &trans) override;
80 bool doesRectClash(const StringRect &rect, double padding) const override;
81
82 double frac_;
83 double angle_;
84 Point2D origPts_[4]{{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
85};
86
88 public:
89 // Points should be size 2 - the first entry is the centre, the second
90 // gives the x and y radii of the ellipse.
91 DrawShapeEllipse(const std::vector<Point2D> &points, double lineWidth = 2,
92 bool scaleLineWidth = false,
94 bool fill = false, int atom1 = -1);
97 ~DrawShapeEllipse() override = default;
100 void myDraw(MolDraw2D &drawer) const override;
101 void findExtremes(double &xmin, double &xmax, double &ymin,
102 double &ymax) const override;
103 void move(const Point2D &trans) override;
104 bool doesRectClash(const StringRect &rect, double padding) const override;
105};
106
108 public:
109 DrawShapeSimpleLine(const std::vector<Point2D> &points,
110 double lineWidth = 2.0, bool scaleLineWidth = false,
112 int atom1 = -1, int atom2 = -1, int bond = -1,
116 ~DrawShapeSimpleLine() override = default;
119 void myDraw(MolDraw2D &drawer) const override;
120 bool doesRectClash(const StringRect &rect, double padding) const override;
121
123};
124
126 public:
127 DrawShapePolyLine(const std::vector<Point2D> &points, double lineWidth = 2.0,
128 bool scaleLineWidth = false,
130 bool fill = false, int atom1 = -1, int atom2 = -1,
131 int bond = -1, DashPattern dashPattern = noDash);
134 ~DrawShapePolyLine() override = default;
137 void myDraw(MolDraw2D &drawer) const override;
138 bool doesRectClash(const StringRect &rect, double padding) const override;
139
141};
142
144 public:
145 DrawShapeSolidWedge(const std::vector<Point2D> points, const DrawColour &col1,
146 const DrawColour &col2, bool splitBonds,
147 std::vector<Point2D> &otherBondVecs,
148 double lineWidth = 1.0, int atom1 = -1, int atom2 = -1,
149 int bond = -1);
152 ~DrawShapeSolidWedge() override = default;
158 void myDraw(MolDraw2D &drawer) const override;
159 bool doesRectClash(const StringRect &rect, double padding) const override;
160 // if otherBondVecs_.size() > 2, then we only want the two vecs with the
161 // widest angle between them.
163 // if there are 2 otherBondVecs_ (assuming we've already trimmed down to 2 if
164 // necessary) make sure the first is on the points_[1] side, the second on
165 // the points_[2] side, so that the merging of the triangles to the bond
166 // lines is correct.
168
171 std::vector<Point2D> otherBondVecs_;
172};
173
175 public:
176 // oneLessDash means that the last dash at the fat end of the wedge
177 // isn't drawn. The wedge will be as fat as it would have been with
178 // the extra dash. This is so that bonds coming out of the fat end
179 // of the wedge aren't directly incident on a dash.
180 DrawShapeDashedWedge(const std::vector<Point2D> points,
181 const DrawColour &col1, const DrawColour &col2,
182 bool oneLessDash = true, double lineWidth = 1.0,
183 int atom1 = -1, int atom2 = -1, int bond = -1);
186 ~DrawShapeDashedWedge() override = default;
190 void myDraw(MolDraw2D &drawer) const override;
191 void scale(const Point2D &scale_factor) override;
192 void move(const Point2D &trans) override;
193 void findExtremes(double &xmin, double &xmax, double &ymin,
194 double &ymax) const override;
195 bool doesRectClash(const StringRect &rect, double padding) const override;
196
199 std::vector<DrawColour> lineColours_;
200 // for when we re-create the lines, such as after scaling, this is
201 // the initial points[0-2] from the c'tor.
203};
204
206 public:
207 DrawShapeWavyLine(const std::vector<Point2D> points, double lineWidth = 2.0,
208 bool scaleLineWidth = false,
209 const DrawColour &col1 = DrawColour(0, 0, 0),
210 const DrawColour &col2 = DrawColour(0, 0, 0),
211 double offset = 0.05, int atom1 = -1, int atom2 = -1,
212 int bond = -1);
215 ~DrawShapeWavyLine() override = default;
218 void myDraw(MolDraw2D &drawer) const override;
219 void scale(const Point2D &scaleFactor) override;
220 bool doesRectClash(const StringRect &rect, double padding) const override;
221
223 double offset_;
224};
225
226class DrawShapeArc : public DrawShape {
227 public:
228 // draw the arc of an ellipse between ang1 and ang2. Note that 0 is
229 // at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
230 // BUT because y increases down the screen, the angles go anticlockwise, such
231 // that 90 is actually at 6 o'clock on the screen.
232 // ang2 must be > ang1 - it won't draw backwards. Angles in degrees,
233 // between 0 and 360.0.
234 // Points should be size 2 - the first entry is the centre, the second
235 // gives the x and y radii of the ellipse.
236 DrawShapeArc(const std::vector<Point2D> points, double ang1, double ang2,
237 double lineWidth = 2.0, bool scaleLineWidth = false,
238 const DrawColour &col1 = DrawColour(0, 0, 0), bool fill = false,
239 int atom1 = -1);
240 DrawShapeArc(const DrawShapeArc &) = delete;
242 ~DrawShapeArc() override = default;
245
246 void myDraw(MolDraw2D &drawer) const override;
247 void findExtremes(double &xmin, double &xmax, double &ymin,
248 double &ymax) const override;
249 void move(const Point2D &trans) override;
250 bool doesRectClash(const StringRect &rect, double padding) const override;
251
252 double ang1_, ang2_;
253};
254
255} // namespace MolDraw2D_detail
256} // namespace RDKit
257
258#endif // RDKIT_DRAWSHAPE_H
#define M_PI
Definition MMFF/Params.h:26
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
void scale(const Point2D &scale_factor) override
void move(const Point2D &trans) 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