GLWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 GAZEBO_GUI_GLWIDGET_HH_
18 #define GAZEBO_GUI_GLWIDGET_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "gazebo/gui/qt.h"
25 #include "gazebo/msgs/msgs.hh"
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  class MouseEvent;
34  }
35 
36  namespace gui
37  {
38  class GLWidgetPrivate;
39 
40  class GZ_GUI_VISIBLE GLWidget : public QWidget
41  {
42  Q_OBJECT
43 
46  public: enum SelectionLevels {
50  LINK
51  };
52 
53  public: explicit GLWidget(QWidget *_parent = 0);
54  public: virtual ~GLWidget();
55 
61  public: void ViewScene(rendering::ScenePtr _scene);
62 
66 
69  public: rendering::ScenePtr Scene() const;
70 
71  public: void Clear();
72 
75  public: std::vector<rendering::VisualPtr> SelectedVisuals() const;
76 
79  public: void SetRenderRate(double _renderRate);
80 
81  signals: void clicked();
82 
85  signals: void selectionMsgReceived(const QString &_name);
86 
87  protected: virtual void moveEvent(QMoveEvent *_e);
88  protected: virtual void paintEvent(QPaintEvent *_e);
89  protected: virtual void resizeEvent(QResizeEvent *_e);
90 
95  protected: virtual void showEvent(QShowEvent *_e);
96 
97  protected: virtual void enterEvent(QEvent *_event);
98 
99 
100  protected: void keyPressEvent(QKeyEvent *_event);
101  protected: void keyReleaseEvent(QKeyEvent *_event);
102  protected: void wheelEvent(QWheelEvent *_event);
103  protected: void mousePressEvent(QMouseEvent *_event);
104  protected: void mouseDoubleClickEvent(QMouseEvent *_event);
105  protected: void mouseMoveEvent(QMouseEvent *_event);
106  protected: void mouseReleaseEvent(QMouseEvent *_event);
107 
111  protected: virtual QPaintEngine *paintEngine() const;
112 
113  private: std::string OgreHandle() const;
114 
118  private: bool OnMouseMove(const common::MouseEvent &_event);
119 
121  private: void OnMouseMoveNormal();
122 
124  private: void OnMouseMoveMakeEntity();
125 
129  private: bool OnMouseRelease(const common::MouseEvent &_event);
130 
132  private: void OnMouseReleaseNormal();
133 
135  private: void OnMouseReleaseMakeEntity();
136 
140  private: bool OnMousePress(const common::MouseEvent &_event);
141 
143  private: void OnMousePressNormal();
144 
146  private: void OnMousePressMakeEntity();
147 
151  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
152 
153  private: void OnRequest(ConstRequestPtr &_msg);
154  private: void OnCreateScene(const std::string &_name);
155  private: void OnRemoveScene(const std::string &_name);
156  private: void OnMoveMode(bool _mode);
157  private: void OnCreateEntity(const std::string &_type,
158  const std::string &_data);
159 
160  private: void OnFPS();
161  private: void OnOrbit();
162  private: void OnManipMode(const std::string &_mode);
163 
164  private: void OnSetSelectedEntity(const std::string &_name,
165  const std::string &_mode);
166 
167  private: bool eventFilter(QObject *_obj, QEvent *_event);
168 
169  private: void ClearSelection();
170 
173  private: void SetSelectedVisual(rendering::VisualPtr _vis);
174 
176  private: void DeselectAllVisuals();
177 
185  private: void OnAlignMode(const std::string &_axis,
186  const std::string &_config, const std::string &_target,
187  const bool _preview, const bool _inverted = false);
188 
191  private: void Copy(const std::string &_name);
192 
195  private: void Paste(const std::string &_name);
196 
198  private slots: void OnCopy();
199 
201  private slots: void OnPaste();
202 
205  private slots: void OnModelEditor(bool _checked);
206 
208  private slots: void OnOrtho();
209 
211  private slots: void OnPerspective();
212 
218  private: void SetMouseEventButton(const Qt::MouseButton &_button);
219 
225  private: void SetMouseEventButtons(const Qt::MouseButtons &_buttons);
226 
229  private: std::unique_ptr<GLWidgetPrivate> dataPtr;
230  };
231  }
232 }
233 
234 #endif
common
Definition: FuelModelDatabase.hh:42
gui
Definition: KeyEventHandler.hh:29
Generic description of a mouse event.
Definition: MouseEvent.hh:36
Definition: GLWidget.hh:41
GLWidget(QWidget *_parent=0)
virtual void paintEvent(QPaintEvent *_e)
virtual QPaintEngine * paintEngine() const
Override paintEngine to stop Qt From trying to draw on top of OGRE.
void mouseReleaseEvent(QMouseEvent *_event)
void SetRenderRate(double _renderRate)
Change render rate for GLWidget.
virtual void moveEvent(QMoveEvent *_e)
void mousePressEvent(QMouseEvent *_event)
void keyPressEvent(QKeyEvent *_event)
rendering::UserCameraPtr Camera() const
Return the user camera.
SelectionLevels
Unique identifiers for all selection levels supported.
Definition: GLWidget.hh:46
@ MODEL
Model level.
Definition: GLWidget.hh:48
void mouseMoveEvent(QMouseEvent *_event)
void selectionMsgReceived(const QString &_name)
QT signal to notify when we received a selection msg.
void wheelEvent(QWheelEvent *_event)
rendering::ScenePtr Scene() const
Return the scene.
virtual void enterEvent(QEvent *_event)
void keyReleaseEvent(QKeyEvent *_event)
void mouseDoubleClickEvent(QMouseEvent *_event)
virtual void resizeEvent(QResizeEvent *_e)
std::vector< rendering::VisualPtr > SelectedVisuals() const
Returns the list of selected visuals.
void ViewScene(rendering::ScenePtr _scene)
View a scene in this widget.
virtual void showEvent(QShowEvent *_e)
Custom processing for the QT showEvent.
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:94
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
Forward declarations for the common classes.
Definition: Animation.hh:27