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  {
75  }
76 
78  {
80  }
81 }
82 
XmlRpc::XmlRpcValue::size
int size() const
empty_service_call_interface.h
ros::package::getPath
ROSLIB_DECL std::string getPath(const std::string &package_name)
config.h
rviz::Panel
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
jsk_rviz_plugins::ServiceCallButtonInfo::service_name
std::string service_name
Definition: empty_service_call_interface.h:20
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::nh_
ros::NodeHandle nh_
Definition: empty_service_call_interface.h:37
ros::NodeHandle::serviceClient
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::signal_mapper
QSignalMapper * signal_mapper
Definition: empty_service_call_interface.h:41
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::save
virtual void save(rviz::Config config) const
Definition: empty_service_call_interface.cpp:72
class_list_macros.h
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::service_call_button_infos_
std::vector< ServiceCallButtonInfo > service_call_button_infos_
Definition: empty_service_call_interface.h:38
rviz
ros::ServiceClient
jsk_rviz_plugins::ServiceCallButtonInfo::icon_file_path
std::string icon_file_path
Definition: empty_service_call_interface.h:19
package.h
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::h_layout
QHBoxLayout * h_layout
Definition: empty_service_call_interface.h:40
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::load
virtual void load(const rviz::Config &config)
Definition: empty_service_call_interface.cpp:77
jsk_rviz_plugins::ServiceCallButtonInfo::text
std::string text
Definition: empty_service_call_interface.h:21
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
jsk_rviz_plugins::ServiceCallButtonInfo
Definition: empty_service_call_interface.h:17
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::parseROSParameters
void parseROSParameters()
Definition: empty_service_call_interface.cpp:38
rviz::Panel::load
virtual void load(const Config &config)
ROS_ERROR
#define ROS_ERROR(...)
jsk_rviz_plugins::EmptyServiceCallInterfaceAction
Definition: empty_service_call_interface.h:24
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
rviz::Panel::save
virtual void save(Config config) const
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
contact_state_marker.srv
srv
Definition: contact_state_marker.py:98
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::callRequestEmptyCommand
void callRequestEmptyCommand(int button_id)
Definition: empty_service_call_interface.cpp:62
ROS_INFO
#define ROS_INFO(...)
jsk_rviz_plugins::EmptyServiceCallInterfaceAction::layout
QVBoxLayout * layout
Definition: empty_service_call_interface.h:39
config
config
jsk_rviz_plugins
Definition: __init__.py:1
rviz::Config
XmlRpc::XmlRpcValue
ros::NodeHandle


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Mon Jan 22 2024 03:47:13