All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MarkRendererManager.cpp
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/MarkRendererManager.cpp
22 
23  \brief This is a singleton for managing all mark renderers instances available in the system.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/StringUtils.h"
29 #include "../common/Translator.h"
30 #include "../se/Mark.h"
31 #include "AbstractMarkRenderer.h"
32 #include "Exception.h"
33 #include "MarkRendererManager.h"
34 
35 // Boost
36 #include <boost/format.hpp>
37 
38 // STL
39 #include <cassert>
40 #include <vector>
41 
43 {
44 }
45 
47 {
48  te::common::FreeContents(m_renderers);
49 }
50 
52 {
53  LockWrite l;
54 
55  if(size == 0)
56  throw Exception(TE_TR("Requested size is invalid!"));
57 
58  if(mark == 0)
59  throw Exception(TE_TR("The given mark is invalid!"));
60 
61  const std::string* name = mark->getWellKnownName();
62  if(name == 0)
63  throw Exception(TE_TR("The given mark not have a valid well known name!"));
64 
65  if(name->empty())
66  throw Exception(TE_TR("The mark well known name is empty!"));
67 
68  // Default renderer key
69  std::string key("");
70 
71  // Try find the renderer key
72  std::vector<std::string> tokens;
73  te::common::Tokenize(*name, tokens, "://");
74 
75  if(tokens.size() > 1)
76  key = tokens[0];
77 
78  std::map<std::string, AbstractMarkRenderer*>::iterator it = m_renderers.find(key);
79 
80  if(it == m_renderers.end())
81  throw Exception((boost::format(TE_TR("There is not a mark renderer registered for the given mark %1%.")) % *name).str());
82 
83  return it->second->render(mark, size);
84 }
85 
86 void te::map::MarkRendererManager::getAllSupportedMarks(std::vector<std::string>& marks) const
87 {
88  std::map<std::string, AbstractMarkRenderer*>::const_iterator it;
89  for(it = m_renderers.begin(); it != m_renderers.end(); ++it)
90  it->second->getSupportedMarks(marks);
91 }
92 
93 void te::map::MarkRendererManager::add(const std::string& key, AbstractMarkRenderer* renderer)
94 {
95  std::map<std::string, AbstractMarkRenderer*>::iterator it = m_renderers.find(key);
96 
97  if(it != m_renderers.end())
98  throw Exception((boost::format(TE_TR("There is already a mark renderer registered with the given key %1%.")) % key).str());
99 
100  m_renderers[key] = renderer;
101 }
void getAllSupportedMarks(std::vector< std::string > &marks) const
It informs the set of all supported marks available in the system.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
~MarkRendererManager()
Singleton destructor.
This is a singleton for managing all mark renderers instances available in the system.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
An exception class for the MapTools module.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:216
void add(const std::string &key, AbstractMarkRenderer *renderer)
It adds a new mark renderer to the manager.
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
An abstract class for conversion of Symbology Enconding Mark elements to an image pattern...
An abstract class for conversion of Symbology Enconding Mark elements to an image pattern...
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
te::color::RGBAColor ** render(const te::se::Mark *mark, std::size_t size)
It generates the image pattern from the given Symbology Enconding Mark element.
MarkRendererManager()
It initializes the singleton instance of the mark renderer manager.