Chemical Data Processing Library C++ API - Version 1.0.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 <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 
437  {
438 
439  public:
443  typedef std::shared_ptr<StructureView2D> SharedPointer;
444 
450  StructureView2D(const Chem::MolecularGraph* molgraph = 0);
451 
456 
457  void render(Renderer2D& renderer);
458 
459  void setFontMetrics(FontMetrics* font_metrics);
460 
466 
476  void setStructure(const Chem::MolecularGraph* molgraph);
477 
483 
489 
490  private:
491  class CustomGraphicsData;
492  friend class ReactionView2D;
493 
494  typedef std::shared_ptr<CustomGraphicsData> CustomGraphicsDataPtr;
495  typedef std::vector<CustomGraphicsDataPtr> CustomGraphicsDataList;
496 
498  StructureView2D(bool);
499 
500  StructureView2D& operator=(const StructureView2D&);
501 
502  void paintBackground(Renderer2D&) const;
503 
504  void renderGraphicsPrimitives(Renderer2D&) const;
505 
506  void init();
507 
508  void initTextLabelBounds();
509 
510  void createAtomPrimitives();
511  void createAtomPrimitives(const Chem::Atom&);
512  double createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
513  void createAtomQueryInfoLabelPrimitive(const Chem::Atom&, const std::string&, double, Rectangle2D&);
514  double createAtomSymbolLabelPrimitive(const Chem::Atom&, const std::string&, Rectangle2D&);
515  void createRadicalElectronPrimitives(const Chem::Atom&, std::size_t, Rectangle2D&);
516  void createAtomIsotopeLabelPrimitive(const Chem::Atom&, std::size_t, Rectangle2D&);
517  void createAtomChargeLabelPrimitive(const Chem::Atom&, long, std::size_t, Rectangle2D&);
518  void createAtomHCountLabelPrimitives(const Chem::Atom&, std::size_t, double, Rectangle2D&);
519  void createAtomMappingLabelPrimitive(const Chem::Atom&, std::size_t, const Rectangle2D&);
520 
521  void createBondPrimitives();
522 
523  void createBondLabelPrimitives(const Chem::Bond&, const Line2D&, int);
524  double createBondRxnInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int);
525  void createBondQueryInfoLabelPrimitive(const Chem::Bond&, const Line2D&, int, double);
526 
527  void createUndefOrderBondPrimitives(const Chem::Bond&, const Line2D&);
528  void createSingleBondPrimitives(const Chem::Bond&, const Line2D&);
529  void createUpSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
530  void extendUpBondWedgeSides(const Chem::Bond&, const Chem::Atom&, Line2D&, Line2D&, bool, bool) const;
531  void extendWedgeSideToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
532  void createDownSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
533  void createEitherSingleBondPrimitives(const Chem::Bond&, const Line2D&, bool);
534  void createPlainSingleBondPrimitives(const Chem::Bond&, const Line2D&);
535 
536  void createDoubleBondPrimitives(const Chem::Bond&, const Line2D&, int);
537  void createAsymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&, int);
538  void createSymDoubleBondPrimitives(const Chem::Bond&, bool, const Line2D&);
539 
540  void createTripleBondPrimitives(const Chem::Bond&, const Line2D&);
541 
542  void createBondRxnCenterPrimitives(const Chem::Bond&, const Line2D&, int);
543 
544  int getBondAsymmetryShiftDirection(const Chem::Bond&) const;
545 
546  bool trimLine(Line2D&, double, bool) const;
547 
548  bool clipLineAgainstAtomBounds(Line2D&, const Chem::Bond&) const;
549  bool clipLineAgainstAtomBounds(Line2D&, std::size_t, bool) const;
550 
551  void extendBondLineToNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
552  void clipLineAgainstNeighborBonds(Line2D&, const Chem::Bond&, const Chem::Atom&, bool) const;
553  void clipLineAgainstBondLabel(LinePrimitive2D*, std::size_t);
554 
555  std::size_t getHydrogenCount(const Chem::Atom&) const;
556 
557  double calcCongestionFactor(const Rectangle2D&, const Base::PropertyContainer&) const;
558 
559  double calcBondAngle(const Chem::Bond&, const Chem::Bond&) const;
560  double calcInputBondLength(const Chem::Bond&) const;
561 
562  void prepareStructureData();
563  void initInputAtomPosTable();
564 
565  void calcViewTransforms();
566 
567  double calcAvgInputBondLength() const;
568 
569  void calcStdBondLengthScalingFactor();
570  void calcViewportAdjustmentScalingFactor();
571 
572  void calcInputStructureBounds();
573  void calcOutputStructureBounds();
574  void calcOutputAtomCoords();
575 
576  void initOutputBondLineTable();
577 
578  unsigned int getBondStereoFlag(const Chem::Bond&, const Chem::MolecularGraph&) const;
579  std::size_t getBondOrder(const Chem::Bond& bond) const;
580 
581  void setHasAtomCoordsFlag();
582 
583  double getLineWidth(const Chem::Bond&) const;
584  double getRxnCenterLineLength(const Chem::Bond&) const;
585  double getRxnCenterLineSpacing(const Chem::Bond&) const;
586  double getDoubleBondTrimLength(const Chem::Bond&) const;
587  double getTripleBondTrimLength(const Chem::Bond&) const;
588  double getLineSpacing(const Chem::Bond&) const;
589  double getWedgeWidth(const Chem::Bond&) const;
590  double getHashSpacing(const Chem::Bond&) const;
591  double getLabelSize(const Chem::Bond&) const;
592 
593  const Color& getColor(const Chem::Bond&) const;
594  const Font& getLabelFont(const Chem::Bond&) const;
595  const SizeSpecification& getLabelSizeSpec(const Chem::Bond&) const;
596  const SizeSpecification& getLabelMarginSpec(const Chem::Bond&) const;
597 
598  void setupLabelMargin(const Chem::Bond&);
599  void setupPen(const Chem::Bond&);
600  void setupLabelFont(const Chem::Bond&);
601 
602  double getLabelSize(const Chem::Atom&) const;
603  double getSecondaryLabelSize(const Chem::Atom&) const;
604  double getElectronDotSize(const Chem::Atom&) const;
605 
606  const Color& getColor(const Chem::Atom&) const;
607  const Font& getLabelFont(const Chem::Atom&) const;
608  const Font& getSecondaryLabelFont(const Chem::Atom&) const;
609  const SizeSpecification& getLabelSizeSpec(const Chem::Atom&) const;
610  const SizeSpecification& getSecondaryLabelSizeSpec(const Chem::Atom&) const;
611  const SizeSpecification& getLabelMarginSpec(const Chem::Atom&) const;
612  const SizeSpecification& getElectronDotSizeSpec(const Chem::Atom&) const;
613 
614  void setupLabelMargin(const Chem::Atom&);
615  void setupPen(const Chem::Atom&);
616  void setupLabelFont(const Chem::Atom&);
617  void setupSecondaryLabelFont(const Chem::Atom&);
618 
619  double calcOutputSize(const Chem::Bond&, const SizeSpecification&) const;
620  double calcOutputSize(const Chem::Atom&, const SizeSpecification&) const;
621 
622  double calcOutputSize(const SizeSpecification&) const;
623  double calcOutputSize(double, const SizeSpecification&) const;
624 
625  void freeGraphicsPrimitives();
626 
627  LinePrimitive2D* allocLinePrimitive(bool = true);
628  PolylinePrimitive2D* allocPolylinePrimitive();
629  PolygonPrimitive2D* allocPolygonPrimitive();
630  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
631  PointListPrimitive2D* allocPointListPrimitive();
632  TextLabelPrimitive2D* allocTextLabelPrimitive();
633 
634  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
635  typedef std::vector<Rectangle2D> RectangleList;
636  typedef std::vector<RectangleList> RectangleListTable;
637  typedef std::vector<Line2D> BondLineTable;
644 
645  typedef std::unique_ptr<StructureView2DParameters> StructureView2DParametersPtr;
646  typedef std::unique_ptr<Chem::Fragment> FragmentPtr;
647 
648  StructureView2DParametersPtr parameters;
649  const Chem::MolecularGraph* structure;
650  const Chem::MolecularGraph* origStructure;
651  FragmentPtr hDepleteStructure;
652  FontMetrics* fontMetrics;
653  Rectangle2D inputStructureBounds;
654  Rectangle2D outputStructureBounds;
655  Util::UIArray calcBondStereoFlags;
656  Math::Vector2DArray calcInputAtomCoords;
657  Math::Vector2DArray inputAtomCoords;
658  Math::Vector2DArray outputAtomCoords;
659  BondLineTable outputBondLines;
660  RectangleListTable atomLabelBounds;
661  RectangleList bondLabelBounds;
662  GraphicsPrimitiveList drawList;
663  double avgInputBondLength;
664  double stdBondLengthScalingFactor;
665  double viewportAdjustmentScalingFactor;
666  double viewScalingFactor;
667  Math::Vector2D viewTranslations[2];
668  bool structureChanged;
669  bool fontMetricsChanged;
670  Pen activePen;
671  Font activeLabelFont;
672  Font activeSecondaryLabelFont;
673  double activeLabelMargin;
674  bool reactionContext;
675  bool hasAtomCoords;
676  LinePrimitiveCache lineCache;
677  PolylinePrimitiveCache polylineCache;
678  PolygonPrimitiveCache polygonCache;
679  LineSegListPrimitiveCache lineSegListCache;
680  PointListPrimitiveCache pointListCache;
681  TextLabelPrimitiveCache textLabelCache;
682  };
683  } // namespace Vis
684 } // namespace CDPL
685 
686 #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:81
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:437
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:443
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