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 
69  // Forward declare private data.
70  class JointMakerPrivate;
71 
74 
77  class GZ_GUI_VISIBLE JointMaker : public QObject
78  {
79  Q_OBJECT
80 
83  public: enum JointType
84  {
102  JOINT_GEARBOX
103  };
104 
106  public: JointMaker();
107 
109  public: virtual ~JointMaker();
110 
112  public: void Reset();
113 
115  public: void EnableEventHandlers();
116 
118  public: void DisableEventHandlers();
119 
122  public: void AddJoint(const std::string &_type);
123 
126  public: void AddJoint(const JointType _type);
127 
132  public: JointData *CreateJoint(const rendering::VisualPtr &_parent,
133  const rendering::VisualPtr &_child);
134 
138  public: std::string CreateHotSpot(JointData *_joint);
139 
141  public: void Update();
142 
146  public: void RemoveJoint(const std::string &_jointName);
147 
150  public: void RemoveJointsByLink(const std::string &_linkName);
151 
156  public: std::vector<JointData *> JointDataByLink(
157  const std::string &_linkName) const;
158 
160  public: void GenerateSDF();
161 
164  public: sdf::ElementPtr SDF() const;
165 
169  public: static unsigned int JointAxisCount(
170  const JointMaker::JointType _type);
171 
175  public: static std::string TypeAsString(
176  const JointMaker::JointType _type);
177 
181  public: static JointType ConvertJointType(const std::string &_type);
182 
186  public: static std::string JointMaterial(const std::string &_type);
187 
192  public: JointMaker::JointType State() const;
193 
195  public: void Stop();
196 
199  public: unsigned int JointCount();
200 
205  public: void CreateJointFromSDF(sdf::ElementPtr _jointElem,
206  const std::string &_modelName = "");
207 
213  public: void AddScopedLinkName(const std::string &_name);
214 
217  public slots: void ShowJoints(const bool _show);
218 
222  public: void SetSelected(const std::string &_name, const bool selected);
223 
227  public: void SetSelected(const rendering::VisualPtr &_jointVis,
228  const bool selected);
229 
232  public: std::map<std::string, std::string> LinkList() const;
233 
237  public slots: void OnType(const int _typeInt);
238 
243  public slots: void SetAxis(const std::string &_axis,
244  const ignition::math::Vector3d &_value);
245 
249  public: void SetJointPose(const ignition::math::Pose3d &_pose);
250 
255  public: void SetParentLink(const std::string &_name);
256 
261  public: void SetChildLink(const std::string &_name);
262 
270  public: void SetLinksRelativePose(
271  const ignition::math::Pose3d &_pose, const bool _resetAll,
272  const int _resetAxis = -1);
273 
280  public: void AlignLinks(const bool _childToParent,
281  const std::string &_axis, const std::string &_mode,
282  const bool _reverse);
283 
285  public: void FinalizeCreation();
286 
290  private: bool OnMousePress(const common::MouseEvent &_event);
291 
295  private: bool OnMouseRelease(const common::MouseEvent &_event);
296 
300  private: bool OnMouseMove(const common::MouseEvent &_event);
301 
305  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
306 
310  private: bool OnKeyPress(const common::KeyEvent &_event);
311 
315  private: ignition::math::Vector3d LinkWorldCentroid(
316  const rendering::VisualPtr &_visual);
317 
320  private: void OpenInspector(const std::string &_name);
321 
325  private: std::string ScopedLinkName(const std::string &_name);
326 
329  private: void ShowContextMenu(const std::string &_joint);
330 
332  private: void DeselectAll();
333 
337  private: void OnSetSelectedEntity(const std::string &_name,
338  const std::string &_mode);
339 
344  private: void OnSetSelectedJoint(const std::string &_name,
345  const bool _selected);
346 
349  private: void OnLinkInserted(const std::string &_linkName);
350 
353  private: void OnLinkRemoved(const std::string &_linkName);
354 
359  private: JointData *CreateJointLine(const std::string &_name,
360  const rendering::VisualPtr &_parent);
361 
365  private: rendering::VisualPtr LinkVisualFromName(
366  const std::string &_name);
367 
372  private: bool SetParentLink(const rendering::VisualPtr &_parentLink);
373 
378  private: bool SetChildLink(const rendering::VisualPtr &_childLink);
379 
384  private: void SetVisualMoved(const rendering::VisualPtr &_vis,
385  const bool _moved);
386 
388  Q_SIGNALS: void JointAdded();
389 
392  Q_SIGNALS: void EmitLinkInserted(const std::string &_linkId);
393 
396  Q_SIGNALS: void EmitLinkRemoved(const std::string &_linkId);
397 
399  private slots: void OnOpenInspector();
400 
403  private slots: void OnDelete();
404 
406  public: static std::map<JointMaker::JointType, std::string> jointTypes;
407 
409  public: static std::vector<ignition::math::Vector3d> unitVectors;
410 
412  public: static std::map<JointMaker::JointType, std::string>
414 
417  private: std::unique_ptr<JointMakerPrivate> dataPtr;
418  };
420 
421 
424  class GZ_GUI_VISIBLE JointData : public QObject
425  {
426  Q_OBJECT
427 
429  public: void OpenInspector();
430 
433  public: void Update();
434 
436  public: void UpdateMsg();
437 
439  public: std::string name;
440 
443 
446 
449 
452 
455 
458  public: ignition::math::Pose3d parentPose;
459 
462  public: ignition::math::Pose3d childPose;
463 
466  public: ignition::math::Vector3d childScale;
467 
470 
472  public: Ogre::BillboardSet *handles;
473 
476 
478  public: std::vector<ignition::math::Vector3d> axes;
479 
481  public: bool dirty;
482 
485 
488 
490  private slots: void OnOpenInspector();
491 
494  private slots: void OnApply();
495  };
497  }
498 }
499 #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:100
Definition: JointMaker.hh:46
Forward declarations for the common classes.
Definition: Animation.hh:33
none
Definition: JointMaker.hh:86
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:451
static std::vector< ignition::math::Vector3d > unitVectors
Constant vector containing [UnitX, UnitY, UnitZ].
Definition: JointMaker.hh:409
Screw joint.
Definition: JointMaker.hh:96
Hinge joint.
Definition: JointMaker.hh:92
Fixed joint.
Definition: JointMaker.hh:88
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:108
static std::map< JointMaker::JointType, std::string > jointMaterials
A map of joint type to its corresponding material.
Definition: JointMaker.hh:413
msgs::JointPtr jointMsg
Msg containing joint data.
Definition: JointMaker.hh:484
Slider joint.
Definition: JointMaker.hh:90
ignition::math::Pose3d parentPose
Definition: JointMaker.hh:458
Hinge2 joint.
Definition: JointMaker.hh:94
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:472
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:77
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:487
Universal joint.
Definition: JointMaker.hh:98
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:469
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:475
rendering::JointVisualPtr jointVisual
Joint visual.
Definition: JointMaker.hh:445
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:478
ignition::math::Pose3d childPose
Definition: JointMaker.hh:462
Definition: JointMaker.hh:41
std::string name
Name of the joint.
Definition: JointMaker.hh:439
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:454
rendering::VisualPtr hotspot
Visual of the hotspot
Definition: JointMaker.hh:448
static std::map< JointMaker::JointType, std::string > jointTypes
A map of joint type to its string value.
Definition: JointMaker.hh:406
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:442
bool dirty
True if the joint needs update.
Definition: JointMaker.hh:481
ignition::math::Vector3d childScale
Definition: JointMaker.hh:466
JointType
Definition: JointMaker.hh:83
Helper class to store joint data.
Definition: JointMaker.hh:424