Chemical Data Processing Library C++ API - Version 1.2.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 
589  {
590 
591  public:
595  typedef std::shared_ptr<ReactionView2D> SharedPointer;
596 
603 
604  ReactionView2D(const ReactionView2D&) = delete;
605 
610 
612 
613  void render(Renderer2D& renderer);
614 
615  void setFontMetrics(FontMetrics* font_metrics);
616 
622 
631  void setReaction(const Chem::Reaction* rxn);
632 
637  const Chem::Reaction* getReaction() const;
638 
640 
641  private:
642  void paintBackground(Renderer2D&) const;
643 
644  void renderComponents(Renderer2D&) const;
645  void renderGraphicsPrimitives(Renderer2D&) const;
646 
647  void init();
648 
649  void initComponentViews();
650  void initComponentBoundsTable();
651  void layoutReaction();
652  void calcOutputTransforms();
653  void initComponentViewViewports();
654  void createPlusSignPrimitives();
655  void createArrowPrimitives();
656 
657  void createStdReactionArrow(bool);
658 
659  void layoutComponents(unsigned int, std::size_t, std::size_t);
660  void createPackedComponentLayout(unsigned int, std::size_t, std::size_t);
661  void createLinearComponentLayout(unsigned int, std::size_t, std::size_t);
662  void createHLinearComponentLayout(unsigned int, std::size_t, std::size_t);
663  void createVLinearComponentLayout(unsigned int, std::size_t, std::size_t);
664 
665  unsigned int getComponentLayout(unsigned int) const;
666  unsigned int getComponentLayoutDirection(unsigned int) const;
667 
668  void shiftComponentPositions(std::size_t, std::size_t, const Math::Vector2D&);
669  void shiftPlusSignPositions(std::size_t, std::size_t, const Math::Vector2D&);
670 
671  void calcArrowDimensions();
672  void calcPlusSignDimensions();
673 
674  void freeComponentViews();
675  void freeGraphicsPrimitives();
676 
677  void initArrowStyle();
678  void initArrowLength();
679 
680  const Color& getArrowColor() const;
681  const SizeSpecification& getArrowHeadLength() const;
682  const SizeSpecification& getArrowHeadWidth() const;
683  const SizeSpecification& getArrowShaftWidth() const;
684  const SizeSpecification& getArrowLineWidth() const;
685 
686  void initComponentLayout();
687  void initComponentLayoutDirection();
688  void initComponentMargin();
689  void initComponentVisibility();
690  void initAgentAlignment();
691  void initAgentLayout();
692  void initAgentLayoutDirection();
693 
694  const Color& getPlusSignColor() const;
695  const SizeSpecification& getPlusSignSize() const;
697 
698  void initPlusSignVisibility();
699 
700  StructureView2D* allocComponentView(const Chem::Molecule&);
701  PolygonPrimitive2D* allocPolygonPrimitive();
702  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
703 
704  typedef std::vector<StructureView2D*> ComponentViewList;
705  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
706  typedef std::map<const Chem::MolecularGraph*, Rectangle2D> ComponentBoundsMap;
707  typedef std::vector<Math::Vector2D> Vector2DArray;
711  typedef std::unique_ptr<ReactionView2DParameters> ReactionView2DParametersPtr;
712 
713  const Chem::Reaction* reaction;
714  ReactionView2DParametersPtr parameters;
715  FontMetrics* fontMetrics;
716  ComponentViewList componentViews;
717  GraphicsPrimitiveList drawList;
718  Rectangle2D totalComponentBounds;
719  Rectangle2D totalReactionBounds;
720  ComponentBoundsMap componentBounds;
721  Vector2DArray componentPositions;
722  Vector2DArray plusSignPositions;
723  Math::Vector2D arrowPosition;
724  double unscaledArrowLength;
725  double unscaledArrowHeadLength;
726  double unscaledArrowHeadWidth;
727  double unscaledArrowShaftWidth;
728  double unscaledArrowLineWidth;
729  double maxUnscaledArrowWidth;
730  double unscaledPlusSignSize;
731  double unscaledPlusSignLineWidth;
732  double outputScalingFactor;
733  Math::Vector2D outputTranslation;
734  unsigned int arrowStyle;
735  SizeSpecification arrowLength;
736  unsigned int componentLayout;
737  unsigned int componentLayoutDirection;
738  SizeSpecification componentMargin;
739  unsigned int agentAlignment;
740  unsigned int agentLayout;
741  unsigned int agentLayoutDirection;
742  bool showReactants;
743  bool showAgents;
744  bool showProducts;
745  bool plusSignsVisible;
746  bool reactionChanged;
747  bool fontMetricsChanged;
748  ComponentViewCache compViewCache;
749  PolygonPrimitiveCache polygonCache;
750  LineSegListPrimitiveCache lineSegListCache;
751  };
752  } // namespace Vis
753 } // namespace CDPL
754 
755 #endif // CDPL_VIS_REACTIONVIEW2D_HPP
Definition of the class CDPL::Vis::Color.
Definition of the class CDPL::Vis::LineSegmentListPrimitive2D.
Definition of the class CDPL::Util::ObjectStack.
Definition of the class CDPL::Vis::PolygonPrimitive2D.
Definition of the class CDPL::Vis::Rectangle2D.
Definition of the class CDPL::Vis::SizeSpecification.
Definition of the class CDPL::Vis::StructureView2D.
Definition of vector data types.
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.
Molecule.
Definition: Molecule.hpp:49
Reaction.
Definition: Reaction.hpp:52
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
A graphics primitive representing a list of disjoint line segments.
Definition: LineSegmentListPrimitive2D.hpp:51
A graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:589
~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 used font metrics object.
void setReaction(const Chem::Reaction *rxn)
Specifies the chemical reaction to visualize.
void setFontMetrics(FontMetrics *font_metrics)
Specifies a font metrics object that will be used to measure the dimension of text labels.
void getModelBounds(Rectangle2D &bounds)
Calculates the 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 s...
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:595
ReactionView2D(const ReactionView2D &)=delete
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
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
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
CDPL_VIS_API const SizeSpecification & getArrowHeadLength(const Chem::Reaction &rxn)
CDPL_VIS_API const SizeSpecification & getArrowLineWidth(const Chem::Reaction &rxn)
CDPL_VIS_API const Color & getArrowColor(const Chem::Reaction &rxn)
CDPL_VIS_API const SizeSpecification & getPlusSignLineWidth(const Chem::Reaction &rxn)
CDPL_VIS_API const SizeSpecification & getPlusSignSize(const Chem::Reaction &rxn)
CDPL_VIS_API unsigned int getComponentLayoutDirection(const Chem::Reaction &rxn)
CDPL_VIS_API unsigned int getComponentLayout(const Chem::Reaction &rxn)
CDPL_VIS_API const SizeSpecification & getArrowHeadWidth(const Chem::Reaction &rxn)
CDPL_VIS_API const SizeSpecification & getArrowShaftWidth(const Chem::Reaction &rxn)
CDPL_VIS_API const Color & getPlusSignColor(const Chem::Reaction &rxn)
The namespace of the Chemical Data Processing Library.