1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
//
// Copyright (C) 2021-2022 David Cosgrove and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
// Original author: David Cosgrove (CozChemIx Limited)
//
// A set of shapes used in 2D drawing.d Not part of the public API.
#ifndef RDKIT_DRAWSHAPE_H
#define RDKIT_DRAWSHAPE_H
#include <vector>
#include <Geometry/point.h>
#include <GraphMol/MolDraw2D/MolDraw2DHelpers.h>
namespace RDKit {
class MolDraw2D;
const DashPattern noDash;
const DashPattern dots{2.0, 6.0};
const DashPattern dashes{6.0, 4.0};
const DashPattern shortDashes{2.0, 2.0};
namespace MolDraw2D_detail {
struct StringRect;
class DrawShape {
public:
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);
DrawShape(const DrawShape &) = delete;
DrawShape(DrawShape &&) = delete;
virtual ~DrawShape() = default;
DrawShape &operator=(const DrawShape &) = delete;
DrawShape &operator=(DrawShape &&) = delete;
void draw(MolDraw2D &drawer);
virtual void myDraw(MolDraw2D &drawer) const = 0;
virtual void findExtremes(double &xmin, double &xmax, double &ymin,
double &ymax) const;
virtual void scale(const Point2D &scale_factor);
virtual void move(const Point2D &trans);
virtual bool doesRectClash(const StringRect &rect, double padding) const;
std::vector<Point2D> points_;
double lineWidth_;
bool scaleLineWidth_;
DrawColour lineColour_;
bool fill_;
int atom1_, atom2_, bond_;
};
class DrawShapeArrow : public DrawShape {
public:
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(const DrawShapeArrow &) = delete;
DrawShapeArrow(DrawShapeArrow &&) = delete;
~DrawShapeArrow() = default;
DrawShapeArrow &operator=(const DrawShapeArrow &) = delete;
DrawShapeArrow &operator=(DrawShapeArrow &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
bool doesRectClash(const StringRect &rect, double padding) const override;
double frac_;
double angle_;
};
class DrawShapeEllipse : public DrawShape {
public:
// Points should be size 2 - the first entry is the centre, the second
// gives the x and y radii of the ellipse.
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(const DrawShapeEllipse &) = delete;
DrawShapeEllipse(DrawShapeEllipse &&) = delete;
~DrawShapeEllipse() = default;
DrawShapeEllipse &operator=(const DrawShapeEllipse &) = delete;
DrawShapeEllipse &operator=(DrawShapeEllipse &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
void findExtremes(double &xmin, double &xmax, double &ymin,
double &ymax) const override;
void move(const Point2D &trans) override;
bool doesRectClash(const StringRect &rect, double padding) const override;
};
class DrawShapeSimpleLine : public DrawShape {
public:
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);
DrawShapeSimpleLine(const DrawShapeSimpleLine &) = delete;
DrawShapeSimpleLine(DrawShapeSimpleLine &&) = delete;
~DrawShapeSimpleLine() = default;
DrawShapeSimpleLine &operator=(const DrawShapeSimpleLine &) = delete;
DrawShapeSimpleLine &operator=(DrawShapeSimpleLine &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
bool doesRectClash(const StringRect &rect, double padding) const override;
DashPattern dashPattern_;
};
class DrawShapePolyLine : public DrawShape {
public:
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);
DrawShapePolyLine(const DrawShapePolyLine &) = delete;
DrawShapePolyLine(DrawShapePolyLine &&) = delete;
~DrawShapePolyLine() = default;
DrawShapePolyLine &operator=(const DrawShapePolyLine &) = delete;
DrawShapePolyLine &operator=(DrawShapePolyLine &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
bool doesRectClash(const StringRect &rect, double padding) const override;
DashPattern dashPattern_;
};
class DrawShapeSolidWedge : public DrawShape {
public:
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(const DrawShapeSolidWedge &) = delete;
DrawShapeSolidWedge(DrawShapeSolidWedge &&) = delete;
~DrawShapeSolidWedge() = default;
DrawShapeSolidWedge &operator=(const DrawShapeSolidWedge &) = delete;
DrawShapeSolidWedge &operator=(DrawShapeSolidWedge &&) = delete;
void buildTriangles();
void buildSingleColorTriangles();
void buildTwoColorTriangles();
void myDraw(MolDraw2D &drawer) const override;
bool doesRectClash(const StringRect &rect, double padding) const override;
// if otherBondVecs_.size() > 2, then we only want the two vecs with the
// widest angle between them.
void trimOtherBondVecs();
// if there are 2 otherBondVecs_ (assuming we've already trimmed down to 2 if
// necessary) make sure the first is on the points_[1] side, the second on
// the points_[2] side, so that the merging of the triangles to the bond
// lines is correct.
void orderOtherBondVecs();
DrawColour col2_;
bool splitBonds_;
std::vector<Point2D> otherBondVecs_;
};
class DrawShapeDashedWedge : public DrawShape {
public:
// oneLessDash means that the last dash at the fat end of the wedge
// isn't drawn. The wedge will be as fat as it would have been with
// the extra dash. This is so that bonds coming out of the fat end
// of the wedge aren't directly incident on a dash.
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);
DrawShapeDashedWedge(const DrawShapeDashedWedge &) = delete;
DrawShapeDashedWedge(DrawShapeDashedWedge &&) = delete;
~DrawShapeDashedWedge() = default;
DrawShapeDashedWedge &operator=(const DrawShapeDashedWedge &) = delete;
DrawShapeDashedWedge &operator=(DrawShapeDashedWedge &&) = delete;
void buildLines();
void myDraw(MolDraw2D &drawer) 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;
DrawColour col2_;
bool oneLessDash_;
std::vector<DrawColour> lineColours_;
// for when we re-create the lines, such as after scaling, this is
// the initial points[0-2] from the c'tor.
Point2D at1Cds_, end1Cds_, end2Cds_;
};
class DrawShapeWavyLine : public DrawShape {
public:
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);
DrawShapeWavyLine(const DrawShapeWavyLine &) = delete;
DrawShapeWavyLine(DrawShapeWavyLine &&) = delete;
~DrawShapeWavyLine() = default;
DrawShapeWavyLine &operator=(const DrawShapeWavyLine &) = delete;
DrawShapeWavyLine &operator=(DrawShapeWavyLine &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
void scale(const Point2D &scaleFactor) override;
bool doesRectClash(const StringRect &rect, double padding) const override;
DrawColour col2_;
double offset_;
};
class DrawShapeArc : public DrawShape {
public:
// draw the arc of an ellipse between ang1 and ang2. Note that 0 is
// at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
// BUT because y increases down the screen, the angles go anticlockwise, such
// that 90 is actually at 6 o'clock on the screen.
// ang2 must be > ang1 - it won't draw backwards. Angles in degrees,
// between 0 and 360.0.
// Points should be size 2 - the first entry is the centre, the second
// gives the x and y radii of the ellipse.
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);
DrawShapeArc(const DrawShapeArc &) = delete;
DrawShapeArc(DrawShapeArc &&) = delete;
~DrawShapeArc() = default;
DrawShapeArc &operator=(const DrawShapeArc &) = delete;
DrawShapeArc &operator=(DrawShapeArc &&) = delete;
void myDraw(MolDraw2D &drawer) const override;
void findExtremes(double &xmin, double &xmax, double &ymin,
double &ymax) const override;
void move(const Point2D &trans) override;
bool doesRectClash(const StringRect &rect, double padding) const override;
double ang1_, ang2_;
};
} // namespace MolDraw2D_detail
} // namespace RDKit
#endif // RDKIT_DRAWSHAPE_H
|