All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExternalGraphicRendererManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2011 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/ExternalGraphicRendererManager.cpp
22 
23  \brief This is a singleton for managing all external graphic renderers instances available in the system.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/Translator.h"
30 #include "Exception.h"
32 
33 // STL
34 #include <cassert>
35 #include <vector>
36 
38 {
39 }
40 
42 {
43  te::common::FreeContents(m_renderers);
44 }
45 
47 {
48  LockWrite l;
49 
50  if(height == 0)
51  throw Exception(TR_MAP("Requested size is invalid!"));
52 
53  if(eg == 0)
54  throw Exception(TR_MAP("The given external graphic is invalid!"));
55 
56  if(m_renderers.empty())
57  throw Exception(TR_MAP("There are not external graphic renderers registered!"));
58 
59  for(std::size_t i = 0; i < m_renderers.size(); ++i)
60  {
61  te::color::RGBAColor** image = m_renderers[i]->render(eg, height, width);
62  if(image != 0)
63  return image;
64  }
65 
66  throw Exception(TR_MAP("The given external graphic cannot be processed by any registered external graphic renderer!"));
67 }
68 
70 {
71  m_renderers.push_back(renderer);
72 }
te::color::RGBAColor ** render(const te::se::ExternalGraphic *eg, std::size_t height, std::size_t &width)
It generates the image pattern from the given Symbology Enconding External Graphic element...
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
An exception class for the MapTools module.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
#define TR_MAP(message)
It marks a string in order to get translated. This is a special mark used in the Map Rendering module...
ExternalGraphicRendererManager()
It initializes the singleton instance of the external graphic renderer manager.
An abstract class for conversion of Symbology Enconding ExternalGraphic elements to an image pattern...
An abstract class for conversion of Symbology Enconding ExternalGraphic elements to an image pattern...
void add(AbstractExternalGraphicRenderer *renderer)
It adds a new external graphic renderer to the manager.
This is a singleton for managing all external graphic renderers instances available in the system...