All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Stroke.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/Stroke.cpp
22 
23  \brief A Stroke specifies the appearance of a linear geometry.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "Graphic.h"
29 #include "GraphicStroke.h"
30 #include "Stroke.h"
31 #include "SvgParameter.h"
32 
33 // STL
34 #include <cassert>
35 
36 const std::string te::se::Stroke::sm_stroke = "stroke";
37 const std::string te::se::Stroke::sm_opacity = "stroke-opacity";
38 const std::string te::se::Stroke::sm_width = "stroke-width";
39 const std::string te::se::Stroke::sm_linejoin = "stroke-linejoin";
40 const std::string te::se::Stroke::sm_linecap = "stroke-linecap";
41 const std::string te::se::Stroke::sm_dasharray = "stroke-dasharray";
42 const std::string te::se::Stroke::sm_dashoffset = "stroke-dashoffset";
43 
45  : m_fill(0),
46  m_stroke(0)
47 {
48 }
49 
51 {
52  delete m_fill;
53  delete m_stroke;
54  te::common::FreeContents(m_svgParams);
55 }
56 
58 {
59  delete m_fill;
60  m_fill = fill;
61 }
62 
64 {
65  return m_fill;
66 }
67 
69 {
70  delete m_stroke;
71  m_stroke = stroke;
72 }
73 
75 {
76  return m_stroke;
77 }
78 
80 {
81  std::string name = p->getName();
82  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
83  if(it != m_svgParams.end())
84  delete it->second;
85  m_svgParams[name] = p;
86 }
87 
88 void te::se::Stroke::setColor(const std::string& color)
89 {
90  setParameter(sm_stroke, color);
91 }
92 
93 void te::se::Stroke::setOpacity(const std::string& opacity)
94 {
95  setParameter(sm_opacity, opacity);
96 }
97 
98 void te::se::Stroke::setWidth(const std::string& width)
99 {
100  setParameter(sm_width, width);
101 }
102 
103 void te::se::Stroke::setLineJoin(const std::string& join)
104 {
105  setParameter(sm_linejoin, join);
106 }
107 
108 void te::se::Stroke::setLineCap(const std::string& cap)
109 {
110  setParameter(sm_linecap, cap);
111 }
112 
113 void te::se::Stroke::setDashArray(const std::string& dasharray)
114 {
115  setParameter(sm_dasharray, dasharray);
116 }
117 
118 void te::se::Stroke::setDashOffset(const std::string& offset)
119 {
120  setParameter(sm_dashoffset, offset);
121 }
122 
124 {
125  return getParameter(sm_stroke);
126 }
127 
129 {
130  return getParameter(sm_opacity);
131 }
132 
134 {
135  return getParameter(sm_width);
136 }
137 
139 {
140  return getParameter(sm_linejoin);
141 }
142 
144 {
145  return getParameter(sm_linecap);
146 }
147 
149 {
150  return getParameter(sm_dasharray);
151 }
152 
154 {
155  return getParameter(sm_dashoffset);
156 }
157 
159 {
160  Stroke* stroke = new Stroke;
161 
162  std::map<std::string, SvgParameter*>::const_iterator it;
163  for(it = m_svgParams.begin(); it != m_svgParams.end(); ++it)
164  stroke->add(it->second->clone());
165 
166  const Graphic* graphicFill = getGraphicFill();
167  if(graphicFill)
168  stroke->setGraphicFill(graphicFill->clone());
169 
170  const GraphicStroke* graphicStroke = getGraphicStroke();
171  if(graphicStroke)
172  stroke->setGraphicStroke(graphicStroke->clone());
173 
174  return stroke;
175 }
176 
177 void te::se::Stroke::setParameter(const std::string& name, const std::string& value)
178 {
179  std::map<std::string, te::se::SvgParameter*>::iterator it = m_svgParams.find(name);
180  if(it != m_svgParams.end())
181  delete it->second;
182  m_svgParams[name] = new te::se::SvgParameter(name, value);
183 }
184 
185 const te::se::SvgParameter* te::se::Stroke::getParameter(const std::string& name) const
186 {
187  std::map<std::string, te::se::SvgParameter*>::const_iterator it = m_svgParams.find(name);
188  if(it != m_svgParams.end())
189  return it->second;
190 
191  return 0; // Not found
192 }
Stroke * clone() const
It creates a new copy of this object.
Definition: Stroke.cpp:158
static const std::string sm_opacity
SVG/CSS "stroke-opacity parameter.
Definition: Stroke.h:174
Stroke()
It initializes a new Stroke.
Definition: Stroke.cpp:44
void setGraphicFill(Graphic *fill)
Sets the GraphicFill element to this Stroke. GraphicFill defines that the pixels of the line will be ...
Definition: Stroke.cpp:57
GraphicStroke * clone() const
It creates a new copy of this object.
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
const SvgParameter * getLineCap() const
Definition: Stroke.cpp:143
void setWidth(const std::string &width)
Definition: Stroke.cpp:98
static const std::string sm_linejoin
SVG/CSS "stroke-linejoin" parameter.
Definition: Stroke.h:176
const SvgParameter * getParameter(const std::string &name) const
Definition: Stroke.cpp:185
const SvgParameter * getLineJoin() const
Definition: Stroke.cpp:138
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
void setDashArray(const std::string &dasharray)
Definition: Stroke.cpp:113
void setColor(const std::string &color)
Definition: Stroke.cpp:88
static const std::string sm_width
SVG/CSS "stroke-width" parameter.
Definition: Stroke.h:175
void setOpacity(const std::string &opacity)
Definition: Stroke.cpp:93
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
const SvgParameter * getOpacity() const
Definition: Stroke.cpp:128
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Stroke.
Definition: Stroke.cpp:63
const SvgParameter * getColor() const
Definition: Stroke.cpp:123
const GraphicStroke * getGraphicStroke() const
Gets the GraphicStroke element associate to this Stroke.
Definition: Stroke.cpp:74
void setLineCap(const std::string &cap)
Definition: Stroke.cpp:108
std::string getName() const
static const std::string sm_dashoffset
SVG/CSS "stroke-dashoffset" parameter.
Definition: Stroke.h:179
A GraphicStroke defines a repeated-linear graphic pattern to be used for stroking a line...
void setParameter(const std::string &name, const std::string &value)
Definition: Stroke.cpp:177
void setLineJoin(const std::string &join)
Definition: Stroke.cpp:103
const SvgParameter * getDashArray() const
Definition: Stroke.cpp:148
void setGraphicStroke(GraphicStroke *stroke)
Sets the GraphicStroke element to this Stroke. GraphicStroke defines that a repeated linear graphic i...
Definition: Stroke.cpp:68
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
static const std::string sm_stroke
SVG/CSS "stroke" parameter.
Definition: Stroke.h:173
A SvgParameter refers to an SVG/CSS graphical-formatting parameter.
Definition: SvgParameter.h:48
const SvgParameter * setDashOffset() const
Definition: Stroke.cpp:153
static const std::string sm_linecap
SVG/CSS "stroke-linecap" parameter.
Definition: Stroke.h:177
~Stroke()
Destructor.
Definition: Stroke.cpp:50
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
A Stroke specifies the appearance of a linear geometry.
void add(SvgParameter *p)
Add a SvgParameter to this Stroke.
Definition: Stroke.cpp:79
A GraphicStroke defines a repeated-linear graphic pattern to be used for stroking a line...
Definition: GraphicStroke.h:50
const SvgParameter * getWidth() const
Definition: Stroke.cpp:133
static const std::string sm_dasharray
SVG/CSS "stroke-dasharray" parameter.
Definition: Stroke.h:178