record_action.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <QLineEdit>
3 #include <QPushButton>
4 #include <QVBoxLayout>
5 #include <QHBoxLayout>
6 #include <QLabel>
7 
8 #include "record_action.h"
9 
10 namespace jsk_rviz_plugins
11 {
12 
13  RecordAction::RecordAction( QWidget* parent )
14  : rviz::Panel( parent )
15  {
16  layout = new QVBoxLayout;
17 
18  //Text Box and Add Button to add new topic
19  QHBoxLayout* motion_record_layout = new QHBoxLayout;
20  record_motion_name_editor_ = new QLineEdit;
21  record_motion_name_editor_->setPlaceholderText(QString("Motion Name"));
22  motion_record_layout->addWidget( record_motion_name_editor_ );
23 
24  record_interface_button_ = new QPushButton("Record");
25  motion_record_layout->addWidget( record_interface_button_ );
26 
27  layout->addLayout( motion_record_layout );
28  //End of Text Box and Add Button
29  m_play_sigmap_ = new QSignalMapper(this);
30  connect(m_play_sigmap_, SIGNAL(mapped(int)),this, SLOT(OnClickPlayButton(int)));
31 
32  m_delete_sigmap_ = new QSignalMapper(this);
33  connect(m_delete_sigmap_, SIGNAL(mapped(int)),this, SLOT(OnClickDeleteButton(int)));
34 
35  setLayout( layout );
36  connect( record_interface_button_, SIGNAL( clicked() ), this, SLOT( recordClick() ));
37  pub_ = nh_.advertise<jsk_rviz_plugins::RecordCommand>( "/record_command", 1 );
38  rstate_ = IDLE;
39  }
40 
42  std::vector<motionListLayout>::iterator it = motion_list_layouts_.begin();
43  while( it != motion_list_layouts_.end()){
44  if(it->id == id){
45  jsk_rviz_plugins::RecordCommand msg;
46  msg.target = (it->target_name_)->text().toStdString();
47  msg.command = jsk_rviz_plugins::RecordCommand::PLAY;
48  pub_.publish(msg);
49  break;
50  }
51  ++it;
52  }
53  }
54 
56  std::vector<motionListLayout>::iterator it = motion_list_layouts_.begin();
57  while( it != motion_list_layouts_.end()){
58  if(it->id == id){
59  it->target_name_->hide();
60  delete it->target_name_;
61 
62  it->play_button_->hide();
63  delete it->play_button_;
64 
65  it->remove_button_->hide();
66  delete it->remove_button_;
67 
68  delete it->layout_;
69  it = motion_list_layouts_.erase( it );
70  Q_EMIT configChanged();
71  }else{
72  ++it;
73  }
74  }
75  }
76 
78  {
80  if( output_topic_ != "" ){
81  addTopicList(output_topic_.toStdString());
82  }
83  Q_EMIT configChanged();
84  }
85 
86  void RecordAction::addTopicList(std::string topic_name){
87  if(rstate_ == IDLE){
88  jsk_rviz_plugins::RecordCommand msg;
89  msg.target = topic_name;
90  msg.command = jsk_rviz_plugins::RecordCommand::RECORD;
91  pub_.publish(msg);
92  rstate_ = RECORD;
93  record_interface_button_->setText(QString("Stop"));
94  record_motion_name_editor_->setDisabled(true);
95  }else{
96  record_interface_button_->setText(QString("Record"));
97  record_motion_name_editor_->setDisabled(false);
98 
99  jsk_rviz_plugins::RecordCommand msg;
100  msg.target = topic_name;
101  msg.command = jsk_rviz_plugins::RecordCommand::RECORD_STOP;
102  pub_.publish(msg);
103  rstate_ = IDLE;
104 
105  motionListLayout tll;
106  if(!motion_list_layouts_.empty()){
107  motionListLayout lastTll = motion_list_layouts_.back();
108  tll.id = lastTll.id + 1;
109  }else{
110  tll.id = 0;
111  }
112 
113  tll.layout_ = new QHBoxLayout;
114  tll.target_name_ = new QLabel( topic_name.c_str() );
115  tll.layout_->addWidget( tll.target_name_ );
116  tll.play_button_ = new QPushButton("Play");
117  tll.layout_->addWidget( tll.play_button_ );
118  tll.remove_button_ = new QPushButton("Delete");
119  tll.layout_->addWidget( tll.remove_button_ );
120  layout->addLayout(tll.layout_);
121 
122  motion_list_layouts_.push_back(tll);
123 
124  connect(tll.play_button_, SIGNAL(clicked()), m_play_sigmap_, SLOT(map()));
125  m_play_sigmap_->setMapping(tll.play_button_, tll.id);
126 
127  connect(tll.remove_button_, SIGNAL(clicked()), m_delete_sigmap_, SLOT(map()));
128  m_delete_sigmap_->setMapping(tll.remove_button_, tll.id);
129  }
130  }
131 
132  void RecordAction::save( rviz::Config config ) const
133  {
135  }
136 
137  void RecordAction::load( const rviz::Config& config )
138  {
140  }
141 
142 }
143 
rviz::Panel::configChanged
void configChanged()
jsk_rviz_plugins::RecordAction::IDLE
@ IDLE
Definition: record_action.h:25
jsk_rviz_plugins::RecordAction
Definition: record_action.h:22
msg
msg
rviz::Panel
jsk_rviz_plugins::RecordAction::output_topic_
QString output_topic_
Definition: record_action.h:54
jsk_rviz_plugins::RecordAction::motionListLayout
Definition: record_action.h:65
jsk_rviz_plugins::RecordAction::recordClick
void recordClick()
Definition: record_action.cpp:77
jsk_rviz_plugins::RecordAction::motionListLayout::play_button_
QPushButton * play_button_
Definition: record_action.h:68
jsk_rviz_plugins::RecordAction::motionListLayout::id
int id
Definition: record_action.h:66
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
jsk_rviz_plugins::RecordAction::motionListLayout::remove_button_
QPushButton * remove_button_
Definition: record_action.h:69
jsk_rviz_plugins::RecordAction::save
virtual void save(rviz::Config config) const
Definition: record_action.cpp:132
overlay_sample.text
text
Definition: overlay_sample.py:21
class_list_macros.h
jsk_rviz_plugins::RecordAction::record_motion_name_editor_
QLineEdit * record_motion_name_editor_
Definition: record_action.h:52
jsk_rviz_plugins::RecordAction::RecordAction
RecordAction(QWidget *parent=0)
Definition: record_action.cpp:13
jsk_rviz_plugins::RecordAction::m_delete_sigmap_
QSignalMapper * m_delete_sigmap_
Definition: record_action.h:60
rviz
jsk_rviz_plugins::RecordAction::nh_
ros::NodeHandle nh_
Definition: record_action.h:76
jsk_rviz_plugins::RecordAction::OnClickPlayButton
void OnClickPlayButton(int id)
Definition: record_action.cpp:41
jsk_rviz_plugins::RecordAction::m_play_sigmap_
QSignalMapper * m_play_sigmap_
Definition: record_action.h:61
jsk_rviz_plugins::RecordAction::pub_
ros::Publisher pub_
Definition: record_action.h:75
record_action.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
jsk_rviz_plugins::RecordAction::load
virtual void load(const rviz::Config &config)
Definition: record_action.cpp:137
rviz::Panel::load
virtual void load(const Config &config)
jsk_rviz_plugins::RecordAction::OnClickDeleteButton
void OnClickDeleteButton(int id)
Definition: record_action.cpp:55
rviz::Panel::save
virtual void save(Config config) const
jsk_rviz_plugins::RecordAction::motionListLayout::layout_
QHBoxLayout * layout_
Definition: record_action.h:67
jsk_rviz_plugins::RecordAction::record_interface_button_
QPushButton * record_interface_button_
Definition: record_action.h:56
jsk_rviz_plugins::RecordAction::rstate_
RecordState rstate_
Definition: record_action.h:77
jsk_rviz_plugins::RecordAction::layout
QVBoxLayout * layout
Definition: record_action.h:63
jsk_rviz_plugins::RecordAction::motionListLayout::target_name_
QLabel * target_name_
Definition: record_action.h:70
jsk_rviz_plugins::RecordAction::motion_list_layouts_
std::vector< motionListLayout > motion_list_layouts_
Definition: record_action.h:73
config
config
jsk_rviz_plugins::RecordAction::RECORD
@ RECORD
Definition: record_action.h:26
jsk_rviz_plugins
Definition: __init__.py:1
jsk_rviz_plugins::RecordAction::addTopicList
void addTopicList(std::string topic_name)
Definition: record_action.cpp:86
rviz::Config


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