JointMaker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2016 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 
32 
33 #include "gazebo/gui/qt.h"
34 
35 #include "gazebo/msgs/msgs.hh"
36 
38 
39 #include "gazebo/util/system.hh"
40 
41 namespace Ogre
42 {
43  class BillboardSet;
44 }
45 
46 namespace boost
47 {
48  class recursive_mutex;
49 }
50 
51 namespace gazebo
52 {
53  namespace common
54  {
55  class KeyEvent;
56  class MouseEvent;
57  }
58 
59  namespace rendering
60  {
61  class DynamicLines;
62  }
63 
64  namespace gui
65  {
66  class JointData;
67  class JointInspector;
68  class MEUserCmdManager;
69 
70  // Forward declare private data.
71  class JointMakerPrivate;
72 
75 
78  class GZ_GUI_VISIBLE JointMaker : public QObject
79  {
80  Q_OBJECT
81 
84  public: enum JointType
85  {
103  JOINT_GEARBOX
104  };
105 
107  public: JointMaker();
108 
110  public: virtual ~JointMaker();
111 
113  public: void Reset();
114 
116  public: void EnableEventHandlers();
117 
119  public: void DisableEventHandlers();
120 
123  public: void AddJoint(const std::string &_type);
124 
127  public: void AddJoint(const JointType _type);
128 
133  public: JointData *CreateJoint(const rendering::VisualPtr &_parent,
134  const rendering::VisualPtr &_child);
135 
139  public: std::string CreateHotSpot(JointData *_joint);
140 
142  public: void Update();
143 
147  public: void RemoveJoint(const std::string &_jointName);
148 
151  public: void RemoveJointByUser(const std::string &_jointName);
152 
155  public: void RemoveJointsByLink(const std::string &_linkName);
156 
161  public: std::vector<JointData *> JointDataByLink(
162  const std::string &_linkName) const;
163 
165  public: void GenerateSDF();
166 
169  public: sdf::ElementPtr SDF() const;
170 
174  public: static unsigned int JointAxisCount(
175  const JointMaker::JointType _type);
176 
180  public: static std::string TypeAsString(
181  const JointMaker::JointType _type);
182 
186  public: static JointType ConvertJointType(const std::string &_type);
187 
191  public: static std::string JointMaterial(const std::string &_type);
192 
197  public: JointMaker::JointType State() const;
198 
200  public: void Stop();
201 
204  public: unsigned int JointCount();
205 
210  public: void CreateJointFromSDF(sdf::ElementPtr _jointElem,
211  const std::string &_modelName = "");
212 
218  public: void AddScopedLinkName(const std::string &_name);
219 
222  public slots: void ShowJoints(const bool _show);
223 
227  public: void SetSelected(const std::string &_name, const bool selected);
228 
232  public: void SetSelected(const rendering::VisualPtr &_jointVis,
233  const bool selected);
234 
237  public: std::map<std::string, std::string> LinkList() const;
238 
242  public slots: void OnType(const int _typeInt);
243 
248  public slots: void SetAxis(const std::string &_axis,
249  const ignition::math::Vector3d &_value);
250 
254  public: void SetJointPose(const ignition::math::Pose3d &_pose);
255 
260  public: void SetParentLink(const std::string &_name);
261 
266  public: void SetChildLink(const std::string &_name);
267 
275  public: void SetLinksRelativePose(
276  const ignition::math::Pose3d &_pose, const bool _resetAll,
277  const int _resetAxis = -1);
278 
285  public: void AlignLinks(const bool _childToParent,
286  const std::string &_axis, const std::string &_mode,
287  const bool _reverse);
288 
290  public: void FinalizeCreation();
291 
294  public: void SetUserCmdManager(MEUserCmdManager *_manager);
295 
299  private: bool OnMousePress(const common::MouseEvent &_event);
300 
304  private: bool OnMouseRelease(const common::MouseEvent &_event);
305 
309  private: bool OnMouseMove(const common::MouseEvent &_event);
310 
314  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
315 
319  private: bool OnKeyPress(const common::KeyEvent &_event);
320 
323  private: void OpenInspector(const std::string &_name);
324 
328  private: std::string ScopedLinkName(const std::string &_name);
329 
332  private: void ShowContextMenu(const std::string &_joint);
333 
335  private: void DeselectAll();
336 
340  private: void OnSetSelectedEntity(const std::string &_name,
341  const std::string &_mode);
342 
347  private: void OnSetSelectedJoint(const std::string &_name,
348  const bool _selected);
349 
352  private: void OnLinkInserted(const std::string &_linkName);
353 
356  private: void OnLinkRemoved(const std::string &_linkName);
357 
362  private: JointData *CreateJointLine(const std::string &_name,
363  const rendering::VisualPtr &_parent);
364 
368  private: rendering::VisualPtr LinkVisualFromName(
369  const std::string &_name);
370 
375  private: bool SetParentLink(const rendering::VisualPtr &_parentLink);
376 
381  private: bool SetChildLink(const rendering::VisualPtr &_childLink);
382 
387  private: void SetVisualMoved(const rendering::VisualPtr &_vis,
388  const bool _moved);
389 
391  Q_SIGNALS: void JointAdded();
392 
395  Q_SIGNALS: void EmitLinkInserted(const std::string &_linkId);
396 
399  Q_SIGNALS: void EmitLinkRemoved(const std::string &_linkId);
400 
402  private slots: void OnOpenInspector();
403 
406  private slots: void OnDelete();
407 
409  public: static std::map<JointMaker::JointType, std::string> jointTypes;
410 
412  public: static std::vector<ignition::math::Vector3d> unitVectors;
413 
415  public: static std::map<JointMaker::JointType, std::string>
417 
420  private: std::unique_ptr<JointMakerPrivate> dataPtr;
421  };
423 
424 
427  class GZ_GUI_VISIBLE JointData : public QObject
428  {
429  Q_OBJECT
430 
432  public: void OpenInspector();
433 
436  public: void Update();
437 
439  public: void UpdateMsg();
440 
442  public: std::string name;
443 
446 
449 
452 
455 
458 
461  public: ignition::math::Pose3d parentPose;
462 
465  public: ignition::math::Pose3d childPose;
466 
469  public: ignition::math::Vector3d childScale;
470 
473 
475  public: Ogre::BillboardSet *handles;
476 
479 
481  public: std::vector<ignition::math::Vector3d> axes;
482 
484  public: bool dirty;
485 
488 
491 
493  private slots: void OnOpenInspector();
494 
497  private slots: void OnApply();
498  };
500  }
501 }
502 #endif
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Ball joint.
Definition: JointMaker.hh:101
none
Definition: JointMaker.hh:87
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:454
static std::vector< ignition::math::Vector3d > unitVectors
Constant vector containing [UnitX, UnitY, UnitZ].
Definition: JointMaker.hh:412
Screw joint.
Definition: JointMaker.hh:97
Hinge joint.
Definition: JointMaker.hh:93
Fixed joint.
Definition: JointMaker.hh:89
GAZEBO_VISIBLE msgs::Joint::Type ConvertJointType(const std::string &_str)
Convert a string to a msgs::Joint::Type enum.
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
static std::map< JointMaker::JointType, std::string > jointMaterials
A map of joint type to its corresponding material.
Definition: JointMaker.hh:416
msgs::JointPtr jointMsg
Msg containing joint data.
Definition: JointMaker.hh:487
Slider joint.
Definition: JointMaker.hh:91
ignition::math::Pose3d parentPose
Definition: JointMaker.hh:461
Hinge2 joint.
Definition: JointMaker.hh:95
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:475
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:78
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:490
Universal joint.
Definition: JointMaker.hh:99
Class which manages user commands in the model editor.
Definition: MEUserCmdManager.hh:114
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:472
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:478
rendering::JointVisualPtr jointVisual
Joint visual.
Definition: JointMaker.hh:448
std::shared_ptr< JointVisual > JointVisualPtr
Definition: RenderTypes.hh:140
A class to inspect and modify joints.
Definition: JointInspector.hh:42
std::vector< ignition::math::Vector3d > axes
Last known axes values.
Definition: JointMaker.hh:481
ignition::math::Pose3d childPose
Definition: JointMaker.hh:465
std::string name
Name of the joint.
Definition: JointMaker.hh:442
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:457
rendering::VisualPtr hotspot
Visual of the hotspot
Definition: JointMaker.hh:451
static std::map< JointMaker::JointType, std::string > jointTypes
A map of joint type to its string value.
Definition: JointMaker.hh:409
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:445
bool dirty
True if the joint needs update.
Definition: JointMaker.hh:484
ignition::math::Vector3d childScale
Definition: JointMaker.hh:469
JointType
Definition: JointMaker.hh:84
Helper class to store joint data.
Definition: JointMaker.hh:427