Utils.h
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/Utils.h
22 
23 \brief Utility functions for TerraLib Edit module.
24 */
25 
26 #ifndef __TERRALIB_EDIT_INTERNAL_UTILS_H
27 #define __TERRALIB_EDIT_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "../color/RGBAColor.h"
31 #ifndef Q_MOC_RUN
32 #include "../maptools/AbstractLayer.h"
33 #endif
34 #include "Config.h"
35 
36 // STL
37 #include <string>
38 #include <vector>
39 
40 namespace te
41 {
42  // Forward declarations
43  namespace da
44  {
45  class ObjectId;
46  }
47 
48  namespace gm
49  {
50  struct Coord2D;
51  class Envelope;
52  class Geometry;
53  class GeometryCollection;
54  class LineString;
55  class Polygon;
56  }
57 
58  namespace edit
59  {
60  // Forward declaration
61  class Feature;
62 
63  struct VertexIndex
64  {
65  void setIndex(const std::size_t& line, const std::size_t& pos)
66  {
67  m_line = line;
68  m_pos = pos;
69  }
70 
71  void makeInvalid()
72  {
73  m_line = std::string::npos;
74  m_pos = std::string::npos;
75  }
76 
77  bool isValid() const
78  {
79  return m_line != std::string::npos && m_pos != std::string::npos;
80  }
81 
82  std::size_t m_line;
83  std::size_t m_pos;
84  };
85 
86  /*!
87  \enum FeatureType
88 
89  \brief Defines the feature type(Add, Update, Delete ...).
90  */
92  {
93  TO_BLOCKEDIT = 0, //!< block feature to edition.
94  TO_ADD = 1, //!< To be added.
95  TO_UPDATE = 2, //!< To be updated.
96  TO_DELETE = 3 //!< To be removed.
97  };
98 
99  /*!
100  \enum MouseEventEdition
101 
102  \brief Defines which mouse event will be used in the tool to complete an operation.
103  */
105  {
108  };
109 
110  TEEDITEXPORT Feature* PickFeature(const te::map::AbstractLayerPtr& layer, const te::gm::Envelope& env, int srid, FeatureType type);
111 
112  TEEDITEXPORT Feature* PickFeature(const te::map::AbstractLayer* layer, const te::gm::Envelope& env, int srid, FeatureType type);
113 
114  TEEDITEXPORT void GetLines(te::gm::Geometry* geom, std::vector<te::gm::LineString*>& lines);
115 
116  TEEDITEXPORT void GetLines(te::gm::GeometryCollection* gc, std::vector<te::gm::LineString*>& lines);
117 
118  TEEDITEXPORT void GetLines(te::gm::Polygon* p, std::vector<te::gm::LineString*>& lines);
119 
120  TEEDITEXPORT void GetLines(te::gm::LineString* l, std::vector<te::gm::LineString*>& lines);
121 
122  TEEDITEXPORT void MoveVertex(std::vector<te::gm::LineString*>& lines, const VertexIndex& index, const double& x, const double& y);
123 
124  TEEDITEXPORT void RemoveVertex(std::vector<te::gm::LineString*>& lines, const VertexIndex& index);
125 
126  TEEDITEXPORT void AddVertex(std::vector<te::gm::LineString*>& lines, const double& x, const double& y, const te::gm::Envelope& env, int srid);
127 
128  TEEDITEXPORT VertexIndex FindSegment(std::vector<te::gm::LineString*>& lines, const te::gm::Envelope& env, int srid);
129 
130  TEEDITEXPORT void MoveGeometry(te::gm::Geometry* geom, const double& deltax, const double& deltay);
131 
132  TEEDITEXPORT bool IsSpecialRingVertex(te::gm::LineString* l, const VertexIndex& index);
133 
134  TEEDITEXPORT double GetDistance(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
135 
136  TEEDITEXPORT void GetCoordinates(te::gm::Geometry* geom, std::vector<te::gm::Coord2D>& coords);
137 
138  TEEDITEXPORT void TrySnap(te::gm::Coord2D& coord, int srid);
139 
141 
143 
144  } // end namespace edit
145 } // end namespace te
146 
147 #endif // __TERRALIB_EDIT_INTERNAL_UTILS_H
FeatureType
Defines the feature type(Add, Update, Delete ...).
Definition: Utils.h:91
TEEDITEXPORT te::gm::Geometry * ConvertGeomType(const te::map::AbstractLayerPtr &layer, te::gm::Geometry *geom, int srid)
TEEDITEXPORT void AddVertex(std::vector< te::gm::LineString * > &lines, const double &x, const double &y, const te::gm::Envelope &env, int srid)
This is the base class for layers.
Definition: AbstractLayer.h:76
To be updated.
Definition: Utils.h:95
#define TEEDITEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:68
TEEDITEXPORT te::da::ObjectId * GenerateId()
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
TEEDITEXPORT void RemoveVertex(std::vector< te::gm::LineString * > &lines, const VertexIndex &index)
TEEDITEXPORT void GetLines(te::gm::Geometry *geom, std::vector< te::gm::LineString * > &lines)
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void setIndex(const std::size_t &line, const std::size_t &pos)
Definition: Utils.h:65
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
To be added.
Definition: Utils.h:94
URI C++ Library.
To be removed.
Definition: Utils.h:96
TEEDITEXPORT void MoveVertex(std::vector< te::gm::LineString * > &lines, const VertexIndex &index, const double &x, const double &y)
Configuration flags for the TerraLib Edit module.
TEEDITEXPORT VertexIndex FindSegment(std::vector< te::gm::LineString * > &lines, const te::gm::Envelope &env, int srid)
TEEDITEXPORT Feature * PickFeature(const te::map::AbstractLayerPtr &layer, const te::gm::Envelope &env, int srid, FeatureType type)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:74
TEEDITEXPORT void GetCoordinates(te::gm::Geometry *geom, std::vector< te::gm::Coord2D > &coords)
std::size_t m_pos
Definition: Utils.h:83
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
std::size_t m_line
Definition: Utils.h:82
bool isValid() const
Definition: Utils.h:77
TEEDITEXPORT void TrySnap(te::gm::Coord2D &coord, int srid)
TEEDITEXPORT void MoveGeometry(te::gm::Geometry *geom, const double &deltax, const double &deltay)
block feature to edition.
Definition: Utils.h:93
void makeInvalid()
Definition: Utils.h:71
It is a collection of other geometric objects.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEEDITEXPORT bool IsSpecialRingVertex(te::gm::LineString *l, const VertexIndex &index)
TEEDITEXPORT double GetDistance(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)
MouseEventEdition
Defines which mouse event will be used in the tool to complete an operation.
Definition: Utils.h:104