Go to the documentation of this file.00001 #include <stdio.h>
00002 #include <QLineEdit>
00003 #include <QPushButton>
00004 #include <QVBoxLayout>
00005 #include <QHBoxLayout>
00006 #include <QLabel>
00007
00008 #include "record_action.h"
00009
00010 namespace jsk_rviz_plugins
00011 {
00012
00013 RecordAction::RecordAction( QWidget* parent )
00014 : rviz::Panel( parent )
00015 {
00016 layout = new QVBoxLayout;
00017
00018
00019 QHBoxLayout* motion_record_layout = new QHBoxLayout;
00020 record_motion_name_editor_ = new QLineEdit;
00021 record_motion_name_editor_->setPlaceholderText(QString("Motion Name"));
00022 motion_record_layout->addWidget( record_motion_name_editor_ );
00023
00024 record_interface_button_ = new QPushButton("Record");
00025 motion_record_layout->addWidget( record_interface_button_ );
00026
00027 layout->addLayout( motion_record_layout );
00028
00029 m_play_sigmap_ = new QSignalMapper(this);
00030 connect(m_play_sigmap_, SIGNAL(mapped(int)),this, SLOT(OnClickPlayButton(int)));
00031
00032 m_delete_sigmap_ = new QSignalMapper(this);
00033 connect(m_delete_sigmap_, SIGNAL(mapped(int)),this, SLOT(OnClickDeleteButton(int)));
00034
00035 setLayout( layout );
00036 connect( record_interface_button_, SIGNAL( clicked() ), this, SLOT( recordClick() ));
00037 pub_ = nh_.advertise<jsk_rviz_plugins::RecordCommand>( "/record_command", 1 );
00038 rstate_ = IDLE;
00039 }
00040
00041 void RecordAction::OnClickPlayButton(int id){
00042 std::vector<motionListLayout>::iterator it = motion_list_layouts_.begin();
00043 while( it != motion_list_layouts_.end()){
00044 if(it->id == id){
00045 jsk_rviz_plugins::RecordCommand msg;
00046 msg.target = (it->target_name_)->text().toStdString();
00047 msg.command = jsk_rviz_plugins::RecordCommand::PLAY;
00048 pub_.publish(msg);
00049 break;
00050 }
00051 ++it;
00052 }
00053 }
00054
00055 void RecordAction::OnClickDeleteButton(int id){
00056 std::vector<motionListLayout>::iterator it = motion_list_layouts_.begin();
00057 while( it != motion_list_layouts_.end()){
00058 if(it->id == id){
00059 it->target_name_->hide();
00060 delete it->target_name_;
00061
00062 it->play_button_->hide();
00063 delete it->play_button_;
00064
00065 it->remove_button_->hide();
00066 delete it->remove_button_;
00067
00068 delete it->layout_;
00069 it = motion_list_layouts_.erase( it );
00070 Q_EMIT configChanged();
00071 }else{
00072 ++it;
00073 }
00074 }
00075 }
00076
00077 void RecordAction::recordClick()
00078 {
00079 output_topic_ = record_motion_name_editor_->text();
00080 if( output_topic_ != "" ){
00081 addTopicList(output_topic_.toStdString());
00082 }
00083 Q_EMIT configChanged();
00084 }
00085
00086 void RecordAction::addTopicList(std::string topic_name){
00087 if(rstate_ == IDLE){
00088 jsk_rviz_plugins::RecordCommand msg;
00089 msg.target = topic_name;
00090 msg.command = jsk_rviz_plugins::RecordCommand::RECORD;
00091 pub_.publish(msg);
00092 rstate_ = RECORD;
00093 record_interface_button_->setText(QString("Stop"));
00094 record_motion_name_editor_->setDisabled(true);
00095 }else{
00096 record_interface_button_->setText(QString("Record"));
00097 record_motion_name_editor_->setDisabled(false);
00098
00099 jsk_rviz_plugins::RecordCommand msg;
00100 msg.target = topic_name;
00101 msg.command = jsk_rviz_plugins::RecordCommand::RECORD_STOP;
00102 pub_.publish(msg);
00103 rstate_ = IDLE;
00104
00105 motionListLayout tll;
00106 if(!motion_list_layouts_.empty()){
00107 motionListLayout lastTll = motion_list_layouts_.back();
00108 tll.id = lastTll.id + 1;
00109 }else{
00110 tll.id = 0;
00111 }
00112
00113 tll.layout_ = new QHBoxLayout;
00114 tll.target_name_ = new QLabel( topic_name.c_str() );
00115 tll.layout_->addWidget( tll.target_name_ );
00116 tll.play_button_ = new QPushButton("Play");
00117 tll.layout_->addWidget( tll.play_button_ );
00118 tll.remove_button_ = new QPushButton("Delete");
00119 tll.layout_->addWidget( tll.remove_button_ );
00120 layout->addLayout(tll.layout_);
00121
00122 motion_list_layouts_.push_back(tll);
00123
00124 connect(tll.play_button_, SIGNAL(clicked()), m_play_sigmap_, SLOT(map()));
00125 m_play_sigmap_->setMapping(tll.play_button_, tll.id);
00126
00127 connect(tll.remove_button_, SIGNAL(clicked()), m_delete_sigmap_, SLOT(map()));
00128 m_delete_sigmap_->setMapping(tll.remove_button_, tll.id);
00129 }
00130 }
00131
00132 void RecordAction::save( rviz::Config config ) const
00133 {
00134 rviz::Panel::save( config );
00135 }
00136
00137 void RecordAction::load( const rviz::Config& config )
00138 {
00139 rviz::Panel::load( config );
00140 }
00141
00142 }
00143
00144 #include <pluginlib/class_list_macros.h>
00145 PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::RecordAction, rviz::Panel )