-
Couldn't load subscription status.
- Fork 341
Adds a "Attach Plugin" context menu #2956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,9 +159,9 @@ void EntityContextMenuItem::SetEntityContextMenuHandler( | |
| } | ||
|
|
||
| /////////////////////////////////////////////////// | ||
| void EntityContextMenuItem::OnContextMenuRequested(QString _entity) | ||
| void EntityContextMenuItem::OnContextMenuRequested(QString _entity, uint64_t _eid) | ||
| { | ||
| emit openContextMenu(std::move(_entity)); | ||
| emit openContextMenu(std::move(_entity), _eid); | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////// | ||
|
|
@@ -197,7 +197,13 @@ void EntityContextMenuHandler::HandleMouseContextMenu( | |
| visual = std::dynamic_pointer_cast<rendering::Visual>(visual->Parent()); | ||
| } | ||
|
|
||
| emit ContextMenuRequested(visual->Name().c_str()); | ||
| uint64_t entityId = kNullEntity; | ||
| if (std::holds_alternative<uint64_t>(visual->UserData("gazebo-entity"))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||
| { | ||
| entityId = std::get<uint64_t>(visual->UserData("gazebo-entity")); | ||
| } | ||
|
|
||
| emit ContextMenuRequested(visual->Name().c_str(), entityId); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||||||||
| #include <gz/msgs/boolean.pb.h> | ||||||||||||
| #include <gz/msgs/cameratrack.pb.h> | ||||||||||||
| #include <gz/msgs/entity.pb.h> | ||||||||||||
| #include <gz/msgs/entity_plugin_v.pb.h> | ||||||||||||
| #include <gz/msgs/stringmsg.pb.h> | ||||||||||||
|
|
||||||||||||
| #include <iostream> | ||||||||||||
|
|
@@ -89,6 +90,9 @@ namespace gz::sim | |||||||||||
| /// \brief Storing last follow target for look at. | ||||||||||||
| public: std::string followTargetLookAt; | ||||||||||||
|
|
||||||||||||
| /// \brief Add plugin service | ||||||||||||
| public: std::string addPluginService; | ||||||||||||
|
|
||||||||||||
| /// \brief Flag used to disable look at when not following target. | ||||||||||||
| public: bool followingTarget{false}; | ||||||||||||
|
|
||||||||||||
|
|
@@ -217,6 +221,7 @@ void EntityContextMenu::OnRemove( | |||||||||||
|
|
||||||||||||
| this->dataPtr->removeService = | ||||||||||||
| "/world/" + this->dataPtr->worldName + "/remove"; | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| std::function<void(const msgs::Boolean &, const bool)> cb = | ||||||||||||
|
|
@@ -325,7 +330,7 @@ void EntityContextMenu::OnRequest(const QString &_request, const QString &_data) | |||||||||||
| } | ||||||||||||
| else if (request == "view_frames") | ||||||||||||
| { | ||||||||||||
| gz::msgs::StringMsg req; | ||||||||||||
| msgs::StringMsg req; | ||||||||||||
| req.set_data(_data.toStdString()); | ||||||||||||
| this->dataPtr->node.Request(this->dataPtr->viewFramesService, req, cb); | ||||||||||||
| } | ||||||||||||
|
|
@@ -342,6 +347,58 @@ void EntityContextMenu::OnRequest(const QString &_request, const QString &_data) | |||||||||||
| } | ||||||||||||
| else | ||||||||||||
| { | ||||||||||||
|
|
||||||||||||
| gzwarn << "Unknown request [" << request << "]" << std::endl; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| ///////////////////////////////////////////////// | ||||||||||||
| void EntityContextMenu::OnAddPlugin(const QString &_name, | ||||||||||||
| const QString &_filename, const QString &_innerXml, | ||||||||||||
| const uint64_t _entity) { | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||||||||||||
|
|
||||||||||||
| if (this->dataPtr->worldName.empty()) | ||||||||||||
| { | ||||||||||||
| auto runners = gui::App()->findChildren<GuiRunner *>(); | ||||||||||||
| if (runners.empty() || runners[0] == nullptr) | ||||||||||||
| { | ||||||||||||
| gzerr << "Internal error: no GuiRunner found." << std::endl; | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| this->dataPtr->worldName = "default"; | ||||||||||||
| auto worldNameVariant = runners[0]->property("worldName"); | ||||||||||||
| if (!worldNameVariant.isValid()) | ||||||||||||
| { | ||||||||||||
| gzwarn << "GuiRunner's worldName not set, using[" | ||||||||||||
| << this->dataPtr->worldName << "]" << std::endl; | ||||||||||||
| } | ||||||||||||
| else | ||||||||||||
| { | ||||||||||||
| this->dataPtr->worldName = worldNameVariant.toString().toStdString(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| this->dataPtr->removeService = | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if service name is valid |
||||||||||||
| "/world/" + this->dataPtr->worldName + "/remove"; | ||||||||||||
|
|
||||||||||||
| } | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| this->dataPtr->addPluginService = | ||||||||||||
| "/world/" + this->dataPtr->worldName + "/entity/system/add"; | ||||||||||||
| std::function<void(const msgs::Boolean &, const bool)> cb = | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include |
||||||||||||
| [](const msgs::Boolean &/*_rep*/, const bool _result) | ||||||||||||
| { | ||||||||||||
| if (!_result) | ||||||||||||
| gzerr << "Error creating new plugin" << std::endl; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| msgs::EntityPlugin_V entity_plugin_message; | ||||||||||||
| msgs::Entity* entity = entity_plugin_message.mutable_entity(); | ||||||||||||
| entity->set_id(_entity); | ||||||||||||
| msgs::Plugin* new_plugin = entity_plugin_message.add_plugins(); | ||||||||||||
| new_plugin->set_name(_name.toStdString()); | ||||||||||||
| new_plugin->set_filename(_filename.toStdString()); | ||||||||||||
| new_plugin->set_innerxml(_innerXml.toStdString()); | ||||||||||||
|
|
||||||||||||
| this->dataPtr->node.Request( | ||||||||||||
| this->dataPtr->addPluginService, entity_plugin_message, cb); | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,13 @@ namespace sim | |
| public: Q_INVOKABLE void OnRequest(const QString &_request, | ||
| const QString &_data); | ||
|
|
||
| /// \brief Callback when a new plugin window finishes configuring | ||
| /// \param[in] _request Request type | ||
| /// \param[in] _data Request data | ||
|
||
| public: Q_INVOKABLE void OnAddPlugin(const QString &_name, | ||
| const QString &_filename, const QString &_innerXml, | ||
| const uint64_t _entity); | ||
|
|
||
| /// \internal | ||
| /// \brief Pointer to private data. | ||
| private: std::unique_ptr<EntityContextMenuPrivate> dataPtr; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include
<cstdint>