All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 const std::string te::map::FolderLayer::sm_type("FOLDERLAYER");
30 
32  : AbstractLayer(parent)
33 {
34 }
35 
36 te::map::FolderLayer::FolderLayer(const std::string& id, AbstractLayer* parent)
37  : AbstractLayer(id, parent)
38 {
39 }
40 
41 te::map::FolderLayer::FolderLayer(const std::string& id,
42  const std::string& title,
43  AbstractLayer* parent)
44  : AbstractLayer(id, title, parent)
45 {
46 }
47 
49 {
50 }
51 
53 {
54  if(hasChildren())
55  {
56  int numChildren = getChildrenCount();
57  std::vector<AbstractLayer*> childrenVec(numChildren);
58 
59  for(int i = 0; i < numChildren; ++i)
60  {
61  childrenVec[i] = static_cast<AbstractLayer*>(getChild(i).get());
62  childrenVec[i]->setVisibility(v);
63  }
64  }
65 
66  // Set the status of the flag that indicates if the layer visibility has changed
67  m_visibilityChanged = false;
68  Visibility prevVisibility = m_visibility;
69  m_visibility = v;
70 
71  if(m_visibility != prevVisibility)
72  m_visibilityChanged = true;
73 }
74 
76 {
77  Visibility prevVisibility = m_visibility;
78  m_visibilityChanged = false;
79 
80  if(hasChildren() == false)
81  {
82  m_visibility = te::map::NOT_VISIBLE;
83 
84  if(m_visibility != prevVisibility)
85  m_visibilityChanged = true;
86 
87  return;
88  }
89 
90  bool allVisible = true;
91  bool allNotVisible = true;
92 
93  int numChildren = getChildrenCount();
94  std::vector<AbstractLayer*> childrenVec(numChildren);
95 
96  for(int i = 0; i < numChildren; ++i)
97  {
98  childrenVec[i] = static_cast<AbstractLayer*>(getChild(i).get());
99 
100  if(childrenVec[i]->getVisibility() == te::map::NOT_VISIBLE)
101  allVisible = false;
102  else if(childrenVec[i]->getVisibility() == te::map::VISIBLE)
103  allNotVisible = false;
104  else if(childrenVec[i]->getVisibility() == te::map::PARTIALLY_VISIBLE)
105  {
106  allVisible = false;
107  allNotVisible = false;
108  }
109  }
110 
111  m_visibility = te::map::PARTIALLY_VISIBLE;
112 
113  if(allVisible)
114  m_visibility = te::map::VISIBLE;
115  else if(allNotVisible)
116  m_visibility = te::map::NOT_VISIBLE;
117 
118  if(m_visibility != prevVisibility)
119  m_visibilityChanged = true;
120 
121  updateVisibilityOfAncestors();
122 }
123 
124 std::auto_ptr<te::map::LayerSchema> te::map::FolderLayer::getSchema() const
125 {
126  return std::auto_ptr<LayerSchema>(0);
127 }
128 
129 std::auto_ptr<te::da::DataSet> te::map::FolderLayer::getData(te::common::TraverseType /*travType*/,
130  const te::common::AccessPolicy) const
131 {
132  return std::auto_ptr<te::da::DataSet>(0);
133 }
134 
135 std::auto_ptr<te::da::DataSet> te::map::FolderLayer::getData(const std::string& /*propertyName*/,
136  const te::gm::Envelope* /*e*/,
138  te::common::TraverseType /*travType*/,
139  const te::common::AccessPolicy) const
140 {
141  return std::auto_ptr<te::da::DataSet>(0);
142 }
143 
144 std::auto_ptr<te::da::DataSet> te::map::FolderLayer::getData(const std::string& /*propertyName*/,
145  const te::gm::Geometry* /*g*/,
147  te::common::TraverseType /*travType*/,
148  const te::common::AccessPolicy) const
149 {
150  return std::auto_ptr<te::da::DataSet>(0);
151 }
152 
153 std::auto_ptr<te::da::DataSet> te::map::FolderLayer::getData(te::da::Expression* /*restriction*/,
154  te::common::TraverseType /*travType*/,
155  const te::common::AccessPolicy accessPolicy) const
156 {
157  return std::auto_ptr<te::da::DataSet>(0);
158 }
159 
160 std::auto_ptr<te::da::DataSet> te::map::FolderLayer::getData(const te::da::ObjectIdSet* oids,
161  te::common::TraverseType /*travType*/,
162  const te::common::AccessPolicy) const
163 {
164  return std::auto_ptr<te::da::DataSet>(0);
165 }
166 
168 {
169  return true;
170 }
171 
172 void te::map::FolderLayer::draw(Canvas* /*canvas*/, const te::gm::Envelope& /*bbox*/, int /*srid*/)
173 {
174 }
175 
176 const std::string& te::map::FolderLayer::getType() const
177 {
178  return sm_type;
179 }
This is the base class for layers.
Definition: AbstractLayer.h:76
void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
void updateVisibility()
It updates the visibility of this layer.
Definition: FolderLayer.cpp:75
This is an abstract class that models a query expression.
Definition: Expression.h:47
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
static const std::string sm_type
A static data member used in the implementation of getType method.
Definition: FolderLayer.h:118
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
~FolderLayer()
Destructor.
Definition: FolderLayer.cpp:48
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:52
virtual void setVisibility(Visibility v)
It sets the layer visibility.
std::auto_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.
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.
Definition: Geometry.h:73
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
FolderLayer(AbstractLayer *parent=0)
It initializes a new layer.
Definition: FolderLayer.cpp:31
Visibility
Each layer can have three states of visibility.
Definition: Enums.h:138
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.