Chemical Data Processing Library C++ API - Version 1.1.1
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  class FontMetrics;
64 
590  {
591 
592  public:
596  typedef std::shared_ptr<ReactionView2D> SharedPointer;
597 
604 
609 
610  void render(Renderer2D& renderer);
611 
612  void setFontMetrics(FontMetrics* font_metrics);
613 
619 
628  void setReaction(const Chem::Reaction* rxn);
629 
634  const Chem::Reaction* getReaction() const;
635 
637 
638  private:
640 
641  ReactionView2D& operator=(const ReactionView2D&);
642 
643  void paintBackground(Renderer2D&) const;
644 
645  void renderComponents(Renderer2D&) const;
646  void renderGraphicsPrimitives(Renderer2D&) const;
647 
648  void init();
649 
650  void initComponentViews();
651  void initComponentBoundsTable();
652  void layoutReaction();
653  void calcOutputTransforms();
654  void initComponentViewViewports();
655  void createPlusSignPrimitives();
656  void createArrowPrimitives();
657 
658  void createStdReactionArrow(bool);
659 
660  void layoutComponents(unsigned int, std::size_t, std::size_t);
661  void createPackedComponentLayout(unsigned int, std::size_t, std::size_t);
662  void createLinearComponentLayout(unsigned int, std::size_t, std::size_t);
663  void createHLinearComponentLayout(unsigned int, std::size_t, std::size_t);
664  void createVLinearComponentLayout(unsigned int, std::size_t, std::size_t);
665 
666  unsigned int getComponentLayout(unsigned int) const;
667  unsigned int getComponentLayoutDirection(unsigned int) const;
668 
669  void shiftComponentPositions(std::size_t, std::size_t, const Math::Vector2D&);
670  void shiftPlusSignPositions(std::size_t, std::size_t, const Math::Vector2D&);
671 
672  void calcArrowDimensions();
673  void calcPlusSignDimensions();
674 
675  void freeComponentViews();
676  void freeGraphicsPrimitives();
677 
678  void initArrowStyle();
679  void initArrowLength();
680 
681  const Color& getArrowColor() const;
682  const SizeSpecification& getArrowHeadLength() const;
683  const SizeSpecification& getArrowHeadWidth() const;
684  const SizeSpecification& getArrowShaftWidth() const;
685  const SizeSpecification& getArrowLineWidth() const;
686 
687  void initComponentLayout();
688  void initComponentLayoutDirection();
689  void initComponentMargin();
690  void initComponentVisibility();
691  void initAgentAlignment();
692  void initAgentLayout();
693  void initAgentLayoutDirection();
694 
695  const Color& getPlusSignColor() const;
696  const SizeSpecification& getPlusSignSize() const;
698 
699  void initPlusSignVisibility();
700 
701  StructureView2D* allocComponentView(const Chem::Molecule&);
702  PolygonPrimitive2D* allocPolygonPrimitive();
703  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
704 
705  typedef std::vector<StructureView2D*> ComponentViewList;
706  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
707  typedef std::map<const Chem::MolecularGraph*, Rectangle2D> ComponentBoundsMap;
708  typedef std::vector<Math::Vector2D> Vector2DArray;
712  typedef std::unique_ptr<ReactionView2DParameters> ReactionView2DParametersPtr;
713 
714  const Chem::Reaction* reaction;
715  ReactionView2DParametersPtr parameters;
716  FontMetrics* fontMetrics;
717  ComponentViewList componentViews;
718  GraphicsPrimitiveList drawList;
719  Rectangle2D totalComponentBounds;
720  Rectangle2D totalReactionBounds;
721  ComponentBoundsMap componentBounds;
722  Vector2DArray componentPositions;
723  Vector2DArray plusSignPositions;
724  Math::Vector2D arrowPosition;
725  double unscaledArrowLength;
726  double unscaledArrowHeadLength;
727  double unscaledArrowHeadWidth;
728  double unscaledArrowShaftWidth;
729  double unscaledArrowLineWidth;
730  double maxUnscaledArrowWidth;
731  double unscaledPlusSignSize;
732  double unscaledPlusSignLineWidth;
733  double outputScalingFactor;
734  Math::Vector2D outputTranslation;
735  unsigned int arrowStyle;
736  SizeSpecification arrowLength;
737  unsigned int componentLayout;
738  unsigned int componentLayoutDirection;
739  SizeSpecification componentMargin;
740  unsigned int agentAlignment;
741  unsigned int agentLayout;
742  unsigned int agentLayoutDirection;
743  bool showReactants;
744  bool showAgents;
745  bool showProducts;
746  bool plusSignsVisible;
747  bool reactionChanged;
748  bool fontMetricsChanged;
749  ComponentViewCache compViewCache;
750  PolygonPrimitiveCache polygonCache;
751  LineSegListPrimitiveCache lineSegListCache;
752  };
753  } // namespace Vis
754 } // namespace CDPL
755 
756 #endif // CDPL_VIS_REACTIONVIEW2D_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::ReactionView2D::setFontMetrics
void setFontMetrics(FontMetrics *font_metrics)
Specifies a font metrics object that will be used to measure the dimension of text labels.
CDPL::Vis::ReactionView2D::getModelBounds
void getModelBounds(Rectangle2D &bounds)
Calculates the bounding rectangle of the visualized model.
CDPL::Vis::getArrowLineWidth
CDPL_VIS_API const SizeSpecification & getArrowLineWidth(const Chem::Reaction &rxn)
SizeSpecification.hpp
Definition of the class CDPL::Vis::SizeSpecification.
CDPL::Vis::ReactionView2D::render
void render(Renderer2D &renderer)
Renders the visual representation of the model using the specified Vis::Renderer2D instance.
CDPL::Vis::View2D
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
CDPL::Vis::ReactionView2D
Implements the 2D visualization of chemical reactions.
Definition: ReactionView2D.hpp:590
CDPL::Vis::getArrowShaftWidth
CDPL_VIS_API const SizeSpecification & getArrowShaftWidth(const Chem::Reaction &rxn)
LineSegmentListPrimitive2D.hpp
Definition of the class CDPL::Vis::LineSegmentListPrimitive2D.
CDPL::Vis::ReactionView2D::setReaction
void setReaction(const Chem::Reaction *rxn)
Specifies the chemical reaction to visualize.
CDPL::Vis::getArrowHeadWidth
CDPL_VIS_API const SizeSpecification & getArrowHeadWidth(const Chem::Reaction &rxn)
CDPL::Vis::ReactionView2D::~ReactionView2D
~ReactionView2D()
Destructor.
CDPL::Vis::getComponentLayout
CDPL_VIS_API unsigned int getComponentLayout(const Chem::Reaction &rxn)
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::getPlusSignColor
CDPL_VIS_API const Color & getPlusSignColor(const Chem::Reaction &rxn)
CDPL::Vis::ReactionView2D::getFontMetrics
FontMetrics * getFontMetrics() const
Returns a pointer to the used font metrics object.
CDPL::Vis::StructureView2D
Implements the 2D visualization of chemical structures.
Definition: StructureView2D.hpp:493
CDPL::Vis::getPlusSignSize
CDPL_VIS_API const SizeSpecification & getPlusSignSize(const Chem::Reaction &rxn)
CDPL::Chem::Molecule
Molecule.
Definition: Molecule.hpp:49
CDPL::Vis::getComponentLayoutDirection
CDPL_VIS_API unsigned int getComponentLayoutDirection(const Chem::Reaction &rxn)
CDPL_VIS_API
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
View2D.hpp
Definition of the class CDPL::Vis::View2D.
CDPL::Vis::getArrowColor
CDPL_VIS_API const Color & getArrowColor(const Chem::Reaction &rxn)
CDPL::Vis::PolygonPrimitive2D
A graphics primitive representing a polygon.
Definition: PolygonPrimitive2D.hpp:52
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::Reaction
Reaction.
Definition: Reaction.hpp:52
CDPL::Vis::Rectangle2D
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
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.
CDPL::Vis::getArrowHeadLength
CDPL_VIS_API const SizeSpecification & getArrowHeadLength(const Chem::Reaction &rxn)
StructureView2D.hpp
Definition of the class CDPL::Vis::StructureView2D.
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
Color.hpp
Definition of the class CDPL::Vis::Color.
CDPL::Util::ObjectStack< StructureView2D >
APIPrefix.hpp
Definition of the preprocessor macro CDPL_VIS_API.
CDPL::Vis::getPlusSignLineWidth
CDPL_VIS_API const SizeSpecification & getPlusSignLineWidth(const Chem::Reaction &rxn)
CDPL::Vis::ReactionView2D::ReactionView2D
ReactionView2D(const Chem::Reaction *rxn=0)
Constructs and initializes a ReactionView2D instance for the visualization of the chemical reaction s...
CDPL::Vis::ReactionView2D::SharedPointer
std::shared_ptr< ReactionView2D > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ReactionView2D instances.
Definition: ReactionView2D.hpp:596
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
Vector.hpp
Definition of vector data types.
CDPL::Vis::ReactionView2D::getReaction
const Chem::Reaction * getReaction() const
Returns a pointer to the visualized chemical reaction.