All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AbstractLayer.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/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  m_compositionMode(te::map::SourceOver)
44 {
45 }
46 
48  : te::common::TreeItem(parent),
49  m_id(id),
50  m_srid(TE_UNKNOWN_SRS),
51  m_visibility(NOT_VISIBLE),
52  m_visibilityChanged(false),
53  m_selected(0),
54  m_style(0),
55  m_grouping(0),
56  m_chart(0),
57  m_compositionMode(te::map::SourceOver)
58 {
59 }
60 
62  const std::string& title,
63  AbstractLayer* parent)
64  : te::common::TreeItem(parent),
65  m_id(id),
66  m_title(title),
67  m_srid(TE_UNKNOWN_SRS),
68  m_visibility(NOT_VISIBLE),
69  m_visibilityChanged(false),
70  m_selected(0),
71  m_style(0),
72  m_grouping(0),
73  m_chart(0),
74  m_compositionMode(te::map::SourceOver)
75 {
76 }
77 
79 {
80  delete m_selected;
81  delete m_style;
82  delete m_grouping;
83  delete m_chart;
84 }
85 
86 const std::string& te::map::AbstractLayer::getId() const
87 {
88  return m_id;
89 }
90 
91 void te::map::AbstractLayer::setId(const std::string& id)
92 {
93  m_id = id;
94 }
95 
96 const std::string& te::map::AbstractLayer::getTitle() const
97 {
98  return m_title;
99 }
100 
101 void te::map::AbstractLayer::setTitle(const std::string& title)
102 {
103  m_title = title;
104 }
105 
106 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getDescendants()
107 {
108  std::vector<AbstractLayer*> layers;
109  std::vector<AbstractLayer*> childrenLayers;
110 
111  std::size_t numChildren = getChildrenCount();
112  for(std::size_t i = 0; i < numChildren; ++i)
113  {
114  AbstractLayer* childLayer = static_cast<AbstractLayer*>(getChild(i).get());
115  layers.push_back(childLayer);
116 
117  if(childLayer->hasChildren())
118  {
119  childrenLayers = childLayer->getDescendants();
120  for(std::size_t i = 0; i < childrenLayers.size(); ++i)
121  layers.push_back(childrenLayers[i]);
122  }
123  }
124 
125  return layers;
126 }
127 
128 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getAncestors()
129 {
130  std::vector<AbstractLayer*> layers;
131 
132  AbstractLayer* parentLayer = static_cast<AbstractLayer*>(getParent());
133  while(parentLayer)
134  {
135  layers.push_back(parentLayer);
136  parentLayer = static_cast<AbstractLayer*>(parentLayer->getParent());
137  }
138 
139  return layers;
140 }
141 
143 {
144  return m_visibility;
145 }
146 
148 {
149  Visibility prevVisibility = m_visibility;
150 
151  m_visibilityChanged = false;
152 
153  m_visibility = v;
154 
155  if(m_visibility != prevVisibility)
156  m_visibilityChanged = true;
157 }
158 
160 {
161  return m_visibilityChanged;
162 }
163 
165 {
166  m_visibilityChanged = visChanged;
167 }
168 
170 {
171  AbstractLayer* parent = static_cast<AbstractLayer*>(getParent());
172  while(parent)
173  {
174  bool allVisible = true;
175  bool allNotVisible = true;
176 
177  Visibility prevParentVisibility = parent->getVisibility();
178  parent->m_visibilityChanged = false;
179 
180  int numChildren = parent->getChildrenCount();
181  std::vector<AbstractLayer*> childrenVec(numChildren);
182 
183  for(int i = 0; i < numChildren; ++i)
184  {
185  childrenVec[i] = static_cast<AbstractLayer*>(parent->getChild(i).get());
186 
187  if(childrenVec[i]->getVisibility() == te::map::NOT_VISIBLE)
188  allVisible = false;
189  else if(childrenVec[i]->getVisibility() == te::map::VISIBLE)
190  allNotVisible = false;
191  else if(childrenVec[i]->getVisibility() == te::map::PARTIALLY_VISIBLE)
192  {
193  allVisible = false;
194  allNotVisible = false;
195  }
196  }
197 
198  // Set parent visibility;
199  Visibility parentVisibility = te::map::PARTIALLY_VISIBLE;
200  if(allVisible)
201  parentVisibility = te::map::VISIBLE;
202  else if(allNotVisible)
203  parentVisibility = te::map::NOT_VISIBLE;
204 
205  parent->m_visibility = parentVisibility;
206 
207  if(parentVisibility != prevParentVisibility)
208  parent->m_visibilityChanged = true;
209 
210  parent = static_cast<AbstractLayer*>(parent->getParent());
211  }
212 }
213 
215 {
216 }
217 
219 {
220  return m_mbr;
221 }
222 
224 {
225  m_mbr = mbr;
226 }
227 
229 {
230  return m_srid;
231 }
232 
234 {
235  m_srid = srid;
236 }
237 
239 {
240  assert(oids);
241 
242  if(m_selected == 0)
243  {
244  m_selected = oids;
245  return;
246  }
247 
248  if(m_selected->size() == 0)
249  {
250  delete m_selected;
251  m_selected = oids;
252  return;
253  }
254 
255  assert(m_selected);
256 
257  m_selected->Union(oids);
258 }
259 
261 {
262  return m_selected;
263 }
264 
266 {
267  if(m_selected)
268  m_selected->clear();
269 }
270 
272 {
273  assert(m_selected);
274 
275  if(m_selected->size() == 0)
276  return;
277 
278  m_selected->difference(oids);
279 }
280 
282 {
283  return m_style;
284 }
285 
287 {
288  delete m_style;
289  m_style = style;
290 }
291 
293 {
294  return m_grouping;
295 }
296 
298 {
299  delete m_grouping;
300  m_grouping = grouping;
301 }
302 
304 {
305  return m_chart;
306 }
307 
309 {
310  delete m_chart;
311  m_chart = chart;
312 }
313 
315 {
316  return m_geomPropertyName;
317 }
318 
319 void te::map::AbstractLayer::setGeomPropertytName(const std::string& name)
320 {
321  m_geomPropertyName = name;
322 }
323 
325 {
326  return m_compositionMode;
327 }
328 
330 {
331  m_compositionMode = mode;
332 }
333 
335 {
336 }
virtual const std::string & getId() const
It returns the layer id.
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
Definition: TreeItem.cpp:75
virtual ~AbstractLayer()
Virtual destructor.
std::size_t getChildrenCount() const
It returns the number of children of this node.
Definition: TreeItem.cpp:183
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
This is the base class for layers.
Definition: AbstractLayer.h:76
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
virtual const std::string & getTitle() const
It returns the layer title.
virtual void updateVisibility()
It updates the visibility of this layer.
bool hasChildren() const
It returns true if the item has descendants.
Definition: TreeItem.cpp:60
void setCompositionMode(te::map::CompositionMode mode)
It sets the composition mode.
This is the base class for Layers.
bool hasVisibilityChanged()
It gets the flag that indicates if the layer visibility has changed.
virtual void setGrouping(te::map::Grouping *grouping)
It sets the Grouping associated to the Layer.
virtual void setOutOfDate()
Its indicate that the layer schema is out of date.
virtual Visibility getVisibility() const
It returns the layer visibility.
virtual void setTitle(const std::string &title)
It sets the layer title.
virtual te::map::Chart * getChart() const
It returns the Chart associated to the Layer.
te::map::CompositionMode getCompositionMode() const
It returns the composition mode.
CompositionMode
The composition mode used to render the canvas.
Definition: Enums.h:174
virtual void setGeomPropertytName(const std::string &name)
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
virtual void setChart(te::map::Chart *chart)
It sets the Chart associated to the Layer.
This class represents the informations needed to build map charts.
Definition: Chart.h:51
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::vector< te::map::AbstractLayer * > getAncestors()
It returns a list with the ancestors of this layer.
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
void updateVisibilityOfAncestors()
It updates the visibility of the ancestors of this layer, if any.
virtual void setVisibility(Visibility v)
It sets the layer visibility.
std::vector< te::map::AbstractLayer * > getDescendants()
It returns a list with the descendants of this layer.
virtual void clearSelected()
It clears the selected group of this Layer.
virtual void setExtent(const te::gm::Envelope &mbr)
It sets the Layer extent (or minimum bounding box).
This class represents the informations needed to build map charts.
virtual void select(te::da::ObjectIdSet *oids)
It adds the given oids to the selected group of this Layer.
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
virtual void setSRID(int srid)
It sets the Spatial Reference System ID associated to the Layer.
virtual te::map::Grouping * getGrouping() const
It returns the Grouping associated to the Layer.
TreeItem * getParent() const
It returns a pointer to the parent of this node.
Definition: TreeItem.cpp:65
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
virtual const std::string & getGeomPropertyName() const
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
This class contains the parameters needed for grouping the values of a Property.
AbstractLayer(AbstractLayer *parent=0)
It initializes a new layer.
Visibility
Each layer can have three states of visibility.
Definition: Enums.h:138
Visibility m_visibility
It indicates the layer visibility.
virtual void setId(const std::string &id)
It sets the layer id.
void setVisibilityAsChanged(bool visChanged)
It sets that the status of the layer visibility is to be changed or not..
bool m_visibilityChanged
It indicates if the layer visibility has changed.
virtual void deselect(const te::da::ObjectIdSet *oids)
It removes the given oids from the selected group of this Layer.