Skip to content

Commit

Permalink
Update ROS node graph API
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jacobperron committed Mar 27, 2019
1 parent 3344a8e commit 802c765
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RosNodeAbstraction : public RosNodeAbstractionIface
* \return map of topic names and their types
*/
RVIZ_COMMON_PUBLIC
std::map<std::string, std::vector<std::string>>
std::map<std::string, std::vector<std::vector<std::string>>>
get_topic_names_and_types() const override;

// TODO(wjwwood): think about a suitable way to extend the abstraction to also cover subscriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class RosNodeAbstractionIface

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

virtual std::map<std::string, std::vector<std::string>>
virtual std::map<std::string, std::vector<std::vector<std::string>>>
get_topic_names_and_types() const = 0;

// TODO(anhosi): remove once the RosNodeAbstraction is extended to handle subscriptions
Expand Down
13 changes: 7 additions & 6 deletions rviz_common/src/rviz_common/add_display_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,26 @@ void getPluginGroups(
std::vector<std::string> * unvisualizable,
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node)
{
std::map<std::string, std::vector<std::string>> topic_names_and_types =
std::map<std::string, std::vector<std::vector<std::string>>> topic_names_and_types =
rviz_ros_node.lock()->get_topic_names_and_types();

for (const auto & map_pair : topic_names_and_types) {
QString topic = QString::fromStdString(map_pair.first);
if (map_pair.second.empty()) {
throw std::runtime_error("topic '" + map_pair.first + "' unexpectedly has not types.");
if (map_pair.second.empty() || map_pair.second[0].empty()) {
throw std::runtime_error("topic '" + map_pair.first + "' unexpectedly has no types.");
}
std::string datatype_stdstring = map_pair.second[0].front() + "/" + map_pair.second[0].back();
if (map_pair.second.size() > 1) {
std::stringstream ss;
ss << "topic '" << map_pair.first <<
"' has more than one types associated, rviz will arbitrarily use the type '" <<
map_pair.second[0] << "' -- all types for the topic:";
datatype_stdstring << "' -- all types for the topic:";
for (const auto & topic_type_name : map_pair.second) {
ss << " '" << topic_type_name << "'";
ss << " '" << topic_type_name.front() << "/" << topic_type_name.back() << "'";
}
RVIZ_COMMON_LOG_WARNING(ss.str());
}
QString datatype = QString::fromStdString(map_pair.second[0]);
QString datatype = QString::fromStdString(datatype_stdstring);

if (datatype_plugins.contains(datatype)) {
if (groups->empty() ||
Expand Down
5 changes: 3 additions & 2 deletions rviz_common/src/rviz_common/properties/ros_topic_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ void RosTopicProperty::fillTopicList()
clearOptions();

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

for (const auto & topic : published_topics) {
// Only add topics whose type matches.
for (const auto & type : topic.second) {
for (const auto & type_parts : topic.second) {
std::string type = type_parts.front() + "/" + type_parts.back();
// TODO(Martin-Idel-SI): revisit after message_traits become available.
// We only want to show the types of the topic we subscribe to, however, currently we can't
// get the type, so std_message_type will always be empty --> show all topics instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RosNodeAbstraction::get_node_name() const
return raw_node_->get_name();
}

std::map<std::string, std::vector<std::string>>
std::map<std::string, std::vector<std::vector<std::string>>>
RosNodeAbstraction::get_topic_names_and_types() const
{
return raw_node_->get_topic_names_and_types();
Expand Down

0 comments on commit 802c765

Please sign in to comment.