Skip to content

Commit 815ebb2

Browse files
add ros action property (#1549)
Signed-off-by: Joshua Supratman <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]>
1 parent a33b5e9 commit 815ebb2

File tree

3 files changed

+272
-0
lines changed

3 files changed

+272
-0
lines changed

rviz_common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ set(rviz_common_headers_to_moc
110110
include/rviz_common/properties/property_tree_model.hpp
111111
include/rviz_common/properties/property_tree_with_help.hpp
112112
include/rviz_common/properties/qos_profile_property.hpp
113+
include/rviz_common/properties/ros_action_property.hpp
113114
include/rviz_common/properties/ros_topic_property.hpp
114115
include/rviz_common/properties/status_list.hpp
115116
include/rviz_common/properties/status_property.hpp
@@ -190,6 +191,7 @@ set(rviz_common_source_files
190191
src/rviz_common/properties/property_tree_widget.cpp
191192
src/rviz_common/properties/property_tree_with_help.cpp
192193
src/rviz_common/properties/property.cpp
194+
src/rviz_common/properties/ros_action_property.cpp
193195
src/rviz_common/properties/ros_topic_property.cpp
194196
src/rviz_common/properties/quaternion_property.cpp
195197
src/rviz_common/properties/qos_profile_property.cpp
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
//
10+
// * Redistributions in binary form must reproduce the above copyright
11+
// notice, this list of conditions and the following disclaimer in the
12+
// documentation and/or other materials provided with the distribution.
13+
//
14+
// * Neither the name of the copyright holder nor the names of its
15+
// contributors may be used to endorse or promote products derived from
16+
// this software without specific prior written permission.
17+
//
18+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
// POSSIBILITY OF SUCH DAMAGE.
29+
#ifndef RVIZ_COMMON__PROPERTIES__ROS_ACTION_PROPERTY_HPP_
30+
#define RVIZ_COMMON__PROPERTIES__ROS_ACTION_PROPERTY_HPP_
31+
32+
#include <QObject>
33+
#include <QRegExp>
34+
#include <QString>
35+
36+
#include <memory>
37+
#include <string>
38+
39+
#include "rviz_common/properties/editable_enum_property.hpp"
40+
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
41+
#include "rviz_common/visibility_control.hpp"
42+
43+
namespace rviz_common
44+
{
45+
namespace properties
46+
{
47+
48+
class RVIZ_COMMON_PUBLIC RosActionProperty : public EditableEnumProperty
49+
{
50+
Q_OBJECT
51+
52+
public:
53+
explicit RosActionProperty(
54+
const QString & name = QString(),
55+
const QString & default_value = QString(),
56+
const QString & action_type = QString(),
57+
const QString & description = QString(),
58+
Property * parent = nullptr,
59+
const char * changed_slot = nullptr,
60+
QObject * receiver = nullptr);
61+
62+
void initialize(ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node);
63+
64+
void setActionType(const QString & action_type);
65+
66+
QString getActionType() const;
67+
68+
QString getAction() const;
69+
70+
std::string getActionStd() const;
71+
72+
bool isEmpty() const;
73+
74+
protected Q_SLOTS:
75+
virtual void fillActionList();
76+
77+
private:
78+
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
79+
QString action_type_;
80+
};
81+
82+
class RVIZ_COMMON_PUBLIC RosFilteredActionProperty
83+
: public rviz_common::properties::RosActionProperty
84+
{
85+
Q_OBJECT
86+
87+
public:
88+
RosFilteredActionProperty(
89+
const QString & name = QString(),
90+
const QString & default_value = QString(),
91+
const QString & action_type = QString(),
92+
const QString & description = QString(),
93+
const QRegExp & filter = QRegExp(),
94+
Property * parent = 0,
95+
const char * changed_slot = 0,
96+
QObject * receiver = 0);
97+
98+
void enableFilter(bool enabled);
99+
100+
QRegExp filter() const;
101+
102+
protected Q_SLOTS:
103+
void fillActionList() override;
104+
105+
private:
106+
QRegExp filter_;
107+
bool filter_enabled_;
108+
};
109+
110+
} // end namespace properties
111+
} // end namespace rviz_common
112+
113+
#endif // RVIZ_COMMON__PROPERTIES__ROS_ACTION_PROPERTY_HPP_
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
//
10+
// * Redistributions in binary form must reproduce the above copyright
11+
// notice, this list of conditions and the following disclaimer in the
12+
// documentation and/or other materials provided with the distribution.
13+
//
14+
// * Neither the name of the copyright holder nor the names of its
15+
// contributors may be used to endorse or promote products derived from
16+
// this software without specific prior written permission.
17+
//
18+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
// POSSIBILITY OF SUCH DAMAGE.
29+
30+
#include <map>
31+
#include <memory>
32+
#include <string>
33+
#include <vector>
34+
35+
#include <QApplication> // NOLINT: cpplint can't handle Qt imports
36+
#include <QObject> // NOLINT: cpplint can't handle Qt imports
37+
#include <QRegExp> // NOLINT: cpplint can't handle Qt imports
38+
#include <QString> // NOLINT: cpplint can't handle Qt imports
39+
#include <QStringList> // NOLINT: cpplint can't handle Qt imports
40+
41+
#include "rviz_common/properties/ros_action_property.hpp"
42+
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
43+
44+
namespace rviz_common
45+
{
46+
namespace properties
47+
{
48+
49+
RosActionProperty::RosActionProperty(
50+
const QString & name,
51+
const QString & default_value,
52+
const QString & action_type,
53+
const QString & description,
54+
Property * parent,
55+
const char * changed_slot,
56+
QObject * receiver)
57+
: EditableEnumProperty(name, default_value, description, parent, changed_slot, receiver),
58+
rviz_ros_node_(),
59+
action_type_(action_type)
60+
{
61+
connect(
62+
this, SIGNAL(requestOptions(EditableEnumProperty*)),
63+
this, SLOT(fillActionList()));
64+
}
65+
66+
void RosActionProperty::initialize(ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node)
67+
{
68+
rviz_ros_node_ = rviz_ros_node;
69+
}
70+
71+
void RosActionProperty::setActionType(const QString & action_type)
72+
{
73+
action_type_ = action_type;
74+
}
75+
76+
QString RosActionProperty::getActionType() const
77+
{
78+
return action_type_;
79+
}
80+
81+
QString RosActionProperty::getAction() const
82+
{
83+
return getValue().toString();
84+
}
85+
86+
std::string RosActionProperty::getActionStd() const
87+
{
88+
return getValue().toString().toStdString();
89+
}
90+
91+
bool RosActionProperty::isEmpty() const
92+
{
93+
return getActionStd().empty();
94+
}
95+
96+
void RosActionProperty::fillActionList()
97+
{
98+
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
99+
clearOptions();
100+
101+
std::string std_action_type = action_type_.toStdString() + "_FeedbackMessage";
102+
std::string suffix = "/_action/feedback";
103+
std::map<std::string, std::vector<std::string>> published_topics =
104+
rviz_ros_node_.lock()->get_topic_names_and_types();
105+
106+
for (const auto & topic : published_topics) {
107+
// Only add topics whose type matches.
108+
for (const auto & type : topic.second) {
109+
if (type == std_action_type) {
110+
auto action = topic.first.substr(0, topic.first.size() - suffix.size());
111+
addOptionStd(action);
112+
}
113+
}
114+
}
115+
sortOptions();
116+
QApplication::restoreOverrideCursor();
117+
}
118+
119+
RosFilteredActionProperty::RosFilteredActionProperty(
120+
const QString & name,
121+
const QString & default_value,
122+
const QString & action_type,
123+
const QString & description,
124+
const QRegExp & filter,
125+
Property * parent,
126+
const char * changed_slot,
127+
QObject * receiver)
128+
: RosActionProperty(name, default_value, action_type, description, parent, changed_slot, receiver)
129+
, filter_(filter)
130+
, filter_enabled_(true)
131+
{
132+
}
133+
134+
void RosFilteredActionProperty::enableFilter(bool enabled)
135+
{
136+
filter_enabled_ = enabled;
137+
fillActionList();
138+
}
139+
140+
QRegExp RosFilteredActionProperty::filter() const
141+
{
142+
return filter_;
143+
}
144+
145+
void RosFilteredActionProperty::fillActionList()
146+
{
147+
QStringList filtered_strings_;
148+
149+
// Obtain list of available actions
150+
RosActionProperty::fillActionList();
151+
// Apply filter
152+
if (filter_enabled_) {
153+
strings_ = strings_.filter(filter_);
154+
}
155+
}
156+
} // end namespace properties
157+
} // end namespace rviz_common

0 commit comments

Comments
 (0)