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