RDKit
Open-source cheminformatics and machine learning.
AtomSymbol.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 // This class is a helper class used by MolDraw2D to draw an ROMol.
13 // It is not part of the public API and is not intended to be used except
14 // by MolDraw2D.
15 // It holds the information needed to draw an atom symbol, including
16 // all the extra bits like isotope labels.
17 
18 #ifndef RDKIT_ATOMSYMBOL_H
19 #define RDKIT_ATOMSYMBOL_H
20 
21 #include <string>
22 
25 
26 namespace RDKit {
27 
28 class MolDraw2D;
29 
30 namespace MolDraw2D_detail {
31 
32 class AtomSymbol {
33 
34  public:
35  virtual ~AtomSymbol() = default;
36 
37  /*!
38  *
39  * @param symbol : the full symbol
40  * @param orient : text orientation (up, down, left, right)
41  * @param textDrawer : instance of DrawText to get the character sizes
42  * etc.
43  */
44  AtomSymbol(const std::string &symbol, int atIdx, OrientType orient,
45  const Point2D &cds, const DrawColour &colour,
46  DrawText &textDrawer);
47 
48  AtomSymbol(const AtomSymbol &) = delete;
49  AtomSymbol(AtomSymbol &&) = delete;
50  AtomSymbol &operator=(const AtomSymbol &) = delete;
52 
53  std::string symbol_;
54  int atIdx_;
59 
60  std::vector<std::shared_ptr<StringRect>> rects_;
61  std::vector<TextDrawType> drawModes_;
62  std::vector<char> drawChars_;
63 
64  // expects xmin etc to be initialised to something sensible.
65  virtual void findExtremes(double &xmin, double &xmax, double &ymin,
66  double &ymax) const;
67  // scaleFactor moves the cds_, but the fontScaleFactor changes rects_, because
68  // we might be scaling the font differently from the drawing as a whole.
69  virtual void scale(const Point2D &scaleFactor);
70  virtual void move(const Point2D &trans);
71  void draw(MolDraw2D &molDrawer) const;
72  bool doesRectClash(const StringRect &rect, double padding) const;
73  // Because a colon is a lot shorter than other characters, there are cases,
74  // such as rxn_test1_2 in rxn_test1.cpp, where a vertical bond can slip
75  // between the atom symbol and the atom map (C:8 in that case) which looks
76  // a bit pants. This stretches the colon to be the same height as the
77  // smaller of the chars on either side.
78  void adjustColons();
79 
80  // this is for debugging almost always.
81  void drawRects(MolDraw2D &molDrawer) const;
82 };
83 
84 } // namespace MolDraw2D_detail
85 } // namespace RDKit
86 
87 #endif // RDKIT_ATOMSYMBOL_H
virtual void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const
std::vector< std::shared_ptr< StringRect > > rects_
Definition: AtomSymbol.h:60
bool doesRectClash(const StringRect &rect, double padding) const
AtomSymbol(AtomSymbol &&)=delete
virtual void move(const Point2D &trans)
AtomSymbol & operator=(AtomSymbol &&)=delete
std::vector< TextDrawType > drawModes_
Definition: AtomSymbol.h:61
AtomSymbol & operator=(const AtomSymbol &)=delete
AtomSymbol(const std::string &symbol, int atIdx, OrientType orient, const Point2D &cds, const DrawColour &colour, DrawText &textDrawer)
void drawRects(MolDraw2D &molDrawer) const
void draw(MolDraw2D &molDrawer) const
virtual void scale(const Point2D &scaleFactor)
AtomSymbol(const AtomSymbol &)=delete
std::vector< char > drawChars_
Definition: AtomSymbol.h:62
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:47
static const char * symbol[119]
Definition: mf.h:257
Std stuff.
Definition: Abbreviations.h:18