Chemical Data Processing Library C++ API - Version 1.4.0
StructureView2D.hpp
Go to the documentation of this file.
1 /*
2  * StructureView2D.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_VIS_STRUCTUREVIEW2D_HPP
30 #define CDPL_VIS_STRUCTUREVIEW2D_HPP
31 
32 #include <vector>
33 #include <memory>
34 #include <string>
35 #include <cstddef>
36 #include <utility>
37 
38 #include "CDPL/Vis/APIPrefix.hpp"
39 #include "CDPL/Vis/View2D.hpp"
40 #include "CDPL/Vis/Rectangle2D.hpp"
41 #include "CDPL/Vis/Line2D.hpp"
42 #include "CDPL/Vis/Color.hpp"
43 #include "CDPL/Vis/Font.hpp"
44 #include "CDPL/Vis/Pen.hpp"
45 #include "CDPL/Vis/Brush.hpp"
56 #include "CDPL/Util/BitSet.hpp"
58 
59 
60 namespace CDPL
61 {
62 
63  namespace Base
64  {
65 
66  class PropertyContainer;
67  }
68 
69  namespace Chem
70  {
71 
72  class MolecularGraph;
73  class Fragment;
74  class Atom;
75  class Bond;
76  } // namespace Chem
77 
78  namespace Vis
79  {
80 
81  class StructureView2DParameters;
82 
680  {
681 
682  public:
686  typedef std::shared_ptr<StructureView2D> SharedPointer;
687 
692  StructureView2D(const Chem::MolecularGraph* molgraph = 0);
693 
695 
700 
702 
703  void render(Renderer2D& renderer);
704 
705  void setFontMetrics(FontMetrics* font_metrics);
706 
712 
721  void setStructure(const Chem::MolecularGraph* molgraph);
722 
728 
730 
731  private:
732  friend class ReactionView2D;
733 
734  StructureView2D(bool);
735 
736  void paintBackground(Renderer2D&) const;
737 
738  void renderGraphicsPrimitives(Renderer2D&) const;
739 
740  void init();
741 
742  void initTextLabelBounds();
743 
744  void createAtomPrimitives();
745  void createBondPrimitives();
746 
747  void createHighlightingPrimitives();
748 
749  void createAtomHighlightingPrimitives(double, double, double);
750  void createAtomHighlightingPrimitives(const Chem::Atom&, double, double, double);
751 
752  void createBondHighlightingPrimitives(double, double, double);
753  void createBondHighlightingPrimitives(const Chem::Bond&, double, double, double);
754 
755  void createAtomPrimitives(const Chem::Atom&);
756  double createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
757  void createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, double, Rectangle2D&);
758  double createAtomSymbolLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
759  void createRadicalElectronPrimitives(const Chem::Atom&, std::size_t, Rectangle2D&);
760  void createAtomIsotopeLabelPrimitive(const Chem::Atom&, std::size_t, Rectangle2D&);
761  void createAtomChargeLabelPrimitive(const Chem::Atom&, long, std::size_t, Rectangle2D&);
762  void createAtomHCountLabelPrimitives(const Chem::Atom&, std::size_t, double, Rectangle2D&);
763  void createAtomMappingLabelPrimitive(const Chem::Atom&, std::size_t, const Rectangle2D&);
764  void createAtomConfigLabelPrimitive(const Chem::Atom&, char);
765  void createAtomCustomLabelPrimitive(const Chem::Atom&, const std::string&, bool);
766 
767  void createBondLabelPrimitives(const Chem::Bond&, const Line2D&, int);
768  double createBondRxnInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int);
769  void createBondQueryInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int, double);
770  void createBondConfigLabelPrimitive(const Chem::Bond&, const Line2D&, int);
771  void createBondCustomLabelPrimitive(const Chem::Bond&, const Line2D&, int);
772 
773  void createUndefOrderBondPrimitives(const Chem::Bond&, const Line2D&);
774  void createSingleBondPrimitives(const Chem::Bond&, const Line2D&);
775  void createUpSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
776  void extendUpBondWedgeSides(const Chem::Bond&, const Chem::Atom&, Line2D&, Line2D&, bool, bool) const;
777  void extendWedgeSideToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
778  void createDownSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
779  void createEitherSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
780  void createPlainSingleBondPrimitives(const Chem::Bond&, const Line2D&);
781 
782  void createDoubleBondPrimitives(const Chem::Bond&, const Line2D&, int);
783  void createAsymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&, int);
784  void createSymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&);
785 
786  void createTripleBondPrimitives(const Chem::Bond&, const Line2D&);
787 
788  void createBondRxnCenterPrimitives(const Chem::Bond&, const Line2D&, int);
789 
790  int getBondAsymmetryShiftDirection(const Chem::Bond&) const;
791 
792  bool trimLine(Line2D&, double, bool) const;
793 
794  bool clipLineAgainstAtomBounds(Line2D&, const Chem::Bond&) const;
795  bool clipLineAgainstAtomBounds(Line2D&, std::size_t, bool) const;
796 
797  void extendBondLineToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
798  void clipLineAgainstNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
799  void clipLineAgainstBondLabel(LinePrimitive2D*, std::size_t);
800 
801  std::size_t getHydrogenCount(const Chem::Atom&) const;
802 
803  double calcCongestionFactor(const Rectangle2D&, const Base::PropertyContainer&) const;
804 
805  double calcBondAngle(const Chem::Bond&, const Chem::Bond&) const;
806  double calcInputBondLength(const Chem::Bond&) const;
807 
808  void prepareStructureData();
809  void initInputAtomPosArray();
810 
811  void calcViewTransforms();
812 
813  double calcAvgInputBondLength() const;
814 
815  void calcStdBondLengthScalingFactor();
816  void calcViewportAdjustmentScalingFactor();
817 
818  void calcInputStructureBounds();
819  void calcOutputStructureBounds();
820  void calcOutputAtomCoords();
821 
822  void initOutputBondLineArray();
823 
824  unsigned int getBondStereoFlag(const Chem::Bond&, const Chem::MolecularGraph&) const;
825  std::size_t getBondOrder(const Chem::Bond& bond) const;
826 
827  void setHasAtomCoordsFlag();
828 
829  double getLineWidth(const Chem::Bond&) const;
830  double getRxnCenterLineLength(const Chem::Bond&) const;
831  double getRxnCenterLineSpacing(const Chem::Bond&) const;
832  double getDoubleBondTrimLength(const Chem::Bond&) const;
833  double getTripleBondTrimLength(const Chem::Bond&) const;
834  double getLineSpacing(const Chem::Bond&) const;
835  double getWedgeWidth(const Chem::Bond&) const;
836  double getHashSpacing(const Chem::Bond&) const;
837  double getLabelSize(const Chem::Bond&) const;
838  double getConfigLabelSize(const Chem::Bond&) const;
839  double getCustomLabelSize(const Chem::Bond&) const;
840 
841  const Color& getColor(const Chem::Bond&) const;
842  const Color& getConfigLabelColor(const Chem::Bond&) const;
843  const Color& getCustomLabelColor(const Chem::Bond&) const;
844  const Font& getLabelFont(const Chem::Bond&) const;
845  const Font& getConfigLabelFont(const Chem::Bond&) const;
846  const Font& getCustomLabelFont(const Chem::Bond&) const;
847  const Brush& getHighlightAreaBrush(const Chem::Bond&) const;
848  const Pen& getHighlightAreaPen(const Chem::Bond&) const;
849  const SizeSpecification& getLabelSizeSpec(const Chem::Bond&) const;
850  const SizeSpecification& getLabelMarginSpec(const Chem::Bond&) const;
851  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Bond&) const;
852  const SizeSpecification& getCustomLabelSizeSpec(const Chem::Bond&) const;
853 
854  void setupLabelMargin(const Chem::Bond&);
855  void setupPen(const Chem::Bond&);
856  void setupLabelFont(const Chem::Bond&);
857  void setupConfigLabelFont(const Chem::Bond&);
858  void setupCustomLabelFont(const Chem::Bond&);
859 
860  double getLabelSize(const Chem::Atom&) const;
861  double getSecondaryLabelSize(const Chem::Atom&) const;
862  double getConfigLabelSize(const Chem::Atom&) const;
863  double getCustomLabelSize(const Chem::Atom&) const;
864  double getElectronDotSize(const Chem::Atom&) const;
865 
866  const Color& getColor(const Chem::Atom&) const;
867  const Color& getConfigLabelColor(const Chem::Atom&) const;
868  const Color& getCustomLabelColor(const Chem::Atom&) const;
869  const Font& getLabelFont(const Chem::Atom&) const;
870  const Font& getSecondaryLabelFont(const Chem::Atom&) const;
871  const Font& getConfigLabelFont(const Chem::Atom&) const;
872  const Font& getCustomLabelFont(const Chem::Atom&) const;
873  const Brush& getHighlightAreaBrush(const Chem::Atom&) const;
874  const Pen& getHighlightAreaPen(const Chem::Atom&) const;
875  const SizeSpecification& getLabelSizeSpec(const Chem::Atom&) const;
876  const SizeSpecification& getSecondaryLabelSizeSpec(const Chem::Atom&) const;
877  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Atom&) const;
878  const SizeSpecification& getCustomLabelSizeSpec(const Chem::Atom&) const;
879  const SizeSpecification& getLabelMarginSpec(const Chem::Atom&) const;
880  const SizeSpecification& getElectronDotSizeSpec(const Chem::Atom&) const;
881 
882  void setupLabelMargin(const Chem::Atom&);
883  void setupPen(const Chem::Atom&);
884  void setupLabelFont(const Chem::Atom&);
885  void setupSecondaryLabelFont(const Chem::Atom&);
886  void setupConfigLabelFont(const Chem::Atom&);
887  void setupCustomLabelFont(const Chem::Atom&);
888 
889  const SizeSpecification& getAtomHighlightAreaSizeSpec() const;
890  const SizeSpecification& getBondHighlightAreaWidthSpec() const;
891  const SizeSpecification& getHighlightAreaOutlineWidthSpec() const;
892 
893  double getAtomHighlightAreaSize() const;
894  double getBondHighlightAreaWidth() const;
895  double getHighlightAreaOutlineWidth() const;
896 
897  double calcOutputSize(const Chem::Bond&, const SizeSpecification&, bool = false) const;
898  double calcOutputSize(const Chem::Atom&, const SizeSpecification&) const;
899 
900  double calcOutputSize(const SizeSpecification&) const;
901  double calcOutputSize(double, const SizeSpecification&) const;
902 
903  void freeGraphicsPrimitives();
904 
905  LinePrimitive2D* allocLinePrimitive(bool = true);
906  PolylinePrimitive2D* allocPolylinePrimitive();
907  PolygonPrimitive2D* allocPolygonPrimitive();
908  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
909  PointListPrimitive2D* allocPointListPrimitive();
910  TextLabelPrimitive2D* allocTextLabelPrimitive(const Font&);
911  PathPrimitive2D* allocPathPrimitive(const Brush&, const Pen&);
912  ClipPathPrimitive2D* allocClipPathPrimitive();
913 
914  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
915  typedef std::vector<Rectangle2D> RectangleList;
916  typedef std::vector<RectangleList> RectangleListArray;
917  typedef std::vector<Line2D> BondLineArray;
918  typedef std::vector<std::size_t> UIntArray;
919  typedef std::pair<std::size_t, double> UIntDoublePair;
920  typedef std::vector<UIntDoublePair> UIntDoublePairList;
921  typedef std::vector<UIntDoublePairList> UIntDoublePairListArray;
922  typedef std::vector<double> DoubleArray;
931  typedef std::unique_ptr<StructureView2DParameters> StructureView2DParametersPtr;
932  typedef std::unique_ptr<Chem::Fragment> FragmentPtr;
933 
934  StructureView2DParametersPtr parameters;
935  const Chem::MolecularGraph* structure;
936  const Chem::MolecularGraph* origStructure;
937  FragmentPtr hDepleteStructure;
938  FontMetrics* fontMetrics;
939  Rectangle2D inputStructureBounds;
940  Rectangle2D outputStructureBounds;
941  Util::UIArray calcBondStereoFlags;
942  Math::Vector2DArray calcInputAtomCoords;
943  Math::Vector2DArray inputAtomCoords;
944  Math::Vector2DArray outputAtomCoords;
945  BondLineArray outputBondLines;
946  RectangleListArray atomLabelBounds;
947  RectangleListArray bondLabelBounds;
948  UIntArray atomCoreLabelCounts;
949  Util::BitSet ctrLabeledBonds;
950  UIntDoublePairListArray highlightedBondLists;
951  DoubleArray atomHighlightAreaRadii;
952  GraphicsPrimitiveList drawListLayer0;
953  GraphicsPrimitiveList drawListLayer1;
954  GraphicsPrimitiveList drawListLayer2;
955  GraphicsPrimitiveList drawListLayer3;
956  double avgInputBondLength;
957  double stdBondLengthScalingFactor;
958  double viewportAdjustmentScalingFactor;
959  double viewScalingFactor;
960  Math::Vector2D viewTranslations[2];
961  bool structureChanged;
962  bool fontMetricsChanged;
963  Pen activePen;
964  Font activeLabelFont;
965  Font activeSecondaryLabelFont;
966  double activeLabelMargin;
967  bool reactionContext;
968  bool hasAtomCoords;
969  LinePrimitiveCache lineCache;
970  PolylinePrimitiveCache polylineCache;
971  PolygonPrimitiveCache polygonCache;
972  LineSegListPrimitiveCache lineSegListCache;
973  PointListPrimitiveCache pointListCache;
974  TextLabelPrimitiveCache textLabelCache;
975  PathPrimitiveCache pathCache;
976  ClipPathPrimitiveCache clipPathCache;
977  };
978  } // namespace Vis
979 } // namespace CDPL
980 
981 #endif // CDPL_VIS_STRUCTUREVIEW2D_HPP
Declaration of type CDPL::Util::BitSet.
Definition of class CDPL::Vis::Brush.
Definition of class CDPL::Vis::ClipPathPrimitive2D.
Definition of class CDPL::Vis::Color.
Definition of class CDPL::Vis::Font.
Definition of class CDPL::Vis::Line2D.
Definition of class CDPL::Vis::LinePrimitive2D.
Definition of class CDPL::Vis::LineSegmentListPrimitive2D.
Definition of class CDPL::Util::ObjectStack.
Definition of class CDPL::Vis::PathPrimitive2D.
Definition of class CDPL::Vis::Pen.
Definition of class CDPL::Vis::PointListPrimitive2D.
Definition of class CDPL::Vis::PolygonPrimitive2D.
Definition of class CDPL::Vis::PolylinePrimitive2D.
Definition of class CDPL::Vis::Rectangle2D.
Definition of class CDPL::Vis::SizeSpecification.
Definition of class CDPL::Vis::TextLabelPrimitive2D.
Definition of class CDPL::Math::VectorArray.
Definition of class CDPL::Vis::View2D.
Definition of the preprocessor macro CDPL_VIS_API.
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Base class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
Specifies the fill pattern and fill color of shapes.
Definition: Brush.hpp:50
2D graphics primitive representing a clipping region in 2D space.
Definition: ClipPathPrimitive2D.hpp:51
Specifies a color in terms of its red, green and blue components and an alpha-channel for transparenc...
Definition: Color.hpp:52
Interface providing methods for querying information about the metrics of a font.
Definition: FontMetrics.hpp:71
Specifies a font for drawing text.
Definition: Font.hpp:54
Specifies a line segment in 2D space.
Definition: Line2D.hpp:48
2D graphics primitive representing a single line.
Definition: LinePrimitive2D.hpp:51
2D graphics primitive representing a list of disjoint line segments.
Definition: LineSegmentListPrimitive2D.hpp:51
2D graphics primitive representing an arbitrary path in 2D space.
Definition: PathPrimitive2D.hpp:53
Specifies how to draw lines and outlines of shapes.
Definition: Pen.hpp:53
2D graphics primitive representing a list of points.
Definition: PointListPrimitive2D.hpp:51
2D graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
2D graphics primitive representing a set of connected line segments.
Definition: PolylinePrimitive2D.hpp:51
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:829
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
Interface providing methods for low level 2D drawing operations.
Definition: Renderer2D.hpp:86
Specifies the value and type of a size attribute and defines how the value may change during processi...
Definition: SizeSpecification.hpp:45
Implements the 2D visualization of chemical structures.
Definition: StructureView2D.hpp:680
void getModelBounds(Rectangle2D &bounds)
Calculates the axis-aligned bounding rectangle of the visualized model.
void setStructure(const Chem::MolecularGraph *molgraph)
Specifies the chemical structure to visualize.
StructureView2D & operator=(const StructureView2D &)=delete
StructureView2D(const Chem::MolecularGraph *molgraph=0)
Constructs and initializes a StructureView2D instance for the visualization of the molecular graph mo...
void setFontMetrics(FontMetrics *font_metrics)
Specifies a Vis::FontMetrics instance that will be used to measure the dimension of text labels.
StructureView2D(const StructureView2D &)=delete
const Chem::MolecularGraph * getStructure() const
Returns a pointer to the visualized chemical structure.
std::shared_ptr< StructureView2D > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated StructureView2D instances.
Definition: StructureView2D.hpp:686
void render(Renderer2D &renderer)
Renders the visual representation of the model using the specified Vis::Renderer2D instance.
FontMetrics * getFontMetrics() const
Returns a pointer to the Vis::FontMetrics instance used for measuring the dimension of text labels.
2D graphics primitive representing a text label.
Definition: TextLabelPrimitive2D.hpp:51
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
ValueType calcBondAngle(const CoordsVec &term_atom1_pos, const CoordsVec &ctr_atom_pos, const CoordsVec &term_atom2_pos)
Calculates the bond angle between the two bonds i-j and j-k.
CVector< double, 2 > Vector2D
Bounded 2 element vector holding floating-point values of type double.
Definition: Vector.hpp:3213
VectorArray< Vector2D > Vector2DArray
Array storing vectors of type Math::Vector2D.
Definition: VectorArray.hpp:82
Array< unsigned int > UIArray
Array storing unsigned integers of type unsigned int.
Definition: Array.hpp:573
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
CDPL_VIS_API const Color & getCustomLabelColor(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::CUSTOM_LABEL_COLOR property of the atom atom.
CDPL_VIS_API const SizeSpecification & getCustomLabelSize(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::CUSTOM_LABEL_SIZE property of the atom atom.
CDPL_VIS_API const Font & getLabelFont(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::LABEL_FONT property of the atom atom.
CDPL_VIS_API const Color & getColor(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::COLOR property of the atom atom.
CDPL_VIS_API const Font & getSecondaryLabelFont(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::SECONDARY_LABEL_FONT property of the atom atom.
CDPL_VIS_API const Brush & getHighlightAreaBrush(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::HIGHLIGHT_AREA_BRUSH property of the atom atom.
CDPL_VIS_API const SizeSpecification & getLabelSize(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::LABEL_SIZE property of the atom atom.
CDPL_VIS_API const SizeSpecification & getDoubleBondTrimLength(const Chem::Bond &bond)
Returns the value of the Vis::BondProperty::DOUBLE_BOND_TRIM_LENGTH property of the bond bond.
CDPL_VIS_API const SizeSpecification & getBondHighlightAreaWidth(const Chem::MolecularGraph &molgraph)
Returns the value of the Vis::MolecularGraphProperty::BOND_HIGHLIGHT_AREA_WIDTH property of the molec...
CDPL_VIS_API const SizeSpecification & getLineSpacing(const Chem::Bond &bond)
Returns the value of the Vis::BondProperty::LINE_SPACING property of the bond bond.
CDPL_VIS_API const SizeSpecification & getHighlightAreaOutlineWidth(const Chem::MolecularGraph &molgraph)
Returns the value of the Vis::MolecularGraphProperty::HIGHLIGHT_AREA_OUTLINE_WIDTH property of the mo...
CDPL_VIS_API const SizeSpecification & getTripleBondTrimLength(const Chem::Bond &bond)
Returns the value of the Vis::BondProperty::TRIPLE_BOND_TRIM_LENGTH property of the bond bond.
CDPL_VIS_API const SizeSpecification & getAtomHighlightAreaSize(const Chem::MolecularGraph &molgraph)
Returns the value of the Vis::MolecularGraphProperty::ATOM_HIGHLIGHT_AREA_SIZE property of the molecu...
CDPL_VIS_API const SizeSpecification & getLineWidth(const Chem::Bond &bond)
Returns the value of the Vis::BondProperty::LINE_WIDTH property of the bond bond.
CDPL_VIS_API const SizeSpecification & getSecondaryLabelSize(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::SECONDARY_LABEL_SIZE property of the atom atom.
CDPL_VIS_API const Font & getCustomLabelFont(const Chem::Atom &atom)
Returns the value of the Vis::AtomProperty::CUSTOM_LABEL_FONT property of the atom atom.
The namespace of the Chemical Data Processing Library.