Skip to content

Commit

Permalink
Model editor: Add links to model (#1165)
Browse files Browse the repository at this point in the history
* add an add entity button to component inspector. Currently only enabled for models

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* add model editor gui plugin that inserts visuals to the scene in the render thread

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* write to ECM

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* support adding light links

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* notify other GUI plugins of added/removed entities via GUI events

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* use const ref for constructor input params

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* guarantee 64 bit entity IDs with gazebo::Entity instead of unsigned int

Signed-off-by: Ashton Larkin <ashton@openrobotics.org>

* testing makr as new entity  func

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* rm printouts

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* register type

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* refactor render util

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* workaround for avoiding crash on exit

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* refactor, comment out unused menu items

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* remove commented out code, add CreateLight function

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* add model editor src files

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* remove more commented out code

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* use entity instead of entity name (#1176)

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Co-authored-by: Nate Koenig <nate@openrobotics.org>

* Add link menu updates (#1177)

* use entity instead of entity name

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* Update link add menu

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Co-authored-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Ian Chen <ichen@osrfoundation.org>

* fix adding ellipsoid

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* merge model_editor into component_inspector

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* fixing warnings

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* Adjust tool tips

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* fix adding light

Signed-off-by: Ian Chen <ichen@osrfoundation.org>

* Fix codecheck

Signed-off-by: Nate Koenig <nate@openrobotics.org>

* Fixed documentation

Signed-off-by: Nate Koenig <nate@openrobotics.org>

Co-authored-by: Ashton Larkin <ashton@openrobotics.org>
Co-authored-by: Nate Koenig <nate@openrobotics.org>
Co-authored-by: Nate Koenig <nkoenig@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 10, 2021
1 parent c7bd39f commit cebbedc
Show file tree
Hide file tree
Showing 13 changed files with 1,035 additions and 149 deletions.
47 changes: 47 additions & 0 deletions include/ignition/gazebo/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#define IGNITION_GAZEBO_GUI_GUIEVENTS_HH_

#include <QEvent>
#include <QString>

#include <set>
#include <string>
#include <utility>
Expand Down Expand Up @@ -182,6 +184,51 @@ namespace events
/// \brief True if a transform mode is active.
private: bool tranformModeActive;
};

/// \brief Event that notifies an entity is to be added to the model editor
class ModelEditorAddEntity : public QEvent
{
/// \brief Constructor
/// \param[in] _tranformModeActive is the transform control mode active
public: explicit ModelEditorAddEntity(QString _entity, QString _type,
ignition::gazebo::Entity _parent, QString _uri) :
QEvent(kType), entity(_entity), type(_type), parent(_parent), uri(_uri)
{
}

/// \brief Get the entity to add
public: QString Entity() const
{
return this->entity;
}

/// \brief Get the URI, if any, associated with the entity to add
public: QString Uri() const
{
return this->uri;
}

/// \brief Get the entity type
public: QString EntityType() const
{
return this->type;
}

/// \brief Get the parent entity to add the entity to
public: ignition::gazebo::Entity ParentEntity() const
{
return this->parent;
}

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::User + 7);

private: QString entity;
private: QString type;
private: ignition::gazebo::Entity parent;
private: QString uri;
};

} // namespace events
}
} // namespace gui
Expand Down
9 changes: 9 additions & 0 deletions include/ignition/gazebo/rendering/RenderUtil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define IGNITION_GAZEBO_RENDERUTIL_HH_

#include <memory>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -76,6 +77,14 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
public: void UpdateFromECM(const UpdateInfo &_info,
const EntityComponentManager &_ecm);

/// \brief Helper function to create visuals for new entities created in
/// ECM. This function is intended to be used by other GUI plugins when
/// new entities are created on the GUI side.
/// \param[in] _ecm Const reference to the entity component manager
/// \param[in] _entities Entities to create visuals for.
public: void CreateVisualsForEntities(const EntityComponentManager &_ecm,
const std::set<Entity> &_entities);

