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 _GAZEBO_JOINTMAKER_HH_
19 #define _GAZEBO_JOINTMAKER_HH_
20 
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include <sdf/sdf.hh>
26 
30 #include "gazebo/msgs/msgs.hh"
31 #include "gazebo/math/Pose.hh"
33 #include "gazebo/gui/qt.h"
34 #include "gazebo/util/system.hh"
35 
36 namespace Ogre
37 {
38  class BillboardSet;
39 }
40 
41 namespace boost
42 {
43  class recursive_mutex;
44 }
45 
46 namespace gazebo
47 {
48  namespace gui
49  {
50  class JointData;
51  class JointInspector;
52 
55 
58  class GZ_GUI_MODEL_VISIBLE JointMaker : public QObject
59  {
60  Q_OBJECT
61 
64  public: enum JointType
65  {
81  JOINT_BALL
82  };
83 
85  public: JointMaker();
86 
88  public: virtual ~JointMaker();
89 
91  public: void Reset();
92 
94  public: void EnableEventHandlers();
95 
97  public: void DisableEventHandlers();
98 
101  public: void AddJoint(const std::string &_type);
102 
105  public: void AddJoint(JointType _type);
106 
111  public: JointData *CreateJoint(rendering::VisualPtr _parent,
112  rendering::VisualPtr _child);
113 
116  public: void CreateHotSpot(JointData *_joint);
117 
119  public: void Update();
120 
123  public: void RemoveJoint(const std::string &_jointName);
124 
127  public: void RemoveJointsByLink(const std::string &_linkName);
128 
133  public: std::vector<JointData *> GetJointDataByLink(
134  const std::string &_linkName) const;
135 
137  public: void GenerateSDF();
138 
140  public: sdf::ElementPtr GetSDF() const;
141 
144  public: static unsigned int GetJointAxisCount(
145  JointMaker::JointType _type);
146 
150  public: static std::string GetTypeAsString(JointMaker::JointType _type);
151 
155  public: static JointType ConvertJointType(const std::string &_type);
156 
160  public: JointMaker::JointType GetState() const;
161 
163  public: void Stop();
164 
167  public: unsigned int GetJointCount();
168 
173  public: void CreateJointFromSDF(sdf::ElementPtr _jointElem,
174  const std::string &_modelName = "");
175 
181  public: void AddScopedLinkName(const std::string &_name);
182 
185  public slots: void ShowJoints(bool _show);
186 
190  public: void SetSelected(const std::string &_name, const bool selected);
191 
195  public: void SetSelected(rendering::VisualPtr _jointVis,
196  const bool selected);
197 
201  private: bool OnMousePress(const common::MouseEvent &_event);
202 
206  private: bool OnMouseRelease(const common::MouseEvent &_event);
207 
211  private: bool OnMouseMove(const common::MouseEvent &_event);
212 
216  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
217 
221  private: bool OnKeyPress(const common::KeyEvent &_event);
222 
226  private: math::Vector3 GetLinkWorldCentroid(
227  const rendering::VisualPtr _visual);
228 
231  private: void OpenInspector(const std::string &_name);
232 
236  private: std::string GetScopedLinkName(const std::string &_name);
237 
240  private: void ShowContextMenu(const std::string &_joint);
241 
243  private: void DeselectAll();
244 
248  private: void OnSetSelectedEntity(const std::string &_name,
249  const std::string &_mode);
250 
255  private: void OnSetSelectedJoint(const std::string &_name,
256  const bool _selected);
257 
262  private: JointData *CreateJointLine(const std::string &_name,
263  rendering::VisualPtr _parent);
264 
266  Q_SIGNALS: void JointAdded();
267 
269  private slots: void OnOpenInspector();
270 
273  private slots: void OnDelete();
274 
276  private: std::vector<ignition::math::Vector3d> unitVectors;
277 
279  private: JointMaker::JointType jointType;
280 
282  private: rendering::VisualPtr hoverVis;
283 
285  private: rendering::VisualPtr prevHoverVis;
286 
288  private: rendering::VisualPtr selectedVis;
289 
291  private: std::string inspectName;
292 
294  private: std::map<std::string, JointData *> joints;
295 
297  private: JointData *mouseJoint;
298 
300  private: std::vector<event::ConnectionPtr> connections;
301 
303  private: bool newJointCreated;
304 
306  private: std::map<JointMaker::JointType, std::string>
307  jointMaterials;
308 
310  private: sdf::ElementPtr modelSDF;
311 
313  private: int jointCounter;
314 
316  private: QAction *inspectAct;
317 
319  private: boost::recursive_mutex *updateMutex;
320 
322  private: std::vector<rendering::VisualPtr> selectedJoints;
323 
325  private: std::vector<std::string> scopedLinkedNames;
326 
328  private: static std::map<JointMaker::JointType, std::string> jointTypes;
329  };
331 
332 
335  class GZ_GUI_MODEL_VISIBLE JointData : public QObject
336  {
337  Q_OBJECT
338 
340  public: std::string name;
341 
344 
347 
350 
353 
356 
360 
364 
368 
371 
373  public: Ogre::BillboardSet *handles;
374 
377 
379  public: bool dirty;
380 
383 
386 
388  public: void OpenInspector();
389 
391  private slots: void OnOpenInspector();
392 
395  private slots: void OnApply();
396  };
398  }
399 }
400 #endif
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:355
bool dirty
True if the joint visual needs update.
Definition: JointMaker.hh:379
math::Pose childPose
Definition: JointMaker.hh:363
GAZEBO_VISIBLE msgs::Joint::Type ConvertJointType(const std::string &_str)
Convert a string to a msgs::Joint::Type enum.
math::Vector3 childScale
Definition: JointMaker.hh:367
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Fixed joint.
Definition: JointMaker.hh:69
std::string name
Name of the joint.
Definition: JointMaker.hh:340
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:376
boost::shared_ptr< JointVisual > JointVisualPtr
Definition: RenderTypes.hh:131
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:385
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:352
math::Pose parentPose
Definition: JointMaker.hh:359
Joint visualization.
Definition: JointMaker.hh:58
msgs::JointPtr jointMsg
Msg containing joint data.
Definition: JointMaker.hh:382
JointType
Definition: JointMaker.hh:64
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:373
Hinge2 joint.
Definition: JointMaker.hh:75
Screw joint.
Definition: JointMaker.hh:77
A class to inspect and modify joints.
Definition: JointInspector.hh:38
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:370
Slider joint.
Definition: JointMaker.hh:71
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:100
rendering::JointVisualPtr jointVisual
Joint visual.
Definition: JointMaker.hh:346
#define GZ_GUI_MODEL_VISIBLE
Definition: system.hh:418
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:343
Universal joint.
Definition: JointMaker.hh:79
Hinge joint.
Definition: JointMaker.hh:73
rendering::VisualPtr hotspot
Visual of the hotspot
Definition: JointMaker.hh:349
Helper class to store joint data.
Definition: JointMaker.hh:335
none
Definition: JointMaker.hh:67