Rule.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/Rule.cpp
22 
23  \brief A Rule is used to attach property/scale conditions to and group the individual symbols used for rendering.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../fe/Filter.h"
29 #include "Description.h"
30 #include "Graphic.h"
31 #include "Rule.h"
32 #include "Symbolizer.h"
33 
34 // STL
35 #include <cassert>
36 #include <limits>
37 
39  : m_name(nullptr),
40  m_description(nullptr),
41  m_legendGraphic(nullptr),
42  m_filter(nullptr),
43  m_elseFilter(false),
44  m_minScaleDenominator(0.0),
45  m_maxScaleDenominator(std::numeric_limits<double>::infinity())
46 {
47 }
48 
50 {
51  delete m_name;
52  delete m_description;
53  delete m_legendGraphic;
54  delete m_filter;
56 }
57 
58 void te::se::Rule::setName(std::string* name)
59 {
60  delete m_name;
61  m_name = name;
62 }
63 
64 const std::string* te::se::Rule::getName() const
65 {
66  return m_name;
67 }
68 
70 {
71  delete m_description;
72  m_description = d;
73 }
74 
76 {
77  return m_description;
78 }
79 
81 {
82  delete m_legendGraphic;
83  m_legendGraphic = legendGraphic;
84 }
85 
87 {
88  return m_legendGraphic;
89 }
90 
92 {
93  delete m_filter;
94  m_filter = f;
95 }
96 
98 {
99  return m_filter;
100 }
101 
103 {
104  assert(m_filter == nullptr);
105  m_elseFilter = true;
106 }
107 
109 {
110  m_elseFilter = false;
111 }
112 
114 {
115  return m_elseFilter;
116 }
117 
118 void te::se::Rule::setMinScaleDenominator(const double& minScaleDenominator)
119 {
120  m_minScaleDenominator = minScaleDenominator;
121 }
122 
124 {
125  return m_minScaleDenominator;
126 }
127 
128 void te::se::Rule::setMaxScaleDenominator(const double& maxScaleDenominator)
129 {
130  m_maxScaleDenominator = maxScaleDenominator;
131 }
132 
134 {
135  return m_maxScaleDenominator;
136 }
137 
139 {
140  assert(s);
141  m_symbolizers.push_back(s);
142 }
143 
145 {
146  assert(s);
147  assert(i < m_symbolizers.size());
148  delete m_symbolizers[i];
149  m_symbolizers[i] = s;
150 }
151 
152 void te::se::Rule::setSymbolizers(const std::vector<Symbolizer*>& symbs)
153 {
155  m_symbolizers = symbs;
156 }
157 
158 const std::vector<te::se::Symbolizer*>& te::se::Rule::getSymbolizers() const
159 {
160  return m_symbolizers;
161 }
162 
164 {
165  assert(i < m_symbolizers.size());
166  return m_symbolizers[i];
167 }
168 
170 {
171  assert(i < m_symbolizers.size());
172 
173  delete m_symbolizers[i];
174 
175  m_symbolizers.erase(m_symbolizers.begin() + i);
176 }
177 
179 {
181  m_symbolizers.clear();
182 }
183 
185 {
186  Rule* rule = new Rule;
187 
188  if(m_name)
189  rule->setName(new std::string(*m_name));
190 
191  if(m_description)
193 
194  if(m_legendGraphic)
196 
197  if(m_filter)
198  rule->setFilter(m_filter->clone());
199 
201 
203 
205 
206  for(std::size_t i = 0; i < m_symbolizers.size(); ++i)
207  {
208  if(m_symbolizers[i])
209  rule->m_symbolizers.push_back(m_symbolizers[i]->clone());
210  }
211 
212  return rule;
213 }
~Rule()
Destructor.
Definition: Rule.cpp:49
void disableElseFilter()
Definition: Rule.cpp:108
A Description gives human-readable descriptive information for the object it is included within...
Definition: Description.h:56
bool hasElseFilter() const
Definition: Rule.cpp:113
void setLegendGraphic(Graphic *legendGraphic)
Definition: Rule.cpp:80
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
Graphic * m_legendGraphic
It allows an optional explicit Graphic Symbolizer to be displayed in a legend for this rule...
Definition: Rule.h:163
double m_minScaleDenominator
It defines the range of map-rendering scales for which the rule should be applied. Default: 0.0. (Optional)
Definition: Rule.h:166
const double & getMinScaleDenominator() const
Definition: Rule.cpp:123
void setDescription(Description *d)
Definition: Rule.cpp:69
Rule * clone() const
It creates a new copy of this object.
Definition: Rule.cpp:184
Rule()
It initializes a new Rule.
Definition: Rule.cpp:38
void setName(std::string *name)
Definition: Rule.cpp:58
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
void setFilter(te::fe::Filter *f)
Definition: Rule.cpp:91
const te::fe::Filter * getFilter() const
Definition: Rule.cpp:97
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
te::fe::Filter * m_filter
It allows the selection of features in rules to be controlled by attribute conditions. (Optional)
Definition: Rule.h:164
void push_back(Symbolizer *s)
Definition: Rule.cpp:138
std::string * m_name
It allows the rule to be referenced externally, which is needed in some methods of SE usage...
Definition: Rule.h:161
void setMaxScaleDenominator(const double &maxScaleDenominator)
Definition: Rule.cpp:128
double m_maxScaleDenominator
It defines the range of map-rendering scales for which the rule should be applied. Default: TE_DOUBLE_INFINITY. (Optional)
Definition: Rule.h:167
void clearSymbolizers()
Definition: Rule.cpp:178
Filter * clone() const
It creates a new copy of this object.
A Description gives human-readable descriptive information for the object it is included within...
Description * m_description
It gives the familiar short title for display lists and longer description for the rule...
Definition: Rule.h:162
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
Description * clone() const
It creates a new copy of this object.
Definition: Description.cpp:53
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
A filter is any valid predicate expression.
Definition: fe/Filter.h:55
void setSymbolizers(const std::vector< Symbolizer * > &symbs)
Definition: Rule.cpp:152
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
void removeSymbolizer(std::size_t i)
Definition: Rule.cpp:169
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
std::vector< Symbolizer * > m_symbolizers
A Symbolizer describes how a feature/coverage is to appear on a map. (Mandatory)
Definition: Rule.h:168
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
A Symbolizer describes how a Feature is to appear on a map.
void setMinScaleDenominator(const double &minScaleDenominator)
Definition: Rule.cpp:118
const double & getMaxScaleDenominator() const
Definition: Rule.cpp:133
void setSymbolizer(std::size_t i, Symbolizer *s)
Definition: Rule.cpp:144
const Description * getDescription() const
Definition: Rule.cpp:75
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
const Symbolizer * getSymbolizer(std::size_t i) const
Definition: Rule.cpp:163
void enableElseFilter()
Definition: Rule.cpp:102
const Graphic * getLegendGraphic() const
Definition: Rule.cpp:86
bool m_elseFilter
It allows rules to be specified that are activated for features that are not selected by any other ru...
Definition: Rule.h:165
const std::string * getName() const
Definition: Rule.cpp:64