interaction_tool.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreCamera.h>
31 #include <OgrePlane.h>
32 #include <OgreRay.h>
33 #include <OgreSceneNode.h>
34 #include <OgreViewport.h>
35 
36 #include <rviz/render_panel.h>
39 #include <rviz/view_controller.h>
43 #include <rviz/load_resource.h>
45 
47 
48 namespace rviz
49 {
51 {
52  shortcut_key_ = 'i';
54  new BoolProperty("Hide Inactive Objects", true,
55  "While holding down a mouse button, hide all other Interactive Objects.",
57 }
58 
60 {
61 }
62 
64 {
67  deactivate();
68 }
69 
71 {
74 }
75 
77 {
79 }
80 
82 {
83  M_Picked results;
84  // Pick exactly 1 pixel
85  context_->getSelectionManager()->pick(event.viewport, event.x, event.y, event.x + 1, event.y + 1,
86  results, true);
87 
89 
90  InteractiveObjectPtr new_focused_object;
91 
92  // look for a valid handle in the result.
93  M_Picked::iterator result_it = results.begin();
94  if (result_it != results.end())
95  {
96  Picked pick = result_it->second;
98  if (pick.pixel_count > 0 && handler)
99  {
100  InteractiveObjectPtr object = handler->getInteractiveObject().lock();
101  if (object && object->isInteractive())
102  {
103  new_focused_object = object;
104  }
105  }
106  }
107 
108  // If the mouse has gone from one object to another, defocus the old
109  // and focus the new.
110  InteractiveObjectPtr new_obj = new_focused_object;
111  InteractiveObjectPtr old_obj = focused_object_.lock();
112  if (new_obj != old_obj)
113  {
114  // Only copy the event contents here, once we know we need to use
115  // a modified version of it.
116  ViewportMouseEvent event_copy = event;
117  if (old_obj)
118  {
119  event_copy.type = QEvent::FocusOut;
120  old_obj->handleMouseEvent(event_copy);
121  }
122 
123  if (new_obj)
124  {
125  event_copy.type = QEvent::FocusIn;
126  new_obj->handleMouseEvent(event_copy);
127  }
128  }
129 
130  focused_object_ = new_focused_object;
131 }
132 
134 {
135  int flags = 0;
136 
137  if (event.panel->contextMenuVisible())
138  {
139  return flags;
140  }
141 
142  // make sure we let the vis. manager render at least one frame between selection updates
143  bool need_selection_update = context_->getFrameCount() > last_selection_frame_count_;
144 
145  // We are dragging if a button was down and is still down
146  Qt::MouseButtons buttons = event.buttons_down & (Qt::LeftButton | Qt::RightButton | Qt::MiddleButton);
147  if (event.type == QEvent::MouseButtonPress)
148  buttons &= ~event.acting_button;
149  bool dragging = buttons != 0;
150 
151  // unless we're dragging, check if there's a new object under the mouse
152  if (need_selection_update && !dragging && event.type != QEvent::MouseButtonRelease)
153  {
154  updateFocus(event);
155  flags = Render;
156  }
157 
158  {
159  InteractiveObjectPtr focused_object = focused_object_.lock();
160  if (focused_object)
161  {
162  focused_object->handleMouseEvent(event);
163  setCursor(focused_object->getCursor());
164  // this will disable everything but the current interactive object
166  {
168  }
169  }
170  else if (event.panel->getViewController())
171  {
175  {
177  }
178  }
179  }
180 
181  if (event.type == QEvent::MouseButtonRelease)
182  {
183  updateFocus(event);
184  }
185 
186  return flags;
187 }
188 
189 int InteractionTool::processKeyEvent(QKeyEvent* event, RenderPanel* panel)
190 {
191  return move_tool_.processKeyEvent(event, panel);
192 }
193 
194 } // end namespace rviz
195 
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition: bool_property.cpp:48
rviz::SelectionManager::enableInteraction
void enableInteraction(bool enable)
Definition: selection_manager.cpp:423
rviz::InteractionTool::deactivate
void deactivate() override
Definition: interaction_tool.cpp:76
rviz::InteractionTool::InteractionTool
InteractionTool()
Definition: interaction_tool.cpp:50
rviz::InteractionTool::updateFocus
void updateFocus(const ViewportMouseEvent &event)
Check if the mouse has moved from one object to another, and update focused_object_ if so.
Definition: interaction_tool.cpp:81
rviz::Tool
Definition: tool.h:56
boost::shared_ptr
rviz::SelectionManager::getHandler
SelectionHandler * getHandler(CollObjectHandle obj)
Definition: selection_manager.cpp:1168
rviz::Picked::handle
CollObjectHandle handle
Definition: forwards.h:59
rviz::SelectionManager::pick
void pick(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2, M_Picked &results, bool single_render_pass=false)
Definition: selection_manager.cpp:865
rviz::BoolProperty
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
rviz::ViewportMouseEvent
Definition: viewport_mouse_event.h:45
rviz::ViewportMouseEvent::x
int x
Definition: viewport_mouse_event.h:157
rviz::Tool::context_
DisplayContext * context_
Definition: tool.h:207
rviz::RenderPanel::getViewController
ViewController * getViewController()
Definition: render_panel.h:90
rviz::Tool::setCursor
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
viewport_mouse_event.h
selection_manager.h
bool_property.h
rviz::InteractionTool::processKeyEvent
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
Definition: interaction_tool.cpp:189
rviz::InteractionTool::focused_object_
InteractiveObjectWPtr focused_object_
The object (control) which currently has the mouse focus.
Definition: interaction_tool.h:70
rviz::Picked
Definition: forwards.h:53
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition: viewport_mouse_event.h:155
rviz::RenderPanel::contextMenuVisible
bool contextMenuVisible()
Definition: render_panel.cpp:182
selection_handler.h
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::Tool::shortcut_key_
char shortcut_key_
Definition: tool.h:209
rviz
Definition: add_display_dialog.cpp:54
rviz::Tool::Render
@ Render
Definition: tool.h:102
rviz::ViewportMouseEvent::y
int y
Definition: viewport_mouse_event.h:158
rviz::ViewportMouseEvent::panel
RenderPanel * panel
Definition: viewport_mouse_event.h:154
interaction_tool.h
rviz::ViewportMouseEvent::type
QEvent::Type type
Definition: viewport_mouse_event.h:156
rviz::InteractionTool::activate
void activate() override
Definition: interaction_tool.cpp:70
rviz::Tool::getPropertyContainer
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:76
rviz::Picked::pixel_count
int pixel_count
Definition: forwards.h:60
rviz::InteractionTool::~InteractionTool
~InteractionTool() override
Definition: interaction_tool.cpp:59
rviz::InteractionTool::last_selection_frame_count_
uint64_t last_selection_frame_count_
Definition: interaction_tool.h:72
rviz::InteractionTool
Definition: interaction_tool.h:45
visualization_manager.h
render_panel.h
rviz::InteractionTool::hideInactivePropertyChanged
void hideInactivePropertyChanged()
Definition: interaction_tool.h:62
rviz::InteractionTool::onInitialize
void onInitialize() override
Definition: interaction_tool.cpp:63
rviz::SelectionHandler
Definition: selection_handler.h:64
rviz::MoveTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition: move_tool.cpp:49
class_list_macros.hpp
rviz::InteractionTool::hide_inactive_property_
BoolProperty * hide_inactive_property_
Definition: interaction_tool.h:76
load_resource.h
view_controller.h
rviz::SelectionHandler::getInteractiveObject
virtual InteractiveObjectWPtr getInteractiveObject()
Get the object to listen to mouse events and other interaction calls during use of the 'interact' too...
Definition: selection_handler.cpp:261
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::RenderPanel
Definition: render_panel.h:74
rviz::SelectionManager::setTextureSize
void setTextureSize(unsigned size)
Definition: selection_manager.cpp:375
rviz::Tool::initialize
void initialize(DisplayContext *context)
Definition: tool.cpp:52
rviz::DisplayContext::getFrameCount
virtual uint64_t getFrameCount() const =0
Return the current value of the frame count.
rviz::InteractionTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition: interaction_tool.cpp:133
rviz::ViewportMouseEvent::acting_button
Qt::MouseButton acting_button
Definition: viewport_mouse_event.h:161
rviz::InteractionTool::move_tool_
MoveTool move_tool_
Definition: interaction_tool.h:74
rviz::M_Picked
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:63
rviz::Tool::getCursor
const QCursor & getCursor()
Get current cursor of this tool.
Definition: tool.h:186
rviz::MoveTool::processKeyEvent
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
Definition: move_tool.cpp:59


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53