topic_info.cpp
Go to the documentation of this file.
2 
3 namespace topics_rviz_plugin
4 {
5 
6 TopicInfo::TopicInfo(const std::string topic_name,
7  const std::string topic_type) :
8  topic_name_(topic_name),
9  topic_type_(topic_type)
10 {
11  label_ = std::make_shared<QLabel>(QString::fromStdString(topic_name_));
12  label_->setToolTip(QString::fromStdString(topic_type_));
13 
14  if (topic_type_ == "std_msgs/Bool" ||
15  topic_type_ == "std_msgs/Duration" ||
16  topic_type_ == "std_msgs/String" ||
17  topic_type_ == "std_msgs/Time")
18  {
19  display_ = std::make_shared<QLabel>();
20  }
21  else if (topic_type_ == "std_msgs/Int8" ||
22  topic_type_ == "std_msgs/Int16" ||
23  topic_type_ == "std_msgs/Int32" ||
24  topic_type_ == "std_msgs/Int64" ||
25  topic_type_ == "std_msgs/UInt8" ||
26  topic_type_ == "std_msgs/UInt16" ||
27  topic_type_ == "std_msgs/UInt32" ||
28  topic_type_ == "std_msgs/UInt64" ||
29  topic_type_ == "std_msgs/Float32" ||
30  topic_type_ == "std_msgs/Float64")
31  {
32  display_ = std::make_shared<QLCDNumber>();
33  std::static_pointer_cast<QLCDNumber>(display_)->setFrameShape(QFrame::Shape::NoFrame);
34  }
35  else
36  {
37  ROS_ERROR_STREAM("Unsupported built-in type, cannot display topic " << topic_name_ << " of type " << topic_type_);
38  display_ = std::make_shared<QLabel>("Unsupported topic type");
39  return;
40  };
41 
42  if (topic_type == "std_msgs/Bool")
44  else if (topic_type == "std_msgs/Duration")
46  else if (topic_type == "std_msgs/Float32")
48  else if (topic_type == "std_msgs/Float64")
50  else if (topic_type == "std_msgs/Int8")
52  else if (topic_type == "std_msgs/Int16")
54  else if (topic_type == "std_msgs/Int32")
56  else if (topic_type == "std_msgs/Int64")
58  else if (topic_type == "std_msgs/String")
60  else if (topic_type == "std_msgs/Time")
62  else if (topic_type == "std_msgs/UInt8")
64  else if (topic_type == "std_msgs/UInt16")
66  else if (topic_type == "std_msgs/UInt32")
68  else if (topic_type == "std_msgs/UInt64")
70  else
71  {
72  ROS_ERROR_STREAM("Could not find callback for topic type " << topic_type_);
73  return;
74  }
75 
76  connect(this, SIGNAL(adjustLCDNumberOfDigits(const long unsigned)), this,
77  SLOT(adjustLCDNumberOfDigitsHandler(const long unsigned)));
78 }
79 
81 {
82  nh_.shutdown();
83 }
84 
85 void
86 TopicInfo::adjustLCDNumberOfDigitsHandler(const long unsigned number)
87 {
88  std::shared_ptr<QLCDNumber> lcd(std::dynamic_pointer_cast<QLCDNumber>(display_));
89  if (!lcd)
90  return;
91 
92  if (number < 100)
93  lcd->setDigitCount(5);
94  else if (number < 10000)
95  lcd->setDigitCount(7);
96  else if (number < 1000000)
97  lcd->setDigitCount(9);
98  else if (number < 100000000)
99  lcd->setDigitCount(11);
100  else
101  lcd->setDigitCount(20);
102 }
103 
104 void
105 TopicInfo::boolCallback(const std_msgs::BoolConstPtr &msg)
106 {
107  QString label("False");
108  if (msg->data)
109  label = "True";
110 
111  std::static_pointer_cast<QLabel>(display_)->setText(label);
112 }
113 
114 void
115 TopicInfo::durationCallback(const std_msgs::DurationConstPtr &msg)
116 {
117  QString label(QString::number(msg->data.sec));
118  label.append(" sec, ");
119  label.append(QString::number(msg->data.nsec));
120  label.append(" nsec");
121 
122  std::static_pointer_cast<QLabel>(display_)->setText(label);
123 }
124 
125 void
126 TopicInfo::float32Callback(const std_msgs::Float32ConstPtr &msg)
127 {
128  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
129  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
130  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
131 }
132 
133 void
134 TopicInfo::float64Callback(const std_msgs::Float64ConstPtr &msg)
135 {
136  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
137  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
138  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
139 }
140 
141 void
142 TopicInfo::int8Callback(const std_msgs::Int8ConstPtr &msg)
143 {
144  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
145  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
146  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
147 }
148 
149 void
150 TopicInfo::int16Callback(const std_msgs::Int16ConstPtr &msg)
151 {
152  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
153  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
154  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
155 }
156 
157 void
158 TopicInfo::int32Callback(const std_msgs::Int32ConstPtr &msg)
159 {
160  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
161  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
162  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
163 }
164 
165 void
166 TopicInfo::int64Callback(const std_msgs::Int64ConstPtr &msg)
167 {
168  long unsigned digits_counting(msg->data > 0 ? msg->data : -msg->data);
169  Q_EMIT adjustLCDNumberOfDigits(digits_counting);
170  int32_t casted(msg->data);
171  std::static_pointer_cast<QLCDNumber>(display_)->display(casted);
172 }
173 
174 void
175 TopicInfo::stringCallback(const std_msgs::StringConstPtr &msg)
176 {
177  std::static_pointer_cast<QLabel>(display_)->setText(QString::fromStdString(msg->data));
178 }
179 
180 void
181 TopicInfo::timeCallback(const std_msgs::TimeConstPtr &msg)
182 {
183  QDateTime time;
184  time.setMSecsSinceEpoch(msg->data.sec * 1e3 + msg->data.nsec / 1e6);
185  std::static_pointer_cast<QLabel>(display_)->setText(time.toString(Qt::DateFormat::ISODate));
186 }
187 
188 void
189 TopicInfo::uint8Callback(const std_msgs::UInt8ConstPtr &msg)
190 {
191  Q_EMIT adjustLCDNumberOfDigits(msg->data);
192  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
193 }
194 
195 void
196 TopicInfo::uint16Callback(const std_msgs::UInt16ConstPtr &msg)
197 {
198  Q_EMIT adjustLCDNumberOfDigits(msg->data);
199  std::static_pointer_cast<QLCDNumber>(display_)->display(msg->data);
200 }
201 
202 void
203 TopicInfo::uint32Callback(const std_msgs::UInt32ConstPtr &msg)
204 {
205  uint16_t casted(msg->data);
206  Q_EMIT adjustLCDNumberOfDigits(casted);
207  std::static_pointer_cast<QLCDNumber>(display_)->display(casted);
208 }
209 
210 void
211 TopicInfo::uint64Callback(const std_msgs::UInt64ConstPtr &msg)
212 {
213  uint16_t casted(msg->data);
214  Q_EMIT adjustLCDNumberOfDigits(casted);
215  std::static_pointer_cast<QLCDNumber>(display_)->display(casted);
216 }
217 
218 }
void uint64Callback(const std_msgs::UInt64ConstPtr &msg)
Definition: topic_info.cpp:211
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void int8Callback(const std_msgs::Int8ConstPtr &msg)
Definition: topic_info.cpp:142
void adjustLCDNumberOfDigitsHandler(const long unsigned number)
Definition: topic_info.cpp:86
const std::string topic_type_
Definition: topic_info.hpp:37
void float32Callback(const std_msgs::Float32ConstPtr &msg)
Definition: topic_info.cpp:126
void durationCallback(const std_msgs::DurationConstPtr &msg)
Definition: topic_info.cpp:115
void stringCallback(const std_msgs::StringConstPtr &msg)
Definition: topic_info.cpp:175
void float64Callback(const std_msgs::Float64ConstPtr &msg)
Definition: topic_info.cpp:134
const std::string topic_name_
Definition: topic_info.hpp:36
void timeCallback(const std_msgs::TimeConstPtr &msg)
Definition: topic_info.cpp:181
std::shared_ptr< QLabel > label_
Definition: topic_info.hpp:38
void int16Callback(const std_msgs::Int16ConstPtr &msg)
Definition: topic_info.cpp:150
std::shared_ptr< QWidget > display_
Definition: topic_info.hpp:39
void uint8Callback(const std_msgs::UInt8ConstPtr &msg)
Definition: topic_info.cpp:189
#define ROS_ERROR_STREAM(args)
TopicInfo(const std::string topic_name, const std::string topic_type)
Definition: topic_info.cpp:6
void uint32Callback(const std_msgs::UInt32ConstPtr &msg)
Definition: topic_info.cpp:203
void int64Callback(const std_msgs::Int64ConstPtr &msg)
Definition: topic_info.cpp:166
void int32Callback(const std_msgs::Int32ConstPtr &msg)
Definition: topic_info.cpp:158
void uint16Callback(const std_msgs::UInt16ConstPtr &msg)
Definition: topic_info.cpp:196
void adjustLCDNumberOfDigits(const long unsigned number)
void boolCallback(const std_msgs::BoolConstPtr &msg)
Definition: topic_info.cpp:105


topics_rviz_plugin
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 15:34:43