Go to the documentation of this file.00001 #include "yes_no_button_interface.h"
00002 #include <boost/thread.hpp>
00003 #include <rviz/config.h>
00004 #include <ros/package.h>
00005 #include <QVBoxLayout>
00006 #include <QHBoxLayout>
00007 #include <QSignalMapper>
00008
00009 #include <jsk_gui_msgs/YesNo.h>
00010
00011
00012 namespace jsk_rviz_plugins
00013 {
00014
00015 YesNoButtonInterface::YesNoButtonInterface(QWidget* parent)
00016 : rviz::Panel(parent)
00017 {
00018 layout_ = new QHBoxLayout;
00019
00020 yes_button_ = new QPushButton("Yes");
00021 layout_->addWidget(yes_button_);
00022 yes_button_->setEnabled(false);
00023
00024 no_button_ = new QPushButton("No");
00025 layout_->addWidget(no_button_);
00026 no_button_->setEnabled(false);
00027
00028 connect(yes_button_, SIGNAL(clicked()), this, SLOT(respondYes()));
00029 connect(no_button_, SIGNAL(clicked()), this, SLOT(respondNo()));
00030
00031 setLayout(layout_);
00032 }
00033
00034 void YesNoButtonInterface::onInitialize()
00035 {
00036 ros::NodeHandle nh;
00037 if (!ros::service::exists("/rviz/yes_no_button", false)) {
00038 yes_no_button_service_ = nh.advertiseService(
00039 "/rviz/yes_no_button",
00040 &YesNoButtonInterface::requested,
00041 this);
00042 }
00043 }
00044
00045 bool YesNoButtonInterface::requested(
00046 jsk_gui_msgs::YesNo::Request& req,
00047 jsk_gui_msgs::YesNo::Response& res)
00048 {
00049 need_user_input_ = true;
00050 yes_button_->setEnabled(true);
00051 no_button_->setEnabled(true);
00052 while (need_user_input_) {
00053 QApplication::processEvents(QEventLoop::AllEvents, 100);
00054 }
00055 yes_button_->setEnabled(false);
00056 no_button_->setEnabled(false);
00057 res.yes = yes_;
00058 return true;
00059 }
00060
00061 void YesNoButtonInterface::respondYes()
00062 {
00063 boost::mutex::scoped_lock lock(mutex_);
00064 yes_ = true;
00065 need_user_input_ = false;
00066 }
00067
00068 void YesNoButtonInterface::respondNo()
00069 {
00070 boost::mutex::scoped_lock lock(mutex_);
00071 yes_ = false;
00072 need_user_input_ = false;
00073 }
00074
00075 void YesNoButtonInterface::save(rviz::Config config) const
00076 {
00077 rviz::Panel::save(config);
00078 }
00079
00080 void YesNoButtonInterface::load(const rviz::Config& config)
00081 {
00082 rviz::Panel::load(config);
00083 }
00084
00085 }
00086
00087
00088 #include <pluginlib/class_list_macros.h>
00089 PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::YesNoButtonInterface, rviz::Panel)