-
Notifications
You must be signed in to change notification settings - Fork 342
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 all commits
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 |
---|---|---|
|
@@ -17,8 +17,10 @@ | |
|
||
#include "EntityContextMenuPlugin.hh" | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <utility> | ||
#include <variant> | ||
|
||
#include <QtQml> | ||
|
||
|
@@ -159,9 +161,10 @@ 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 +200,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,8 +21,10 @@ | |
#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 <functional> | ||
#include <iostream> | ||
#include <mutex> | ||
#include <string> | ||
|
@@ -89,6 +91,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}; | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -345,3 +350,52 @@ void EntityContextMenu::OnRequest(const QString &_request, const QString &_data) | |
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"; | ||
} | ||
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); | ||
} |
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>