ProfileTools.cpp
Go to the documentation of this file.
1 /*!
2 \file terralib/mnt/qt/ProfileTools.cpp
3 
4 \brief This file defines the profile trajectory edition tools
5 
6 */
7 
8 #include <algorithm>
9 // TerraLib
10 #include "../../edit/Feature.h"
11 #include "../../edit/qt/Renderer.h"
12 #include "../../edit/qt/Utils.h"
13 #include "../../edit/Repository.h"
14 #include "../../edit/RepositoryManager.h"
15 #include "../../edit/Utils.h"
16 #include "../../geometry/Envelope.h"
17 #include "../../geometry/Geometry.h"
18 #include "../../geometry/MultiLineString.h"
19 #include "../../qt/af/ApplicationController.h"
20 #include "../../qt/af/BaseApplication.h"
21 #include "../../qt/widgets/canvas/Canvas.h"
22 #include "../../qt/widgets/canvas/MapDisplay.h"
23 #include "../../qt/widgets/Utils.h"
24 
25 #include "ProfileTools.h"
26 
27 #include <QMessageBox>
28 
29 
31 : te::edit::VertexTool(display, layer, parent),
32 m_type(NONE)
33 {
34  te::edit::VertexTool::pickFeature(layer, layer->getExtent());
35 }
36 
38 {
39  m_lines.clear();
40 }
41 
43 {
44  m_type = t;
45  switch (m_type)
46  {
47  case VERTEX_MOVE:
48  case VERTEX_DELETE:
50  break;
51  case VERTEX_ADD:
53  default:
54  break;
55  }
56 }
57 
58 void te::mnt::ProfileTools::setLines(std::vector<te::gm::LineString*> &l)
59 {
60  m_lines.clear();
61  m_lines = l;
62 
63  if (m_rtree.size())
64  updateRTree();
65 
67 
68 }
69 
71 {
72 
73  std::vector<te::edit::Feature*> vet = te::edit::RepositoryManager::getInstance().getRepository(m_layer->getId())->getAllFeatures();
74  for (size_t j = 0; j < vet.size(); ++j)
75  {
76  bool found = false;
77  for (size_t i = 0; i < m_lines.size(); ++i)
78  {
79  if (vet[j]->getGeometry() == m_lines[i])
80  {
81  found = true;
82  break;
83  }
84  }
85  if (!found)
86  {
87  te::edit::RepositoryManager::getInstance().removeFeature(m_layer->getId(), vet[j]->getId());
88  vet.erase(vet.begin() + j);
89  --j;
90  }
91  }
92 
93  for (size_t i = 0; i < m_lines.size(); ++i)
94  {
95  bool found = false;
96  for (size_t j = 0; j < vet.size(); ++j)
97  {
98  if (vet[j]->getGeometry() == m_lines[i])
99  {
100  found = true;
101  break;
102  }
103  }
104  if (!found)
106  }
107 }
108 
110 {
111  if (m_type == VERTEX_ADD)
112  return true;
113 
114  if (m_type == VERTEX_DELETE)
115  e->setModifiers(Qt::ShiftModifier);
116 
118 }
119 
121 {
122  m_feature = nullptr;
123  if (m_type == LINE_INVERT || m_type == LINE_DELETE)
124  return true;
125 
126  bool ret = (te::edit::VertexTool::mouseMoveEvent(e));
127  return ret;
128 }
129 
131 {
132  if (m_type == VERTEX_ADD)
133  return true;
134 
137 
138  if (m_type == LINE_INVERT)
139  {
141 
143  env_line.setPoint(0, env.getLowerLeftX(), env.getLowerLeftY());
144  env_line.setPoint(1, env.getLowerLeftX(), env.getUpperRightY());
145  env_line.setPoint(2, env.getUpperRightX(), env.getUpperRightY());
146  env_line.setPoint(3, env.getUpperRightX(), env.getLowerLeftY());
147  env_line.setPoint(4, env.getLowerLeftX(), env.getLowerLeftY());
148 
149  te::color::RGBAColor green(0, 255, 0, 255);
150  for (size_t i = 0; i < m_lines.size(); i++)
151  {
152  if (m_lines[i]->intersects(&env_line))
153  {
154  std::unique_ptr<te::gm::Point> startPoint = m_lines[i]->getStartPoint();
155  std::unique_ptr<te::gm::Point> endPoint = m_lines[i]->getEndPoint();
156 
157  const te::gm::Envelope& displayExtent = m_display->getExtent();
159  canvas.setWindow(displayExtent.m_llx, displayExtent.m_lly, displayExtent.m_urx, displayExtent.m_ury);
160  canvas.setLineColor(green);
161  canvas.setLineWidth(3);
162  canvas.setLineDashStyle(te::map::SolidLine);
163  canvas.draw(m_lines[i]);
164  te::qt::widgets::Config2DrawPoints(&canvas, "circle", 16, QColor(green.getRgba()), QColor(green.getRgba()), 1);
165  canvas.draw(startPoint.get());
166  te::qt::widgets::Config2DrawPoints(&canvas, "star", 16, QColor(green.getRgba()), QColor(green.getRgba()), 1);
167  canvas.draw(endPoint.get());
168 
169  if (QMessageBox::question(nullptr, tr("Profile"), tr("Invert this trajectory?")) == QMessageBox::Yes)
170  {
171  te::gm::Coord2D *coords = m_lines[i]->getCoordinates();
172  std::vector<te::gm::Coord2D> pts;
173  for (size_t j = 0; j < m_lines[i]->getNPoints(); j++)
174  {
175  pts.push_back(coords[j]);
176  }
177  std::reverse(pts.begin(),pts.end());
178  for (size_t j = 0; j < m_lines[i]->getNPoints(); j++)
179  {
180  coords[j].x = pts[j].getX();
181  coords[j].y = pts[j].getY();
182  }
183 
184  updateRTree();
185  }
186  break;
187  }
188  }
189  }
190 
191  if (m_type == LINE_DELETE)
192  {
194 
196  env_line.setPoint(0, env.getLowerLeftX(), env.getLowerLeftY());
197  env_line.setPoint(1, env.getLowerLeftX(), env.getUpperRightY());
198  env_line.setPoint(2, env.getUpperRightX(), env.getUpperRightY());
199  env_line.setPoint(3, env.getUpperRightX(), env.getLowerLeftY());
200  env_line.setPoint(4, env.getLowerLeftX(), env.getLowerLeftY());
201 
202  te::color::RGBAColor red(255, 0, 0, 255);
203  for (size_t i = 0; i < m_lines.size(); i++)
204  {
205  if (m_lines[i]->intersects(&env_line))
206  {
207  const te::gm::Envelope& displayExtent = m_display->getExtent();
209  canvas.setWindow(displayExtent.m_llx, displayExtent.m_lly, displayExtent.m_urx, displayExtent.m_ury);
210  canvas.setLineColor(red);
211  canvas.setLineWidth(3);
212  canvas.setLineDashStyle(te::map::SolidLine);
213  canvas.draw(m_lines[i]);
214 
215  if (QMessageBox::question(nullptr, tr("Profile"), tr("Delete this trajectory?")) == QMessageBox::Yes)
216  {
217  te::gm::LineString* l = m_lines[i];
218 
219  m_lines.erase(m_lines.begin() + i);
220 
221  std::vector<te::edit::Feature*> vet = te::edit::RepositoryManager::getInstance().getRepository(m_layer->getId())->getAllFeatures();
222  for (size_t j = 0; j < vet.size(); ++j)
223  {
224  if (vet[j]->getGeometry() == l)
225  {
226  te::edit::RepositoryManager::getInstance().removeFeature(m_layer->getId(), vet[j]->getId());
227  vet.erase(vet.begin() + j);
228  break;
229  }
230  }
231  }
232  break;
233  }
234  }
235  }
236 
238 
239  emit geometriesEdited();
240 
242  return ret;
243 }
244 
246 {
247  if (m_type == VERTEX_ADD)
248  {
252  return ret;
253  }
254 
256 }
257 
258 
void getRgba(int *r, int *g, int *b, int *a=0) const
It gets the color value.
Definition: RGBAColor.h:327
virtual const std::string & getId() const
It returns the layer id.
LINE_INVERT
Definition: ProfileTools.h:44
This file defines the profile trajectory edition tools.
ProfileTools(te::qt::widgets::MapDisplay *display, const te::map::AbstractLayerPtr &layer, QObject *parent=0)
double y
y-coordinate.
Definition: Coord2D.h:114
VERTEX_ADD
Definition: ProfileTools.h:44
void setLines(std::vector< te::gm::LineString * > &l)
double x
x-coordinate.
Definition: Coord2D.h:113
void setType(EditType t)
void setStage(StageType stage)
Definition: VertexTool.cpp:407
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
VERTEX_DELETE
Definition: ProfileTools.h:44
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
double m_urx
Upper right corner x-coordinate.
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: VertexTool.cpp:187
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
VERTEX_MOVE
Definition: ProfileTools.h:44
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: VertexTool.cpp:71
std::vector< te::gm::LineString * > m_lines
Definition: VertexTool.h:151
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
static RepositoryManager & getInstance()
It returns a reference to the singleton instance.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An Envelope defines a 2D rectangular region.
te::gm::Envelope buildEnvelope(const QPointF &pos)
Definition: VertexTool.cpp:370
URI C++ Library.
Definition: Attributes.h:37
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: VertexTool.cpp:120
TEEDITQTEXPORT QPointF GetPosition(QMouseEvent *e)
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw points.
te::sam::rtree::Index< VertexIndex, 8 > m_rtree
Definition: VertexTool.h:153
double m_lly
Lower left corner y-coordinate.
te::map::AbstractLayer * m_layer
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
double m_ury
Upper right corner y-coordinate.
bool mouseDoubleClickEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse double click events...
StageType m_currentStage
Definition: VertexTool.h:154
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
bool mouseDoubleClickEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse double click events...
Definition: VertexTool.cpp:226
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
LINE_DELETE
Definition: ProfileTools.h:44
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void pickFeature(const te::map::AbstractLayerPtr &layer, const QPointF &pos)
Definition: VertexTool.cpp:272
virtual QPixmap * getDisplayPixmap() const
It returns the map display pixmap.