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 "../maptools/RasterContrast.h"
29 #include "../se/Style.h"
30 #include "../srs/Config.h"
31 #include "AbstractLayer.h"
32 #include "Chart.h"
33 #include "Grouping.h"
34 
36  : te::common::TreeItem(parent),
37  m_srid(TE_UNKNOWN_SRS),
38  m_visibility(NOT_VISIBLE),
39  m_visibilityChanged(false),
40  m_selected(nullptr),
41  m_style(nullptr),
42  m_selectionStyle(nullptr),
43  m_grouping(nullptr),
44  m_chart(nullptr),
45  m_contrast(nullptr),
46  m_compositionMode(te::map::SourceOver),
47  m_encoding(te::core::EncodingType::UTF8)
48 {
49 }
50 
52  : te::common::TreeItem(parent),
53  m_id(id),
56  m_visibilityChanged(false),
57  m_selected(nullptr),
58  m_style(nullptr),
59  m_selectionStyle(nullptr),
60  m_grouping(nullptr),
61  m_chart(nullptr),
62  m_contrast(nullptr),
64  m_encoding(te::core::EncodingType::UTF8)
65 {
66 }
67 
69  const std::string& title,
70  AbstractLayer* parent)
71  : te::common::TreeItem(parent),
72  m_id(id),
73  m_title(title),
76  m_visibilityChanged(false),
77  m_selected(nullptr),
78  m_style(nullptr),
79  m_selectionStyle(nullptr),
80  m_grouping(nullptr),
81  m_chart(nullptr),
82  m_contrast(nullptr),
84  m_encoding(te::core::EncodingType::UTF8)
85 {
86 }
87 
89 {
90  delete m_selected;
91  delete m_style;
92  delete m_selectionStyle;
93  delete m_grouping;
94  delete m_chart;
95  delete m_contrast;
96 }
97 
98 const std::string& te::map::AbstractLayer::getId() const
99 {
100  return m_id;
101 }
102 
103 void te::map::AbstractLayer::setId(const std::string& id)
104 {
105  m_id = id;
106 }
107 
108 const std::string& te::map::AbstractLayer::getTitle() const
109 {
110  return m_title;
111 }
112 
113 void te::map::AbstractLayer::setTitle(const std::string& title)
114 {
115  m_title = title;
116 }
117 
118 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getDescendants()
119 {
120  std::vector<AbstractLayer*> layers;
121  std::vector<AbstractLayer*> childrenLayers;
122 
123  std::size_t numChildren = getChildrenCount();
124  for(std::size_t i = 0; i < numChildren; ++i)
125  {
126  AbstractLayer* childLayer = static_cast<AbstractLayer*>(getChild(i).get());
127  layers.push_back(childLayer);
128 
129  if(childLayer->hasChildren())
130  {
131  childrenLayers = childLayer->getDescendants();
132  for(std::size_t i = 0; i < childrenLayers.size(); ++i)
133  layers.push_back(childrenLayers[i]);
134  }
135  }
136 
137  return layers;
138 }
139 
140 std::vector<te::map::AbstractLayer*> te::map::AbstractLayer::getAncestors()
141 {
142  std::vector<AbstractLayer*> layers;
143 
144  AbstractLayer* parentLayer = static_cast<AbstractLayer*>(getParent());
145  while(parentLayer)
146  {
147  layers.push_back(parentLayer);
148  parentLayer = static_cast<AbstractLayer*>(parentLayer->getParent());
149  }
150 
151  return layers;
152 }
153 
155 {
156  return m_visibility;
157 }
158 
160 {
161  Visibility prevVisibility = m_visibility;
162 
163  m_visibilityChanged = false;
164 
165  m_visibility = v;
166 
167  if(m_visibility != prevVisibility)
168  m_visibilityChanged = true;
169 }
170 
172 {
173  return m_visibilityChanged;
174 }
175 
177 {
178  m_visibilityChanged = visChanged;
179 }
180 
182 {
183  AbstractLayer* parent = static_cast<AbstractLayer*>(getParent());
184  while(parent)
185  {
186  bool allVisible = true;
187  bool allNotVisible = true;
188 
189  Visibility prevParentVisibility = parent->getVisibility();
190  parent->m_visibilityChanged = false;
191 
192  size_t numChildren = parent->getChildrenCount();
193 
194  std::vector<AbstractLayer*> childrenVec(numChildren);
195 
196  for(size_t i = 0; i < numChildren; ++i)
197  {
198  childrenVec[i] = static_cast<AbstractLayer*>(parent->getChild(i).get());
199 
200  if(childrenVec[i]->getVisibility() == te::map::NOT_VISIBLE)
201  allVisible = false;
202  else if(childrenVec[i]->getVisibility() == te::map::VISIBLE)
203  allNotVisible = false;
204  else if(childrenVec[i]->getVisibility() == te::map::PARTIALLY_VISIBLE)
205  {
206  allVisible = false;
207  allNotVisible = false;
208  }
209  }
210 
211  // Set parent visibility;
212  Visibility parentVisibility = te::map::PARTIALLY_VISIBLE;
213  if(allVisible)
214  parentVisibility = te::map::VISIBLE;
215  else if(allNotVisible)
216  parentVisibility = te::map::NOT_VISIBLE;
217 
218  parent->m_visibility = parentVisibility;
219 
220  if(parentVisibility != prevParentVisibility)
221  parent->m_visibilityChanged = true;
222 
223  parent = static_cast<AbstractLayer*>(parent->getParent());
224  }
225 }
226 
228 {
229 }
230 
232 {
233  return m_mbr;
234 }
235 
237 {
238  m_mbr = mbr;
239 }
240 
242 {
243  return m_srid;
244 }
245 
247 {
248  m_srid = srid;
249 }
250 
252 {
253  assert(oids);
254 
255  if(m_selected == nullptr)
256  {
257  m_selected = oids;
258  return;
259  }
260 
261  if(m_selected->size() == 0)
262  {
263  delete m_selected;
264  m_selected = oids;
265  return;
266  }
267 
268  assert(m_selected);
269 
270  m_selected->Union(oids);
271 }
272 
274 {
275  return m_selected;
276 }
277 
279 {
280  if(m_selected)
281  m_selected->clear();
282 }
283 
285 {
286  assert(m_selected);
287 
288  if(m_selected->size() == 0)
289  return;
290 
291  m_selected->difference(oids);
292 }
293 
295 {
296  return m_style;
297 }
298 
300 {
301  delete m_style;
302  m_style = style;
303 }
304 
306 {
307  return m_selectionStyle;
308 }
309 
311 {
312  delete m_selectionStyle;
313  m_selectionStyle = style;
314 }
315 
317 {
318  return m_grouping;
319 }
320 
322 {
323  delete m_grouping;
324  m_grouping = grouping;
325 }
326 
328 {
329  return m_chart;
330 }
331 
333 {
334  delete m_chart;
335  m_chart = chart;
336 }
337 
339 {
340  return m_contrast;
341 }
342 
344 {
345  delete m_contrast;
346  m_contrast = contrast;
347 }
348 
350 {
351  return m_geomPropertyName;
352 }
353 
354 void te::map::AbstractLayer::setGeomPropertytName(const std::string& name)
355 {
356  m_geomPropertyName = name;
357 }
358 
360 {
361  return m_compositionMode;
362 }
363 
365 {
366  m_compositionMode = mode;
367 }
368 
370 {
371  return m_encoding;
372 }
373 
375 {
376  m_encoding = et;
377 }
378 
380 {
381 }
382 
383 const std::string& te::map::AbstractLayer::getDataSourceId() const
384 {
385  return m_datasourceId;
386 }
387 
388 void te::map::AbstractLayer::setDataSourceId(const std::string& id)
389 {
390  m_datasourceId = id;
391 }
392 
393 const std::string& te::map::AbstractLayer::getDataSetName() const
394 {
395  return m_datasetName;
396 }
397 
398 void te::map::AbstractLayer::setDataSetName(const std::string& name)
399 {
400  m_datasetName = name;
401 }
te::map::RasterContrast * m_contrast
The contrast information to be applied to a raster object in the layer.
te::map::Grouping * m_grouping
The grouping information.
virtual const std::string & getId() const
It returns the layer id.
virtual void setDataSourceId(const std::string &id)
std::string m_datasetName
The dataset name where we will retrieve the layer objects.
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
virtual ~AbstractLayer()
Virtual destructor.
std::size_t getChildrenCount() const
It returns the number of children of this node.
te::map::Chart * m_chart
The chart information.
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:77
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
std::string m_id
Layer id.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual const std::string & getTitle() const
It returns the layer title.
virtual te::se::Style * getSelectionStyle() const
It returns the selection Style associated to the layer.
virtual void setRasterContrast(te::map::RasterContrast *contrast)
It sets the raster contrast associated to the Layer.
void setDataSetName(const std::string &name)
virtual void updateVisibility()
It updates the visibility of this layer.
bool hasChildren() const
It returns true if the item has descendants.
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.
te::da::ObjectIdSet * m_selected
The selected group of the layer.
virtual Visibility getVisibility() const
It returns the layer visibility.
virtual void setTitle(const std::string &title)
It sets the layer title.
std::string m_geomPropertyName
The name of the referenced geometry property.
virtual te::map::Chart * getChart() const
It returns the Chart associated to the Layer.
int m_srid
The identifier of the layer spatial reference system.
TreeItem(TreeItem *parent=0)
It initializes a new item having a parent.
te::core::EncodingType getEncoding() const
It returns the encoding type.
EncodingType
Supported character encodings.
Definition: CharEncoding.h:50
te::map::CompositionMode getCompositionMode() const
It returns the composition mode.
CompositionMode
The composition mode used to render the canvas.
virtual void setGeomPropertytName(const std::string &name)
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:57
te::map::CompositionMode m_compositionMode
The composition mode used to merged the canvas.
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.
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::size_t size() const
It returns the object id set size.
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.
URI C++ Library.
Definition: Attributes.h:37
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.
te::gm::Envelope m_mbr
The layer bounding box.
virtual void clearSelected()
It clears the selected group of this Layer.
te::se::Style * m_selectionStyle
The selection style to be applied to the geographic objects in the 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 setSelectionStyle(te::se::Style *style)
It sets the selection Style associated to the layer.
std::string m_title
A brief description of this Layer that can be used by applications to show a text identifying this la...
void setEncoding(te::core::EncodingType et)
It set the encoding type.
virtual void select(te::da::ObjectIdSet *oids)
It adds the given oids to the selected group of this Layer.
virtual te::map::RasterContrast * getRasterContrast() const
It returns the raster contrast associated to the Layer.
This class contains the parameters needed to apply dynamic contrast over a raster.
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
const std::string & getDataSetName() const
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.
std::string m_datasourceId
DataSource id.
TreeItem * getParent() const
It returns a pointer to the parent of this node.
void Union(ObjectIdSet *rhs)
It performs the union operation between this ObjectIdSet and the given ObjectIdSet.
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
void clear()
It clears this object id set.
virtual const std::string & getGeomPropertyName() const
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
te::se::Style * m_style
The style to be applied to the geographic objects in 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.
Visibility m_visibility
It indicates the layer visibility.
virtual void setId(const std::string &id)
It sets the layer id.
virtual const std::string & getDataSourceId() const
void setVisibilityAsChanged(bool visChanged)
It sets that the status of the layer visibility is to be changed or not..
void difference(const ObjectIdSet *rhs)
It performs the difference operation between this ObjectIdSet and the given ObjectIdSet.
te::core::EncodingType m_encoding
The char encoding of the layer;.
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.