-
Notifications
You must be signed in to change notification settings - Fork 276
rviz common ros service property #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ahcorde
merged 8 commits into
ros2:rolling
from
jsupratman13:feature/rviz_common_ros_service_property
Sep 2, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f75b8a8
added get_service_names_and_types
jsupratman13 cd48ce9
added get ros service property
jsupratman13 8f44646
Update copyright
jsupratman13 27af0e6
Update copyright
jsupratman13 38af523
added headers
jsupratman13 c015894
declare functions in cpp
jsupratman13 2fe6f90
fix copyright header
jsupratman13 1a4a373
Merge branch 'rolling' into feature/rviz_common_ros_service_property
ahcorde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
rviz_common/include/rviz_common/properties/ros_service_property.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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(), | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
rviz_common/src/rviz_common/properties/ros_service_property.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| 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 | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return filter_; | ||
| } | ||
|
|
||
| void RosFilteredServiceProperty::fillServiceList() | ||
| { | ||
| QStringList filtered_strings_; | ||
jsupratman13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Obtain list of available services | ||
| RosServiceProperty::fillServiceList(); | ||
| // Apply filter | ||
| if (filter_enabled_) { | ||
| strings_ = strings_.filter(filter_); | ||
| } | ||
| } | ||
| } // end namespace properties | ||
| } // end namespace rviz_common | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.