All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GLWidget.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 
156  private: void Copy(const std::string &_name);
157 
160  private: void Paste(const std::string &_name);
161 
163  private slots: void OnCopy();
164 
166  private slots: void OnPaste();
167 
168  private: int windowId;
169 
170  private: rendering::UserCameraPtr userCamera;
171  private: rendering::ScenePtr scene;
172  private: QFrame *renderFrame;
173  private: common::MouseEvent mouseEvent;
174 
176  private: common::KeyEvent keyEvent;
177 
178  private: std::vector<event::ConnectionPtr> connections;
179 
180  private: EntityMaker *entityMaker;
181  private: BoxMaker boxMaker;
182  private: SphereMaker sphereMaker;
183  private: CylinderMaker cylinderMaker;
184  private: MeshMaker meshMaker;
185  private: ModelMaker modelMaker;
186  private: PointLightMaker pointLightMaker;
187  private: SpotLightMaker spotLightMaker;
188  private: DirectionalLightMaker directionalLightMaker;
189 
191  private: LightMaker lightMaker;
192 
193  private: rendering::VisualPtr hoverVis, selectedVis;
194 
195  private: transport::NodePtr node;
196  private: transport::PublisherPtr modelPub, factoryPub;
197  private: transport::SubscriberPtr selectionSub, requestSub;
198 
199  private: std::string keyText;
200  private: Qt::KeyboardModifiers keyModifiers;
201  private: QPoint onShiftMousePos;
202 
203  private: std::string copiedObject;
204 
205  private: std::string state;
206 
207  private: std::list<std::pair<std::string, math::Pose> > moveHistory;
208 
210  private: std::string copyEntityName;
211 
214  private: bool sceneCreated;
215  };
216  }
217 }
218 
219 #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:48
Definition: LightMaker.hh:80
Definition: ModelMaker.hh:36
Definition: MeshMaker.hh:33
Generic description of a keyboard event.
Definition: KeyEvent.hh:31
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:52
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:72
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:100
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:84
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48