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  {
74  rviz::Panel::save( config );
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  {
81  rviz::Panel::load( config );
82  QString topic;
83  if( config.mapGetString( "Topic", &topic ))
84  {
85  output_topic_editor_->setText( topic );
86  updateTopic();
87  }
88  }
89 
90 }
91 
94 
msg
PublishTopic(QWidget *parent=0)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
ros::Publisher velocity_publisher_
Definition: publish_topic.h:43
virtual void save(Config config) const
bool mapGetString(const QString &key, QString *value_out) const
void configChanged()
void mapSetValue(const QString &key, QVariant value)
void publish(const boost::shared_ptr< M > &message) const
void setTopic(const QString &topic)
topic
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
virtual void load(const rviz::Config &config)
virtual void save(rviz::Config config) const
virtual void load(const Config &config)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Thu Jun 1 2023 02:45:58