Chemical Data Processing Library C++ API - Version 1.3.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 
693  StructureView2D(const Chem::MolecularGraph* molgraph = 0);
694 
696 
701 
703 
704  void render(Renderer2D& renderer);
705 
706  void setFontMetrics(FontMetrics* font_metrics);
707 
713 
723  void setStructure(const Chem::MolecularGraph* molgraph);
724 
730 
736 
737  private:
738  friend class ReactionView2D;
739 
740  StructureView2D(bool);
741 
742  void paintBackground(Renderer2D&) const;
743 
744  void renderGraphicsPrimitives(Renderer2D&) const;
745 
746  void init();
747 
748  void initTextLabelBounds();
749 
750  void createAtomPrimitives();
751  void createBondPrimitives();
752 
753  void createHighlightingPrimitives();
754 
755  void createAtomHighlightingPrimitives(double, double, double);
756  void createAtomHighlightingPrimitives(const Chem::Atom&, double, double, double);
757 
758  void createBondHighlightingPrimitives(double, double, double);
759  void createBondHighlightingPrimitives(const Chem::Bond&, double, double, double);
760 
761  void createAtomPrimitives(const Chem::Atom&);
762  double createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
763  void createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, double, Rectangle2D&);
764  double createAtomSymbolLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
765  void createRadicalElectronPrimitives(const Chem::Atom&, std::size_t, Rectangle2D&);
766  void createAtomIsotopeLabelPrimitive(const Chem::Atom&, std::size_t, Rectangle2D&);
767  void createAtomChargeLabelPrimitive(const Chem::Atom&, long, std::size_t, Rectangle2D&);
768  void createAtomHCountLabelPrimitives(const Chem::Atom&, std::size_t, double, Rectangle2D&);
769  void createAtomMappingLabelPrimitive(const Chem::Atom&, std::size_t, const Rectangle2D&);
770  void createAtomConfigLabelPrimitive(const Chem::Atom&, char);
771  void createAtomCustomLabelPrimitive(const Chem::Atom&, const std::string&, bool);
772 
773  void createBondLabelPrimitives(const Chem::Bond&, const Line2D&, int);
774  double createBondRxnInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int);
775  void createBondQueryInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int, double);
776  void createBondConfigLabelPrimitive(const Chem::Bond&, const Line2D&, int);
777  void createBondCustomLabelPrimitive(const Chem::Bond&, const Line2D&, int);
778 
779  void createUndefOrderBondPrimitives(const Chem::Bond&, const Line2D&);
780  void createSingleBondPrimitives(const Chem::Bond&, const Line2D&);
781  void createUpSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
782  void extendUpBondWedgeSides(const Chem::Bond&, const Chem::Atom&, Line2D&, Line2D&, bool, bool) const;
783  void extendWedgeSideToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
784  void createDownSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
785  void createEitherSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
786  void createPlainSingleBondPrimitives(const Chem::Bond&, const Line2D&);
787 
788  void createDoubleBondPrimitives(const Chem::Bond&, const Line2D&, int);
789  void createAsymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&, int);
790  void createSymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&);
791 
792  void createTripleBondPrimitives(const Chem::Bond&, const Line2D&);
793 
794  void createBondRxnCenterPrimitives(const Chem::Bond&, const Line2D&, int);
795 
796  int getBondAsymmetryShiftDirection(const Chem::Bond&) const;
797 
798  bool trimLine(Line2D&, double, bool) const;
799 
800  bool clipLineAgainstAtomBounds(Line2D&, const Chem::Bond&) const;
801  bool clipLineAgainstAtomBounds(Line2D&, std::size_t, bool) const;
802 
803  void extendBondLineToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
804  void clipLineAgainstNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
805  void clipLineAgainstBondLabel(LinePrimitive2D*, std::size_t);
806 
807  std::size_t getHydrogenCount(const Chem::Atom&) const;
808 
809  double calcCongestionFactor(const Rectangle2D&, const Base::PropertyContainer&) const;
810 
811  double calcBondAngle(const Chem::Bond&, const Chem::Bond&) const;
812  double calcInputBondLength(const Chem::Bond&) const;
813 
814  void prepareStructureData();
815  void initInputAtomPosArray();
816 
817  void calcViewTransforms();
818 
819  double calcAvgInputBondLength() const;
820 
821  void calcStdBondLengthScalingFactor();
822  void calcViewportAdjustmentScalingFactor();
823 
824  void calcInputStructureBounds();
825  void calcOutputStructureBounds();
826  void calcOutputAtomCoords();
827 
828  void initOutputBondLineArray();
829 
830  unsigned int getBondStereoFlag(const Chem::Bond&, const Chem::MolecularGraph&) const;
831  std::size_t getBondOrder(const Chem::Bond& bond) const;
832 
833  void setHasAtomCoordsFlag();
834 
835  double getLineWidth(const Chem::Bond&) const;
836  double getRxnCenterLineLength(const Chem::Bond&) const;
837  double getRxnCenterLineSpacing(const Chem::Bond&) const;
838  double getDoubleBondTrimLength(const Chem::Bond&) const;
839  double getTripleBondTrimLength(const Chem::Bond&) const;
840  double getLineSpacing(const Chem::Bond&) const;
841  double getWedgeWidth(const Chem::Bond&) const;
842  double getHashSpacing(const Chem::Bond&) const;
843  double getLabelSize(const Chem::Bond&) const;
844  double getConfigLabelSize(const Chem::Bond&) const;
845  double getCustomLabelSize(const Chem::Bond&) const;
846 
847  const Color& getColor(const Chem::Bond&) const;
848  const Color& getConfigLabelColor(const Chem::Bond&) const;
849  const Color& getCustomLabelColor(const Chem::Bond&) const;
850  const Font& getLabelFont(const Chem::Bond&) const;
851  const Font& getConfigLabelFont(const Chem::Bond&) const;
852  const Font& getCustomLabelFont(const Chem::Bond&) const;
853  const Brush& getHighlightAreaBrush(const Chem::Bond&) const;
854  const Pen& getHighlightAreaPen(const Chem::Bond&) const;
855  const SizeSpecification& getLabelSizeSpec(const Chem::Bond&) const;
856  const SizeSpecification& getLabelMarginSpec(const Chem::Bond&) const;
857  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Bond&) const;
858  const SizeSpecification& getCustomLabelSizeSpec(const Chem::Bond&) const;
859 
860  void setupLabelMargin(const Chem::Bond&);
861  void setupPen(const Chem::Bond&);
862  void setupLabelFont(const Chem::Bond&);
863  void setupConfigLabelFont(const Chem::Bond&);
864  void setupCustomLabelFont(const Chem::Bond&);
865 
866  double getLabelSize(const Chem::Atom&) const;
867  double getSecondaryLabelSize(const Chem::Atom&) const;
868  double getConfigLabelSize(const Chem::Atom&) const;
869  double getCustomLabelSize(const Chem::Atom&) const;
870  double getElectronDotSize(const Chem::Atom&) const;
871 
872  const Color& getColor(const Chem::Atom&) const;
873  const Color& getConfigLabelColor(const Chem::Atom&) const;
874  const Color& getCustomLabelColor(const Chem::Atom&) const;
875  const Font& getLabelFont(const Chem::Atom&) const;
876  const Font& getSecondaryLabelFont(const Chem::Atom&) const;
877  const Font& getConfigLabelFont(const Chem::Atom&) const;
878  const Font& getCustomLabelFont(const Chem::Atom&) const;
879  const Brush& getHighlightAreaBrush(const Chem::Atom&) const;
880  const Pen& getHighlightAreaPen(const Chem::Atom&) const;
881  const SizeSpecification& getLabelSizeSpec(const Chem::Atom&) const;
882  const SizeSpecification& getSecondaryLabelSizeSpec(const Chem::Atom&) const;
883  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Atom&) const;
884  const SizeSpecification& getCustomLabelSizeSpec(const Chem::Atom&) const;
885  const SizeSpecification& getLabelMarginSpec(const Chem::Atom&) const;
886  const SizeSpecification& getElectronDotSizeSpec(const Chem::Atom&) const;
887 
888  void setupLabelMargin(const Chem::Atom&);
889  void setupPen(const Chem::Atom&);
890  void setupLabelFont(const Chem::Atom&);
891  void setupSecondaryLabelFont(const Chem::Atom&);
892  void setupConfigLabelFont(const Chem::Atom&);
893  void setupCustomLabelFont(const Chem::Atom&);
894 
895  const SizeSpecification& getAtomHighlightAreaSizeSpec() const;
896  const SizeSpecification& getBondHighlightAreaWidthSpec() const;
897  const SizeSpecification& getHighlightAreaOutlineWidthSpec() const;
898 
899  double getAtomHighlightAreaSize() const;
900  double getBondHighlightAreaWidth() const;
901  double getHighlightAreaOutlineWidth() const;
902 
903  double calcOutputSize(const Chem::Bond&, const SizeSpecification&, bool = false) const;
904  double calcOutputSize(const Chem::Atom&, const SizeSpecification&) const;
905 
906  double calcOutputSize(const SizeSpecification&) const;
907  double calcOutputSize(double, const SizeSpecification&) const;
908 
909  void freeGraphicsPrimitives();
910 
911  LinePrimitive2D* allocLinePrimitive(bool = true);
912  PolylinePrimitive2D* allocPolylinePrimitive();
913  PolygonPrimitive2D* allocPolygonPrimitive();
914  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
915  PointListPrimitive2D* allocPointListPrimitive();
916  TextLabelPrimitive2D* allocTextLabelPrimitive(const Font&);
917  PathPrimitive2D* allocPathPrimitive(const Brush&, const Pen&);
918  ClipPathPrimitive2D* allocClipPathPrimitive();
919 
920  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
921  typedef std::vector<Rectangle2D> RectangleList;
922  typedef std::vector<RectangleList> RectangleListArray;
923  typedef std::vector<Line2D> BondLineArray;
924  typedef std::vector<std::size_t> UIntArray;
925  typedef std::pair<std::size_t, double> UIntDoublePair;
926  typedef std::vector<UIntDoublePair> UIntDoublePairList;
927  typedef std::vector<UIntDoublePairList> UIntDoublePairListArray;
928  typedef std::vector<double> DoubleArray;
937  typedef std::unique_ptr<StructureView2DParameters> StructureView2DParametersPtr;
938  typedef std::unique_ptr<Chem::Fragment> FragmentPtr;
939 
940  StructureView2DParametersPtr parameters;
941  const Chem::MolecularGraph* structure;
942  const Chem::MolecularGraph* origStructure;
943  FragmentPtr hDepleteStructure;
944  FontMetrics* fontMetrics;
945  Rectangle2D inputStructureBounds;
946  Rectangle2D outputStructureBounds;
947  Util::UIArray calcBondStereoFlags;
948  Math::Vector2DArray calcInputAtomCoords;
949  Math::Vector2DArray inputAtomCoords;
950  Math::Vector2DArray outputAtomCoords;
951  BondLineArray outputBondLines;
952  RectangleListArray atomLabelBounds;
953  RectangleListArray bondLabelBounds;
954  UIntArray atomCoreLabelCounts;
955  Util::BitSet ctrLabeledBonds;
956  UIntDoublePairListArray highlightedBondLists;
957  DoubleArray atomHighlightAreaRadii;
958  GraphicsPrimitiveList drawListLayer0;
959  GraphicsPrimitiveList drawListLayer1;
960  GraphicsPrimitiveList drawListLayer2;
961  GraphicsPrimitiveList drawListLayer3;
962  double avgInputBondLength;
963  double stdBondLengthScalingFactor;
964  double viewportAdjustmentScalingFactor;
965  double viewScalingFactor;
966  Math::Vector2D viewTranslations[2];
967  bool structureChanged;
968  bool fontMetricsChanged;
969  Pen activePen;
970  Font activeLabelFont;
971  Font activeSecondaryLabelFont;
972  double activeLabelMargin;
973  bool reactionContext;
974  bool hasAtomCoords;
975  LinePrimitiveCache lineCache;
976  PolylinePrimitiveCache polylineCache;
977  PolygonPrimitiveCache polygonCache;
978  LineSegListPrimitiveCache lineSegListCache;
979  PointListPrimitiveCache pointListCache;
980  TextLabelPrimitiveCache textLabelCache;
981  PathPrimitiveCache pathCache;
982  ClipPathPrimitiveCache clipPathCache;
983  };
984  } // namespace Vis
985 } // namespace CDPL
986 
987 #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.
A class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
Atom.
Definition: Atom.hpp:52
Bond.
Definition: Bond.hpp:50
MolecularGraph.
Definition: MolecularGraph.hpp:52
Specifies the fill pattern and fill color of shapes.
Definition: Brush.hpp:50
A 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
An interface class with methods that provide 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
A graphics primitive representing a single line.
Definition: LinePrimitive2D.hpp:51
A graphics primitive representing a list of disjoint line segments.
Definition: LineSegmentListPrimitive2D.hpp:51
A 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
A graphics primitive representing a list of points.
Definition: PointListPrimitive2D.hpp:51
A graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
A graphics primitive representing a set of connected line segments.
Definition: PolylinePrimitive2D.hpp:51
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:589
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
An interface that provides 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 bounds of the rendered structure in output space.
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 chemical structure...
void setFontMetrics(FontMetrics *font_metrics)
Specifies a font metrics object 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 used font metrics object.
A 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
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
VectorArray< Vector2D > Vector2DArray
An array of Math::Vector2D objects.
Definition: VectorArray.hpp:79
Array< unsigned int > UIArray
An array of unsigned integers.
Definition: Array.hpp:562
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
CDPL_VIS_API const Color & getCustomLabelColor(const Chem::Atom &atom)
CDPL_VIS_API const SizeSpecification & getCustomLabelSize(const Chem::Atom &atom)
CDPL_VIS_API const Font & getLabelFont(const Chem::Atom &atom)
CDPL_VIS_API const Color & getColor(const Chem::Atom &atom)
CDPL_VIS_API const Font & getSecondaryLabelFont(const Chem::Atom &atom)
CDPL_VIS_API const Brush & getHighlightAreaBrush(const Chem::Atom &atom)
CDPL_VIS_API const SizeSpecification & getLabelSize(const Chem::Atom &atom)
CDPL_VIS_API const SizeSpecification & getDoubleBondTrimLength(const Chem::Bond &bond)
CDPL_VIS_API const SizeSpecification & getBondHighlightAreaWidth(const Chem::MolecularGraph &molgraph)
CDPL_VIS_API const SizeSpecification & getLineSpacing(const Chem::Bond &bond)
CDPL_VIS_API const SizeSpecification & getHighlightAreaOutlineWidth(const Chem::MolecularGraph &molgraph)
CDPL_VIS_API const SizeSpecification & getTripleBondTrimLength(const Chem::Bond &bond)
CDPL_VIS_API const SizeSpecification & getAtomHighlightAreaSize(const Chem::MolecularGraph &molgraph)
CDPL_VIS_API const SizeSpecification & getLineWidth(const Chem::Bond &bond)
CDPL_VIS_API const SizeSpecification & getSecondaryLabelSize(const Chem::Atom &atom)
CDPL_VIS_API const Font & getCustomLabelFont(const Chem::Atom &atom)
The namespace of the Chemical Data Processing Library.