publish_topic.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 
13 #include "publish_topic.h"
14 
15 namespace jsk_rviz_plugins
16 {
17  PublishTopic::PublishTopic( QWidget* parent )
18  : rviz::Panel( parent )
19  {
20  QHBoxLayout* topic_layout = new QHBoxLayout;
21  topic_layout->addWidget( new QLabel( "Topic:" ));
22  output_topic_editor_ = new QLineEdit;
23  topic_layout->addWidget( output_topic_editor_ );
24 
25 
26  // Lay out the topic field above the control widget.
27  QVBoxLayout* layout = new QVBoxLayout;
28  layout->addLayout( topic_layout );
29 
30  QPushButton* send_topic_button_ = new QPushButton("Send Topic");
31  layout->addWidget( send_topic_button_ );
32  setLayout( layout );
33 
34 
35  connect( send_topic_button_, SIGNAL( clicked() ), this, SLOT( sendTopic ()));
36  connect( output_topic_editor_, SIGNAL( editingFinished() ), this, SLOT( updateTopic() ));
37 
38  }
39 
41  {
42  setTopic( output_topic_editor_->text() );
43  }
44 
45  // Set the topic name we are publishing to.
46  void PublishTopic::setTopic( const QString& new_topic )
47  {
48  // Only take action if the name has changed.
49  if( new_topic != output_topic_ )
50  {
51  output_topic_ = new_topic;
52  // If the topic is the empty string, don't publish anything.
53  if( output_topic_ == "" )
54  {
56  }
57  else
58  {
59  velocity_publisher_ = nh_.advertise<std_msgs::Empty>( output_topic_.toStdString(), 1 );
60  }
61 
62  Q_EMIT configChanged();
63  }
64  }
65 
67  std_msgs::Empty msg;
69  }
70 
71 
72  void PublishTopic::save( rviz::Config config ) const
73  {
75  config.mapSetValue( "Topic", output_topic_ );
76  }
77 
78  // Load all configuration data for this panel from the given Config object.
79  void PublishTopic::load( const rviz::Config& config )
80  {
82  QString topic;
83  if( config.mapGetString( "Topic", &topic ))
84  {
85  output_topic_editor_->setText( topic );
86  updateTopic();
87  }
88  }
89 
90 }
91 
94 
jsk_rviz_plugins::PublishTopic::nh_
ros::NodeHandle nh_
Definition: publish_topic.h:45
rviz::Panel::configChanged
void configChanged()
jsk_rviz_plugins::PublishTopic::send_topic_button_
QPushButton * send_topic_button_
Definition: publish_topic.h:41
msg
msg
rviz::Panel
jsk_rviz_plugins::PublishTopic::output_topic_editor_
QLineEdit * output_topic_editor_
Definition: publish_topic.h:37
publish_topic.h
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
jsk_rviz_plugins::PublishTopic::velocity_publisher_
ros::Publisher velocity_publisher_
Definition: publish_topic.h:43
class_list_macros.h
jsk_rviz_plugins::PublishTopic::sendTopic
void sendTopic()
Definition: publish_topic.cpp:66
ros::Publisher::shutdown
void shutdown()
jsk_rviz_plugins::PublishTopic::updateTopic
void updateTopic()
Definition: publish_topic.cpp:40
rviz
jsk_rviz_plugins::PublishTopic::setTopic
void setTopic(const QString &topic)
Definition: publish_topic.cpp:46
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::Panel::load
virtual void load(const Config &config)
rviz::Panel::save
virtual void save(Config config) const
jsk_rviz_plugins::PublishTopic::save
virtual void save(rviz::Config config) const
Definition: publish_topic.cpp:72
jsk_rviz_plugins::PublishTopic
Definition: publish_topic.h:15
jsk_rviz_plugins::PublishTopic::load
virtual void load(const rviz::Config &config)
Definition: publish_topic.cpp:79
config
config
jsk_rviz_plugins
Definition: __init__.py:1
jsk_rviz_plugins::PublishTopic::PublishTopic
PublishTopic(QWidget *parent=0)
Definition: publish_topic.cpp:17
rviz::Config
jsk_rviz_plugins::PublishTopic::output_topic_
QString output_topic_
Definition: publish_topic.h:39


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Aug 2 2024 08:50:14