empty_service_call_interface.cpp
Go to the documentation of this file.
1 #include "rviz/config.h"
3 #include <ros/package.h>
4 #include <QVBoxLayout>
5 #include <QHBoxLayout>
6 #include <QSignalMapper>
7 
8 using namespace rviz;
9 namespace jsk_rviz_plugins
10 {
11  EmptyServiceCallInterfaceAction::EmptyServiceCallInterfaceAction( QWidget* parent )
12  : rviz::Panel( parent )
13  {
15 
16  QHBoxLayout* h_layout = new QHBoxLayout;
17  h_layout->setAlignment(Qt::AlignLeft);
18  layout = new QVBoxLayout();
19  signal_mapper = new QSignalMapper(this);
20 
21  for(size_t i = 0; i < service_call_button_infos_.size();i++){
23  QToolButton* tbutton = new QToolButton(this);
24  tbutton->setText(target_button.text.c_str());
25  tbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
26  tbutton->setIconSize(QSize(100, 100));
27  tbutton->setIcon(QIcon(QPixmap(QString(target_button.icon_file_path.c_str()))));
28  connect(tbutton, SIGNAL(clicked()), signal_mapper, SLOT(map()));
29  signal_mapper->setMapping(tbutton, i);
30  h_layout->addWidget(tbutton);
31  };
32  connect(signal_mapper, SIGNAL(mapped(int)),
33  this, SLOT(callRequestEmptyCommand(int)));
34  layout->addLayout(h_layout);
35  setLayout( layout );
36  }
37 
39  ros::NodeHandle nh("~");
40 
41  //icon file package file_name
42  std::string icon_package_name;
43  nh.param<std::string>("icon_include_package", icon_package_name, std::string("jsk_rviz_plugins"));
44  ROS_INFO("Find Icons In %s package.", icon_package_name.c_str());
45 
46  std::string icon_path_prefix;
47  if(!icon_package_name.empty())
48  icon_path_prefix = ros::package::getPath(icon_package_name) + std::string("/icons/");
49 
50  XmlRpc::XmlRpcValue buttons_list;
51  nh.getParam("rviz_service_call/buttons", buttons_list);
52  for (int32_t i = 0; i < buttons_list.size(); ++i)
53  {
54  ServiceCallButtonInfo new_button;
55  new_button.icon_file_path = icon_path_prefix + static_cast<std::string>(buttons_list[i]["icon"]);
56  new_button.service_name = static_cast<std::string>(buttons_list[i]["service_name"]);
57  new_button.text = static_cast<std::string>(buttons_list[i]["text"]);
58  service_call_button_infos_.push_back(new_button);
59  }
60  };
61 
63  ros::ServiceClient client = nh_.serviceClient<std_srvs::Empty>(service_call_button_infos_[button_id].service_name, true);
64  std_srvs::Empty srv;
65  if(client.call(srv))
66  ROS_INFO("Call Success");
67  else{
68  ROS_ERROR("Service call FAIL");
69  };
70  }
71 
73  {
74  rviz::Panel::save( config );
75  }
76 
78  {
79  rviz::Panel::load( config );
80  }
81 }
82 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
bool call(MReq &req, MRes &res)
virtual void save(Config config) const
bool param(const std::string &param_name, T &param_val, const T &default_val) const
#define ROS_INFO(...)
bool getParam(const std::string &key, std::string &s) const
ROSLIB_DECL std::string getPath(const std::string &package_name)
virtual void load(const Config &config)
std::vector< ServiceCallButtonInfo > service_call_button_infos_
#define ROS_ERROR(...)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Thu Jun 1 2023 02:45:58