All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Fill.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/se/Fill.cpp
22 
23  \brief A Fill specifies the pattern for filling an area geometry.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "Fill.h"
29 #include "Graphic.h"
30 #include "SvgParameter.h"
31 
32 const std::string te::se::Fill::sm_fill = "fill";
33 const std::string te::se::Fill::sm_opacity = "fill-opacity";
34 
36  : m_graphicFill(0)
37 {
38 }
39 
41 {
42  delete m_graphicFill;
43  te::common::FreeContents(m_svgParams);
44 }
45 
47 {
48  delete m_graphicFill;
49  m_graphicFill = g;
50 }
51 
53 {
54  return m_graphicFill;
55 }
56 
58 {
59  std::string name = p->getName();
60  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
61  if(it != m_svgParams.end())
62  delete it->second;
63  m_svgParams[name] = p;
64 }
65 
66 void te::se::Fill::setColor(const std::string& color)
67 {
68  setParameter(sm_fill, color);
69 }
70 
71 void te::se::Fill::setOpacity(const std::string& opacity)
72 {
73  setParameter(sm_opacity, opacity);
74 }
75 
77 {
78  return getParameter(sm_fill);
79 }
80 
82 {
83  return getParameter(sm_opacity);
84 }
85 
87 {
88  Fill* fill = new Fill;
89 
90  std::map<std::string, SvgParameter*>::const_iterator it;
91  for(it = m_svgParams.begin(); it != m_svgParams.end(); ++it)
92  fill->add(it->second->clone());
93 
94  const Graphic* graphicFill = getGraphicFill();
95  if(graphicFill)
96  fill->setGraphicFill(graphicFill->clone());
97 
98  return fill;
99 }
100 
101 void te::se::Fill::setParameter(const std::string& name, const std::string& value)
102 {
103  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
104  if(it != m_svgParams.end())
105  delete it->second;
106  m_svgParams[name] = new te::se::SvgParameter(name, value);
107 }
108 
109 const te::se::SvgParameter* te::se::Fill::getParameter(const std::string& name) const
110 {
111  std::map<std::string, te::se::SvgParameter*>::const_iterator it = m_svgParams.find(name);
112  if(it != m_svgParams.end())
113  return it->second;
114 
115  return 0; // Not found
116 }
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Fill()
It initializes a new Fill.
Definition: Fill.cpp:35
A Fill specifies the pattern for filling an area geometry.
void setColor(const std::string &color)
Definition: Fill.cpp:66
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
static const std::string sm_fill
SVG/CSS "fill" parameter.
Definition: Fill.h:128
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
static const std::string sm_opacity
SVG/CSS "fill-opacity parameter.
Definition: Fill.h:129
~Fill()
Destructor.
Definition: Fill.cpp:40
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Fill.
Definition: Fill.cpp:52
const SvgParameter * getParameter(const std::string &name) const
Definition: Fill.cpp:109
void setOpacity(const std::string &opacity)
Definition: Fill.cpp:71
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
std::string getName() const
void add(SvgParameter *p)
Add a SvgParameter to this Fill.
Definition: Fill.cpp:57
void setGraphicFill(Graphic *g)
Sets the GraphicFill element to this Fill. GraphicFill defines that the pixels of the area will be dr...
Definition: Fill.cpp:46
Fill * clone() const
It creates a new copy of this object.
Definition: Fill.cpp:86
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
const SvgParameter * getColor() const
Definition: Fill.cpp:76
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Definition: SvgParameter.h:48
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
void setParameter(const std::string &name, const std::string &value)
Definition: Fill.cpp:101
const SvgParameter * getOpacity() const
Definition: Fill.cpp:81