All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorScheme.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/color/ColorScheme.cpp
22 
23  \brief Implementation of the color scheme concept.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "ColorScheme.h"
29 #include "ColorSchemeGroup.h"
30 
31 te::color::ColorScheme::ColorScheme(const std::string& name)
32  : m_parent(0),
33  m_name(name)
34 {
35 }
36 
38 {
39  te::common::FreeContents(m_colorSet);
40 }
41 
42 const std::string& te::color::ColorScheme::getName() const
43 {
44  return m_name;
45 }
46 
47 void te::color::ColorScheme::setName(const std::string& name)
48 {
49  assert(name.empty() == false);
50 
51  if(m_parent == 0)
52  {
53  m_name = name;
54  return;
55  }
56 // disconnect from the parent, change name and re-connect
57  m_parent->disconnect(this);
58  m_name = name;
59  m_parent->push_back(this);
60 }
61 
62 void te::color::ColorScheme::push_back(std::vector<RGBAColor>* colors)
63 {
64  assert(colors);
65  m_colorSet.push_back(colors);
66 }
67 
68 const std::vector<std::vector<te::color::RGBAColor>* >& te::color::ColorScheme::getColors() const
69 {
70  return m_colorSet;
71 }
72 
73 std::vector<te::color::RGBAColor>* te::color::ColorScheme::getColors(size_t size) const
74 {
75  const size_t n = m_colorSet.size();
76 
77  for(size_t i = 0; i < n; ++i)
78  if(m_colorSet[i]->size() == size)
79  return m_colorSet[i];
80 
81  return 0;
82 }
83 
85 {
86  return m_parent;
87 }
88 
90 {
91  m_parent = parent;
92 }
93 
ColorScheme(const std::string &name)
It initializes a new ColorScheme and adds it to the parent group of schemes.
Definition: ColorScheme.cpp:31
This class represents a group of color schemes.
const std::vector< std::vector< RGBAColor > * > & getColors() const
It returns all color lists.
Definition: ColorScheme.cpp:68
void setParent(ColorSchemeGroup *parent)
It sets the parent color scheme group for this scheme.
Definition: ColorScheme.cpp:89
void setName(const std::string &name)
It sets the color schema name and adjust its entry in the scheme group if needed. ...
Definition: ColorScheme.cpp:47
const std::string & getName() const
It returns the color schema name.
Definition: ColorScheme.cpp:42
The concept of color scheme.
void push_back(std::vector< RGBAColor > *colors)
It adds a new list of colors to the color scheme.
Definition: ColorScheme.cpp:62
ColorSchemeGroup * getParent() const
It returns the parent scheme group or NULL if it doesn't belong to a group.
Definition: ColorScheme.cpp:84
This class represents a group of color schemes.
~ColorScheme()
Destructor.
Definition: ColorScheme.cpp:37
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