Feature.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/edit/Feature.h
22 
23  \brief This class represents a geographic feature.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../dataaccess/dataset/ObjectId.h"
29 #include "../datatype/AbstractData.h"
30 #include "../geometry/Geometry.h"
31 #include "Feature.h"
32 
33 // STL
34 #include <cassert>
35 
37  : m_geom(nullptr),
38  m_fillColor(TE_EDIT_FEATURE_FILL_COLOR),
39  m_contourColor(TE_EDIT_FEATURE_CONTOUR_COLOR),
40  m_colorChanged(false),
41  m_currentOperationType(SELECT),
42  m_isEditable(true)
43 {
44  m_id = GenerateId();
45 }
46 
48  : m_id(id),
49  m_geom(nullptr),
52  m_colorChanged(false),
54  m_isEditable(true)
55 {
56  assert(m_id);
57 }
58 
60  : m_id(id),
61  m_geom(geom),
64  m_colorChanged(false),
66  m_isEditable(true)
67 {
68  assert(m_id);
69  assert(m_geom);
70 }
71 
73 {
74  delete m_id;
75  delete m_geom;
76  m_geom = nullptr;
78  m_data.clear();
79 }
80 
82 {
83  setId(id);
84  setGeometry(geom);
85 }
86 
88 {
89  assert(id);
90 
91  delete m_id;
92  m_id = id;
93 }
94 
96 {
97  assert(geom);
98 
99  delete m_geom;
100  m_geom = geom;
101 }
102 
103 void te::edit::Feature::setData(const std::map<std::size_t, te::dt::AbstractData*>& data)
104 {
106  m_data.clear();
107  m_data = data;
108 }
109 
111 {
112  m_fillColor = fillColor;
113 
114  m_colorChanged = true;
115 }
116 
118 {
119  m_contourColor = contourColor;
120 
121  m_colorChanged = true;
122 }
123 
125 {
126  m_currentOperationType = currentOperationType;
127 }
128 
129 void te::edit::Feature::setEditable(const bool &editable)
130 {
131  m_isEditable = editable;
132 }
133 
135 {
136  return m_id;
137 }
138 
140 {
141  return m_geom;
142 }
143 
144 const std::map<std::size_t, te::dt::AbstractData*>& te::edit::Feature::getData() const
145 {
146  return m_data;
147 }
148 
150 {
151  return m_fillColor;
152 }
153 
155 {
156  return m_contourColor;
157 }
158 
160 {
161  return m_currentOperationType;
162 }
163 
165 {
166  return m_colorChanged;
167 }
168 
170 {
171  assert(m_id);
172  assert(id);
173 
174  return m_id->getValueAsString() == id->getValueAsString();
175 }
176 
178 {
179  return m_isEditable;
180 }
181 
183 {
184  assert(m_id);
185 
186  // The clone
187  Feature* f = new Feature(m_id->clone());
188 
189  // Clone geometry
190  if(m_geom)
191  f->setGeometry(dynamic_cast<te::gm::Geometry*>(m_geom->clone()));
192 
193  // Clone data
194  std::map<std::size_t, te::dt::AbstractData*> data;
195  for(std::map<std::size_t, te::dt::AbstractData*>::const_iterator it = m_data.begin(); it != m_data.end(); ++it)
196  {
197  if(it->second != NULL)
198  data[it->first] = it->second->clone();
199  }
200 
201  f->setData(data);
202 
204 
206 
207  if (m_colorChanged)
208  {
210 
212  }
213 
214  return f;
215 }
void setId(te::da::ObjectId *id)
Definition: Feature.cpp:87
#define TE_EDIT_FEATURE_FILL_COLOR
TEEDITEXPORT te::da::ObjectId * GenerateId()
te::gm::Geometry * m_geom
Definition: Feature.h:108
bool hasColorChanged()
Definition: Feature.cpp:164
te::color::RGBAColor getFillColor() const
Definition: Feature.cpp:149
te::da::ObjectId * getId() const
Definition: Feature.cpp:134
Feature * clone() const
Definition: Feature.cpp:182
te::gm::Geometry * getGeometry() const
Definition: Feature.cpp:139
void setFillColor(const te::color::RGBAColor &fillColor)
Definition: Feature.cpp:110
std::map< std::size_t, te::dt::AbstractData * > m_data
Definition: Feature.h:109
void set(te::da::ObjectId *id, te::gm::Geometry *geom)
Definition: Feature.cpp:81
This class represents a geographic feature.
te::edit::OperationType getOperationTypeId() const
Definition: Feature.cpp:159
te::color::RGBAColor m_fillColor
Definition: Feature.h:111
te::color::RGBAColor getContourColor() const
Definition: Feature.cpp:154
bool m_colorChanged
Definition: Feature.h:113
void setOperationTypeId(const te::edit::OperationType &currentOperationType)
Definition: Feature.cpp:124
te::edit::OperationType m_currentOperationType
Definition: Feature.h:115
This class represents an unique id for a data set element.
bool isEquals(te::da::ObjectId *id)
Definition: Feature.cpp:169
std::string getValueAsString() const
It gets the properties values used to uniquely identify a data set element as string.
virtual AbstractData * clone() const =0
It returns a clone of this object.
void setData(const std::map< std::size_t, te::dt::AbstractData * > &data)
Definition: Feature.cpp:103
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
#define TE_EDIT_FEATURE_CONTOUR_COLOR
bool isEditable() const
Definition: Feature.cpp:177
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::da::ObjectId * m_id
Definition: Feature.h:107
void setGeometry(te::gm::Geometry *geom)
Definition: Feature.cpp:95
void setContourColor(const te::color::RGBAColor &contourColor)
Definition: Feature.cpp:117
te::color::RGBAColor m_contourColor
Definition: Feature.h:112
void setEditable(const bool &editable)
Definition: Feature.cpp:129
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
const std::map< std::size_t, te::dt::AbstractData * > & getData() const
Definition: Feature.cpp:144