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 {
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 
126  private:
127 
128  };
129 }
130 
131 #endif
#define NULL
virtual bool handleDisplayClick(rviz::Property *property, rviz::ViewportMouseEvent &event)
virtual int processMouseEvent(rviz::ViewportMouseEvent &event)
virtual void onRelease(rviz::ViewportMouseEvent &event)
void movePosition(rviz::ViewportMouseEvent &event)
void setPosition(rviz::ViewportMouseEvent &event)
bool startMovement(rviz::Property *property, rviz::ViewportMouseEvent &event, const std::string &type)
virtual void onClicked(rviz::ViewportMouseEvent &event)
virtual int processKeyEvent(QKeyEvent *event, rviz::RenderPanel *panel)
virtual void onMove(rviz::ViewportMouseEvent &event)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Thu Jun 1 2023 02:45:58