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 std::string buttons_names("emtpy_call_buttons");
00041
00042
00043 std::string button_names;
00044 nh.param<std::string>(buttons_names.c_str(), button_names, std::string(""));
00045
00046
00047 std::string icon_package_name;
00048 nh.param<std::string>("icon_include_package", icon_package_name, std::string("jsk_rviz_plugins"));
00049 ROS_INFO("Find Icons In %s package.", icon_package_name.c_str());
00050
00051 std::string icon_path_prefix;
00052 if(!icon_package_name.empty())
00053 icon_path_prefix = ros::package::getPath(icon_package_name) + std::string("/icons/");
00054
00055 XmlRpc::XmlRpcValue buttons_list;
00056 nh.getParam("rviz_service_call/buttons", buttons_list);
00057 for (int32_t i = 0; i < buttons_list.size(); ++i)
00058 {
00059 ServiceCallButtonInfo new_button;
00060 new_button.icon_file_path = icon_path_prefix + static_cast<std::string>(buttons_list[i]["icon"]);
00061 new_button.service_name = static_cast<std::string>(buttons_list[i]["service_name"]);
00062 new_button.text = static_cast<std::string>(buttons_list[i]["text"]);
00063 service_call_button_infos_.push_back(new_button);
00064 }
00065 };
00066
00067 void EmptyServiceCallInterfaceAction::callRequestEmptyCommand(const int button_id){
00068 ros::ServiceClient client = nh_.serviceClient<std_srvs::Empty>(service_call_button_infos_[button_id].service_name, true);
00069 std_srvs::Empty srv;
00070 if(client.call(srv))
00071 ROS_INFO("Call Success");
00072 else{
00073 ROS_ERROR("Service call FAIL");
00074 };
00075 }
00076
00077 void EmptyServiceCallInterfaceAction::save( rviz::Config config ) const
00078 {
00079 rviz::Panel::save( config );
00080 }
00081
00082 void EmptyServiceCallInterfaceAction::load( const rviz::Config& config )
00083 {
00084 rviz::Panel::load( config );
00085 }
00086 }
00087
00088 #include <pluginlib/class_list_macros.h>
00089 PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::EmptyServiceCallInterfaceAction, rviz::Panel )