Skip to content

Commit 802c765

Browse files
committed
Update ROS node graph API
The node function get_topic_names_and_types() now returns a vector for each type name containing the parts of the fully qualified name. Signed-off-by: Jacob Perron <[email protected]>
1 parent 3344a8e commit 802c765

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

rviz_common/include/rviz_common/ros_integration/ros_node_abstraction.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class RosNodeAbstraction : public RosNodeAbstractionIface
7979
* \return map of topic names and their types
8080
*/
8181
RVIZ_COMMON_PUBLIC
82-
std::map<std::string, std::vector<std::string>>
82+
std::map<std::string, std::vector<std::vector<std::string>>>
8383
get_topic_names_and_types() const override;
8484

8585
// TODO(wjwwood): think about a suitable way to extend the abstraction to also cover subscriptions

rviz_common/include/rviz_common/ros_integration/ros_node_abstraction_iface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class RosNodeAbstractionIface
6060

6161
virtual std::string get_node_name() const = 0;
6262

63-
virtual std::map<std::string, std::vector<std::string>>
63+
virtual std::map<std::string, std::vector<std::vector<std::string>>>
6464
get_topic_names_and_types() const = 0;
6565

6666
// TODO(anhosi): remove once the RosNodeAbstraction is extended to handle subscriptions

rviz_common/src/rviz_common/add_display_dialog.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,26 @@ void getPluginGroups(
145145
std::vector<std::string> * unvisualizable,
146146
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node)
147147
{
148-
std::map<std::string, std::vector<std::string>> topic_names_and_types =
148+
std::map<std::string, std::vector<std::vector<std::string>>> topic_names_and_types =
149149
rviz_ros_node.lock()->get_topic_names_and_types();
150150

151151
for (const auto & map_pair : topic_names_and_types) {
152152
QString topic = QString::fromStdString(map_pair.first);
153-
if (map_pair.second.empty()) {
154-
throw std::runtime_error("topic '" + map_pair.first + "' unexpectedly has not types.");
153+
if (map_pair.second.empty() || map_pair.second[0].empty()) {
154+
throw std::runtime_error("topic '" + map_pair.first + "' unexpectedly has no types.");
155155
}
156+
std::string datatype_stdstring = map_pair.second[0].front() + "/" + map_pair.second[0].back();
156157
if (map_pair.second.size() > 1) {
157158
std::stringstream ss;
158159
ss << "topic '" << map_pair.first <<
159160
"' has more than one types associated, rviz will arbitrarily use the type '" <<
160-
map_pair.second[0] << "' -- all types for the topic:";
161+
datatype_stdstring << "' -- all types for the topic:";
161162
for (const auto & topic_type_name : map_pair.second) {
162-
ss << " '" << topic_type_name << "'";
163+
ss << " '" << topic_type_name.front() << "/" << topic_type_name.back() << "'";
163164
}
164165
RVIZ_COMMON_LOG_WARNING(ss.str());
165166
}
166-
QString datatype = QString::fromStdString(map_pair.second[0]);
167+
QString datatype = QString::fromStdString(datatype_stdstring);
167168

168169
if (datatype_plugins.contains(datatype)) {
169170
if (groups->empty() ||

rviz_common/src/rviz_common/properties/ros_topic_property.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ void RosTopicProperty::fillTopicList()
7373
clearOptions();
7474

7575
std::string std_message_type = message_type_.toStdString();
76-
std::map<std::string, std::vector<std::string>> published_topics =
76+
std::map<std::string, std::vector<std::vector<std::string>>> published_topics =
7777
rviz_ros_node_.lock()->get_topic_names_and_types();
7878

7979
for (const auto & topic : published_topics) {
8080
// Only add topics whose type matches.
81-
for (const auto & type : topic.second) {
81+
for (const auto & type_parts : topic.second) {
82+
std::string type = type_parts.front() + "/" + type_parts.back();
8283
// TODO(Martin-Idel-SI): revisit after message_traits become available.
8384
// We only want to show the types of the topic we subscribe to, however, currently we can't
8485
// get the type, so std_message_type will always be empty --> show all topics instead

rviz_common/src/rviz_common/ros_integration/ros_node_abstraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RosNodeAbstraction::get_node_name() const
5353
return raw_node_->get_name();
5454
}
5555

56-
std::map<std::string, std::vector<std::string>>
56+
std::map<std::string, std::vector<std::vector<std::string>>>
5757
RosNodeAbstraction::get_topic_names_and_types() const
5858
{
5959
return raw_node_->get_topic_names_and_types();

0 commit comments

Comments
 (0)