JointMaker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
18 #ifndef _GAZEBO_GUI_JOINTMAKER_HH_
19 #define _GAZEBO_GUI_JOINTMAKER_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <ignition/math/Pose3.hh>
27 #include <ignition/math/Vector3.hh>
28 
29 #include <sdf/sdf.hh>
30 
31 #include "gazebo/gui/qt.h"
32 
33 #include "gazebo/msgs/msgs.hh"
34 
36 
37 #include "gazebo/util/system.hh"
38 
39 namespace Ogre
40 {
41  class BillboardSet;
42 }
43 
44 namespace boost
45 {
46  class recursive_mutex;
47 }
48 
49 namespace gazebo
50 {
51  namespace common
52  {
53  class KeyEvent;
54  class MouseEvent;
55  }
56 
57  namespace rendering
58  {
59  class DynamicLines;
60  }
61 
62  namespace gui
63  {
64  class JointData;
65  class JointInspector;
66  class MEUserCmdManager;
67 
68  // Forward declare private data.
69  class JointMakerPrivate;
70 
73 
76  class GZ_GUI_VISIBLE JointMaker : public QObject
77  {
78  Q_OBJECT
79 
82  public: enum JointType
83  {
101  JOINT_GEARBOX
102  };
103 
105  public: JointMaker();
106 
108  public: virtual ~JointMaker();
109 
111  public: void Reset();
112 
114  public: void EnableEventHandlers();
115 
117  public: void DisableEventHandlers();
118 
121  public: void AddJoint(const std::string &_type);
122 
125  public: void AddJoint(const JointType _type);
126 
131  public: JointData *CreateJoint(const rendering::VisualPtr &_parent,
132  const rendering::VisualPtr &_child);
133 
137  public: std::string CreateHotSpot(JointData *_joint);
138 
140  public: void Update();
141 
145  public: void RemoveJoint(const std::string &_jointName);
146 
149  public: void RemoveJointByUser(const std::string &_jointName);
150 
153  public: void RemoveJointsByLink(const std::string &_linkName);
154 
159  public: std::vector<JointData *> JointDataByLink(
160  const std::string &_linkName) const;
161 
163  public: void GenerateSDF();
164 
167  public: sdf::ElementPtr SDF() const;
168 
172  public: static unsigned int JointAxisCount(
173  const JointMaker::JointType _type);
174 
178  public: static std::string TypeAsString(
179  const JointMaker::JointType _type);
180 
184  public: static JointType ConvertJointType(const std::string &_type);
185 
189  public: static std::string JointMaterial(const std::string &_type);
190 
195  public: JointMaker::JointType State() const;
196 
198  public: void Stop();
199 
202  public: unsigned int JointCount();
203 
208  public: void CreateJointFromSDF(sdf::ElementPtr _jointElem,
209  const std::string &_modelName = "");
210 
216  public: void AddScopedLinkName(const std::string &_name);
217 
220  public slots: void ShowJoints(const bool _show);
221 
225  public: void SetSelected(const std::string &_name, const bool selected);
226 
230  public: void SetSelected(const rendering::VisualPtr &_jointVis,
231  const bool selected);
232 
235  public: std::map<std::string, std::string> LinkList() const;
236 
240  public slots: void OnType(const int _typeInt);
241 
246  public slots: void SetAxis(const std::string &_axis,
247  const ignition::math::Vector3d &_value);
248 
252  public: void SetJointPose(const ignition::math::Pose3d &_pose);
253 
258  public: void SetParentLink(const std::string &_name);
259 
264  public: void SetChildLink(const std::string &_name);
265 
273  public: void SetLinksRelativePose(
274  const ignition::math::Pose3d &_pose, const bool _resetAll,
275  const int _resetAxis = -1);
276 
283  public: void AlignLinks(const bool _childToParent,
284  const std::string &_axis, const std::string &_mode,
285  const bool _reverse);
286 
288  public: void FinalizeCreation();
289 
292  public: void SetUserCmdManager(MEUserCmdManager *_manager);
293 
297  private: bool OnMousePress(const common::MouseEvent &_event);
298 
302  private: bool OnMouseRelease(const common::MouseEvent &_event);
303 
307  private: bool OnMouseMove(const common::MouseEvent &_event);
308 
312  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
313 
317  private: bool OnKeyPress(const common::KeyEvent &_event);
318 
321  private: void OpenInspector(const std::string &_name);
322 
326  private: std::string ScopedLinkName(const std::string &_name);
327 
330  private: void ShowContextMenu(const std::string &_joint);
331 
333  private: void DeselectAll();
334 
338  private: void OnSetSelectedEntity(const std::string &_name,
339  const std::string &_mode);
340 
345  private: void OnSetSelectedJoint(const std::string &_name,
346  const bool _selected);
347 
350  private: void OnLinkInserted(const std::string &_linkName);
351 
354  private: void OnLinkRemoved(const std::string &_linkName);
355 
360  private: JointData *CreateJointLine(const std::string &_name,
361  const rendering::VisualPtr &_parent);
362 
366  private: rendering::VisualPtr LinkVisualFromName(
367  const std::string &_name);
368 
373  private: bool SetParentLink(const rendering::VisualPtr &_parentLink);
374 
379  private: bool SetChildLink(const rendering::VisualPtr &_childLink);
380 
385  private: void SetVisualMoved(const rendering::VisualPtr &_vis,
386  const bool _moved);
387 
389  Q_SIGNALS: void JointAdded();
390 
393  Q_SIGNALS: void EmitLinkInserted(const std::string &_linkId);
394 
397  Q_SIGNALS: void EmitLinkRemoved(const std::string &_linkId);
398 
400  private slots: void OnOpenInspector();
401 
404  private slots: void OnDelete();
405 
407  public: static std::map<JointMaker::JointType, std::string> jointTypes;
408 
410  public: static std::vector<ignition::math::Vector3d> unitVectors;
411 
413  public: static std::map<JointMaker::JointType, std::string>
415 
418  private: std::unique_ptr<JointMakerPrivate> dataPtr;
419  };
421 
422 
425  class GZ_GUI_VISIBLE JointData : public QObject
426  {
427  Q_OBJECT
428 
430  public: void OpenInspector();
431 
434  public: void Update();
435 
437  public: void UpdateMsg();
438 
440  public: std::string name;
441 
444 
447 
450 
453 
456 
459  public: ignition::math::Pose3d parentPose;
460 
463  public: ignition::math::Pose3d childPose;
464 
467  public: ignition::math::Vector3d childScale;
468 
471 
473  public: Ogre::BillboardSet *handles;
474 
477 
479  public: std::vector<ignition::math::Vector3d> axes;
480 
482  public: bool dirty;
483 
486 
489 
491  private slots: void OnOpenInspector();
492 
495  private slots: void OnApply();
496  };
498  }
499 }
500 #endif
Class which manages user commands in the model editor.
Definition: MEUserCmdManager.hh:144
static std::string TypeAsString(const JointMaker::JointType _type)
Get the joint type in string.
void Update()
Update callback on PreRender.
void SetChildLink(const std::string &_name)
A new child link for the joint being created has been chosen.
Definition: JointMaker.hh:39
static JointType ConvertJointType(const std::string &_type)
Convert a joint type string to enum.
void Update()
Update this joint data.
rendering::JointVisualPtr jointVisual
Joint visual.
Definition: JointMaker.hh:446
void AlignLinks(const bool _childToParent, const std::string &_axis, const std::string &_mode, const bool _reverse)
Align the parent and child links of the joint being created.
std::string name
Name of the joint.
Definition: JointMaker.hh:440
@ JOINT_FIXED
Fixed joint.
Definition: JointMaker.hh:87
Forward declarations for the common classes.
Definition: Animation.hh:26
bool dirty
True if the joint needs update.
Definition: JointMaker.hh:482
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:76
static std::map< JointMaker::JointType, std::string > jointTypes
A map of joint type to its string value.
Definition: JointMaker.hh:407
void SetAxis(const std::string &_axis, const ignition::math::Vector3d &_value)
A new axis for the joint being created has been chosen.
void RemoveJoint(const std::string &_jointName)
Remove joint by name.
@ JOINT_SCREW
Screw joint.
Definition: JointMaker.hh:95
void EmitLinkRemoved(const std::string &_linkId)
Qt signal to notify that a link has been removed.
void DisableEventHandlers()
Disable the mouse and key event handlers for the joint maker.
void SetJointPose(const ignition::math::Pose3d &_pose)
A new joint pose for the joint being created has been chosen.
@ JOINT_BALL
Ball joint.
Definition: JointMaker.hh:99
void EmitLinkInserted(const std::string &_linkId)
Qt signal to notify that a link has been inserted.
common
Definition: FuelModelDatabase.hh:37
JointType
Definition: JointMaker.hh:82
void CreateJointFromSDF(sdf::ElementPtr _jointElem, const std::string &_modelName="")
Create a joint from SDF.
static unsigned int JointAxisCount(const JointMaker::JointType _type)
Get the axis count for joint type.
void ShowJoints(const bool _show)
Qt Callback to show / hide joint visuals.
Definition: JointMaker.hh:44
GAZEBO_VISIBLE msgs::Joint::Type ConvertJointType(const std::string &_str)
Convert a string to a msgs::Joint::Type enum.
void RemoveJointsByLink(const std::string &_linkName)
Remove all joints connected to link.
@ JOINT_NONE
none
Definition: JointMaker.hh:85
Class for drawing lines that can change.
Definition: DynamicLines.hh:42
std::map< std::string, std::string > LinkList() const
Get the list of links.
@ JOINT_HINGE
Hinge joint.
Definition: JointMaker.hh:91
@ JOINT_SLIDER
Slider joint.
Definition: JointMaker.hh:89
void OnType(const int _typeInt)
A new type for the joint being created has been chosen.
void Stop()
Stop the process of adding joint to the model.
void AddScopedLinkName(const std::string &_name)
Add a scoped link name.
rendering
Definition: RenderEngine.hh:31
Helper class to store joint data.
Definition: JointMaker.hh:425
static std::string JointMaterial(const std::string &_type)
Get the material for the joint type.
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:470
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:473
@ JOINT_HINGE2
Hinge2 joint.
Definition: JointMaker.hh:93
void SetLinksRelativePose(const ignition::math::Pose3d &_pose, const bool _resetAll, const int _resetAxis=-1)
A new relative pose for the child link of the joint being created hass been chosen.
std::shared_ptr< JointVisual > JointVisualPtr
Definition: RenderTypes.hh:142
JointMaker()
Constructor.
virtual ~JointMaker()
Destructor.
void UpdateMsg()
Update the joint message based on the other fields.
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:476
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
@ JOINT_UNIVERSAL
Universal joint.
Definition: JointMaker.hh:97
std::string CreateHotSpot(JointData *_joint)
Helper method to create hotspot visual for mouse interaction.
void EnableEventHandlers()
Enable the mouse and key event handlers for the joint maker.
JointMaker::JointType State() const
Get state.
void FinalizeCreation()
Finalize joint creation.
A class to inspect and modify joints.
Definition: JointInspector.hh:42
void AddJoint(const std::string &_type)
Add a joint.
@ JOINT_GEARBOX
Gearbox joint.
Definition: JointMaker.hh:101
msgs::JointPtr jointMsg
Msg containing joint data.
Definition: JointMaker.hh:485
ignition::math::Vector3d childScale
Definition: JointMaker.hh:467
gui
Definition: KeyEventHandler.hh:29
void SetUserCmdManager(MEUserCmdManager *_manager)
Set the user command manager variable.
void SetParentLink(const std::string &_name)
A new parent link for the joint being created has been chosen.
void GenerateSDF()
Generate SDF for all joints.
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
rendering::VisualPtr hotspot
\brieft Visual of the hotspot
Definition: JointMaker.hh:449
ignition::math::Pose3d childPose
Definition: JointMaker.hh:463
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:443
std::vector< JointData * > JointDataByLink(const std::string &_linkName) const
Get a vector containing data for all joints connected to the given link.
void Reset()
Reset the joint maker;.
JointData * CreateJoint(const rendering::VisualPtr &_parent, const rendering::VisualPtr &_child)
Create a joint with parent and child.
std::vector< ignition::math::Vector3d > axes
Last known axes values.
Definition: JointMaker.hh:479
sdf::ElementPtr SDF() const
Get model SDF element containing all joints.
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:488
void RemoveJointByUser(const std::string &_jointName)
Remove joint by name and register user command.
ignition::math::Pose3d parentPose
Definition: JointMaker.hh:459
void OpenInspector()
Open the joint inspector.
unsigned int JointCount()
Get the number of joints added.
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:455
static std::vector< ignition::math::Vector3d > unitVectors
Constant vector containing [UnitX, UnitY, UnitZ].
Definition: JointMaker.hh:410
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:452
void SetSelected(const std::string &_name, const bool selected)
Set the select state of a joint.
static std::map< JointMaker::JointType, std::string > jointMaterials
A map of joint type to its corresponding material.
Definition: JointMaker.hh:414
Generic description of a mouse event.
Definition: MouseEvent.hh:35
void JointAdded()
Qt signal when the joint creation process has ended.