Chemical Data Processing Library C++ API - Version 1.1.1
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 <memory>
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"
54 
55 
56 namespace CDPL
57 {
58 
59  namespace Base
60  {
61 
62  class PropertyContainer;
63  }
64 
65  namespace Chem
66  {
67 
68  class MolecularGraph;
69  class Fragment;
70  class Atom;
71  class Bond;
72  } // namespace Chem
73 
74  namespace Vis
75  {
76 
77  class FontMetrics;
78  class StructureView2DParameters;
79 
493  {
494 
495  public:
499  typedef std::shared_ptr<StructureView2D> SharedPointer;
500 
506  StructureView2D(const Chem::MolecularGraph* molgraph = 0);
507 
512 
513  void render(Renderer2D& renderer);
514 
515  void setFontMetrics(FontMetrics* font_metrics);
516 
522 
532  void setStructure(const Chem::MolecularGraph* molgraph);
533 
539 
545 
546  private:
547  class CustomGraphicsData;
548  friend class ReactionView2D;
549 
550  typedef std::shared_ptr<CustomGraphicsData> CustomGraphicsDataPtr;
551  typedef std::vector<CustomGraphicsDataPtr> CustomGraphicsDataList;
552 
554  StructureView2D(bool);
555 
556  StructureView2D& operator=(const StructureView2D&);
557 
558  void paintBackground(Renderer2D&) const;
559 
560  void renderGraphicsPrimitives(Renderer2D&) const;
561 
562  void init();
563 
564  void initTextLabelBounds();
565 
566  void createAtomPrimitives();
567  void createAtomPrimitives(const Chem::Atom&);
568  double createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
569  void createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, double, Rectangle2D&);
570  double createAtomSymbolLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
571  void createRadicalElectronPrimitives(const Chem::Atom&, std::size_t, Rectangle2D&);
572  void createAtomIsotopeLabelPrimitive(const Chem::Atom&, std::size_t, Rectangle2D&);
573  void createAtomChargeLabelPrimitive(const Chem::Atom&, long, std::size_t, Rectangle2D&);
574  void createAtomHCountLabelPrimitives(const Chem::Atom&, std::size_t, double, Rectangle2D&);
575  void createAtomMappingLabelPrimitive(const Chem::Atom&, std::size_t, const Rectangle2D&);
576  void createAtomConfigLabelPrimitive(const Chem::Atom&, char);
577 
578  void createBondPrimitives();
579 
580  void createBondLabelPrimitives(const Chem::Bond&, const Line2D&, int);
581  double createBondRxnInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int);
582  void createBondQueryInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int, double);
583  void createBondConfigLabelPrimitive(const Chem::Bond&, const Line2D&, int);
584 
585  void createUndefOrderBondPrimitives(const Chem::Bond&, const Line2D&);
586  void createSingleBondPrimitives(const Chem::Bond&, const Line2D&);
587  void createUpSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
588  void extendUpBondWedgeSides(const Chem::Bond&, const Chem::Atom&, Line2D&, Line2D&, bool, bool) const;
589  void extendWedgeSideToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
590  void createDownSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
591  void createEitherSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
592  void createPlainSingleBondPrimitives(const Chem::Bond&, const Line2D&);
593 
594  void createDoubleBondPrimitives(const Chem::Bond&, const Line2D&, int);
595  void createAsymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&, int);
596  void createSymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&);
597 
598  void createTripleBondPrimitives(const Chem::Bond&, const Line2D&);
599 
600  void createBondRxnCenterPrimitives(const Chem::Bond&, const Line2D&, int);
601 
602  int getBondAsymmetryShiftDirection(const Chem::Bond&) const;
603 
604  bool trimLine(Line2D&, double, bool) const;
605 
606  bool clipLineAgainstAtomBounds(Line2D&, const Chem::Bond&) const;
607  bool clipLineAgainstAtomBounds(Line2D&, std::size_t, bool) const;
608 
609  void extendBondLineToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
610  void clipLineAgainstNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
611  void clipLineAgainstBondLabel(LinePrimitive2D*, std::size_t);
612 
613  std::size_t getHydrogenCount(const Chem::Atom&) const;
614 
615  double calcCongestionFactor(const Rectangle2D&, const Base::PropertyContainer&) const;
616 
617  double calcBondAngle(const Chem::Bond&, const Chem::Bond&) const;
618  double calcInputBondLength(const Chem::Bond&) const;
619 
620  void prepareStructureData();
621  void initInputAtomPosTable();
622 
623  void calcViewTransforms();
624 
625  double calcAvgInputBondLength() const;
626 
627  void calcStdBondLengthScalingFactor();
628  void calcViewportAdjustmentScalingFactor();
629 
630  void calcInputStructureBounds();
631  void calcOutputStructureBounds();
632  void calcOutputAtomCoords();
633 
634  void initOutputBondLineTable();
635 
636  unsigned int getBondStereoFlag(const Chem::Bond&, const Chem::MolecularGraph&) const;
637  std::size_t getBondOrder(const Chem::Bond& bond) const;
638 
639  void setHasAtomCoordsFlag();
640 
641  double getLineWidth(const Chem::Bond&) const;
642  double getRxnCenterLineLength(const Chem::Bond&) const;
643  double getRxnCenterLineSpacing(const Chem::Bond&) const;
644  double getDoubleBondTrimLength(const Chem::Bond&) const;
645  double getTripleBondTrimLength(const Chem::Bond&) const;
646  double getLineSpacing(const Chem::Bond&) const;
647  double getWedgeWidth(const Chem::Bond&) const;
648  double getHashSpacing(const Chem::Bond&) const;
649  double getLabelSize(const Chem::Bond&) const;
650  double getConfigLabelSize(const Chem::Bond&) const;
651 
652  const Color& getColor(const Chem::Bond&) const;
653  const Font& getLabelFont(const Chem::Bond&) const;
654  const Font& getConfigLabelFont(const Chem::Bond&) const;
655  const SizeSpecification& getLabelSizeSpec(const Chem::Bond&) const;
656  const SizeSpecification& getLabelMarginSpec(const Chem::Bond&) const;
657  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Bond&) const;
658 
659  void setupLabelMargin(const Chem::Bond&);
660  void setupPen(const Chem::Bond&);
661  void setupLabelFont(const Chem::Bond&);
662  void setupConfigLabelFont(const Chem::Bond&);
663 
664  double getLabelSize(const Chem::Atom&) const;
665  double getSecondaryLabelSize(const Chem::Atom&) const;
666  double getConfigLabelSize(const Chem::Atom&) const;
667  double getElectronDotSize(const Chem::Atom&) const;
668 
669  const Color& getColor(const Chem::Atom&) const;
670  const Font& getLabelFont(const Chem::Atom&) const;
671  const Font& getSecondaryLabelFont(const Chem::Atom&) const;
672  const Font& getConfigLabelFont(const Chem::Atom&) const;
673  const SizeSpecification& getLabelSizeSpec(const Chem::Atom&) const;
674  const SizeSpecification& getSecondaryLabelSizeSpec(const Chem::Atom&) const;
675  const SizeSpecification& getConfigLabelSizeSpec(const Chem::Atom&) const;
676  const SizeSpecification& getLabelMarginSpec(const Chem::Atom&) const;
677  const SizeSpecification& getElectronDotSizeSpec(const Chem::Atom&) const;
678 
679  void setupLabelMargin(const Chem::Atom&);
680  void setupPen(const Chem::Atom&);
681  void setupLabelFont(const Chem::Atom&);
682  void setupSecondaryLabelFont(const Chem::Atom&);
683  void setupConfigLabelFont(const Chem::Atom&);
684 
685  double calcOutputSize(const Chem::Bond&, const SizeSpecification&) const;
686  double calcOutputSize(const Chem::Atom&, const SizeSpecification&) const;
687 
688  double calcOutputSize(const SizeSpecification&) const;
689  double calcOutputSize(double, const SizeSpecification&) const;
690 
691  void freeGraphicsPrimitives();
692 
693  LinePrimitive2D* allocLinePrimitive(bool = true);
694  PolylinePrimitive2D* allocPolylinePrimitive();
695  PolygonPrimitive2D* allocPolygonPrimitive();
696  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
697  PointListPrimitive2D* allocPointListPrimitive();
698  TextLabelPrimitive2D* allocTextLabelPrimitive();
699 
700  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
701  typedef std::vector<Rectangle2D> RectangleList;
702  typedef std::vector<RectangleList> RectangleListTable;
703  typedef std::vector<Line2D> BondLineTable;
710 
711  typedef std::unique_ptr<StructureView2DParameters> StructureView2DParametersPtr;
712  typedef std::unique_ptr<Chem::Fragment> FragmentPtr;
713 
714  StructureView2DParametersPtr parameters;
715  const Chem::MolecularGraph* structure;
716  const Chem::MolecularGraph* origStructure;
717  FragmentPtr hDepleteStructure;
718  FontMetrics* fontMetrics;
719  Rectangle2D inputStructureBounds;
720  Rectangle2D outputStructureBounds;
721  Util::UIArray calcBondStereoFlags;
722  Math::Vector2DArray calcInputAtomCoords;
723  Math::Vector2DArray inputAtomCoords;
724  Math::Vector2DArray outputAtomCoords;
725  BondLineTable outputBondLines;
726  RectangleListTable atomLabelBounds;
727  RectangleList bondLabelBounds;
728  GraphicsPrimitiveList drawList;
729  double avgInputBondLength;
730  double stdBondLengthScalingFactor;
731  double viewportAdjustmentScalingFactor;
732  double viewScalingFactor;
733  Math::Vector2D viewTranslations[2];
734  bool structureChanged;
735  bool fontMetricsChanged;
736  Pen activePen;
737  Font activeLabelFont;
738  Font activeSecondaryLabelFont;
739  Font activeConfigLabelFont;
740  double activeLabelMargin;
741  bool reactionContext;
742  bool hasAtomCoords;
743  LinePrimitiveCache lineCache;
744  PolylinePrimitiveCache polylineCache;
745  PolygonPrimitiveCache polygonCache;
746  LineSegListPrimitiveCache lineSegListCache;
747  PointListPrimitiveCache pointListCache;
748  TextLabelPrimitiveCache textLabelCache;
749  };
750  } // namespace Vis
751 } // namespace CDPL
752 
753 #endif // CDPL_VIS_STRUCTUREVIEW2D_HPP
CDPL::Vis::SizeSpecification
Specifies the value and type of a size attribute and defines how the value may change during processi...
Definition: SizeSpecification.hpp:45
CDPL::Vis::Renderer2D
An interface that provides methods for low level 2D drawing operations.
Definition: Renderer2D.hpp:86
ObjectStack.hpp
Definition of the class CDPL::Util::ObjectStack.
CDPL::Vis::getSecondaryLabelFont
CDPL_VIS_API const Font & getSecondaryLabelFont(const Chem::Atom &atom)
SizeSpecification.hpp
Definition of the class CDPL::Vis::SizeSpecification.
VectorArray.hpp
Definition of the class CDPL::Math::VectorArray.
CDPL::Vis::View2D
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
CDPL::Vis::StructureView2D::~StructureView2D
~StructureView2D()
Destructor.
Font.hpp
Definition of the class CDPL::Vis::Font.
CDPL::Vis::ReactionView2D
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:590
LineSegmentListPrimitive2D.hpp
Definition of the class CDPL::Vis::LineSegmentListPrimitive2D.
CDPL::Vis::getLabelFont
CDPL_VIS_API const Font & getLabelFont(const Chem::Atom &atom)
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Vis::StructureView2D::getFontMetrics
FontMetrics * getFontMetrics() const
Returns a pointer to the used font metrics object.
CDPL::Vis::getSecondaryLabelSize
CDPL_VIS_API const SizeSpecification & getSecondaryLabelSize(const Chem::Atom &atom)
CDPL::Vis::getDoubleBondTrimLength
CDPL_VIS_API const SizeSpecification & getDoubleBondTrimLength(const Chem::Bond &bond)
CDPL::Vis::Pen
Specifies how to draw lines and outlines of shapes.
Definition: Pen.hpp:53
PointListPrimitive2D.hpp
Definition of the class CDPL::Vis::PointListPrimitive2D.
CDPL::Vis::LinePrimitive2D
A graphics primitive representing a single line.
Definition: LinePrimitive2D.hpp:51
CDPL::Vis::getColor
CDPL_VIS_API const Color & getColor(const Chem::Atom &atom)
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Vis::LineSegmentListPrimitive2D
A graphics primitive representing a list of disjoint line segments.
Definition: LineSegmentListPrimitive2D.hpp:51
PolygonPrimitive2D.hpp
Definition of the class CDPL::Vis::PolygonPrimitive2D.
CDPL::Vis::StructureView2D::StructureView2D
StructureView2D(const Chem::MolecularGraph *molgraph=0)
Constructs and initializes a StructureView2D instance for the visualization of the chemical structure...
CDPL::Vis::Font
Specifies a font for drawing text.
Definition: Font.hpp:54
CDPL::Vis::StructureView2D
Implements the 2D visualization of chemical structures.
Definition: StructureView2D.hpp:493
Pen.hpp
Definition of the class CDPL::Vis::Pen.
CDPL::Vis::StructureView2D::setFontMetrics
void setFontMetrics(FontMetrics *font_metrics)
Specifies a font metrics object that will be used to measure the dimension of text labels.
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
CDPL::Vis::StructureView2D::SharedPointer
std::shared_ptr< StructureView2D > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated StructureView2D instances.
Definition: StructureView2D.hpp:499
CDPL::Vis::getLabelSize
CDPL_VIS_API const SizeSpecification & getLabelSize(const Chem::Atom &atom)
CDPL_VIS_API
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
PolylinePrimitive2D.hpp
Definition of the class CDPL::Vis::PolylinePrimitive2D.
CDPL::Vis::getTripleBondTrimLength
CDPL_VIS_API const SizeSpecification & getTripleBondTrimLength(const Chem::Bond &bond)
LinePrimitive2D.hpp
Definition of the class CDPL::Vis::LinePrimitive2D.
View2D.hpp
Definition of the class CDPL::Vis::View2D.
CDPL::Vis::TextLabelPrimitive2D
A graphics primitive representing a text label.
Definition: TextLabelPrimitive2D.hpp:51
CDPL::Vis::StructureView2D::setStructure
void setStructure(const Chem::MolecularGraph *molgraph)
Specifies the chemical structure to visualize.
CDPL::Vis::StructureView2D::getStructure
const Chem::MolecularGraph * getStructure() const
Returns a pointer to the visualized chemical structure.
CDPL::Base::PropertyContainer
A class providing methods for the storage and lookup of object properties.
Definition: PropertyContainer.hpp:75
CDPL::ForceField::calcBondAngle
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.
CDPL::Vis::PolygonPrimitive2D
A graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Vis::Rectangle2D
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
CDPL::Vis::StructureView2D::getModelBounds
void getModelBounds(Rectangle2D &bounds)
Calculates the bounds of the rendered structure in output space.
CDPL::Math::Vector2D
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
Rectangle2D.hpp
Definition of the class CDPL::Vis::Rectangle2D.
Line2D.hpp
Definition of the class CDPL::Vis::Line2D.
CDPL::Vis::StructureView2D::render
void render(Renderer2D &renderer)
Renders the visual representation of the model using the specified Vis::Renderer2D instance.
CDPL::Vis::getLineSpacing
CDPL_VIS_API const SizeSpecification & getLineSpacing(const Chem::Bond &bond)
CDPL::Vis::FontMetrics
An interface class with methods that provide information about the metrics of a font.
Definition: FontMetrics.hpp:71
CDPL::Math::Vector2DArray
VectorArray< Vector2D > Vector2DArray
An array of Math::Vector2D objects.
Definition: VectorArray.hpp:79
CDPL::Util::UIArray
Array< unsigned int > UIArray
An array of unsigned integers.
Definition: Array.hpp:562
Color.hpp
Definition of the class CDPL::Vis::Color.
CDPL::Util::ObjectStack< LinePrimitive2D >
APIPrefix.hpp
Definition of the preprocessor macro CDPL_VIS_API.
CDPL::Vis::getLineWidth
CDPL_VIS_API const SizeSpecification & getLineWidth(const Chem::Bond &bond)
CDPL::Vis::PointListPrimitive2D
A graphics primitive representing a list of points.
Definition: PointListPrimitive2D.hpp:51
CDPL::Vis::Color
Specifies a color in terms of its red, green and blue components and an alpha-channel for transparenc...
Definition: Color.hpp:52
CDPL::Vis::Line2D
Specifies a line segment in 2D space.
Definition: Line2D.hpp:48
TextLabelPrimitive2D.hpp
Definition of the class CDPL::Vis::TextLabelPrimitive2D.
CDPL::Vis::PolylinePrimitive2D
A graphics primitive representing a set of connected line segments.
Definition: PolylinePrimitive2D.hpp:51