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/o2r 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 
63  {
64  if (event->type() == QEvent::KeyPress && event->key() == 16777248) { // sift
65  shift_pressing_ = true;
66  }
67  else if (event->type() == QEvent::KeyRelease && event->key() == 16777248) {
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 
#define NULL
virtual bool handleDisplayClick(rviz::Property *property, rviz::ViewportMouseEvent &event)
virtual int processMouseEvent(rviz::ViewportMouseEvent &event)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
virtual void onRelease(rviz::ViewportMouseEvent &event)
virtual DisplayGroup * getRootDisplayGroup() const =0
virtual int numChildren() const
Property * childAt(int index) const
DisplayContext * context_
virtual void onClicked(rviz::ViewportMouseEvent &event)
virtual int processKeyEvent(QKeyEvent *event, rviz::RenderPanel *panel)
virtual void onMove(rviz::ViewportMouseEvent &event)
#define ROS_DEBUG(...)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18