Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/gui/plugins/entity_context_menu/EntityContextMenuPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <cstdint>

if (std::holds_alternative<uint64_t>(visual->UserData("gazebo-entity")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <variant>

{
entityId = std::get<uint64_t>(visual->UserData("gazebo-entity"));
}

emit ContextMenuRequested(visual->Name().c_str(), entityId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <gz/rendering/Camera.hh>

#include <gz/sim/Entity.hh>

namespace gz
{
namespace sim
Expand Down Expand Up @@ -70,7 +72,7 @@ namespace sim

/// \brief Signal fired when context menu event is triggered
/// \param[in] _entity Scoped name of entity.
signals: void ContextMenuRequested(QString _entity);
signals: void ContextMenuRequested(QString _entity, uint64_t _entityId);
};

/// \brief A QQUickItem that manages the render window
Expand All @@ -91,11 +93,11 @@ namespace sim
/// Note that the function name needs to start with lowercase in order for
/// the connection to work on the QML side
/// \param[in] _entity Scoped name of entity.
signals: void openContextMenu(QString _entity); // NOLINT
signals: void openContextMenu(QString _entity, uint64_t _entiyI); // NOLINT

/// \brief Qt callback when context menu request is received
/// \param[in] _entity Scoped name of entity.
public slots: void OnContextMenuRequested(QString _entity);
public slots: void OnContextMenuRequested(QString _entity, uint64_t _entityId);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ ColumnLayout {

Connections {
target: renderWindowOverlay
function onOpenContextMenu(_entity)
function onOpenContextMenu(_entity, _eid)
{
entityContextMenu.open(_entity, "model");
entityContextMenu.open(_entity, "model", _eid);
}
}
}
Expand Down
59 changes: 58 additions & 1 deletion src/gui/plugins/modules/EntityContextMenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -217,6 +221,7 @@ void EntityContextMenu::OnRemove(

this->dataPtr->removeService =
"/world/" + this->dataPtr->worldName + "/remove";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove new line

}

std::function<void(const msgs::Boolean &, const bool)> cb =
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <cstdint>


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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if service name is valid transport::TopicUtils::AsValidTopic

"/world/" + this->dataPtr->worldName + "/remove";

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"/world/" + this->dataPtr->worldName + "/remove";
}
"/world/" + this->dataPtr->worldName + "/remove";
}

this->dataPtr->addPluginService =
"/world/" + this->dataPtr->worldName + "/entity/system/add";
std::function<void(const msgs::Boolean &, const bool)> cb =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <functional>

[](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);
}
7 changes: 7 additions & 0 deletions src/gui/plugins/modules/EntityContextMenu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix doc

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;
Expand Down
103 changes: 100 additions & 3 deletions src/gui/plugins/modules/EntityContextMenu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* limitations under the License.
*
*/
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtCore
import QtQuick 2.9
import QtQuick.Controls
import QtQuick.Controls.Material 2.1
import QtQuick.Dialogs
import QtQuick.Layouts 1.3
import GzSim 1.0 as GzSim

Item {
Expand Down Expand Up @@ -80,6 +84,14 @@ Item {
onEntered: thirdMenu.open()
}
}
MenuItem {
id: attachPlugin
text: "Attach Plugin"
onTriggered: {
menu.close()
pluginDialog.open()
}
}
}
Menu {
id: secondMenu
Expand Down Expand Up @@ -109,6 +121,7 @@ Item {
context.OnRequest("look_at", context.entity)
}
}

}
Menu {
id: thirdMenu
Expand Down Expand Up @@ -172,9 +185,10 @@ Item {
}
}

function open(_entity, _type) {
function open(_entity, _type, _eid) {
context.entity = _entity
context.type = _type
context.eid = _eid
moveToMenu.enabled = false
followMenu.enabled = false
followFreeLookMenu.enabled = false
Expand Down Expand Up @@ -233,9 +247,92 @@ Item {
menu.popup()
}

Dialog {
id: pluginDialog
title: "Add Plugin Dialog"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel // Adds standard buttons
parent: Overlay.overlay
//parent: customPlugin.Window.window ? customPlugin.Window.window.contentItem : customPlugin
x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: parent.width * 0.3
height: parent.height * 0.6

contentItem: Item {
// Your dialog content goes here
width: parent.width
height: parent.height

Column {
anchors.centerIn: parent
spacing: 10
width: parent.width * 0.8 // Make inputs a bit narrower than parent
height: parent.height

Text {
id: pluginNameLbl
text: "Plugin Name:"
}

TextInput {
id: pluginNames
width: parent.width
height: 20

}

Text {
id: pluginFilesLbl
text: "Plugin Filename:"
}

TextInput {
id: pluginFilename
width: parent.width
height: 20
}

Text {
id: pluginSdfLbl
text: "Enter the inner-xml of your plugin"
}

TextArea {
id: pluginParams
width: parent.width
height: parent.y + parent.height - (pluginSdfLbl.y + pluginFilesLbl.height) // Set a reasonable height

font.family: "Monospace"
background: Rectangle {
color: "transparent" // No fill
border.width: 2 // No border
border.color: "lightblue"
}
leftPadding: 5
topPadding: 5
rightPadding: 5
bottomPadding: 5
}
}
}

onAccepted: {
console.log("Dialog Accepted!");
context.OnAddPlugin(pluginNames.text, pluginFilename.text, pluginParams.text, context.eid)
// Perform actions when OK is clicked
}

onRejected: {
console.log("Dialog Rejected!");
// Perform actions when Cancel is clicked or dialog is closed
}
}

GzSim.EntityContextMenuItem {
id: context
property string entity
property string type
property int eid
}
}
Loading