LaserView.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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  {
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 
150  private: std::vector<double> ranges;
151 
153  private: double angleMin;
154 
156  private: double angleMax;
157 
159  private: double angleStep;
160 
162  private: double rangeMax;
163 
165  private: double rangeMin;
166 
168  private: double indexAngle;
169 
171  private: double scale;
172 
174  public: bool radians;
175 
177  private: mutable boost::mutex mutex;
178  };
179 
182  private: class CustomView : public QGraphicsView
183  {
186  public: CustomView(QWidget *_parent)
187  : QGraphicsView(_parent), viewZoomed(false) {}
188 
191  private: void wheelEvent(QWheelEvent *_event)
192  {
193  this->viewZoomed = true;
194  _event->delta() > 0 ? this->scale(1.15, 1.15) :
195  this->scale(1.0 / 1.15, 1.0 / 1.15);
196  _event->accept();
197  }
198 
200  public: bool viewZoomed;
201  };
202 
204  private: LaserItem *laserItem;
205 
207  private: CustomView *view;
208 
210  private: bool firstMsg;
211 
213  private: QLineEdit *rangeEdit;
214 
216  private: QLineEdit *angleEdit;
217 
219  private: QSpinBox *vertScanSpin;
220  };
221  }
222 }
223 #endif
Forward declarations for transport.
Base class for widgets that display topic data.
Definition: TopicView.hh:76
#define NULL
Definition: CommonTypes.hh:30
#define GZ_GUI_VIEWERS_VISIBLE
Definition: system.hh:468
Definition: LaserView.hh:37