Skip to content
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

Use simplified /get_scene service #349

Merged
merged 2 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 7 additions & 18 deletions delphyne_gui/visualizer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/////////////////////////////////////////////////
Expand Down Expand Up @@ -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); }
Expand Down
8 changes: 5 additions & 3 deletions delphyne_gui/visualizer/render_widget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ class RenderWidget : public ignition::gui::Plugin {
void ShowContextMenu(const QPoint& _pos);

private:
/// \brief Set the initial scene
/// \param[in] request The scene to be loaded
void OnSetScene(const ignition::msgs::Scene& request);
/// \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);

/// \brief Internal method to create the render window the first time
/// RenderWidget::showEvent is called.
Expand Down