cancel_action.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include <QPainter>
4 #include <QLineEdit>
5 #include <QPushButton>
6 #include <QVBoxLayout>
7 #include <QHBoxLayout>
8 #include <QLabel>
9 #include <QTimer>
10 
11 #include <std_msgs/Empty.h>
12 #include <actionlib_msgs/GoalID.h>
13 
14 #include "cancel_action.h"
15 
16 namespace jsk_rviz_plugins
17 {
18 
19  CancelAction::CancelAction( QWidget* parent )
20  : rviz::Panel( parent )
21  {
22  layout = new QVBoxLayout;
23 
24  //Text Box and Add Button to add new topic
25  QHBoxLayout* topic_layout = new QHBoxLayout;
26 
27  add_topic_box_ = new QComboBox;
28  initComboBox();
29  topic_layout->addWidget( add_topic_box_ );
30 
31  QPushButton* add_topic_button_ = new QPushButton("Add Action");
32  topic_layout->addWidget( add_topic_button_ );
33 
34  layout->addLayout( topic_layout );
35  //End of Text Box and Add Button
36 
37  m_sigmap = new QSignalMapper(this);
38 
39  connect(m_sigmap, SIGNAL(mapped(int)),this, SLOT(OnClickDeleteButton(int)));
40 
41  //Button to send cancel topic
42  QPushButton* send_topic_button_ = new QPushButton("Cancel Action");
43  layout->addWidget( send_topic_button_ );
44 
45  setLayout( layout );
46 
47  connect( send_topic_button_, SIGNAL( clicked() ), this, SLOT( sendTopic ()));
48  connect( add_topic_button_, SIGNAL( clicked() ), this, SLOT( addTopic() ));
49  }
50 
52  add_topic_box_->addItem("");
54  ros::master::getTopics (topics);
55  ros::master::V_TopicInfo::iterator it = topics.begin();
56  while( it != topics.end()){
57  if(it->datatype == "actionlib_msgs/GoalID"){
58  std::string action_name = it->name;
59  std::string delete_string = "/cancel";
60  std::string::size_type index = action_name.find_last_of(delete_string);
61  if(index != std::string::npos){
62  action_name.erase(index - delete_string.length() + 1);
63  add_topic_box_->addItem(action_name.c_str());
64  }
65  }
66  it ++;
67  }
68  }
69 
70 
72  std::vector<topicListLayout>::iterator it = topic_list_layouts_.begin();
73  while( it != topic_list_layouts_.end()){
74  if(it->id == id){
75  it->topic_name_->hide();
76  delete it->topic_name_;
77 
78  it->remove_button_->hide();
79  delete it->remove_button_;
80 
81  delete it->layout_;
82  it->publisher_.shutdown();
83  it = topic_list_layouts_.erase( it );
84  Q_EMIT configChanged();
85  }else{
86  ++it;
87  }
88  }
89  }
90 
92  {
93  output_topic_ = add_topic_box_->currentText();
94  if( output_topic_ != "" ){
95  add_topic_box_->setCurrentIndex( 0 );
96  addTopicList(output_topic_.toStdString());
97  }
98  Q_EMIT configChanged();
99  }
100 
101  void CancelAction::addTopicList(std::string topic_name){
102  topicListLayout tll;
103 
104  if(!topic_list_layouts_.empty()){
105  topicListLayout lastTll = topic_list_layouts_.back();
106  tll.id = lastTll.id + 1;
107  }else{
108  tll.id = 0;
109  }
110 
111  tll.layout_ = new QHBoxLayout;
112 
113  tll.topic_name_ = new QLabel( topic_name.c_str() );
114  tll.layout_->addWidget( tll.topic_name_ );
115 
116  tll.remove_button_ = new QPushButton("Delete");
117  tll.layout_->addWidget( tll.remove_button_ );
118 
119  layout->addLayout(tll.layout_);
120 
121  tll.publisher_ = nh_.advertise<actionlib_msgs::GoalID>( topic_name + "/cancel", 1 );
122 
123  topic_list_layouts_.push_back(tll);
124 
125  connect(tll.remove_button_, SIGNAL(clicked()), m_sigmap, SLOT(map()));
126  m_sigmap->setMapping(tll.remove_button_, tll.id);
127 
128  }
129 
131  std::vector<topicListLayout>::iterator it = topic_list_layouts_.begin();
132  while( it != topic_list_layouts_.end()){
133  actionlib_msgs::GoalID msg;
134  it->publisher_.publish(msg);
135  it++;
136  }
137  }
138 
139  void CancelAction::save( rviz::Config config ) const
140  {
142 
143  rviz::Config topic_list_config = config.mapMakeChild( "topics" );
144 
145  std::vector<topicListLayout>::const_iterator it = topic_list_layouts_.begin();
146  while( it != topic_list_layouts_.end()){
147  topic_list_config.listAppendNew().setValue( it->topic_name_->text() );
148  it ++;
149  }
150  config.mapSetValue( "Topic", output_topic_ );
151  }
152 
153  // Load all configuration data for this panel from the given Config object.
154  void CancelAction::load( const rviz::Config& config )
155  {
157  rviz::Config topic_list_config = config.mapGetChild( "topics" );
158  int num_topics = topic_list_config.listLength();
159 
160  for( int i = 0; i < num_topics; i++ ) {
161  addTopicList(topic_list_config.listChildAt( i ).getValue().toString().toStdString());
162  }
163  }
164 
165 }
166 
rviz::Panel::configChanged
void configChanged()
jsk_rviz_plugins::CancelAction::topicListLayout
Definition: cancel_action.h:63
jsk_rviz_plugins::CancelAction::topic_list_layouts_
std::vector< topicListLayout > topic_list_layouts_
Definition: cancel_action.h:71
jsk_rviz_plugins::CancelAction::topicListLayout::remove_button_
QPushButton * remove_button_
Definition: cancel_action.h:66
msg
msg
jsk_rviz_plugins::CancelAction::output_topic_
QString output_topic_
Definition: cancel_action.h:51
rviz::Panel
jsk_rviz_plugins::CancelAction::addTopic
void addTopic()
Definition: cancel_action.cpp:91
jsk_rviz_plugins::CancelAction::topicListLayout::publisher_
ros::Publisher publisher_
Definition: cancel_action.h:68
jsk_rviz_plugins::CancelAction::send_topic_button_
QPushButton * send_topic_button_
Definition: cancel_action.h:57
jsk_rviz_plugins::CancelAction::add_topic_button_
QPushButton * add_topic_button_
Definition: cancel_action.h:53
jsk_rviz_plugins::CancelAction::sendTopic
void sendTopic()
Definition: cancel_action.cpp:130
rviz::Config::listLength
int listLength() const
ros::master::getTopics
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
jsk_rviz_plugins::CancelAction::initComboBox
void initComboBox()
Definition: cancel_action.cpp:51
jsk_rviz_plugins::CancelAction
Definition: cancel_action.h:22
class_list_macros.h
jsk_rviz_plugins::CancelAction::m_sigmap
QSignalMapper * m_sigmap
Definition: cancel_action.h:59
rviz
ros::master::V_TopicInfo
std::vector< TopicInfo > V_TopicInfo
jsk_rviz_plugins::CancelAction::add_topic_box_
QComboBox * add_topic_box_
Definition: cancel_action.h:55
jsk_rviz_plugins::CancelAction::topicListLayout::layout_
QHBoxLayout * layout_
Definition: cancel_action.h:65
jsk_rviz_plugins::CancelAction::layout
QVBoxLayout * layout
Definition: cancel_action.h:61
jsk_rviz_plugins::CancelAction::load
virtual void load(const rviz::Config &config)
Definition: cancel_action.cpp:154
jsk_rviz_plugins::CancelAction::addTopicList
void addTopicList(std::string topic_name)
Definition: cancel_action.cpp:101
rviz::Config::listAppendNew
Config listAppendNew()
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::Config::listChildAt
Config listChildAt(int i) const
jsk_rviz_plugins::CancelAction::nh_
ros::NodeHandle nh_
Definition: cancel_action.h:77
rviz::Panel::load
virtual void load(const Config &config)
jsk_rviz_plugins::CancelAction::CancelAction
CancelAction(QWidget *parent=0)
Definition: cancel_action.cpp:19
jsk_rviz_plugins::CancelAction::topicListLayout::topic_name_
QLabel * topic_name_
Definition: cancel_action.h:67
rviz::Panel::save
virtual void save(Config config) const
jsk_rviz_plugins::CancelAction::topicListLayout::id
int id
Definition: cancel_action.h:64
jsk_rviz_plugins::CancelAction::OnClickDeleteButton
void OnClickDeleteButton(int id)
Definition: cancel_action.cpp:71
config
config
jsk_rviz_plugins
Definition: __init__.py:1
cancel_action.h
jsk_rviz_plugins::CancelAction::save
virtual void save(rviz::Config config) const
Definition: cancel_action.cpp:139
rviz::Config::setValue
void setValue(const QVariant &value)
rviz::Config
rviz::Config::getValue
QVariant getValue() const


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Dec 13 2024 03:49:56