stdr_map_connector.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
23 
24 namespace stdr_gui{
25 
32  CMapConnector::CMapConnector(int argc, char **argv):
33  QObject(),
34  loader_(argc,argv),
35  argc_(argc),
36  argv_(argv)
37  {
39 
40  loader_.map->setScaledContents(true);
41 
42  loader_.map->installEventFilter(this);
43 
44  QObject::connect(
45  this,SIGNAL(signalUpdateImage(QImage *)),
46  this, SLOT(serveImage(QImage *)));
47 
48  QPixmap p((
50  std::string("/resources/images/zoom_in.png")).c_str());
51  zoom_in_cursor_ = QCursor(p.scaled(20,20));
52 
53  p=QPixmap((
55  std::string("/resources/images/zoom_out.png")).c_str());
56  zoom_out_cursor_ = QCursor(p.scaled(20,20));
57 
58  bool map_initialized_ = false;
59  }
60 
66  {
67 
68  }
69 
76  {
78  }
79 
86  void CMapConnector::updateZoom(QPoint p,bool z)
87  {
88  if ( ! map_initialized_ )
89  {
90  return;
91  }
92  loader_.updateZoom(p,z);
93  }
94 
101  if ( ! map_initialized_ )
102  {
103  return;
104  }
106  }
107 
114  {
115  return loader_.getGlobalPoint(p);
116  }
117 
124  void CMapConnector::drawGrid(QImage *img,float resolution)
125  {
126  if ( ! map_initialized_ )
127  {
128  return;
129  }
130  loader_.drawGrid(img,resolution);
131  }
132 
139  bool CMapConnector::eventFilter( QObject* watched, QEvent* event )
140  {
141  if ( ! map_initialized_ )
142  {
143  return false;
144  }
145  if(watched == loader_.map)
146  {
147  if(event->type() == QEvent::MouseButtonPress)
148  {
149 
150  loader_.map->setFocus(Qt::MouseFocusReason);
151 
152  const QMouseEvent* const me =
153  static_cast<const QMouseEvent*>( event );
154  QPoint p = me->pos();
155  if(me->button() == Qt::RightButton)
156  {
157  map_state_ = NORMAL;
158  loader_.map->setCursor(QCursor(Qt::CrossCursor));
159  Q_EMIT itemClicked(p,Qt::RightButton);
160  }
161  else if(me->button() == Qt::LeftButton)
162  {
163  if(map_state_ == ZOOMIN)
164  {
165  Q_EMIT zoomInPressed(p);
166  }
167  else if(map_state_ == ZOOMOUT)
168  {
169  Q_EMIT zoomOutPressed(p);
170  }
171  else if(map_state_ == SETPLACE)
172  {
173  map_state_ = NORMAL;
174  loader_.map->setCursor(QCursor(Qt::CrossCursor));
175  Q_EMIT robotPlaceSet(p);
176  }
177  else if(map_state_ == NORMAL)
178  {
179  Q_EMIT itemClicked(p,Qt::LeftButton);
180  }
181  else if(map_state_ == SETREPLACE)
182  {
183  map_state_ = NORMAL;
184  loader_.map->setCursor(QCursor(Qt::CrossCursor));
186  }
187  else if(map_state_ == SETPLACERFID)
188  {
189  map_state_ = NORMAL;
190  loader_.map->setCursor(QCursor(Qt::CrossCursor));
191  Q_EMIT rfidPlaceSet(p);
192  }
193  else if(map_state_ == SETPLACETHERMAL)
194  {
195  map_state_ = NORMAL;
196  loader_.map->setCursor(QCursor(Qt::CrossCursor));
197  Q_EMIT thermalPlaceSet(p);
198  }
199  else if(map_state_ == SETPLACECO2)
200  {
201  map_state_ = NORMAL;
202  loader_.map->setCursor(QCursor(Qt::CrossCursor));
203  Q_EMIT co2PlaceSet(p);
204  }
205  else if(map_state_ == SETPLACESOUND)
206  {
207  map_state_ = NORMAL;
208  loader_.map->setCursor(QCursor(Qt::CrossCursor));
209  Q_EMIT soundPlaceSet(p);
210  }
211  }
212  }
213  else if(event->type() == QEvent::Wheel)
214  {
215  const QWheelEvent* const me =
216  static_cast<const QWheelEvent*>( event );
217  QPoint p = me->pos();
218  if(me->delta() > 0)
219  {
220  Q_EMIT zoomInPressed(p);
221  }
222  else
223  {
224  Q_EMIT zoomOutPressed(p);
225  }
226  }
227  else if(event->type() == QEvent::KeyPress)
228  {
229  const QKeyEvent* const me =
230  static_cast<const QKeyEvent*>( event );
231 
232  if ( ! map_initialized_ )
233  {
234  return false;
235  }
236  if(me->key() == Qt::Key_Right)
237  {
238  loader_.moveDirectionally(Qt::Key_Right);
239  }
240  else if(me->key() == Qt::Key_Left)
241  {
242  loader_.moveDirectionally(Qt::Key_Left);
243  }
244  else if(me->key() == Qt::Key_Up)
245  {
246  loader_.moveDirectionally(Qt::Key_Up);
247  }
248  else if(me->key() == Qt::Key_Down)
249  {
250  loader_.moveDirectionally(Qt::Key_Down);
251  }
252  }
253  }
254  return false;
255  }
256 
262  void CMapConnector::updateImage(QImage *img)
263  {
264  Q_EMIT signalUpdateImage(img);
265  }
266 
272  void CMapConnector::serveImage(QImage *img)
273  {
274  loader_.updateImage(img);
275  }
276 
282  QPoint CMapConnector::mapToGlobal(QPoint p)
283  {
284  return loader_.mapToGlobal(p);
285  }
286 
293  {
294  if ( ! map_initialized_ )
295  {
296  return;
297  }
298  if(state)
299  {
300  map_state_ = ZOOMIN;
301  loader_.map->setCursor(zoom_in_cursor_);
302  }
303  else
304  {
305  map_state_ = NORMAL;
306  loader_.map->setCursor(QCursor(Qt::CrossCursor));
307  }
308  }
309 
316  {
317  if ( ! map_initialized_ )
318  {
319  return;
320  }
321  if(state)
322  {
324  loader_.map->setCursor(zoom_out_cursor_);
325  }
326  else
327  {
328  map_state_ = NORMAL;
329  loader_.map->setCursor(QCursor(Qt::CrossCursor));
330  }
331  }
332 
339  {
340  if ( ! map_initialized_ )
341  {
342  return;
343  }
344  loader_.resetZoom();
345  map_state_ = NORMAL;
346  loader_.map->setCursor(QCursor(Qt::CrossCursor));
347  }
348 
354  {
355  if ( ! map_initialized_ )
356  {
357  return;
358  }
360  loader_.map->setCursor(Qt::PointingHandCursor);
361  }
362 
368  {
369  if ( ! map_initialized_ )
370  {
371  return;
372  }
374  loader_.map->setCursor(Qt::PointingHandCursor);
375  }
376 
382  {
383  if ( ! map_initialized_ )
384  {
385  return;
386  }
388  loader_.map->setCursor(Qt::PointingHandCursor);
389  }
390 
396  {
397  if ( ! map_initialized_ )
398  {
399  return;
400  }
402  loader_.map->setCursor(Qt::PointingHandCursor);
403  }
404 
410  {
411  if ( ! map_initialized_ )
412  {
413  return;
414  }
416  loader_.map->setCursor(Qt::PointingHandCursor);
417  }
418 
424  {
425  return static_cast<QWidget *>(&loader_);
426  }
427 
433  void CMapConnector::waitForReplace(std::string robotFrameId){
434  if ( ! map_initialized_ )
435  {
436  return;
437  }
438  current_robot_frame_id_ = robotFrameId;
440  loader_.map->setCursor(Qt::PointingHandCursor);
441  }
442 
449  {
450  map_initialized_ = mi;
451  }
452 }
void updateZoom(QPoint p, bool z)
Updates the map zoom. Wrapper for a loader function.
void updateCenter(QPoint p)
Updates the image center.
bool eventFilter(QObject *watched, QEvent *event)
General event filter. Captures all events.
void waitForSoundPlace(void)
Changes the map state. Waits for a sound source to be placed.
std::string getRosPackagePath(std::string package)
Returns the global path of the ROS package provided.
Definition: stdr_tools.cpp:31
void waitForCo2Place(void)
Changes the map state. Waits for a CO2 source to be placed.
std::string current_robot_frame_id_
Mouse cursor for zoom in.
void rfidPlaceSet(QPoint p)
Emmited when click is captured and state is SETRFIDPLACE.
QWidget * getLoader(void)
Returns the CMapLoader object.
void waitForRfidPlace(void)
Changes the map state. Waits for an RFID tag to be placed.
void drawGrid(QImage *img, float resolution)
Draws a grid in an image.
QCursor zoom_out_cursor_
Holds the map state.
void soundPlaceSet(QPoint p)
Emmited when click is captured and state is SETSOUNDPLACE.
void zoomOutPressed(QPoint p)
Emmited when click is captured and state is ZOOMOUT.
void waitForPlace(void)
Changes the map state. Waits for a robot to be placed.
void updateCenter(QPoint p)
Updates the map center when a robot is followed.
QCursor zoom_in_cursor_
Mouse cursor for zoom out.
QPoint getGlobalPoint(QPoint p)
Calculates the "real" point in the image.
void setInitialImageSize(QSize s)
Sets map initial size to the loader.
void robotPlaceSet(QPoint p)
Emmited when click is captured and state is SETPLACE.
void setMapInitialized(bool mi)
Sets the map initialization status.
void setInitialImageSize(QSize s)
Sets the initial image size.
void updateImage(QImage *img)
Updates the image.
~CMapConnector(void)
Default destructor.
void drawGrid(QImage *img, float resolution)
Wrapper for the draw grid function of loader.
void co2PlaceSet(QPoint p)
Emmited when click is captured and state is SETCO2PLACE.
void robotReplaceSet(QPoint p, std::string robotName)
Emmited when click is captured and state is SETREPLACE.
QPoint getGlobalPoint(QPoint p)
Returns the point in the real map image. Wrapper for a loader function.
void updateZoom(QPoint p, bool zoomIn)
Updates the zoom of the image.
void updateImage(QImage *img)
Emits the signalUpdateImage signal.
void waitForReplace(std::string robotFrameId)
Changes the map state. Waits for a robot to be re-placed.
The main namespace for STDR GUI.
EStdrMapState map_state_
Object of CMapLoader.
void waitForThermalPlace(void)
Changes the map state. Waits for a thermal source to be placed.
void resetZoom(void)
Resets the zoom of the image.
void itemClicked(QPoint p, Qt::MouseButton b)
Emmited when click is captured and state is NORMAL.
void serveImage(QImage *img)
Called from signalUpdateImage signal. Calls the updateImage of CMapLoader.
void signalUpdateImage(QImage *img)
Emmited in updateImage function.
void setCursorAdjusted(bool state)
Called when zoom adjusted event happens.
void moveDirectionally(int key)
Updates the image center by moving directionally.
QPoint mapToGlobal(QPoint p)
Calls the Qt function that gets the real point that the event happened.
void setCursorZoomIn(bool state)
Called when zoom in event happens.
CMapConnector(int argc, char **argv)
Default contructor.
void thermalPlaceSet(QPoint p)
Emmited when click is captured and state is SETTHERMALPLACE.
void zoomInPressed(QPoint p)
Emmited when click is captured and state is ZOOMIN.
CMapLoader loader_
True if map is initialized.
void setCursorZoomOut(bool state)
Called when zoom out event happens.


stdr_gui
Author(s): Manos Tsardoulias
autogenerated on Mon Jun 10 2019 15:15:16