From b3de267ab848c2066c9a59bbc8b9687c75dd3db1 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 28 Jan 2021 11:31:03 -0800 Subject: [PATCH 1/2] Use simplified /get_scene service Use a simplified form of /get_scene that avoids the need for a second service call. --- delphyne_gui/visualizer/render_widget.cc | 25 +++++++----------------- delphyne_gui/visualizer/render_widget.hh | 5 +++-- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/delphyne_gui/visualizer/render_widget.cc b/delphyne_gui/visualizer/render_widget.cc index 06ab038c..3d0894a6 100644 --- a/delphyne_gui/visualizer/render_widget.cc +++ b/delphyne_gui/visualizer/render_widget.cc @@ -115,23 +115,8 @@ RenderWidget::RenderWidget(QWidget*) : Plugin(), initializedScene(false), engine QObject::connect(this, SIGNAL(NewDraw(const ignition::msgs::Model_V&)), this, SLOT(UpdateScene(const ignition::msgs::Model_V&))); - // Setting up a unique-named service name - // i.e: Scene_8493201843; - int randomId = ignition::math::Rand::IntUniform(1, ignition::math::MAX_I32); - std::string sceneServiceName = "Scene_" + std::to_string(randomId); - sceneRequestMsg.set_response_topic(sceneServiceName); - - // Advertise the service with the unique name generated above - if (!node.Advertise(sceneServiceName, &RenderWidget::OnSetScene, this)) { - ignerr << "Error advertising service [" << sceneServiceName << "]" << std::endl; - } - - ignition::msgs::Boolean response; - unsigned int timeout = 100; - bool result; - - // Request a scene to be published into the unique-named channel - this->node.Request("/get_scene", sceneRequestMsg, timeout, response, result); + // Request a scene + this->node.Request("/get_scene", &RenderWidget::OnSetScene, this); } ///////////////////////////////////////////////// @@ -239,7 +224,11 @@ std::string RenderWidget::ConfigStr() const { } ///////////////////////////////////////////////// -void RenderWidget::OnSetScene(const ignition::msgs::Scene& request) { emit this->NewInitialScene(request); } +void RenderWidget::OnSetScene(const ignition::msgs::Scene& reply, const bool result) { + if (result) { + emit this->NewInitialScene(reply); + } +} ///////////////////////////////////////////////// void RenderWidget::OnUpdateScene(const ignition::msgs::Model_V& _msg) { emit this->NewDraw(_msg); } diff --git a/delphyne_gui/visualizer/render_widget.hh b/delphyne_gui/visualizer/render_widget.hh index 4033941e..64e67585 100644 --- a/delphyne_gui/visualizer/render_widget.hh +++ b/delphyne_gui/visualizer/render_widget.hh @@ -132,8 +132,9 @@ class RenderWidget : public ignition::gui::Plugin { private: /// \brief Set the initial scene - /// \param[in] request The scene to be loaded - void OnSetScene(const ignition::msgs::Scene& request); + /// \param[in] reply The scene to be loaded + /// \param[in] result True if the scene request was successful, false otherwise + void OnSetScene(const ignition::msgs::Scene& reply, const bool result); /// \brief Internal method to create the render window the first time /// RenderWidget::showEvent is called. From 93f99b9033152fce214fdca5a8489d0dc6a91dfe Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 29 Jan 2021 13:16:13 -0800 Subject: [PATCH 2/2] update doc-string --- delphyne_gui/visualizer/render_widget.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/delphyne_gui/visualizer/render_widget.hh b/delphyne_gui/visualizer/render_widget.hh index 64e67585..8a6cde4f 100644 --- a/delphyne_gui/visualizer/render_widget.hh +++ b/delphyne_gui/visualizer/render_widget.hh @@ -131,7 +131,8 @@ class RenderWidget : public ignition::gui::Plugin { void ShowContextMenu(const QPoint& _pos); private: - /// \brief Set the initial scene + /// \brief Set the initial scene if the result flag indicates that the service + /// call was successful /// \param[in] reply The scene to be loaded /// \param[in] result True if the scene request was successful, false otherwise void OnSetScene(const ignition::msgs::Scene& reply, const bool result);