Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
ros_action_qevent.hpp
1 // Copyright (c) 2019 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_RVIZ_PLUGINS__ROS_ACTION_QEVENT_HPP_
16 #define NAV2_RVIZ_PLUGINS__ROS_ACTION_QEVENT_HPP_
17 
18 #include <QAbstractTransition>
19 
20 namespace nav2_rviz_plugins
21 {
22 
23 enum class QActionState
24 {
25  ACTIVE,
26  INACTIVE
27 };
28 
30 struct ROSActionQEvent : public QEvent
31 {
32  explicit ROSActionQEvent(QActionState state)
33  : QEvent(QEvent::Type(QEvent::User + 1)),
34  state_(state) {}
35 
36  QActionState state_;
37 };
38 
40 class ROSActionQTransition : public QAbstractTransition
41 {
42 public:
43  explicit ROSActionQTransition(QActionState initial_status)
44  : status_(initial_status)
45  {}
46 
48 
49 protected:
50  virtual bool eventTest(QEvent * e)
51  {
52  if (e->type() != QEvent::Type(QEvent::User + 1)) { // ROSActionEvent
53  return false;
54  }
55  ROSActionQEvent * action_event = static_cast<ROSActionQEvent *>(e);
56  return status_ != action_event->state_;
57  }
58 
59  virtual void onTransition(QEvent *) {}
60  QActionState status_;
61 };
62 
63 } // namespace nav2_rviz_plugins
64 
65 #endif // NAV2_RVIZ_PLUGINS__ROS_ACTION_QEVENT_HPP_
Custom Transition to check whether ROS Action state has changed.
Custom Event to track state of ROS Action.