/// \brief Set the rendering engine to use
/// \param[in] _engineName Name of the rendering engine.
public: void SetEngineName(const std::string &_engineName);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/plugins/component_inspector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gz_add_gui_plugin(ComponentInspector
SOURCES ComponentInspector.cc
QT_HEADERS ComponentInspector.hh
SOURCES ComponentInspector.cc ModelEditor.cc
QT_HEADERS ComponentInspector.hh ModelEditor.hh
)
50 changes: 49 additions & 1 deletion src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <list>
#include <regex>
#include <ignition/common/Console.hh>
#include <ignition/common/MeshManager.hh>
#include <ignition/common/Profiler.hh>
#include <ignition/gui/Application.hh>
#include <ignition/gui/MainWindow.hh>
Expand Down Expand Up @@ -67,6 +68,7 @@
#include "ignition/gazebo/gui/GuiEvents.hh"

#include "ComponentInspector.hh"
#include "ModelEditor.hh"

namespace ignition::gazebo
{
Expand Down Expand Up @@ -101,6 +103,9 @@ namespace ignition::gazebo

/// \brief Transport node for making command requests
public: transport::Node node;

/// \brief Transport node for making command requests
public: ModelEditor modelEditor;
};
}

Expand Down Expand Up @@ -405,10 +410,12 @@ void ComponentInspector::LoadConfig(const tinyxml2::XMLElement *)
// Connect model
this->Context()->setContextProperty(
"ComponentsModel", &this->dataPtr->componentsModel);

this->dataPtr->modelEditor.Load();
}

//////////////////////////////////////////////////
void ComponentInspector::Update(const UpdateInfo &,
void ComponentInspector::Update(const UpdateInfo &_info,
EntityComponentManager &_ecm)
{
IGN_PROFILE("ComponentInspector::Update");
Expand Down Expand Up @@ -789,6 +796,8 @@ void ComponentInspector::Update(const UpdateInfo &,
Qt::QueuedConnection,
Q_ARG(ignition::gazebo::ComponentTypeId, typeId));
}

this->dataPtr->modelEditor.Update(_info, _ecm);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -1029,6 +1038,45 @@ bool ComponentInspector::NestedModel() const
return this->dataPtr->nestedModel;
}

/////////////////////////////////////////////////
void ComponentInspector::OnAddEntity(const QString &_entity,
const QString &_type)
{
// currently just assumes parent is the model
// todo(anyone) support adding visuals / collisions / sensors to links
ignition::gazebo::gui::events::ModelEditorAddEntity addEntityEvent(
_entity, _type, this->dataPtr->entity, QString(""));

ignition::gui::App()->sendEvent(
ignition::gui::App()->findChild<ignition::gui::MainWindow *>(),
&addEntityEvent);
}

/////////////////////////////////////////////////
void ComponentInspector::OnLoadMesh(const QString &_entity,
const QString &_type, const QString &_mesh)
{
std::string meshStr = _mesh.toStdString();
if (QUrl(_mesh).isLocalFile())
{
// mesh to sdf model
common::rtrim(meshStr);

if (!common::MeshManager::Instance()->IsValidFilename(meshStr))
{
QString errTxt = QString::fromStdString("Invalid URI: " + meshStr +
"\nOnly mesh file types DAE, OBJ, and STL are supported.");
return;
}

ignition::gazebo::gui::events::ModelEditorAddEntity addEntityEvent(
_entity, _type, this->dataPtr->entity, QString(meshStr.c_str()));
ignition::gui::App()->sendEvent(
ignition::gui::App()->findChild<ignition::gui::MainWindow *>(),
&addEntityEvent);
}
}

// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gazebo::ComponentInspector,
ignition::gui::Plugin)
13 changes: 13 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ namespace gazebo
/// \brief Notify that paused has changed.
signals: void PausedChanged();

/// \brief Callback in Qt thread when an entity is to be added
/// \param[in] _entity Entity to add, e.g. box, sphere, cylinder, etc
/// \param[in] _type Entity type, e.g. link, visual, collision, etc
public: Q_INVOKABLE void OnAddEntity(const QString &_entity,
const QString &_type);

/// \brief Callback to insert a new entity
/// \param[in] _entity Entity to add, e.g. box, sphere, cylinder, etc
/// \param[in] _type Entity type, e.g. link, visual, collision, etc
/// \param[in] _mesh Mesh file to load.
public: Q_INVOKABLE void OnLoadMesh(const QString &_entity,
const QString &_type, const QString &_mesh);

/// \internal
/// \brief Pointer to private data.
private: std::unique_ptr<ComponentInspectorPrivate> dataPtr;
Expand Down
Loading

0 comments on commit cebbedc

Please sign in to comment.