overlay_picker_tool.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, 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 #ifndef JSK_RVIZ_PLUGIN_OVERLAY_PICKER_TOOL_H_
37 #define JSK_RVIZ_PLUGIN_OVERLAY_PICKER_TOOL_H_
38 
39 #include <rviz/tool.h>
43 #include <rviz/render_panel.h>
44 
45 namespace jsk_rviz_plugins
46 {
47  class OverlayPickerTool: public rviz::Tool
48  {
49  public:
51  virtual void activate() {}
52  virtual void deactivate() {};
53  virtual int processKeyEvent(QKeyEvent* event, rviz::RenderPanel* panel);
54  virtual int processMouseEvent(rviz::ViewportMouseEvent& event);
55  template <class T>
57  {
58  try {
59  return dynamic_cast<T*>(p);
60  }
61  catch (const std::bad_cast& e) {
62  return NULL;
63  }
64  }
65 
66  template <class T>
67  bool startMovement(rviz::Property* property,
68  rviz::ViewportMouseEvent& event, const std::string& type)
69  {
70  if (isPropertyType<T>(property)) {
71  bool res = isPropertyType<T>(property)->isInRegion(event.x, event.y);
72  if (res) {
73  target_property_ = property;
75  move_offset_x_ = event.x - isPropertyType<T>(property)->getX();
76  move_offset_y_ = event.y - isPropertyType<T>(property)->getY();
77  }
78  return res;
79  }
80  else {
81  return false;
82  }
83  }
84 
85  template <class T>
87  {
88  if (shift_pressing_) {
89  int orig_x = event.x - move_offset_x_;
90  int orig_y = event.y - move_offset_y_;
91  isPropertyType<T>(target_property_)->movePosition(
92  20 * (orig_x / 20), 20 * (orig_y / 20));
93  }
94  else {
95  isPropertyType<T>(target_property_)->movePosition(
96  event.x - move_offset_x_, event.y - move_offset_y_);
97  }
98  }
99 
100  template <class T>
102  {
103  if (shift_pressing_) {
104  int orig_x = event.x - move_offset_x_;
105  int orig_y = event.y - move_offset_y_;
106  isPropertyType<T>(target_property_)->setPosition(
107  20 * (orig_x / 20), 20 * (orig_y / 20));
108  }
109  else {
110  isPropertyType<T>(target_property_)->setPosition(
111  event.x - move_offset_x_, event.y - move_offset_y_);
112  }
113  }
114 
115  protected:
116  virtual void onClicked(rviz::ViewportMouseEvent& event);
117  virtual void onMove(rviz::ViewportMouseEvent& event);
118  virtual void onRelease(rviz::ViewportMouseEvent& event);
119  virtual bool handleDisplayClick(rviz::Property* property, rviz::ViewportMouseEvent& event);
120 
121  bool is_moving_;
123  std::string target_property_type_;
125  bool shift_pressing_;
126  private:
127 
128  };
129 }
130 
131 #endif
jsk_rviz_plugins::OverlayPickerTool::processMouseEvent
virtual int processMouseEvent(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:106
NULL
#define NULL
rviz::Tool
jsk_rviz_plugins::OverlayPickerTool::shift_pressing_
bool shift_pressing_
Definition: overlay_picker_tool.h:189
p
p
rviz::ViewportMouseEvent
rviz::ViewportMouseEvent::x
int x
viewport_mouse_event.h
jsk_rviz_plugins::OverlayPickerTool::setPosition
void setPosition(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.h:165
jsk_rviz_plugins::OverlayPickerTool::target_property_
rviz::Property * target_property_
Definition: overlay_picker_tool.h:186
jsk_rviz_plugins::OverlayPickerTool::deactivate
virtual void deactivate()
Definition: overlay_picker_tool.h:116
jsk_rviz_plugins::OverlayPickerTool::handleDisplayClick
virtual bool handleDisplayClick(rviz::Property *property, rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.cpp:122
rviz::Property
jsk_rviz_plugins::OverlayPickerTool::target_property_type_
std::string target_property_type_
Definition: overlay_picker_tool.h:187
jsk_rviz_plugins::OverlayPickerTool::movePosition
void movePosition(rviz::ViewportMouseEvent &event)
Definition: overlay_picker_tool.h:150
jsk_rviz_plugins::OverlayPickerTool::move_offset_y_
int move_offset_y_
Definition: overlay_picker_tool.h:188
render_panel.h
property_tree_model.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
jsk_rviz_plugins::OverlayPickerTool::startMovement
bool startMovement(rviz::Property *property, rviz::ViewportMouseEvent &event, const std::string &type)
Definition: overlay_picker_tool.h:131
jsk_rviz_plugins::OverlayPickerTool::processKeyEvent
virtual int processKeyEvent(QKeyEvent *event, rviz::RenderPanel *panel)
Definition: overlay_picker_tool.cpp:94
jsk_rviz_plugins::OverlayPickerTool::move_offset_x_
int move_offset_x_
Definition: overlay_picker_tool.h:188
property.h
jsk_rviz_plugins::OverlayPickerTool::activate
virtual void activate()
Definition: overlay_picker_tool.h:115
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
tool.h
jsk_rviz_plugins::OverlayPickerTool::isPropertyType
T * isPropertyType(rviz::Property *p)
Definition: overlay_picker_tool.h:120
jsk_rviz_plugins::OverlayPickerTool::OverlayPickerTool
OverlayPickerTool()
Definition: overlay_picker_tool.cpp:88


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