Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rviz_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ set(rviz_common_headers_to_moc
include/rviz_common/properties/property_tree_with_help.hpp
include/rviz_common/properties/qos_profile_property.hpp
include/rviz_common/properties/ros_action_property.hpp
include/rviz_common/properties/ros_service_property.hpp
include/rviz_common/properties/ros_topic_property.hpp
include/rviz_common/properties/status_list.hpp
include/rviz_common/properties/status_property.hpp
Expand Down Expand Up @@ -192,6 +193,7 @@ set(rviz_common_source_files
src/rviz_common/properties/property_tree_with_help.cpp
src/rviz_common/properties/property.cpp
src/rviz_common/properties/ros_action_property.cpp
src/rviz_common/properties/ros_service_property.cpp
src/rviz_common/properties/ros_topic_property.cpp
src/rviz_common/properties/quaternion_property.cpp
src/rviz_common/properties/qos_profile_property.cpp
Expand Down
113 changes: 113 additions & 0 deletions rviz_common/include/rviz_common/properties/ros_service_property.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#ifndef RVIZ_COMMON__PROPERTIES__ROS_SERVICE_PROPERTY_HPP_
#define RVIZ_COMMON__PROPERTIES__ROS_SERVICE_PROPERTY_HPP_

#include <QObject>
#include <QRegExp>
#include <QString>

#include <memory>
#include <string>

#include "rviz_common/properties/editable_enum_property.hpp"
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
#include "rviz_common/visibility_control.hpp"

namespace rviz_common
{
namespace properties
{

class RVIZ_COMMON_PUBLIC RosServiceProperty : public EditableEnumProperty
{
Q_OBJECT

public:
explicit RosServiceProperty(
const QString & name = QString(),
const QString & default_value = QString(),
const QString & service_type = QString(),
const QString & description = QString(),
Property * parent = nullptr,
const char * changed_slot = nullptr,
QObject * receiver = nullptr);

void initialize(ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node);

void setServiceType(const QString & service_type);

QString getServiceType() const;

QString getService() const;

std::string getServiceStd() const;

bool isEmpty() const;

protected Q_SLOTS:
virtual void fillServiceList();

private:
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
QString service_type_;
};

class RVIZ_COMMON_PUBLIC RosFilteredServiceProperty
: public rviz_common::properties::RosServiceProperty
{
Q_OBJECT

public:
RosFilteredServiceProperty(
const QString & name = QString(),
const QString & default_value = QString(),
const QString & service_type = QString(),
const QString & description = QString(),
const QRegExp & filter = QRegExp(),
Property * parent = 0,
const char * changed_slot = 0,
QObject * receiver = 0);

void enableFilter(bool enabled);

QRegExp filter() const;

protected Q_SLOTS:
void fillServiceList() override;

private:
QRegExp filter_;
bool filter_enabled_;
};

} // end namespace properties
} // end namespace rviz_common

#endif // RVIZ_COMMON__PROPERTIES__ROS_SERVICE_PROPERTY_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ class RosNodeAbstraction : public RosNodeAbstractionIface
std::map<std::string, std::vector<std::string>>
get_topic_names_and_types() const override;

/// Return a map with service names mapped to a list of types for that service.
/**
* The node name is what was given when initializing this API.
*
* \return map of service names and their types
*/
RVIZ_COMMON_PUBLIC
std::map<std::string, std::vector<std::string>>
get_service_names_and_types() const override;

// TODO(wjwwood): think about a suitable way to extend the abstraction to also cover subscriptions
RVIZ_COMMON_PUBLIC
rclcpp::Node::SharedPtr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class RosNodeAbstractionIface
virtual std::map<std::string, std::vector<std::string>>
get_topic_names_and_types() const = 0;

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

// TODO(anhosi): remove once the RosNodeAbstraction is extended to handle subscriptions
// and clock
virtual rclcpp::Node::SharedPtr
Expand Down
155 changes: 155 additions & 0 deletions rviz_common/src/rviz_common/properties/ros_service_property.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <QApplication> // NOLINT: cpplint can't handle Qt imports
#include <QObject> // NOLINT: cpplint can't handle Qt imports
#include <QRegExp> // NOLINT: cpplint can't handle Qt imports
#include <QString> // NOLINT: cpplint can't handle Qt imports
#include <QStringList> // NOLINT: cpplint can't handle Qt imports

#include "rviz_common/properties/ros_service_property.hpp"
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"

namespace rviz_common
{
namespace properties
{

RosServiceProperty::RosServiceProperty(
const QString & name,
const QString & default_value,
const QString & service_type,
const QString & description,
Property * parent,
const char * changed_slot,
QObject * receiver)
: EditableEnumProperty(name, default_value, description, parent, changed_slot, receiver),
rviz_ros_node_(),
service_type_(service_type)
{
connect(
this, SIGNAL(requestOptions(EditableEnumProperty*)),
this, SLOT(fillServiceList()));
}

void RosServiceProperty::initialize(ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node)
{
rviz_ros_node_ = rviz_ros_node;
}

void RosServiceProperty::setServiceType(const QString & service_type)
{
service_type_ = service_type;
}

QString RosServiceProperty::getServiceType() const
{
return service_type_;
}

QString RosServiceProperty::getService() const
{
return getValue().toString();
}

std::string RosServiceProperty::getServiceStd() const
{
return getValue().toString().toStdString();
}

bool RosServiceProperty::isEmpty() const
{
return getServiceStd().empty();
}

void RosServiceProperty::fillServiceList()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
clearOptions();

std::string std_service_type = service_type_.toStdString();
std::map<std::string, std::vector<std::string>> service_servers =
rviz_ros_node_.lock()->get_service_names_and_types();

for (const auto & service : service_servers) {
// Only add service whose type matches.
for (const auto & type : service.second) {
if (type == std_service_type) {
addOptionStd(service.first);
}
}
}
sortOptions();
QApplication::restoreOverrideCursor();
}

RosFilteredServiceProperty::RosFilteredServiceProperty(
const QString & name,
const QString & default_value,
const QString & service_type,
const QString & description,
const QRegExp & filter,
Property * parent,
const char * changed_slot,
QObject * receiver)
: RosServiceProperty(name, default_value, service_type, description, parent, changed_slot, receiver)
, filter_(filter)
, filter_enabled_(true)
{
}

void RosFilteredServiceProperty::enableFilter(bool enabled)
{
filter_enabled_ = enabled;
fillServiceList();
}

QRegExp RosFilteredServiceProperty::filter() const
{
return filter_;
}

void RosFilteredServiceProperty::fillServiceList()
{
QStringList filtered_strings_;

// Obtain list of available services
RosServiceProperty::fillServiceList();
// Apply filter
if (filter_enabled_) {
strings_ = strings_.filter(filter_);
}
}
} // end namespace properties
} // end namespace rviz_common
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ RosNodeAbstraction::get_topic_names_and_types() const
return raw_node_->get_topic_names_and_types();
}

std::map<std::string, std::vector<std::string>>
RosNodeAbstraction::get_service_names_and_types() const
{
return raw_node_->get_service_names_and_types();
}

} // namespace ros_integration
} // namespace rviz_common