FolderLayer.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/FolderLayer.cpp
22 
23  \brief A layer that can be used as a container for other kind of layers.
24 */
25 
26 // TerraLib
27 #include "FolderLayer.h"
28 #include "Utils.h"
29 
30 const std::string te::map::FolderLayer::sm_type("FOLDERLAYER");
31 
33  : AbstractLayer(parent)
34 {
35 }
36 
37 te::map::FolderLayer::FolderLayer(const std::string& id, AbstractLayer* parent)
38  : AbstractLayer(id, parent)
39 {
40 }
41 
42 te::map::FolderLayer::FolderLayer(const std::string& id,
43  const std::string& title,
44  AbstractLayer* parent)
45  : AbstractLayer(id, title, parent)
46 {
47 }
48 
50 
52 {
54 
55  te::map::CopyAbstractLayerInfo(this, layer);
56 
57  std::list<te::common::TreeItemPtr> children = getChildren();
58 
59  for (auto child : children)
60  {
61  te::map::AbstractLayer* childLayer = dynamic_cast<te::map::AbstractLayer*>(child.get());
62 
63  layer->add(childLayer->clone());
64  }
65 
66  return layer;
67 }
68 
70 {
71  if(hasChildren())
72  {
73  int numChildren = static_cast<int>(getChildrenCount());
74  std::vector<AbstractLayer*> childrenVec(numChildren);
75 
76  for(int i = 0; i < numChildren; ++i)
77  {
78  childrenVec[i] = static_cast<AbstractLayer*>(getChild(i).get());
79  childrenVec[i]->setVisibility(v);
80  }
81  }
82 
83  // Set the status of the flag that indicates if the layer visibility has changed
84  m_visibilityChanged = false;
85  Visibility prevVisibility = m_visibility;
86  m_visibility = v;
87 
88  if(m_visibility != prevVisibility)
89  m_visibilityChanged = true;
90 }
91 
93 {
94  Visibility prevVisibility = m_visibility;
95  m_visibilityChanged = false;
96 
97  if(hasChildren() == false)
98  {
100 
101  if(m_visibility != prevVisibility)
102  m_visibilityChanged = true;
103 
104  return;
105  }
106 
107  bool allVisible = true;
108  bool allNotVisible = true;
109 
110  int numChildren = static_cast<int>(getChildrenCount());
111  std::vector<AbstractLayer*> childrenVec(numChildren);
112 
113  for(int i = 0; i < numChildren; ++i)
114  {
115  childrenVec[i] = static_cast<AbstractLayer*>(getChild(i).get());
116 
117  if(childrenVec[i]->getVisibility() == te::map::NOT_VISIBLE)
118  allVisible = false;
119  else if(childrenVec[i]->getVisibility() == te::map::VISIBLE)
120  allNotVisible = false;
121  else if(childrenVec[i]->getVisibility() == te::map::PARTIALLY_VISIBLE)
122  {
123  allVisible = false;
124  allNotVisible = false;
125  }
126  }
127 
129 
130  if(allVisible)
132  else if(allNotVisible)
134 
135  if(m_visibility != prevVisibility)
136  m_visibilityChanged = true;
137 
139 }
140 
141 std::unique_ptr<te::map::LayerSchema> te::map::FolderLayer::getSchema() const
142 {
143  return std::unique_ptr<LayerSchema>(nullptr);
144 }
145 
146 std::unique_ptr<te::da::DataSet> te::map::FolderLayer::getData(te::common::TraverseType /*travType*/,
147  const te::common::AccessPolicy) const
148 {
149  return std::unique_ptr<te::da::DataSet>(nullptr);
150 }
151 
152 std::unique_ptr<te::da::DataSet> te::map::FolderLayer::getData(const std::string& /*propertyName*/,
153  const te::gm::Envelope* /*e*/,
155  te::common::TraverseType /*travType*/,
156  const te::common::AccessPolicy) const
157 {
158  return std::unique_ptr<te::da::DataSet>(nullptr);
159 }
160 
161 std::unique_ptr<te::da::DataSet> te::map::FolderLayer::getData(const std::string& /*propertyName*/,
162  const te::gm::Geometry* /*g*/,
164  te::common::TraverseType /*travType*/,
165  const te::common::AccessPolicy) const
166 {
167  return std::unique_ptr<te::da::DataSet>(nullptr);
168 }
169 
170 std::unique_ptr<te::da::DataSet> te::map::FolderLayer::getData(
171  te::da::Expression* /*restriction*/, te::common::TraverseType /*travType*/,
172  const te::common::AccessPolicy /*accessPolicy*/) const
173 {
174  return std::unique_ptr<te::da::DataSet>(nullptr);
175 }
176 
177 std::unique_ptr<te::da::DataSet> te::map::FolderLayer::getData(
178  const te::da::ObjectIdSet* /*oids*/, te::common::TraverseType /*travType*/,
179  const te::common::AccessPolicy) const
180 {
181  return std::unique_ptr<te::da::DataSet>(nullptr);
182 }
183 
185 {
186  return true;
187 }
188 
189 const std::string& te::map::FolderLayer::getType() const
190 {
191  return sm_type;
192 }
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
const std::list< TreeItemPtr > & getChildren() const
It returns the children of this tree item.
AbstractLayer * clone()
It returns a clone of the object.
Definition: FolderLayer.cpp:51
const TreeItemPtr & getChild(std::size_t i) const
It returns the n-th child.
std::size_t getChildrenCount() const
It returns the number of children of this node.
TEMAPEXPORT void CopyAbstractLayerInfo(const te::map::AbstractLayer *refLayer, te::map::AbstractLayer *layer)
Make a copy of refLayer abstract attributes to layer. Creating new id.
This is the base class for layers.
Definition: AbstractLayer.h:77
bool hasChildren() const
It returns true if the item has descendants.
SpatialRelation
Spatial relations between geometric objects.
void updateVisibility()
It updates the visibility of this layer.
Definition: FolderLayer.cpp:92
virtual Visibility getVisibility() const
It returns the layer visibility.
A layer that can be used as a container for other kind of layers.
Definition: FolderLayer.h:45
void add(const TreeItemPtr &childItem)
It adds (appends) the item to the end of the children&#39;s list.
This is an abstract class that models a query expression.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
static const std::string sm_type
A static data member used in the implementation of getType method.
Definition: FolderLayer.h:120
std::unique_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
An Envelope defines a 2D rectangular region.
~FolderLayer()
Destructor.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
void setVisibility(Visibility v)
It sets the layer visibility.
Definition: FolderLayer.cpp:69
void updateVisibilityOfAncestors()
It updates the visibility of the ancestors of this layer, if any.
virtual void setVisibility(Visibility v)
It sets the layer visibility.
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual AbstractLayer * clone()=0
It returns a clone of the object.
FolderLayer(AbstractLayer *parent=0)
It initializes a new layer.
Definition: FolderLayer.cpp:32
Visibility
Each layer can have three states of visibility.
Utility functions for MapTools module.
Visibility m_visibility
It indicates the layer visibility.
A layer that can be used as a container for other kind of layers.
const std::string & getType() const
It returns the layer type: FOLDERLAYER.
bool m_visibilityChanged
It indicates if the layer visibility has changed.