CanvasConfigurer.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/maptools/CanvasConfigurer.h
22 
23  \brief A Symbology Enconding visitor that configures a given canvas based on symbolizers elements.
24 */
25 
26 #ifndef __TERRALIB_MAPTOOLS_INTERNAL_CANVASCONFIGURER_H
27 #define __TERRALIB_MAPTOOLS_INTERNAL_CANVASCONFIGURER_H
28 
29 // TerraLib
30 #include "../color/RGBAColor.h"
31 #include "../se/Font.h"
32 #include "../se/Visitor.h"
33 #include "Config.h"
34 #include "Enums.h"
35 
36 // STL
37 #include <map>
38 
39 // Boost
40 #include <boost/noncopyable.hpp>
41 
42 namespace te
43 {
44 // Forward declarations
45  namespace se
46  {
47  class Fill;
48  class Graphic;
49  class GraphicStroke;
50  class ParameterValue;
51  class Stroke;
52  }
53 
54  namespace map
55  {
56 // Forward declarations
57  class Canvas;
58 
59  /*!
60  \class CanvasConfigurer
61 
62  \brief A Symbology Enconding visitor that configures a given canvas based on symbolizers elements.
63  If you want to use this visitor, use a command like:
64  <code>
65  te::map::CanvasConfigurer cc(canvas);
66  cc.config(symbolizer);
67  </code>
68 
69  \ingroup map
70 
71  \sa te::se::Visitor
72  */
73  class TEMAPEXPORT CanvasConfigurer : public te::se::Visitor, public boost::noncopyable
74  {
75  public:
76 
77  /** @name Initializer Methods
78  */
79  //@{
80 
81  /*!
82  \brief Constructor.
83 
84  \param canvas A pointer to the canvas that will be configured.
85 
86  \note This class will not take the ownership of the given canvas.
87  */
88  CanvasConfigurer(Canvas* canvas);
89 
90  /*! \brief Destructor. */
92 
93  //@}
94 
95  /** @name Config Method
96  * Method that can be used to configure a canvas based on Symbology Enconding symbolizer elements.
97  */
98  //@{
99 
100  /*!
101  \brief It configs the canvas based on given symbolizer.
102 
103  \param symbolizer The symbolizer that will be used to config the canvas.
104  */
105  void config(const te::se::Symbolizer* symbolizer);
106 
107  //@}
108 
109  /** @name Visitor Methods
110  * All concrete visitors must implement these methods.
111  */
112  //@{
113 
114  void visit(const te::se::Style& visited);
115  void visit(const te::se::FeatureTypeStyle& visited);
116  void visit(const te::se::CoverageStyle& visited);
117  void visit(const te::se::Symbolizer& visited);
118  void visit(const te::se::PolygonSymbolizer& visited);
119  void visit(const te::se::LineSymbolizer& visited);
120  void visit(const te::se::PointSymbolizer& visited);
121  void visit(const te::se::TextSymbolizer& visited);
122  void visit(const te::se::RasterSymbolizer& visited);
123 
124  //@}
125 
126  private:
127 
128  /*!
129  \enum ConfigStyle
130 
131  \brief Internal enum that indicates which style that should be configured.
132  */
134  {
135  Point, /*!< Adjust parameters associated with point. */
136  Line, /*!< Adjust parameters associated with line. */
137  Contour, /*!< Adjust parameters associated with contour. */
138  Fill /*!< Adjust parameters associated with fill. */
139  };
140 
141  /*!
142  \brief Internal method that configs the canvas based on given Stroke element.
143 
144  \param stroke The Stroke element that will be used to config the canvas.
145  \param fromLineSymbolizer A flag that indicates if the given stroke come from LineSymbolizer element.
146  */
147  void config(const te::se::Stroke* stroke, const bool& fromLineSymbolizer = true);
148 
149  /*!
150  \brief Internal method that configs the canvas based on given Fill element.
151 
152  \param fill The Fill element that will be used to config the canvas.
153  */
154  void config(const te::se::Fill* fill);
155 
156  /*!
157  \brief Internal method that configs the canvas based on given Graphic element.
158 
159  \param graphic The Graphic element that will be used to config the canvas.
160  \param configStyle Enumerated value that indicates which style that should be configured (for Point, Line, Contour, or Fill).
161  */
162  void config(const te::se::Graphic* graphic, ConfigStyle configStyle);
163 
164  /*! \brief Configs the canvas with default values for polygon styles. */
165  void configDefaultPolygon();
166 
167  /*! \brief Configs the canvas with default values for line styles. */
168  void configDefaultLine();
169 
170  /*! \brief Configs the canvas with default values for point styles. */
171  void configDefaultPoint();
172 
173  /*! \brief Configs the canvas with default values for text styles. */
174  void configDefaultText();
175 
176  private:
177 
178  Canvas* m_canvas; //!< A pointer to the canvas that will be configured.
179 
180  static std::map<std::string, te::map::LineCapStyle> sm_lineCapMap; //!< A map that associates stroke-linecap value to the correct LineCapStyle.
181  static std::map<std::string, te::map::LineJoinStyle> sm_lineJoinMap; //!< A map that associates stroke-linejoin value to the correct LineJoinStyle.
182 
183  static std::map<std::string, te::se::Font::FontStyleType> sm_fontStyleMap; //!< A map that associates FontStyleType to the correct string value.
184  static std::map<std::string, te::se::Font::FontWeightType> sm_fontWeightMap; //!< A map that associates FontWeightType to the correct string value.
185  };
186 
187  } // end namespace map
188 } // end namespace te
189 
190 #endif // __TERRALIB_MAPTOOLS_INTERNAL_CANVASCONFIGURER_H
A TextSymbolizer is used to render text labels according to various graphical parameters.
static std::map< std::string, te::se::Font::FontStyleType > sm_fontStyleMap
A map that associates FontStyleType to the correct string value.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
static std::map< std::string, te::map::LineCapStyle > sm_lineCapMap
A map that associates stroke-linecap value to the correct LineCapStyle.
Canvas * m_canvas
A pointer to the canvas that will be configured.
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
A visitor interface for the SymbologyEncoding hierarchy.
Definition: Visitor.h:41
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
URI C++ Library.
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:60
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:92
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
static std::map< std::string, te::se::Font::FontWeightType > sm_fontWeightMap
A map that associates FontWeightType to the correct string value.
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
ConfigStyle
Internal enum that indicates which style that should be configured.
static std::map< std::string, te::map::LineJoinStyle > sm_lineJoinMap
A map that associates stroke-linejoin value to the correct LineJoinStyle.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...