##

ModelCreator.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_MODEL_MODELCREATOR_HH_
#define GAZEBO_GUI_MODEL_MODELCREATOR_HH_
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <ignition/math/Pose3.hh>
#include <ignition/math/Vector3.hh>
#include <sdf/sdf.hh>
#include "gazebo/gui/qt.h"
#include "gazebo/rendering/RenderTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
class KeyEvent;
class MouseEvent;
}
namespace gui
{
class JointMaker;
class LinkData;
class ModelPluginData;
class NestedModelData;
// Forward declare private data.
class ModelCreatorPrivate;
class GZ_GUI_VISIBLE ModelCreator : public QObject
{
Q_OBJECT
public: enum EntityType
{
ENTITY_NONE,
ENTITY_BOX,
ENTITY_SPHERE,
ENTITY_CYLINDER,
ENTITY_MESH,
ENTITY_POLYLINE,
ENTITY_MODEL
};
public: enum SaveState
{
NEVER_SAVED,
ALL_SAVED,
UNSAVED_CHANGES
};
public: explicit ModelCreator(QObject *_parent = NULL);
public: virtual ~ModelCreator();
public: void EnableEventHandlers();
public: void DisableEventHandlers();
public: void SetModelName(const std::string &_modelName);
public: std::string ModelName() const;
public: void ModelChanged();
public: void SaveModelFiles();
public: void FinishModel();
public: void AddCustomLink(const EntityType _type,
const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
const std::string &_uri = "", const unsigned int _samples = 5);
public: LinkData *AddShape(const EntityType _type,
const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
const std::string &_uri = "", const unsigned int _samples = 5);
public: NestedModelData *AddModel(const sdf::ElementPtr &_sdf);
public: void AddJoint(const std::string &_type);
public: void RemoveEntity(const std::string &_entityName);
public: void RemoveModelPlugin(const std::string &_pluginName,
const bool _newCmd = true);
public: void SetStatic(const bool _static);
public: void SetAutoDisable(const bool _auto);
public: void Reset();
public: void Stop();
public: gui::JointMaker *JointMaker() const;
public: void SetSelected(const std::string &_name, const bool selected);
public: void SetSelected(const rendering::VisualPtr &_entityVis,
const bool selected);
public: enum SaveState CurrentSaveState() const;
public: void AddEntity(const sdf::ElementPtr &_sdf);
public: void AddLink(const EntityType _type);
public: void OnAddModelPlugin(const std::string &_name,
const std::string &_filename, const std::string &_innerxml,
const bool _newCmd = true);
public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
public: ModelPluginData *ModelPlugin(const std::string &_name);
public: void GenerateSDF();
public slots: void ShowCollisions(const bool _show);
public slots: void ShowVisuals(const bool _show);
public slots: void ShowLinkFrames(const bool _show);
public: ignition::math::Pose3d WorldToLocal(
const ignition::math::Pose3d &_world) const;
private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
private: void OnNew();
private: bool OnSave();
private: bool OnSaveAs();
private: void OnNameChanged(const std::string &_modelName);
private: void OnPropertiesChanged(const bool _static,
const bool _autoDisable);
private: void OnExit();
private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
private: void RemoveLinkImpl(const std::string &_linkName);
private slots: void OnEdit(const bool _checked);
private slots: void OnEditModel(const std::string &_modelName);
private slots: void OnCopy();
private slots: void OnPaste();
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 OnManipMode(const std::string &_mode);
private: void OnDeselectAll(const std::string &_name,
const std::string &_mode);
private: void OnSetSelectedEntity(const std::string &_name,
const bool _selected);
private: void OnSetSelectedModelPlugin(const std::string &_name,
const bool _selected);
private: LinkData *CreateLink(const rendering::VisualPtr &_visual);
private: void InsertLinkFromSDF(sdf::ElementPtr _sdf);
private: void InsertNestedModelFromSDF(sdf::ElementPtr _sdf);
private: NestedModelData *CloneNestedModel(const std::string &_modelName);
private: LinkData *CloneLink(const std::string &_linkName);
private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
const rendering::VisualPtr &_parentVis);
private: void OpenInspector(const std::string &_name);
private: void OpenModelPluginInspector(const std::string &_name);
private: virtual void CreateTheEntity();
private: bool Init();
private: std::string CreateModel();
private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
const rendering::VisualPtr &_parentVis = NULL,
const bool _emit = true);
private: void OnAlignMode(const std::string &_axis,
const std::string &_config, const std::string &_target,
const bool _preview, const bool _inverted = false);
private: void OnEntityScaleChanged(const std::string &_name,
const ignition::math::Vector3d &_scale);
private: void OnEntityMoved(const std::string &_name,
const ignition::math::Pose3d &_pose, const bool _isFinal);
private: void DeselectAll();
private: void DeselectAllEntities();
private: void DeselectAllModelPlugins();
private: void OnRequestLinkScale(const std::string &_name,
const std::map<std::string, ignition::math::Vector3d> &_scales);
private: void OnRequestLinkMove(const std::string &_name,
const ignition::math::Pose3d &_pose);
private: void OnRequestNestedModelMove(const std::string &_name,
const ignition::math::Pose3d &_pose);
private: void SetModelVisible(const std::string &_name,
const bool _visible);
private: void SetModelVisible(const rendering::VisualPtr &_visual,
const bool _visible);
private: void ShowContextMenu(const std::string &_link);
private: void ShowModelPluginContextMenu(const std::string &_name);
private: void EmitNestedModelInsertedEvent(
const rendering::VisualPtr &_vis) const;
private slots: void OnDelete();
private slots: void OnDelete(const std::string &_name);
private slots: void OnOpenInspector();
private slots: void OnOpenModelPluginInspector(const QString &_name);
private slots: void OnRemoveModelPlugin(const QString &_name);
Q_SIGNALS: void LinkAdded();
private: std::unique_ptr<ModelCreatorPrivate> dataPtr;
};
}
}
#endif
gazebo::gui::ModelCreator::ModelCreator
ModelCreator(QObject *_parent=NULL)
Constructor.
gazebo::gui::ModelCreator::EntityType
EntityType
Definition: ModelCreator.hh:66
gazebo::gui::ModelCreator::SetModelName
void SetModelName(const std::string &_modelName)
Set the name of the model.
gazebo::gui::ModelCreator::AddCustomLink
void AddCustomLink(const EntityType _type, const ignition::math::Vector3d &_size=ignition::math::Vector3d::One, const ignition::math::Pose3d &_pose=ignition::math::Pose3d::Zero, const std::string &_uri="", const unsigned int _samples=5)
Begin the process of inserting a custom link using the mouse.
gazebo::gui::ModelCreator::DisableEventHandlers
void DisableEventHandlers()
Disable the mouse and key event handlers.
gazebo::gui::ModelCreator::ENTITY_MODEL
Nested model.
Definition: ModelCreator.hh:81
gazebo::gui::ModelCreator::UNSAVED_CHANGES
Has been saved before, but has unsaved changes.
Definition: ModelCreator.hh:95
gazebo::gui::ModelCreator::ModelName
std::string ModelName() const
Get the name of the model.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
qt.h
gazebo::gui::JointMaker
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:76
gazebo::gui::ModelCreator::ENTITY_MESH
Imported 3D mesh.
Definition: ModelCreator.hh:77
gazebo::gui::ModelCreator
Create and manage 3D visuals of a model with links, nested models and joints.
Definition: ModelCreator.hh:60
gazebo::gui::ModelCreator::AddJoint
void AddJoint(const std::string &_type)
Add a joint to the model.
gazebo::gui::ModelCreator::ModelPlugin
ModelPluginData * ModelPlugin(const std::string &_name)
Get a model plugin data by its name.
NULL
#define NULL
Definition: CommonTypes.hh:31
gazebo::gui::ModelCreator::ShowCollisions
void ShowCollisions(const bool _show)
Show or hide collision visuals.
gazebo::gui::ModelCreator::WorldToLocal
ignition::math::Pose3d WorldToLocal(const ignition::math::Pose3d &_world) const
Convert a given pose from the world frame to the local frame of the model being edited.
gazebo::gui::ModelCreator::ENTITY_NONE
none
Definition: ModelCreator.hh:69
common
common
Definition: FuelModelDatabase.hh:37
gazebo::gui::ModelCreator::ShowLinkFrames
void ShowLinkFrames(const bool _show)
Show or hide link frame visuals.
gazebo::gui::ModelCreator::FinishModel
void FinishModel()
Finish the model and create the entity on the gzserver.
gazebo::gui::ModelCreator::SetSelected
void SetSelected(const std::string &_name, const bool selected)
Set the select state of an entity.
system.hh
gazebo::gui::ModelCreator::GenerateSDF
void GenerateSDF()
Generate the SDF from model link and joint visuals.
gazebo::gui::ModelCreator::~ModelCreator
virtual ~ModelCreator()
Destructor.
gazebo::gui::ModelCreator::AddModel
NestedModelData * AddModel(const sdf::ElementPtr &_sdf)
Add a nested model to the model.
gazebo::gui::ModelCreator::NEVER_SAVED
The model has never been saved.
Definition: ModelCreator.hh:89
gazebo::gui::ModelCreator::LinkAdded
void LinkAdded()
Qt signal when the a link has been added.
gazebo::gui::ModelCreator::AddModelPlugin
void AddModelPlugin(const sdf::ElementPtr &_pluginElem)
Add a model plugin to the model.
RenderTypes.hh
gazebo::gui::ModelCreator::Stop
void Stop()
Stop the process of adding a link or joint to the model.
gazebo::gui::ModelCreator::OnAddModelPlugin
void OnAddModelPlugin(const std::string &_name, const std::string &_filename, const std::string &_innerxml, const bool _newCmd=true)
Add a model plugin to the model.
gazebo::gui::ModelCreator::SetAutoDisable
void SetAutoDisable(const bool _auto)
Set the model to allow auto disable at rest.
gazebo::gui::ModelCreator::ShowVisuals
void ShowVisuals(const bool _show)
Show or hide visual visuals.
gazebo::gui::NestedModelData
Helper class to store nested models data.
Definition: ModelData.hh:57
gazebo::gui::ModelCreator::AddLink
void AddLink(const EntityType _type)
Add a link to the model.
gazebo::gui::ModelCreator::SaveModelFiles
void SaveModelFiles()
Helper function to manage writing files to disk.
gazebo::gui::ModelCreator::CurrentSaveState
enum SaveState CurrentSaveState() const
Get current save state.
gazebo::common::KeyEvent
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
gazebo::gui::ModelCreator::AddShape
LinkData * AddShape(const EntityType _type, const ignition::math::Vector3d &_size=ignition::math::Vector3d::One, const ignition::math::Pose3d &_pose=ignition::math::Pose3d::Zero, const std::string &_uri="", const unsigned int _samples=5)
Add a link to the model.
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gui
gui
Definition: KeyEventHandler.hh:29
gazebo::gui::ModelCreator::SetStatic
void SetStatic(const bool _static)
Set the model to be static.
gazebo::gui::ModelCreator::AddEntity
void AddEntity(const sdf::ElementPtr &_sdf)
Add an entity to the model.
gazebo::gui::ModelCreator::SaveState
SaveState
Save states for the model editor.
Definition: ModelCreator.hh:86
gazebo::gui::ModelPluginData
Helper class to store model plugin data.
Definition: ModelData.hh:309
gazebo::gui::ModelCreator::RemoveModelPlugin
void RemoveModelPlugin(const std::string &_pluginName, const bool _newCmd=true)
Remove a model plugin from the model.
gazebo::gui::ModelCreator::ENTITY_SPHERE
Sphere.
Definition: ModelCreator.hh:73
gazebo::gui::ModelCreator::ALL_SAVED
All changes have been saved.
Definition: ModelCreator.hh:92
gazebo::gui::ModelCreator::JointMaker
gui::JointMaker * JointMaker() const
Get joint maker.
gazebo::gui::LinkData
Helper class to store link data.
Definition: ModelData.hh:94
gazebo::gui::ModelCreator::Reset
void Reset()
Reset the model creator and the SDF.
gazebo::gui::ModelCreator::ENTITY_POLYLINE
Extruded polyline.
Definition: ModelCreator.hh:79
gazebo::gui::ModelCreator::EnableEventHandlers
void EnableEventHandlers()
Enable the mouse and key event handlers.
gazebo::rendering::VisualPtr
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
gazebo::ModelPlugin
A plugin with access to physics::Model.
Definition: Plugin.hh:303
gazebo::gui::ModelCreator::ModelChanged
void ModelChanged()
Set save state upon a change to the model.
gazebo::gui::ModelCreator::ENTITY_BOX
Box.
Definition: ModelCreator.hh:71
gazebo::gui::ModelCreator::ENTITY_CYLINDER
Cylinder.
Definition: ModelCreator.hh:75
gazebo::common::MouseEvent
Generic description of a mouse event.
Definition: MouseEvent.hh:35
gazebo::gui::ModelCreator::RemoveEntity
void RemoveEntity(const std::string &_entityName)
Remove an entity from the model.