LaserView.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _LASERVIEW_HH_
18 #define _LASERVIEW_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <boost/thread/mutex.hpp>
23 
24 #include "gazebo/common/Time.hh"
25 #include "gazebo/msgs/msgs.hh"
26 
28 
29 #include "gazebo/gui/qt.h"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace gui
36  {
37  class GZ_GUI_VISIBLE LaserView : public TopicView
38  {
39  Q_OBJECT
40 
43  public: LaserView(QWidget *_parent = NULL);
44 
46  public: virtual ~LaserView();
47 
48  // Documentation inherited
49  public: virtual void SetTopic(const std::string &_topicName);
50 
51  // Documentation inherited
52  private: virtual void UpdateImpl();
53 
56  protected: virtual void resizeEvent(QResizeEvent *_event);
57 
60  private: void OnScan(ConstLaserScanStampedPtr &_msg);
61 
63  private slots: void OnFitInView();
64 
66  private slots: void OnDegree(bool _toggled);
67 
69  private: class LaserItem : public QGraphicsItem
70  {
72  public: LaserItem();
73 
75  public: void Clear();
76 
79  public: unsigned int GetRangeCount();
80 
83  public: void AddRange(double _range);
84 
88  public: void SetRange(unsigned int _index, double _range);
89 
91  public: QRectF GetBoundingRect() const;
92 
96  public: double GetHoverRange() const;
97 
101  public: double GetHoverAngle() const;
102 
109  public: void Update(double _angleMin, double _angleMax,
110  double _angleStep, double _rangeMax,
111  double _rangeMin);
112 
115  private: virtual QRectF boundingRect() const;
116 
124  private: virtual void paint(QPainter *_painter,
125  const QStyleOptionGraphicsItem *_option,
126  QWidget *_widget);
127 
131  private: virtual void hoverEnterEvent(
132  QGraphicsSceneHoverEvent *_event);
133 
137  private: virtual void hoverLeaveEvent(
138  QGraphicsSceneHoverEvent *_event);
139 
143  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
144 
146  private: std::vector<QPointF> points;
147 
149  private: std::vector<QPointF> noHitPoints;
150 
153  private: std::vector<double> ranges;
154 
156  private: double angleMin;
157 
159  private: double angleMax;
160 
162  private: double angleStep;
163 
165  private: double rangeMax;
166 
168  private: double rangeMin;
169 
171  private: double indexAngle;
172 
174  private: double scale;
175 
177  public: bool radians;
178 
180  private: mutable boost::mutex mutex;
181  };
182 
185  private: class CustomView : public QGraphicsView
186  {
189  public: CustomView(QWidget *_parent)
190  : QGraphicsView(_parent), viewZoomed(false) {}
191 
194  private: void wheelEvent(QWheelEvent *_event)
195  {
196  this->viewZoomed = true;
197  _event->delta() > 0 ? this->scale(1.15, 1.15) :
198  this->scale(1.0 / 1.15, 1.0 / 1.15);
199  _event->accept();
200  }
201 
203  public: bool viewZoomed;
204  };
205 
207  private: LaserItem *laserItem;
208 
210  private: CustomView *view;
211 
213  private: bool firstMsg;
214 
216  private: QLineEdit *rangeEdit;
217 
219  private: QLineEdit *angleEdit;
220 
222  private: QSpinBox *vertScanSpin;
223  };
224  }
225 }
226 #endif
Forward declarations for transport.
Base class for widgets that display topic data.
Definition: TopicView.hh:78
#define NULL
Definition: CommonTypes.hh:31
Definition: LaserView.hh:37