##

JointMaker.hh
Go to the documentation of this file.
/*
* Copyright (C) 2014 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GAZEBO_GUI_JOINTMAKER_HH_
#define _GAZEBO_GUI_JOINTMAKER_HH_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Vector3.hh>
#include <sdf/sdf.hh>
#include "gazebo/gui/qt.h"
#include "gazebo/msgs/msgs.hh"
#include "gazebo/rendering/RenderTypes.hh"
#include "gazebo/util/system.hh"
namespace Ogre
{
class BillboardSet;
}
namespace boost
{
class recursive_mutex;
}
namespace gazebo
{
namespace common
{
class KeyEvent;
class MouseEvent;
}
namespace rendering
{
class DynamicLines;
}
namespace gui
{
class JointData;
class JointInspector;
class MEUserCmdManager;
// Forward declare private data.
class JointMakerPrivate;
class GZ_GUI_VISIBLE JointMaker : public QObject
{
Q_OBJECT
public: enum JointType
{
JOINT_NONE,
JOINT_FIXED,
JOINT_SLIDER,
JOINT_HINGE,
JOINT_HINGE2,
JOINT_SCREW,
JOINT_UNIVERSAL,
JOINT_BALL,
JOINT_GEARBOX
};
public: JointMaker();
public: virtual ~JointMaker();
public: void Reset();
public: void EnableEventHandlers();
public: void DisableEventHandlers();
public: void AddJoint(const std::string &_type);
public: void AddJoint(const JointType _type);
public: JointData *CreateJoint(const rendering::VisualPtr &_parent,
const rendering::VisualPtr &_child);
public: std::string CreateHotSpot(JointData *_joint);
public: void Update();
public: void RemoveJoint(const std::string &_jointName);
public: void RemoveJointByUser(const std::string &_jointName);
public: void RemoveJointsByLink(const std::string &_linkName);
public: std::vector<JointData *> JointDataByLink(
const std::string &_linkName) const;
public: void GenerateSDF();
public: sdf::ElementPtr SDF() const;
public: static unsigned int JointAxisCount(
const JointMaker::JointType _type);
public: static std::string TypeAsString(
const JointMaker::JointType _type);
public: static JointType ConvertJointType(const std::string &_type);
public: static std::string JointMaterial(const std::string &_type);
public: JointMaker::JointType State() const;
public: void Stop();
public: unsigned int JointCount();
public: void CreateJointFromSDF(sdf::ElementPtr _jointElem,
const std::string &_modelName = "");
public: void AddScopedLinkName(const std::string &_name);
public slots: void ShowJoints(const bool _show);
public: void SetSelected(const std::string &_name, const bool selected);
public: void SetSelected(const rendering::VisualPtr &_jointVis,
const bool selected);
public: std::map<std::string, std::string> LinkList() const;
public slots: void OnType(const int _typeInt);
public slots: void SetAxis(const std::string &_axis,
const ignition::math::Vector3d &_value);
public: void SetJointPose(const ignition::math::Pose3d &_pose);
public: void SetParentLink(const std::string &_name);
public: void SetChildLink(const std::string &_name);
public: void SetLinksRelativePose(
const ignition::math::Pose3d &_pose, const bool _resetAll,
const int _resetAxis = -1);
public: void AlignLinks(const bool _childToParent,
const std::string &_axis, const std::string &_mode,
const bool _reverse);
public: void FinalizeCreation();
public: void SetUserCmdManager(MEUserCmdManager *_manager);
private: bool OnMousePress(const common::MouseEvent &_event);
private: bool OnMouseRelease(const common::MouseEvent &_event);
private: bool OnMouseMove(const common::MouseEvent &_event);
private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
private: bool OnKeyPress(const common::KeyEvent &_event);
private: void OpenInspector(const std::string &_name);
private: std::string ScopedLinkName(const std::string &_name);
private: void ShowContextMenu(const std::string &_joint);
private: void DeselectAll();
private: void OnSetSelectedEntity(const std::string &_name,
const std::string &_mode);
private: void OnSetSelectedJoint(const std::string &_name,
const bool _selected);
private: void OnLinkInserted(const std::string &_linkName);
private: void OnLinkRemoved(const std::string &_linkName);
private: JointData *CreateJointLine(const std::string &_name,
const rendering::VisualPtr &_parent);
private: rendering::VisualPtr LinkVisualFromName(
const std::string &_name);
private: bool SetParentLink(const rendering::VisualPtr &_parentLink);
private: bool SetChildLink(const rendering::VisualPtr &_childLink);
private: void SetVisualMoved(const rendering::VisualPtr &_vis,
const bool _moved);
Q_SIGNALS: void JointAdded();
Q_SIGNALS: void EmitLinkInserted(const std::string &_linkId);
Q_SIGNALS: void EmitLinkRemoved(const std::string &_linkId);
private slots: void OnOpenInspector();
private slots: void OnDelete();
public: static std::map<JointMaker::JointType, std::string> jointTypes;
public: static std::vector<ignition::math::Vector3d> unitVectors;
public: static std::map<JointMaker::JointType, std::string>
jointMaterials;
private: std::unique_ptr<JointMakerPrivate> dataPtr;
};
class GZ_GUI_VISIBLE JointData : public QObject
{
Q_OBJECT
public: void OpenInspector();
public: void Update();
public: void UpdateMsg();
public: std::string name;
public: rendering::VisualPtr visual;
public: rendering::JointVisualPtr jointVisual;
public: rendering::VisualPtr hotspot;
public: rendering::VisualPtr parent;
public: rendering::VisualPtr child;
public: ignition::math::Pose3d parentPose;
public: ignition::math::Pose3d childPose;
public: ignition::math::Vector3d childScale;
public: rendering::DynamicLines *line;
public: Ogre::BillboardSet *handles;
public: JointMaker::JointType type;
public: std::vector<ignition::math::Vector3d> axes;
public: bool dirty;
public: msgs::JointPtr jointMsg;
public: JointInspector *inspector;
private slots: void OnOpenInspector();
private slots: void OnApply();
};
}
}
#endif
gazebo::gui::MEUserCmdManager
Class which manages user commands in the model editor.
Definition: MEUserCmdManager.hh:144
gazebo::gui::JointMaker::TypeAsString
static std::string TypeAsString(const JointMaker::JointType _type)
Get the joint type in string.
gazebo::gui::JointMaker::Update
void Update()
Update callback on PreRender.
gazebo::gui::JointMaker::SetChildLink
void SetChildLink(const std::string &_name)
A new child link for the joint being created has been chosen.
Ogre
Definition: JointMaker.hh:39
gazebo::gui::JointMaker::ConvertJointType
static JointType ConvertJointType(const std::string &_type)
Convert a joint type string to enum.
gazebo::gui::JointData::Update
void Update()
Update this joint data.
gazebo::gui::JointData::jointVisual
rendering::JointVisualPtr jointVisual
Joint visual.
Definition: JointMaker.hh:446
gazebo::gui::JointMaker::AlignLinks
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.
gazebo::gui::JointData::name
std::string name
Name of the joint.
Definition: JointMaker.hh:440
gazebo::gui::JointMaker::JOINT_FIXED
Fixed joint.
Definition: JointMaker.hh:87
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
qt.h
gazebo::gui::JointData::dirty
bool dirty
True if the joint needs update.
Definition: JointMaker.hh:482
gazebo::gui::JointMaker
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:76
gazebo::gui::JointMaker::jointTypes
static std::map< JointMaker::JointType, std::string > jointTypes
A map of joint type to its string value.
Definition: JointMaker.hh:407
gazebo::gui::JointMaker::SetAxis
void SetAxis(const std::string &_axis, const ignition::math::Vector3d &_value)
A new axis for the joint being created has been chosen.
gazebo::gui::JointMaker::RemoveJoint
void RemoveJoint(const std::string &_jointName)
Remove joint by name.
gazebo::gui::JointMaker::JOINT_SCREW
Screw joint.
Definition: JointMaker.hh:95
gazebo::gui::JointMaker::EmitLinkRemoved
void EmitLinkRemoved(const std::string &_linkId)
Qt signal to notify that a link has been removed.
gazebo::gui::JointMaker::DisableEventHandlers
void DisableEventHandlers()
Disable the mouse and key event handlers for the joint maker.
gazebo::gui::JointMaker::SetJointPose
void SetJointPose(const ignition::math::Pose3d &_pose)
A new joint pose for the joint being created has been chosen.
gazebo::gui::JointMaker::JOINT_BALL
Ball joint.
Definition: JointMaker.hh:99
gazebo::gui::JointMaker::EmitLinkInserted
void EmitLinkInserted(const std::string &_linkId)
Qt signal to notify that a link has been inserted.
common
common
Definition: FuelModelDatabase.hh:37
gazebo::gui::JointMaker::JointType
JointType
Definition: JointMaker.hh:82
gazebo::gui::JointMaker::CreateJointFromSDF
void CreateJointFromSDF(sdf::ElementPtr _jointElem, const std::string &_modelName="")
Create a joint from SDF.
gazebo::gui::JointMaker::JointAxisCount
static unsigned int JointAxisCount(const JointMaker::JointType _type)
Get the axis count for joint type.
gazebo::gui::JointMaker::ShowJoints
void ShowJoints(const bool _show)
Qt Callback to show / hide joint visuals.
boost
Definition: JointMaker.hh:44
system.hh
gazebo::msgs::ConvertJointType
GAZEBO_VISIBLE msgs::Joint::Type ConvertJointType(const std::string &_str)
Convert a string to a msgs::Joint::Type enum.
gazebo::gui::JointMaker::RemoveJointsByLink
void RemoveJointsByLink(const std::string &_linkName)
Remove all joints connected to link.
gazebo::gui::JointMaker::JOINT_NONE
none
Definition: JointMaker.hh:85
msgs.hh
gazebo::rendering::DynamicLines
Class for drawing lines that can change.
Definition: DynamicLines.hh:42
gazebo::gui::JointMaker::LinkList
std::map< std::string, std::string > LinkList() const
Get the list of links.
gazebo::gui::JointMaker::JOINT_HINGE
Hinge joint.
Definition: JointMaker.hh:91
gazebo::gui::JointMaker::JOINT_SLIDER
Slider joint.
Definition: JointMaker.hh:89
gazebo::gui::JointMaker::OnType
void OnType(const int _typeInt)
A new type for the joint being created has been chosen.
gazebo::gui::JointMaker::Stop
void Stop()
Stop the process of adding joint to the model.
gazebo::gui::JointMaker::AddScopedLinkName
void AddScopedLinkName(const std::string &_name)
Add a scoped link name.
RenderTypes.hh
rendering
rendering
Definition: RenderEngine.hh:31
gazebo::gui::JointData
Helper class to store joint data.
Definition: JointMaker.hh:425
gazebo::gui::JointMaker::JointMaterial
static std::string JointMaterial(const std::string &_type)
Get the material for the joint type.
gazebo::gui::JointData::line
rendering::DynamicLines * line
Visual line used to represent joint connecting parent and child.
Definition: JointMaker.hh:470
gazebo::gui::JointData::handles
Ogre::BillboardSet * handles
Visual handle used to represent joint parent.
Definition: JointMaker.hh:473
gazebo::gui::JointMaker::JOINT_HINGE2
Hinge2 joint.
Definition: JointMaker.hh:93
gazebo::gui::JointMaker::SetLinksRelativePose
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.
gazebo::rendering::JointVisualPtr
std::shared_ptr< JointVisual > JointVisualPtr
Definition: RenderTypes.hh:142
gazebo::gui::JointMaker::JointMaker
JointMaker()
Constructor.
gazebo::gui::JointMaker::~JointMaker
virtual ~JointMaker()
Destructor.
gazebo::gui::JointData::UpdateMsg
void UpdateMsg()
Update the joint message based on the other fields.
gazebo::gui::JointData::type
JointMaker::JointType type
Type of joint.
Definition: JointMaker.hh:476
gazebo::common::KeyEvent
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
gazebo::gui::JointMaker::JOINT_UNIVERSAL
Universal joint.
Definition: JointMaker.hh:97
gazebo::gui::JointMaker::CreateHotSpot
std::string CreateHotSpot(JointData *_joint)
Helper method to create hotspot visual for mouse interaction.
gazebo::gui::JointMaker::EnableEventHandlers
void EnableEventHandlers()
Enable the mouse and key event handlers for the joint maker.
gazebo::gui::JointMaker::State
JointMaker::JointType State() const
Get state.
gazebo::gui::JointMaker::FinalizeCreation
void FinalizeCreation()
Finalize joint creation.
gazebo::gui::JointInspector
A class to inspect and modify joints.
Definition: JointInspector.hh:42
gazebo::gui::JointMaker::AddJoint
void AddJoint(const std::string &_type)
Add a joint.
gazebo::gui::JointMaker::JOINT_GEARBOX
Gearbox joint.
Definition: JointMaker.hh:101
gazebo::gui::JointData::jointMsg
msgs::JointPtr jointMsg
Msg containing joint data.
Definition: JointMaker.hh:485
gazebo::gui::JointData::childScale
ignition::math::Vector3d childScale
Definition: JointMaker.hh:467
gui
gui
Definition: KeyEventHandler.hh:29
gazebo::gui::JointMaker::SetUserCmdManager
void SetUserCmdManager(MEUserCmdManager *_manager)
Set the user command manager variable.
gazebo::gui::JointMaker::SetParentLink
void SetParentLink(const std::string &_name)
A new parent link for the joint being created has been chosen.
gazebo::gui::JointMaker::GenerateSDF
void GenerateSDF()
Generate SDF for all joints.
gazebo::physics::JointPtr
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
gazebo::gui::JointData::hotspot
rendering::VisualPtr hotspot
\brieft Visual of the hotspot
Definition: JointMaker.hh:449
gazebo::gui::JointData::childPose
ignition::math::Pose3d childPose
Definition: JointMaker.hh:463
gazebo::gui::JointData::visual
rendering::VisualPtr visual
Visual of the dynamic line.
Definition: JointMaker.hh:443
gazebo::gui::JointMaker::JointDataByLink
std::vector< JointData * > JointDataByLink(const std::string &_linkName) const
Get a vector containing data for all joints connected to the given link.
gazebo::gui::JointMaker::Reset
void Reset()
Reset the joint maker;.
gazebo::gui::JointMaker::CreateJoint
JointData * CreateJoint(const rendering::VisualPtr &_parent, const rendering::VisualPtr &_child)
Create a joint with parent and child.
gazebo::gui::JointData::axes
std::vector< ignition::math::Vector3d > axes
Last known axes values.
Definition: JointMaker.hh:479
gazebo::gui::JointMaker::SDF
sdf::ElementPtr SDF() const
Get model SDF element containing all joints.
gazebo::rendering::VisualPtr
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
gazebo::gui::JointData::inspector
JointInspector * inspector
Inspector for configuring joint properties.
Definition: JointMaker.hh:488
gazebo::gui::JointMaker::RemoveJointByUser
void RemoveJointByUser(const std::string &_jointName)
Remove joint by name and register user command.
gazebo::gui::JointData::parentPose
ignition::math::Pose3d parentPose
Definition: JointMaker.hh:459
gazebo::gui::JointData::OpenInspector
void OpenInspector()
Open the joint inspector.
gazebo::gui::JointMaker::JointCount
unsigned int JointCount()
Get the number of joints added.
gazebo::gui::JointData::child
rendering::VisualPtr child
Child visual the joint is connected to.
Definition: JointMaker.hh:455
gazebo::gui::JointMaker::unitVectors
static std::vector< ignition::math::Vector3d > unitVectors
Constant vector containing [UnitX, UnitY, UnitZ].
Definition: JointMaker.hh:410
gazebo::gui::JointData::parent
rendering::VisualPtr parent
Parent visual the joint is connected to.
Definition: JointMaker.hh:452
gazebo::gui::JointMaker::SetSelected
void SetSelected(const std::string &_name, const bool selected)
Set the select state of a joint.
gazebo::gui::JointMaker::jointMaterials
static std::map< JointMaker::JointType, std::string > jointMaterials
A map of joint type to its corresponding material.
Definition: JointMaker.hh:414
gazebo::common::MouseEvent
Generic description of a mouse event.
Definition: MouseEvent.hh:35
gazebo::gui::JointMaker::JointAdded
void JointAdded()
Qt signal when the joint creation process has ended.