All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLayer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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/AbstractLayer.cpp
22 
23  \brief This is the base class for layers.
24  */
25 
26 // TerraLib
27 #include "../dataaccess/dataset/ObjectIdSet.h"
28 #include "../se/Style.h"
29 #include "../srs/Config.h"
30 #include "AbstractLayer.h"
31 #include "Chart.h"
32 #include "Grouping.h"
33 
35  : te::common::TreeItem(parent),
36  m_srid(TE_UNKNOWN_SRS),
37  m_visibility(NOT_VISIBLE),
38  m_visibilityChanged(false),
39  m_selected(0),
40  m_style(0),
41  m_grouping(0),
42  m_chart(0)
43 {
44 }
45 
47  : te::common::TreeItem(parent),
48  m_id(id),
49  m_srid(TE_UNKNOWN_SRS),
50  m_visibility(NOT_VISIBLE),
51  m_visibilityChanged(false),
52  m_selected(0),
53  m_style(0),
54  m_grouping(0),
55  m_chart(0)
56 {
57 }
58 
60  const std::string& title,
61  AbstractLayer* parent)
62  : te::common::TreeItem(parent),
63  m_id(id),
64  m_title(title),
65  m_srid(TE_UNKNOWN_SRS),
66  m_visibility(NOT_VISIBLE),
67  m_visibilityChanged(false),
68  m_selected(0),
69  m_style(0),
70  m_grouping(0),
71  m_chart(0)
72 {
73 }
74 
76 {
77  delete m_selected;
78  delete m_style;
79  delete m_grouping;
80  delete m_chart;
81 }
82 
83 const std::string& te::map::AbstractLayer::getId() const
84 {
85  return m_id;
86 }
87 
88 void te::map::AbstractLayer::setId(const std::string& id)
89 {
90  m_id = id;
91 }
92 
93 const std::string& te::map::AbstractLayer::getTitle() const
94 {
95  return m_title;
96 }
97 
98 void te::map::AbstractLayer::setTitle(const std::string& title)
99 {
100  m_title = title;
101 }
102 
103 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getDescendants()
104 {
105  std::vector<AbstractLayer*> layers;
106  std::vector<AbstractLayer*> childrenLayers;
107 
108  std::size_t numChildren = getChildrenCount();
109  for(std::size_t i = 0; i < numChildren; ++i)
110  {
111  AbstractLayer* childLayer = static_cast<AbstractLayer*>(getChild(i).get());
112  layers.push_back(childLayer);
113 
114  if(childLayer->hasChildren())
115  {
116  childrenLayers = childLayer->getDescendants();
117  for(std::size_t i = 0; i < childrenLayers.size(); ++i)
118  layers.push_back(childrenLayers[i]);
119  }
120  }
121 
122  return layers;
123 }
124 
125 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getAncestors()
126 {
127  std::vector<AbstractLayer*> layers;
128 
129  AbstractLayer* parentLayer = static_cast<AbstractLayer*>(getParent());
130  while(parentLayer)
131  {
132  layers.push_back(parentLayer);
133  parentLayer = static_cast<AbstractLayer*>(parentLayer->getParent());
134  }
135 
136  return layers;
137 }
138 
140 {
141  return m_visibility;
142 }
143 
145 {
146  Visibility prevVisibility = m_visibility;
147 
148  m_visibilityChanged = false;
149 
150  m_visibility = v;
151 
152  if(m_visibility != prevVisibility)
153  m_visibilityChanged = true;
154 }
155 
157 {
158  return m_visibilityChanged;
159 }
160 
162 {
163  m_visibilityChanged = visChanged;
164 }
165 
167 {
168  AbstractLayer* parent = static_cast<AbstractLayer*>(getParent());
169  while(parent)
170  {
171  bool allVisible = true;
172  bool allNotVisible = true;
173 
174  Visibility prevParentVisibility = parent->getVisibility();
175  parent->m_visibilityChanged = false;
176 
177  int numChildren = parent->getChildrenCount();
178  std::vector<AbstractLayer*> childrenVec(numChildren);
179 
180  for(int i = 0; i < numChildren; ++i)
181  {
182  childrenVec[i] = static_cast<AbstractLayer*>(parent->getChild(i).get());
183 
184  if(childrenVec[i]->getVisibility() == te::map::NOT_VISIBLE)
185  allVisible = false;
186  else if(childrenVec[i]->getVisibility() == te::map::VISIBLE)
187  allNotVisible = false;
188  else if(childrenVec[i]->getVisibility() == te::map::PARTIALLY_VISIBLE)
189  {
190  allVisible = false;
191  allNotVisible = false;
192  }
193  }
194 
195  // Set parent visibility;
196  Visibility parentVisibility = te::map::PARTIALLY_VISIBLE;
197  if(allVisible)
198  parentVisibility = te::map::VISIBLE;
199  else if(allNotVisible)
200  parentVisibility = te::map::NOT_VISIBLE;
201 
202  parent->m_visibility = parentVisibility;
203 
204  if(parentVisibility != prevParentVisibility)
205  parent->m_visibilityChanged = true;
206 
207  parent = static_cast<AbstractLayer*>(parent->getParent());
208  }
209 }
210 
212 {
213 }
214 
216 {
217  return m_mbr;
218 }
219 
221 {
222  m_mbr = mbr;
223 }
224 
226 {
227  return m_srid;
228 }
229 
231 {
232  m_srid = srid;
233 }
234 
236 {
237  assert(oids);
238 
239  if(m_selected == 0)
240  {
241  m_selected = oids;
242  return;
243  }
244 
245  if(m_selected->size() == 0)
246  {
247  delete m_selected;
248  m_selected = oids;
249  return;
250  }
251 
252  assert(m_selected);
253 
254  m_selected->Union(oids);
255 }
256 
258 {
259  return m_selected;
260 }
261 
263 {
264  if(m_selected)
265  m_selected->clear();
266 }
267 
269 {
270  assert(m_selected);
271 
272  if(m_selected->size() == 0)
273  return;
274 
275  m_selected->difference(oids);
276 }
277 
279 {
280  return m_style;
281 }
282 
284 {
285  delete m_style;
286  m_style = style;
287 }
288 
290 {
291  return m_grouping;
292 }
293 
295 {
296  delete m_grouping;
297  m_grouping = grouping;
298 }
299 
301 {
302  return m_chart;
303 }
304 
306 {
307  delete m_chart;
308  m_chart = chart;
309 }
This class represents the informations needed to build map charts.
virtual void setExtent(const te::gm::Envelope &mbr)
It sets the Layer extent (or minimum bounding box).
virtual void clearSelected()
It clears the selected group of this Layer.
virtual te::map::Chart * getChart() const
It returns the Chart associated to the Layer.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
virtual void select(te::da::ObjectIdSet *oids)
It adds the given oids to the selected group of this Layer.
bool hasChildren() const
It returns true if the item has descendants.
Definition: TreeItem.cpp:60
virtual const std::string & getTitle() const
It returns the layer title.
This is the base class for layers.
Definition: AbstractLayer.h:76
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
void setVisibilityAsChanged(bool visChanged)
It sets that the status of the layer visibility is to be changed or not..
virtual ~AbstractLayer()
Virtual destructor.
Visibility
Each layer can have three states of visibility.
Definition: Enums.h:138
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:72
virtual te::map::Grouping * getGrouping() const
It returns the Grouping associated to the Layer.
virtual void setId(const std::string &id)
It sets the layer id.
virtual void setTitle(const std::string &title)
It sets the layer title.
std::size_t getChildrenCount() const
It returns the number of children of this node.
Definition: TreeItem.cpp:183
std::vector< te::map::AbstractLayer * > getDescendants()
It returns a list with the descendants of this layer.
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
virtual void deselect(const te::da::ObjectIdSet *oids)
It removes the given oids from the selected group of this Layer.
virtual void setGrouping(te::map::Grouping *grouping)
It sets the Grouping associated to the Layer.
virtual void setChart(te::map::Chart *chart)
It sets the Chart associated to the Layer.
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
Definition: TreeItem.cpp:75
void updateVisibilityOfAncestors()
It updates the visibility of the ancestors of this layer, if any.
Visibility m_visibility
It indicates the layer visibility.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
virtual void setVisibility(Visibility v)
It sets the layer visibility.
This class contains the parameters needed for grouping the values of a Property.
bool m_visibilityChanged
It indicates if the layer visibility has changed.
This class represents the informations needed to build map charts.
Definition: Chart.h:51
virtual void updateVisibility()
It updates the visibility of this layer.
TreeItem * getParent() const
It returns a pointer to the parent of this node.
Definition: TreeItem.cpp:65
AbstractLayer(AbstractLayer *parent=0)
It initializes a new layer.
This is the base class for Layers.
virtual Visibility getVisibility() const
It returns the layer visibility.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
virtual void setSRID(int srid)
It sets the Spatial Reference System ID associated to the Layer.
virtual const std::string & getId() const
It returns the layer id.
std::vector< te::map::AbstractLayer * > getAncestors()
It returns a list with the ancestors of this layer.
bool hasVisibilityChanged()
It gets the flag that indicates if the layer visibility has changed.
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.