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 
589  {
590 
591  public:
595  typedef std::shared_ptr<ReactionView2D> SharedPointer;
596 
603 
604  ReactionView2D(const ReactionView2D&) = delete;
605 
610 
612 
617  void render(Renderer2D& renderer);
618 
623  void setFontMetrics(FontMetrics* font_metrics);
624 
630 
639  void setReaction(const Chem::Reaction* rxn);
640 
645  const Chem::Reaction* getReaction() const;
646 
652 
653  private:
654  void paintBackground(Renderer2D&) const;
655 
656  void renderComponents(Renderer2D&) const;
657  void renderGraphicsPrimitives(Renderer2D&) const;
658 
659  void init();
660 
661  void initComponentViews();
662  void initComponentBoundsTable();
663  void layoutReaction();
664  void calcOutputTransforms();
665  void initComponentViewViewports();
666  void createPlusSignPrimitives();
667  void createArrowPrimitives();
668 
669  void createStdReactionArrow(bool);
670 
671  void layoutComponents(unsigned int, std::size_t, std::size_t);
672  void createPackedComponentLayout(unsigned int, std::size_t, std::size_t);
673  void createLinearComponentLayout(unsigned int, std::size_t, std::size_t);
674  void createHLinearComponentLayout(unsigned int, std::size_t, std::size_t);
675  void createVLinearComponentLayout(unsigned int, std::size_t, std::size_t);
676 
677  unsigned int getComponentLayout(unsigned int) const;
678  unsigned int getComponentLayoutDirection(unsigned int) const;
679 
680  void shiftComponentPositions(std::size_t, std::size_t, const Math::Vector2D&);
681  void shiftPlusSignPositions(std::size_t, std::size_t, const Math::Vector2D&);
682 
683  void calcArrowDimensions();
684  void calcPlusSignDimensions();
685 
686  void freeComponentViews();
687  void freeGraphicsPrimitives();
688 
689  void initArrowStyle();
690  void initArrowLength();
691 
692  const Color& getArrowColor() const;
693  const SizeSpecification& getArrowHeadLength() const;
694  const SizeSpecification& getArrowHeadWidth() const;
695  const SizeSpecification& getArrowShaftWidth() const;
696  const SizeSpecification& getArrowLineWidth() const;
697 
698  void initComponentLayout();
699  void initComponentLayoutDirection();
700  void initComponentMargin();
701  void initComponentVisibility();
702  void initAgentAlignment();
703  void initAgentLayout();
704  void initAgentLayoutDirection();
705 
706  const Color& getPlusSignColor() const;
707  const SizeSpecification& getPlusSignSize() const;
709 
710  void initPlusSignVisibility();
711 
712  StructureView2D* allocComponentView(const Chem::Molecule&);
713  PolygonPrimitive2D* allocPolygonPrimitive();
714  LineSegmentListPrimitive2D* allocLineSegListPrimitive();
715 
716  typedef std::vector<StructureView2D*> ComponentViewList;
717  typedef std::vector<const GraphicsPrimitive2D*> GraphicsPrimitiveList;
718  typedef std::map<const Chem::MolecularGraph*, Rectangle2D> ComponentBoundsMap;
719  typedef std::vector<Math::Vector2D> Vector2DArray;
723  typedef std::unique_ptr<ReactionView2DParameters> ReactionView2DParametersPtr;
724 
725  const Chem::Reaction* reaction;
726  ReactionView2DParametersPtr parameters;
727  FontMetrics* fontMetrics;
728  ComponentViewList componentViews;
729  GraphicsPrimitiveList drawList;
730  Rectangle2D totalComponentBounds;
731  Rectangle2D totalReactionBounds;
732  ComponentBoundsMap componentBounds;
733  Vector2DArray componentPositions;
734  Vector2DArray plusSignPositions;
735  Math::Vector2D arrowPosition;
736  double unscaledArrowLength;
737  double unscaledArrowHeadLength;
738  double unscaledArrowHeadWidth;
739  double unscaledArrowShaftWidth;
740  double unscaledArrowLineWidth;
741  double maxUnscaledArrowWidth;
742  double unscaledPlusSignSize;
743  double unscaledPlusSignLineWidth;
744  double outputScalingFactor;
745  Math::Vector2D outputTranslation;
746  unsigned int arrowStyle;
747  SizeSpecification arrowLength;
748  unsigned int componentLayout;
749  unsigned int componentLayoutDirection;
750  SizeSpecification componentMargin;
751  unsigned int agentAlignment;
752  unsigned int agentLayout;
753  unsigned int agentLayoutDirection;
754  bool showReactants;
755  bool showAgents;
756  bool showProducts;
757  bool plusSignsVisible;
758  bool reactionChanged;
759  bool fontMetricsChanged;
760  ComponentViewCache compViewCache;
761  PolygonPrimitiveCache polygonCache;
762  LineSegListPrimitiveCache lineSegListCache;
763  };
764  } // namespace Vis
765 } // namespace CDPL
766 
767 #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: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 the font metrics object used for text-size calculations.
void getModelBounds(Rectangle2D &bounds)
Computes the axis-aligned bounding rectangle that contains the rendered reaction 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 visualized reaction via renderer.
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
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:2932
VectorArray< Vector2D > Vector2DArray
Array storing vectors of type Math::Vector2D.
Definition: VectorArray.hpp:80
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.