VertexTool.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/qt/tools/VertexTool.h
22 
23  \brief This class implements a concrete tool for vertex operations (move, add, etc.).
24 */
25 
26 #ifndef __TERRALIB_EDIT_QT_INTERNAL_VERTEXTOOL_H
27 #define __TERRALIB_EDIT_QT_INTERNAL_VERTEXTOOL_H
28 
29 // TerraLib
30 #include "../../../geometry/Envelope.h"
31 #ifndef Q_MOC_RUN
32 #include "../../../maptools/AbstractLayer.h"
33 #include "../../../sam/rtree/Index.h"
34 #include "../../Utils.h"
35 #endif
36 #include "../core/command/AddCommand.h"
37 #include "../core/UndoStackManager.h"
38 #include "../Config.h"
39 #include "GeometriesUpdateTool.h"
40 
41 // STL
42 #include <string>
43 #include <vector>
44 
45 namespace te
46 {
47 // Forward declarations
48  namespace gm
49  {
50  struct Coord2D;
51  class Geometry;
52  class LineString;
53  class Point;
54  }
55 
56  namespace qt
57  {
58  namespace widgets
59  {
60  class MapDisplay;
61  }
62  }
63 
64  namespace edit
65  {
66 // Forward declaration
67  class Feature;
68 
69  /*!
70  \class VertexTool
71 
72  \brief This class implements a concrete tool for vertex operations (move, add, etc.).
73  */
75  {
76  Q_OBJECT
77 
78  public:
79 
80  /*!
81  \enum StageType
82 
83  \brief Defines the operation stage to this tool.
84  */
85  enum StageType
86  {
87  FEATURE_SELECTION, /*!< Selection of feature. */
88  VERTEX_SEARCH, /*!< Search of vertex. */
89  VERTEX_FOUND, /*!< Vertex found. */
90  VERTEX_MOVING, /*!< Vertex movement. */
91  VERTEX_READY_TO_ADD /*!< Vertex add. */
92  };
93 
94  /** @name Initializer Methods
95  * Methods related to instantiation and destruction.
96  */
97  //@{
98 
99  /*!
100  \brief It constructs a vertex tool associated with the given map display.
101 
102  \param display The map display associated with the tool.
103  \param parent The tool's parent.
104 
105  \note The tool will NOT take the ownership of the given pointers.
106  */
107  VertexTool(te::qt::widgets::MapDisplay* display, const te::map::AbstractLayerPtr& layer, bool fixGeometry = false, QObject* parent = 0);
108 
109  /*! \brief Destructor. */
110  ~VertexTool();
111 
112  //@}
113 
114  /** @name AbstractTool Methods
115  * Methods related with tool behavior.
116  */
117  //@{
118 
119  bool mousePressEvent(QMouseEvent* e);
120 
121  bool mouseMoveEvent(QMouseEvent* e);
122 
123  bool mouseReleaseEvent(QMouseEvent* e);
124 
125  bool mouseDoubleClickEvent(QMouseEvent* e);
126 
127  //@}
128 
129  void resetVisualizationTool();
130 
131  private:
132 
133  void reset();
134 
135  void pickFeature(const te::map::AbstractLayerPtr& layer, const QPointF& pos);
136 
137  void draw(te::gm::Point* virtualVertex = 0);
138 
139  void storeFeature();
140 
141  void storeUndoCommand();
142 
143  private slots:
144 
145  void onExtentChanged();
146 
147  void onUndoFeedback(std::vector<te::gm::Coord2D> coords);
148 
149  protected:
150 
151  std::vector<te::gm::LineString*> m_lines;
158 
159  te::gm::Envelope buildEnvelope(const QPointF& pos);
160 
161  void pickFeature(const te::map::AbstractLayerPtr& layer, const te::gm::Envelope& env);
162 
163  void updateRTree();
164 
165  void updateCursor();
166 
167  void setStage(StageType stage);
168 
169  };
170 
171  } // end namespace edit
172 } // end namespace te
173 
174 #endif // __TERRALIB_EDIT_QT_INTERNAL_VERTEXTOOL_H
#define TEEDITQTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:60
UndoStackManager & m_stack
Definition: VertexTool.h:157
StageType
Defines the operation stage to this tool.
Definition: VertexTool.h:85
A class that represents an R-tree.
Definition: Index.h:56
A widget to control the display of a set of layers.
Definition: MapDisplay.h:69
This class implements a concrete tool for vertex operations (move, add, etc.).
Definition: VertexTool.h:74
std::vector< te::gm::LineString * > m_lines
Definition: VertexTool.h:151
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
VertexIndex m_currentVertexIndex
Definition: VertexTool.h:152
te::sam::rtree::Index< VertexIndex, 8 > m_rtree
Definition: VertexTool.h:153
StageType m_currentStage
Definition: VertexTool.h:154
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr