JointMaker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-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 
18 #ifndef _JOINTMAKER_HH_
19 #define _JOINTMAKER_HH_
20 
21 #include <string>
22 #include <vector>
23 #include <boost/unordered/unordered_map.hpp>
24 
25 #include <sdf/sdf.hh>
26 
30 #include "gazebo/math/Pose.hh"
32 #include "gazebo/gui/qt.h"
33 #include "gazebo/util/system.hh"
34 
35 namespace Ogre
36 {
37  class BillboardSet;
38 }
39 
40 namespace boost
41 {
42  class recursive_mutex;
43 }
44 
45 namespace gazebo
46 {
47  namespace gui
48  {
49  class JointData;
50  class JointInspector;
51 
54 
57  class GAZEBO_VISIBLE JointMaker : public QObject
58  {
59  Q_OBJECT
60 
63  public: enum JointType
64  {
80  JOINT_BALL
81  };
82 
84  public: JointMaker();
85 
87  public: virtual ~JointMaker();
88 
90  public: void Reset();
91 
93  public: void EnableEventHandlers();
94 
96  public: void DisableEventHandlers();
97 
100  public: void AddJoint(const std::string &_type);
101 
104  public: void AddJoint(JointType _type);
105 
110  public: JointData *CreateJoint(rendering::VisualPtr _parent,
111  rendering::VisualPtr _child);
112 
115  public: void CreateHotSpot(JointData *_joint);
116 
118  public: void Update();
119 
122  public: void RemoveJoint(const std::string &_jointName);
123 
126  public: void RemoveJointsByPart(const std::string &_partName);
127 
129  public: void GenerateSDF();
130 
132  public: sdf::ElementPtr GetSDF() const;
133 
136  public: static int GetJointAxisCount(JointMaker::JointType _type);
137 
141  public: static std::string GetTypeAsString(JointMaker::JointType _type);
142 
146  public: JointMaker::JointType GetState() const;
147 
149  public: void Stop();
150 
153  public: unsigned int GetJointCount();
154 
158  private: bool OnMousePress(const common::MouseEvent &_event);
159 
163  private: bool OnMouseRelease(const common::MouseEvent &_event);
164 
168  private: bool OnMouseMove(const common::MouseEvent &_event);
169 
173  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
174 
178  private: bool OnKeyPress(const common::KeyEvent &_event);
179 
183  private: math::Vector3 GetPartWorldCentroid(
184  const rendering::VisualPtr _visual);
185 
188  private: void OpenInspector(const std::string &_name);
189 
191  Q_SIGNALS: void JointAdded();
192 
194  private slots: void OnOpenInspector();
195 
197  private: std::vector<math::Vector3> UnitVectors;
198 
200  private: JointMaker::JointType jointType;
201 
203  private: rendering::VisualPtr hoverVis;
204 
206  private: rendering::VisualPtr prevHoverVis;
207 
209  private: rendering::VisualPtr selectedVis;
210 
212  private: rendering::VisualPtr inspectVis;
213 
215  private: boost::unordered_map<std::string, JointData *> joints;
216 
218  private: JointData *mouseJoint;
219 
221  private: std::vector<event::ConnectionPtr> connections;
222 
224  private: bool newJointCreated;
225 
227  private: boost::unordered_map<JointMaker::JointType, std::string>
228  jointMaterials;
229 
231  private: sdf::ElementPtr modelSDF;
232 
234  private: int jointCounter;
235 
237  private: QAction *inspectAct;
238 
240  private: boost::recursive_mutex *updateMutex;
241 
243  private: rendering::VisualPtr selectedJoint;
244  };
246 
247 
250  class GAZEBO_VISIBLE JointData : public QObject
251  {
252  Q_OBJECT
253 
255  public: std::string name;
256 
259 
262 
265 
268 
271 
273  public: Ogre::BillboardSet *handles;
274 
277 
279  public: math::Vector3 axis[2];
280 
282  public: double lowerLimit[2];
283 
285  public: double upperLimit[2];
286 
288  public: math::Pose pose;
289 
291  public: bool dirty;
292 
295 
298  private slots: void OnApply();
299  };
301  }
302 }
303 #endif
math::Pose pose
Joint pose.
Definition: JointMaker.hh:288
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Generic description of a mouse event.
Definition: MouseEvent.hh:32
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:267
bool dirty
True if the joint visual needs update.
Definition: JointMaker.hh:291
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Fixed joint.
Definition: JointMaker.hh:68
std::string name
Name of the joint.
Definition: JointMaker.hh:255
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:276
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:294
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:264
Joint visualization.
Definition: JointMaker.hh:57
JointType
Definition: JointMaker.hh:63
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:273
Hinge2 joint.
Definition: JointMaker.hh:74
Screw joint.
Definition: JointMaker.hh:76
A class to inspect and modify joints.
Definition: JointInspector.hh:37
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:270
Slider joint.
Definition: JointMaker.hh:70
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:258
Universal joint.
Definition: JointMaker.hh:78
Hinge joint.
Definition: JointMaker.hh:72
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
rendering::VisualPtr hotspot
Visual of the hotspot
Definition: JointMaker.hh:261
Helper class to store joint data.
Definition: JointMaker.hh:250
none
Definition: JointMaker.hh:66