overlay_picker_tool.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #include <QApplication>
37 #include <QMenu>
38 #include <QTimer>
39 #include <ros/ros.h>
40 #include <rviz/tool_manager.h>
41 #include <rviz/display_context.h>
42 #include <rviz/view_manager.h>
43 #include <rviz/display_group.h>
44 #include <rviz/display.h>
45 
46 #include "overlay_picker_tool.h"
47 #include "overlay_text_display.h"
48 #include "plotter_2d_display.h"
49 #include "pie_chart_display.h"
50 #include "overlay_image_display.h"
52 #include "overlay_menu_display.h"
53 
54 namespace jsk_rviz_plugins
55 {
57  : is_moving_(false), shift_pressing_(false), rviz::Tool()
58  {
59 
60  }
61 
62  int OverlayPickerTool::processKeyEvent(QKeyEvent* event, rviz::RenderPanel* panel)
63  {
64  if (event->type() == QEvent::KeyPress && event->key() == Qt::Key_Shift) { // shift
65  shift_pressing_ = true;
66  }
67  else if (event->type() == QEvent::KeyRelease && event->key() == Qt::Key_Shift) {
68  shift_pressing_ = false;
69  }
70  return 0;
71  }
72 
73 
75  {
76  if (event.left() && event.leftDown()) {
77  if (!is_moving_) {
78  onClicked(event);
79  }
80  }
81  else if (event.left() && is_moving_) {
82  onMove(event);
83  }
84  else if (is_moving_ && !(event.left() && event.leftDown())) {
85  onRelease(event);
86  }
87  return 0;
88  }
89 
91  {
92  if (isPropertyType<rviz::DisplayGroup>(property)) {
93  rviz::DisplayGroup* group_property = isPropertyType<rviz::DisplayGroup>(property);
94  for (int i = 0; i < group_property->numChildren(); i++) {
95  if (handleDisplayClick(group_property->childAt(i), event)) {
96  return true;
97  }
98  }
99  }
100  else {
101  if (startMovement<OverlayTextDisplay>(property, event, "overlay_text_display")) {
102  return true;
103  }
104  else if (startMovement<Plotter2DDisplay>(property, event, "plotter_2d_display")) {
105  return true;
106  }
107  else if (startMovement<PieChartDisplay>(property, event, "pie_chart_display")) {
108  return true;
109  }
110  else if (startMovement<OverlayImageDisplay>(property, event, "overlay_image_display")) {
111  return true;
112  }
113  else if (startMovement<OverlayDiagnosticDisplay>(property, event, "overlay_diagnostic_display")) {
114  return true;
115  }
116  else if (startMovement<OverlayMenuDisplay>(property, event, "overlay_menu_display")) {
117  return true;
118  }
119  else {
120  return false;
121  }
122  }
123  return false;
124  }
125 
127  {
128  ROS_DEBUG("onClicked");
129  is_moving_ = true;
130  ROS_DEBUG("clicked: (%d, %d)", event.x, event.y);
131  // check the active overlay plugin
132  rviz::DisplayGroup* display_group = context_->getRootDisplayGroup();
133  handleDisplayClick(display_group, event);
134  }
135 
137  {
138  ROS_DEBUG("onMove");
139  ROS_DEBUG("moving: (%d, %d)", event.x, event.y);
140  if (target_property_) {
141  if (target_property_type_ == "overlay_text_display") {
142  movePosition<OverlayTextDisplay>(event);
143  }
144  else if (target_property_type_ == "plotter_2d_display") {
145  movePosition<Plotter2DDisplay>(event);
146  }
147  else if (target_property_type_ == "pie_chart_display") {
148  movePosition<PieChartDisplay>(event);
149  }
150  else if (target_property_type_ == "overlay_image_display") {
151  movePosition<OverlayImageDisplay>(event);
152  }
153  else if (target_property_type_ == "overlay_diagnostic_display") {
154  movePosition<OverlayDiagnosticDisplay>(event);
155  }
156  else if (target_property_type_ == "overlay_menu_display") {
157  movePosition<OverlayMenuDisplay>(event);
158  }
159  }
160  }
161 
163  {
164  ROS_DEBUG("onRelease");
165  is_moving_ = false;
166  ROS_DEBUG("released: (%d, %d)", event.x, event.y);
167  if (target_property_) {
168  if (target_property_type_ == "overlay_text_display") {
169  setPosition<OverlayTextDisplay>(event);
170  }
171  else if (target_property_type_ == "plotter_2d_display") {
172  setPosition<Plotter2DDisplay>(event);
173  }
174  else if (target_property_type_ == "pie_chart_display") {
175  setPosition<PieChartDisplay>(event);
176  }
177  else if (target_property_type_ == "overlay_image_display") {
178  setPosition<OverlayImageDisplay>(event);
179  }
180  else if (target_property_type_ == "overlay_diagnostic_display") {
181  setPosition<OverlayDiagnosticDisplay>(event);
182  }
183  else if (target_property_type_ == "overlay_menu_display") {
184  setPosition<OverlayMenuDisplay>(event);
185  }
186  }
187  // clear cache
190  }
191 
192 }
193 
rviz::Property::childAt
Property * childAt(int index) const
rviz::ViewportMouseEvent::leftDown
bool leftDown()
jsk_rviz_plugins::OverlayPickerTool::processMouseEvent
virtual int processMouseEvent(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:106
overlay_image_display.h
NULL
#define NULL
rviz::Tool
display_group.h
jsk_rviz_plugins::OverlayPickerTool::shift_pressing_
bool shift_pressing_
Definition: overlay_picker_tool.h:189
ros.h
rviz::ViewportMouseEvent
rviz::ViewportMouseEvent::x
int x
rviz::Tool::context_
DisplayContext * context_
jsk_rviz_plugins::OverlayPickerTool::target_property_
rviz::Property * target_property_
Definition: overlay_picker_tool.h:186
rviz::ViewportMouseEvent::left
bool left()
display.h
jsk_rviz_plugins::OverlayPickerTool::handleDisplayClick
virtual bool handleDisplayClick(rviz::Property *property, rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:122
tool_manager.h
overlay_text_display.h
rviz::Property
class_list_macros.h
jsk_rviz_plugins::OverlayPickerTool::target_property_type_
std::string target_property_type_
Definition: overlay_picker_tool.h:187
pie_chart_display.h
overlay_diagnostic_display.h
ROS_DEBUG
#define ROS_DEBUG(...)
rviz
jsk_rviz_plugins::OverlayPickerTool
Definition: overlay_picker_tool.h:79
overlay_picker_tool.h
rviz::ViewportMouseEvent::y
int y
jsk_rviz_plugins::OverlayPickerTool::onRelease
virtual void onRelease(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:194
jsk_rviz_plugins::OverlayPickerTool::onMove
virtual void onMove(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:168
rviz::DisplayContext::getRootDisplayGroup
virtual DisplayGroup * getRootDisplayGroup() const=0
jsk_rviz_plugins::OverlayPickerTool::processKeyEvent
virtual int processKeyEvent(QKeyEvent *event, rviz::RenderPanel *panel)
Definition: overlay_picker_tool.cpp:94
view_manager.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
plotter_2d_display.h
overlay_menu_display.h
rviz::RenderPanel
jsk_rviz_plugins::OverlayPickerTool::onClicked
virtual void onClicked(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:158
jsk_rviz_plugins::OverlayPickerTool::is_moving_
bool is_moving_
Definition: overlay_picker_tool.h:185
jsk_rviz_plugins
Definition: __init__.py:1
rviz::DisplayGroup
rviz::DisplayGroup::numChildren
int numChildren() const override
jsk_rviz_plugins::OverlayPickerTool::OverlayPickerTool
OverlayPickerTool()
Definition: overlay_picker_tool.cpp:88
display_context.h


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Aug 2 2024 08:50:14