GLWidget.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 _GL_WIDGET_HH_
18 #define _GL_WIDGET_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <utility>
23 #include <list>
24 
25 #include <boost/thread/mutex.hpp>
26 
27 #include "gazebo/gui/qt.h"
29 
31 
34 #include "gazebo/common/Event.hh"
35 
36 #include "gazebo/math/Pose.hh"
37 
38 #include "gazebo/msgs/msgs.hh"
39 
40 #include "gazebo/gui/BoxMaker.hh"
43 #include "gazebo/gui/MeshMaker.hh"
44 #include "gazebo/gui/ModelMaker.hh"
45 #include "gazebo/gui/LightMaker.hh"
46 #include "gazebo/util/system.hh"
47 
48 namespace gazebo
49 {
50  namespace gui
51  {
52  class GAZEBO_VISIBLE GLWidget : public QWidget
53  {
54  Q_OBJECT
55 
58  public: enum SelectionLevels {
62  LINK
63  };
64 
65  public: GLWidget(QWidget *_parent = 0);
66  public: virtual ~GLWidget();
67 
73  public: void ViewScene(rendering::ScenePtr _scene);
74  public: rendering::UserCameraPtr GetCamera() const;
75  public: rendering::ScenePtr GetScene() const;
76 
77  public: void Clear();
78 
81  public: std::vector<rendering::VisualPtr> SelectedVisuals() const;
82 
83  signals: void clicked();
84 
87  signals: void selectionMsgReceived(const QString &_name);
88 
89  protected: virtual void moveEvent(QMoveEvent *_e);
90  protected: virtual void paintEvent(QPaintEvent *_e);
91  protected: virtual void resizeEvent(QResizeEvent *_e);
92 
97  protected: virtual void showEvent(QShowEvent *_e);
98 
99  protected: virtual void enterEvent(QEvent * event);
100 
101 
102  protected: void keyPressEvent(QKeyEvent *_event);
103  protected: void keyReleaseEvent(QKeyEvent *_event);
104  protected: void wheelEvent(QWheelEvent *_event);
105  protected: void mousePressEvent(QMouseEvent *_event);
106  protected: void mouseDoubleClickEvent(QMouseEvent *_event);
107  protected: void mouseMoveEvent(QMouseEvent *_event);
108  protected: void mouseReleaseEvent(QMouseEvent *_event);
109 
113  protected: virtual QPaintEngine *paintEngine() const;
114 
115  private: std::string GetOgreHandle() const;
116 
120  private: bool OnMouseMove(const common::MouseEvent &_event);
121 
123  private: void OnMouseMoveNormal();
124 
126  private: void OnMouseMoveMakeEntity();
127 
131  private: bool OnMouseRelease(const common::MouseEvent &_event);
132 
134  private: void OnMouseReleaseNormal();
135 
137  private: void OnMouseReleaseMakeEntity();
138 
142  private: bool OnMousePress(const common::MouseEvent &_event);
143 
145  private: void OnMousePressNormal();
146 
148  private: void OnMousePressMakeEntity();
149 
153  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
154 
155  private: void OnRequest(ConstRequestPtr &_msg);
156  private: void OnCreateScene(const std::string &_name);
157  private: void OnRemoveScene(const std::string &_name);
158  private: void OnMoveMode(bool _mode);
159  private: void OnCreateEntity(const std::string &_type,
160  const std::string &_data);
161 
162  private: void OnFPS();
163  private: void OnOrbit();
164  private: void OnManipMode(const std::string &_mode);
165 
166  private: void OnSetSelectedEntity(const std::string &_name,
167  const std::string &_mode);
168 
169  private: bool eventFilter(QObject *_obj, QEvent *_event);
170 
171  private: void ClearSelection();
172 
173  private: void PushHistory(const std::string &_visName,
174  const math::Pose &_pose);
175  private: void PopHistory();
176 
179  private: void SetSelectedVisual(rendering::VisualPtr _vis);
180 
182  private: void DeselectAllVisuals();
183 
190  private: void OnAlignMode(const std::string &_axis,
191  const std::string &_config, const std::string &_target,
192  bool _preview);
193 
196  private: void Copy(const std::string &_name);
197 
200  private: void Paste(const std::string &_name);
201 
203  private slots: void OnCopy();
204 
206  private slots: void OnPaste();
207 
210  private slots: void OnModelEditor(bool _checked);
211 
213  private slots: void OnOrtho();
214 
216  private slots: void OnPerspective();
217 
223  private: void SetMouseEventButton(const Qt::MouseButton &_button);
224 
230  private: void SetMouseEventButtons(const Qt::MouseButtons &_buttons);
231 
232  private: int windowId;
233 
234  private: rendering::UserCameraPtr userCamera;
235  private: rendering::ScenePtr scene;
236  private: QFrame *renderFrame;
237  private: common::MouseEvent mouseEvent;
238 
240  private: common::KeyEvent keyEvent;
241 
242  private: std::vector<event::ConnectionPtr> connections;
243 
244  private: EntityMaker *entityMaker;
245  private: BoxMaker boxMaker;
246  private: SphereMaker sphereMaker;
247  private: CylinderMaker cylinderMaker;
248  private: MeshMaker meshMaker;
249  private: ModelMaker modelMaker;
250  private: PointLightMaker pointLightMaker;
251  private: SpotLightMaker spotLightMaker;
252  private: DirectionalLightMaker directionalLightMaker;
253 
255  private: LightMaker lightMaker;
256 
258  private: std::vector<rendering::VisualPtr> selectedVisuals;
259 
261  private: SelectionLevels selectionLevel;
262 
263  private: transport::NodePtr node;
264  private: transport::PublisherPtr modelPub, factoryPub;
265 
267  private: transport::PublisherPtr selectionPub;
268 
269  private: transport::SubscriberPtr requestSub;
270 
271  private: std::string keyText;
272  private: Qt::KeyboardModifiers keyModifiers;
273  private: QPoint onShiftMousePos;
274 
275  private: std::string copiedObject;
276 
277  private: std::string state;
278 
279  private: std::list<std::pair<std::string, math::Pose> > moveHistory;
280 
282  private: std::string copyEntityName;
283 
285  private: bool modelEditorEnabled;
286 
288  private: boost::mutex selectedVisMutex;
289  };
290  }
291 }
292 
293 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Definition: GLWidget.hh:52
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
Definition: LightMaker.hh:35
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Definition: LightMaker.hh:80
Definition: ModelMaker.hh:36
Definition: MeshMaker.hh:33
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Definition: SphereMaker.hh:35
Forward declarations for transport.
to make a box
Definition: BoxMaker.hh:41
to make a cylinder
Definition: CylinderMaker.hh:39
Model level.
Definition: GLWidget.hh:60
Definition: LightMaker.hh:70
to make an entity base class
Definition: EntityMaker.hh:41
Definition: LightMaker.hh:96
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:79
SelectionLevels
Unique identifiers for all selection levels supported.
Definition: GLWidget.hh:58
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:91
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66