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  {
134  rviz::Panel::save( config );
135  }
136 
137  void RecordAction::load( const rviz::Config& config )
138  {
139  rviz::Panel::load( config );
140  }
141 
142 }
143 
msg
void publish(const boost::shared_ptr< M > &message) const
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
void addTopicList(std::string topic_name)
RecordAction(QWidget *parent=0)
virtual void save(rviz::Config config) const
void configChanged()
QPushButton * record_interface_button_
Definition: record_action.h:56
std::vector< motionListLayout > motion_list_layouts_
Definition: record_action.h:73
virtual void load(const rviz::Config &config)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
virtual void save(Config config) const
virtual void load(const Config &config)
QSignalMapper * m_delete_sigmap_
Definition: record_action.h:60


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18