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 "gazebo/gui/qt.h"
27 
29 
32 #include "gazebo/common/Event.hh"
33 
34 #include "gazebo/math/Pose.hh"
35 
36 #include "gazebo/msgs/msgs.hh"
37 
38 #include "gazebo/gui/BoxMaker.hh"
41 #include "gazebo/gui/MeshMaker.hh"
42 #include "gazebo/gui/ModelMaker.hh"
43 #include "gazebo/gui/LightMaker.hh"
44 #include "gazebo/util/system.hh"
45 
46 namespace gazebo
47 {
48  namespace gui
49  {
50  class GAZEBO_VISIBLE GLWidget : public QWidget
51  {
52  Q_OBJECT
53 
54  public: GLWidget(QWidget *_parent = 0);
55  public: virtual ~GLWidget();
56 
62  public: void ViewScene(rendering::ScenePtr _scene);
63  public: rendering::UserCameraPtr GetCamera() const;
64  public: rendering::ScenePtr GetScene() const;
65 
66  public: void Clear();
67 
68  signals: void clicked();
69 
70 
71  protected: virtual void moveEvent(QMoveEvent *_e);
72  protected: virtual void paintEvent(QPaintEvent *_e);
73  protected: virtual void resizeEvent(QResizeEvent *_e);
74  protected: virtual void showEvent(QShowEvent *_e);
75  protected: virtual void enterEvent(QEvent * event);
76 
77 
78  protected: void keyPressEvent(QKeyEvent *_event);
79  protected: void keyReleaseEvent(QKeyEvent *_event);
80  protected: void wheelEvent(QWheelEvent *_event);
81  protected: void mousePressEvent(QMouseEvent *_event);
82  protected: void mouseDoubleClickEvent(QMouseEvent *_event);
83  protected: void mouseMoveEvent(QMouseEvent *_event);
84  protected: void mouseReleaseEvent(QMouseEvent *_event);
85 
86  private: std::string GetOgreHandle() const;
87 
91  private: bool OnMouseMove(const common::MouseEvent &_event);
92 
94  private: void OnMouseMoveNormal();
95 
97  private: void OnMouseMoveMakeEntity();
98 
102  private: bool OnMouseRelease(const common::MouseEvent &_event);
103 
105  private: void OnMouseReleaseNormal();
106 
108  private: void OnMouseReleaseMakeEntity();
109 
113  private: bool OnMousePress(const common::MouseEvent &_event);
114 
116  private: void OnMousePressNormal();
117 
119  private: void OnMousePressMakeEntity();
120 
124  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
125 
126  private: void OnRequest(ConstRequestPtr &_msg);
127  private: void OnCreateScene(const std::string &_name);
128  private: void OnRemoveScene(const std::string &_name);
129  private: void OnMoveMode(bool _mode);
130  private: void OnCreateEntity(const std::string &_type,
131  const std::string &_data);
132 
133  private: void OnFPS();
134  private: void OnOrbit();
135  private: void OnManipMode(const std::string &_mode);
136 
137  private: void OnSetSelectedEntity(const std::string &_name,
138  const std::string &_mode);
139 
140  private: void OnSelectionMsg(ConstSelectionPtr &_msg);
141 
142  private: bool eventFilter(QObject *_obj, QEvent *_event);
143 
144  private: void ClearSelection();
145 
146  private: void PushHistory(const std::string &_visName,
147  const math::Pose &_pose);
148  private: void PopHistory();
149 
152  private: void SetSelectedVisual(rendering::VisualPtr _vis);
153 
160  private: void OnAlignMode(const std::string &_axis,
161  const std::string &_config, const std::string &_target,
162  bool _preview);
163 
166  private: void Copy(const std::string &_name);
167 
170  private: void Paste(const std::string &_name);
171 
173  private slots: void OnCopy();
174 
176  private slots: void OnPaste();
177 
180  private slots: void OnModelEditor(bool _checked);
181 
182  private: int windowId;
183 
184  private: rendering::UserCameraPtr userCamera;
185  private: rendering::ScenePtr scene;
186  private: QFrame *renderFrame;
187  private: common::MouseEvent mouseEvent;
188 
190  private: common::KeyEvent keyEvent;
191 
192  private: std::vector<event::ConnectionPtr> connections;
193 
194  private: EntityMaker *entityMaker;
195  private: BoxMaker boxMaker;
196  private: SphereMaker sphereMaker;
197  private: CylinderMaker cylinderMaker;
198  private: MeshMaker meshMaker;
199  private: ModelMaker modelMaker;
200  private: PointLightMaker pointLightMaker;
201  private: SpotLightMaker spotLightMaker;
202  private: DirectionalLightMaker directionalLightMaker;
203 
205  private: LightMaker lightMaker;
206 
207  private: rendering::VisualPtr hoverVis;
208 
210  private: std::vector<rendering::VisualPtr> selectedVisuals;
211 
212  private: transport::NodePtr node;
213  private: transport::PublisherPtr modelPub, factoryPub;
214 
216  private: transport::PublisherPtr selectionPub;
217 
218  private: transport::SubscriberPtr selectionSub, requestSub;
219 
220  private: std::string keyText;
221  private: Qt::KeyboardModifiers keyModifiers;
222  private: QPoint onShiftMousePos;
223 
224  private: std::string copiedObject;
225 
226  private: std::string state;
227 
228  private: std::list<std::pair<std::string, math::Pose> > moveHistory;
229 
231  private: std::string copyEntityName;
232 
235  private: bool sceneCreated;
236 
238  private: bool modelEditorEnabled;
239 
241  private: boost::mutex selectedVisMutex;
242  };
243  }
244 }
245 
246 #endif
Generic description of a mouse event.
Definition: MouseEvent.hh:32
Definition: GLWidget.hh:50
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
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
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:74
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:86
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48