Chemical Data Processing Library C++ API - Version 1.4.0
ReactionView2D.hpp
Go to the documentation of this file.
1 /*
2  * ReactionView2D.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_REACTIONVIEW2D_HPP
30 #define CDPL_VIS_REACTIONVIEW2D_HPP
31 
32 #include <vector>
33 #include <map>
34 #include <memory>
35 #include <cstddef>
36 
37 #include "CDPL/Vis/APIPrefix.hpp"
38 #include "CDPL/Vis/View2D.hpp"
39 #include "CDPL/Vis/Rectangle2D.hpp"
40 #include "CDPL/Vis/Color.hpp"
45 #include "CDPL/Math/Vector.hpp"
47 
48 
49 namespace CDPL
50 {
51 
52  namespace Chem
53  {
54 
55  class Reaction;
56  class Molecule;
57  } // namespace Chem
58 
59  namespace Vis
60  {
61 
62  class ReactionView2DParameters;
63 
829  {
830 
831  public:
835  typedef std::shared_ptr<ReactionView2D> SharedPointer;
836 
843 
844  ReactionView2D(const ReactionView2D&) = delete;
845 
850 
852 
853  void render(Renderer2D& renderer);
854 
855  void setFontMetrics(FontMetrics* font_metrics);
856 
862 
871  void setReaction(const Chem::Reaction* rxn);
872 
877  const Chem::Reaction* getReaction() const;
878 
880 
881  private:
882  void paintBackground(Renderer2D&) const;
883 
884  void renderComponents(Renderer2D&) const;
885  void renderGraphicsPrimitives(Renderer2D&) const;
886 
887  void init();
888 
889  void initComponentViews();
890  void initComponentBoundsTable();
891  void layoutReaction();
892  void calcOutputTransforms();
893  void initComponentViewViewports();
894  void createPlusSignPrimitives();
895  void createArrowPrimitives();
896 
897  void createStdReactionArrow(bool);
898 
899  void layoutComponents(unsigned int, std::size_t, std::size_t);
900  void createPackedComponentLayout(unsigned int, std::size_t, std::size_t);
901  void createLinearComponentLayout(unsigned int, std::size_t, std::size_t);
902  void createHLinearComponentLayout(unsigned int, std::size_t, std::size_t);
903  void createVLinearComponentLayout(unsigned int, std::size_t, std::size_t);
904 
905  unsigned int getComponentLayout(unsigned int) const;
906  unsigned int getComponentLayoutDirection(unsigned int) const;
907 
908  void shiftComponentPositions(std::size_t, std::size_t, const Math::Vector2D&);
909  void shiftPlusSignPositions(std::size_t, std::size_t, const Math::Vector2D&);
910 
911  void calcArrowDimensions();
912  void calcPlusSignDimensions();
913 
914  void freeComponentViews();
915  void freeGraphicsPrimitives();
916 
917  void initArrowStyle();
918  void initArrowLength();
919 
920  const Color& getArrowColor() const;
921  const SizeSpecification& getArrowHeadLength() const;
922  const SizeSpecification& getArrowHeadWidth() const;
923  const SizeSpecification& getArrowShaftWidth() const;
924  const SizeSpecification& getArrowLineWidth() const;
925 
926  void initComponentLayout();
927  void initComponentLayoutDirection();
928  void initComponentMargin();
929  void initComponentVisibility();
930  void initAgentAlignment();
931  void initAgentLayout();
932  void initAgentLayoutDirection();
933 
934  const Color& getPlusSignColor() const;
935  const SizeSpecification& getPlusSignSize() const;
937 
938  void initPlusSignVisibility();
939 
940  StructureView2D* allocComponentView(const Chem::Molecule&);
941  PolygonPrimitive2D* allocPolygonPrimitive();
942  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
943 
944  typedef std::vector<StructureView2D*> ComponentViewList;
945  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
946  typedef std::map<const Chem::MolecularGraph*, Rectangle2D> ComponentBoundsMap;
947  typedef std::vector<Math::Vector2D> Vector2DArray;
951  typedef std::unique_ptr<ReactionView2DParameters> ReactionView2DParametersPtr;
952 
953  const Chem::Reaction* reaction;
954  ReactionView2DParametersPtr parameters;
955  FontMetrics* fontMetrics;
956  ComponentViewList componentViews;
957  GraphicsPrimitiveList drawList;
958  Rectangle2D totalComponentBounds;
959  Rectangle2D totalReactionBounds;
960  ComponentBoundsMap componentBounds;
961  Vector2DArray componentPositions;
962  Vector2DArray plusSignPositions;
963  Math::Vector2D arrowPosition;
964  double unscaledArrowLength;
965  double unscaledArrowHeadLength;
966  double unscaledArrowHeadWidth;
967  double unscaledArrowShaftWidth;
968  double unscaledArrowLineWidth;
969  double maxUnscaledArrowWidth;
970  double unscaledPlusSignSize;
971  double unscaledPlusSignLineWidth;
972  double outputScalingFactor;
973  Math::Vector2D outputTranslation;
974  unsigned int arrowStyle;
975  SizeSpecification arrowLength;
976  unsigned int componentLayout;
977  unsigned int componentLayoutDirection;
978  SizeSpecification componentMargin;
979  unsigned int agentAlignment;
980  unsigned int agentLayout;
981  unsigned int agentLayoutDirection;
982  bool showReactants;
983  bool showAgents;
984  bool showProducts;
985  bool plusSignsVisible;
986  bool reactionChanged;
987  bool fontMetricsChanged;
988  ComponentViewCache compViewCache;
989  PolygonPrimitiveCache polygonCache;
990  LineSegListPrimitiveCache lineSegListCache;
991  };
992  } // namespace Vis
993 } // namespace CDPL
994 
995 #endif // CDPL_VIS_REACTIONVIEW2D_HPP
Definition of class CDPL::Vis::Color.
Definition of class CDPL::Vis::LineSegmentListPrimitive2D.
Definition of class CDPL::Util::ObjectStack.
Definition of class CDPL::Vis::PolygonPrimitive2D.
Definition of class CDPL::Vis::Rectangle2D.
Definition of class CDPL::Vis::SizeSpecification.
Definition of class CDPL::Vis::StructureView2D.
Definition of vector data types.
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.
Abstract base class representing a mutable molecular graph that owns its atoms and bonds.
Definition: Molecule.hpp:53
Abstract base class for chemical reactions composed of role-tagged Chem::Molecule components.
Definition: Reaction.hpp:59
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
2D graphics primitive representing a list of disjoint line segments.
Definition: LineSegmentListPrimitive2D.hpp:51
2D graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:829
~ReactionView2D()
Destructor.
ReactionView2D & operator=(const ReactionView2D &)=delete
const Chem::Reaction * getReaction() const
Returns a pointer to the visualized chemical reaction.
FontMetrics * getFontMetrics() const
Returns a pointer to the Vis::FontMetrics instance used for measuring the dimension of text labels.
void setReaction(const Chem::Reaction *rxn)
Specifies the chemical reaction to visualize.
void setFontMetrics(FontMetrics *font_metrics)
Specifies a Vis::FontMetrics instance that will be used to measure the dimension of text labels.
void getModelBounds(Rectangle2D &bounds)
Calculates the axis-aligned bounding rectangle of the visualized model.
ReactionView2D(const Chem::Reaction *rxn=0)
Constructs and initializes a ReactionView2D instance for the visualization of the chemical reaction r...
void render(Renderer2D &renderer)
Renders the visual representation of the model using the specified Vis::Renderer2D instance.
std::shared_ptr< ReactionView2D > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ReactionView2D instances.
Definition: ReactionView2D.hpp:835
ReactionView2D(const ReactionView2D &)=delete
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
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
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
CDPL_VIS_API const SizeSpecification & getArrowHeadLength(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::ARROW_HEAD_LENGTH property of the reaction rxn.
CDPL_VIS_API const SizeSpecification & getArrowLineWidth(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::ARROW_LINE_WIDTH property of the reaction rxn.
CDPL_VIS_API const Color & getArrowColor(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::ARROW_COLOR property of the reaction rxn.
CDPL_VIS_API const SizeSpecification & getPlusSignLineWidth(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::PLUS_SIGN_LINE_WIDTH property of the reaction rxn.
CDPL_VIS_API const SizeSpecification & getPlusSignSize(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::PLUS_SIGN_SIZE property of the reaction rxn.
CDPL_VIS_API unsigned int getComponentLayoutDirection(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::COMPONENT_LAYOUT_DIRECTION property of the reaction r...
CDPL_VIS_API unsigned int getComponentLayout(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::COMPONENT_LAYOUT property of the reaction rxn.
CDPL_VIS_API const SizeSpecification & getArrowHeadWidth(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::ARROW_HEAD_WIDTH property of the reaction rxn.
CDPL_VIS_API const SizeSpecification & getArrowShaftWidth(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::ARROW_SHAFT_WIDTH property of the reaction rxn.
CDPL_VIS_API const Color & getPlusSignColor(const Chem::Reaction &rxn)
Returns the value of the Vis::ReactionProperty::PLUS_SIGN_COLOR property of the reaction rxn.
The namespace of the Chemical Data Processing Library.