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::MidButton);
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 
void deactivate() override
ViewController * getViewController()
Definition: render_panel.h:90
int processMouseEvent(ViewportMouseEvent &event) override
Definition: move_tool.cpp:49
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:76
void updateFocus(const ViewportMouseEvent &event)
Check if the mouse has moved from one object to another, and update focused_object_ if so...
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:63
virtual uint64_t getFrameCount() const =0
Return the current value of the frame count.
InteractiveObjectWPtr focused_object_
The object (control) which currently has the mouse focus.
virtual InteractiveObjectWPtr getInteractiveObject()
Get the object to listen to mouse events and other interaction calls during use of the &#39;interact&#39; too...
CollObjectHandle handle
Definition: forwards.h:59
char shortcut_key_
Definition: tool.h:209
const QCursor & getCursor()
Get current cursor of this tool.
Definition: tool.h:186
int pixel_count
Definition: forwards.h:60
void enableInteraction(bool enable)
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
void onInitialize() override
SelectionHandler * getHandler(CollObjectHandle obj)
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
void activate() override
void pick(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2, M_Picked &results, bool single_render_pass=false)
void initialize(DisplayContext *context)
Definition: tool.cpp:52
uint64_t last_selection_frame_count_
DisplayContext * context_
Definition: tool.h:207
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
Definition: move_tool.cpp:59
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
BoolProperty * hide_inactive_property_
int processMouseEvent(ViewportMouseEvent &event) override
void setTextureSize(unsigned size)
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
virtual bool getBool() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24