Go to the documentation of this file.00001 #include "rviz/config.h"
00002 #include "empty_service_call_interface.h"
00003 #include <ros/package.h>
00004 #include <QVBoxLayout>
00005 #include <QHBoxLayout>
00006 #include <QSignalMapper>
00007
00008 using namespace rviz;
00009 namespace jsk_rviz_plugins
00010 {
00011 EmptyServiceCallInterfaceAction::EmptyServiceCallInterfaceAction( QWidget* parent )
00012 : rviz::Panel( parent )
00013 {
00014 parseROSParameters();
00015
00016 QHBoxLayout* h_layout = new QHBoxLayout;
00017 h_layout->setAlignment(Qt::AlignLeft);
00018 layout = new QVBoxLayout();
00019 signal_mapper = new QSignalMapper(this);
00020
00021 for(size_t i = 0; i < service_call_button_infos_.size();i++){
00022 ServiceCallButtonInfo target_button = service_call_button_infos_[i];
00023 QToolButton* tbutton = new QToolButton(this);
00024 tbutton->setText(target_button.text.c_str());
00025 tbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
00026 tbutton->setIconSize(QSize(100, 100));
00027 tbutton->setIcon(QIcon(QPixmap(QString(target_button.icon_file_path.c_str()))));
00028 connect(tbutton, SIGNAL(clicked()), signal_mapper, SLOT(map()));
00029 signal_mapper->setMapping(tbutton, i);
00030 h_layout->addWidget(tbutton);
00031 };
00032 connect(signal_mapper, SIGNAL(mapped(int)),
00033 this, SLOT(callRequestEmptyCommand(int)));
00034 layout->addLayout(h_layout);
00035 setLayout( layout );
00036 }
00037
00038 void EmptyServiceCallInterfaceAction::parseROSParameters(){
00039 ros::NodeHandle nh("~");
00040
00041
00042 std::string icon_package_name;
00043 nh.param<std::string>("icon_include_package", icon_package_name, std::string("jsk_rviz_plugins"));
00044 ROS_INFO("Find Icons In %s package.", icon_package_name.c_str());
00045
00046 std::string icon_path_prefix;
00047 if(!icon_package_name.empty())
00048 icon_path_prefix = ros::package::getPath(icon_package_name) + std::string("/icons/");
00049
00050 XmlRpc::XmlRpcValue buttons_list;
00051 nh.getParam("rviz_service_call/buttons", buttons_list);
00052 for (int32_t i = 0; i < buttons_list.size(); ++i)
00053 {
00054 ServiceCallButtonInfo new_button;
00055 new_button.icon_file_path = icon_path_prefix + static_cast<std::string>(buttons_list[i]["icon"]);
00056 new_button.service_name = static_cast<std::string>(buttons_list[i]["service_name"]);
00057 new_button.text = static_cast<std::string>(buttons_list[i]["text"]);
00058 service_call_button_infos_.push_back(new_button);
00059 }
00060 };
00061
00062 void EmptyServiceCallInterfaceAction::callRequestEmptyCommand(const int button_id){
00063 ros::ServiceClient client = nh_.serviceClient<std_srvs::Empty>(service_call_button_infos_[button_id].service_name, true);
00064 std_srvs::Empty srv;
00065 if(client.call(srv))
00066 ROS_INFO("Call Success");
00067 else{
00068 ROS_ERROR("Service call FAIL");
00069 };
00070 }
00071
00072 void EmptyServiceCallInterfaceAction::save( rviz::Config config ) const
00073 {
00074 rviz::Panel::save( config );
00075 }
00076
00077 void EmptyServiceCallInterfaceAction::load( const rviz::Config& config )
00078 {
00079 rviz::Panel::load( config );
00080 }
00081 }
00082
00083 #include <pluginlib/class_list_macros.h>
00084 PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::EmptyServiceCallInterfaceAction, rviz::Panel )