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 {
50 
52 {
53  shortcut_key_ = 'i';
54  hide_inactive_property_ = 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
86  event.x, event.y,
87  event.x + 1, event.y + 1,
88  results, true );
89 
91 
92  InteractiveObjectPtr new_focused_object;
93 
94  // look for a valid handle in the result.
95  M_Picked::iterator result_it = results.begin();
96  if( result_it != results.end() )
97  {
98  Picked pick = result_it->second;
100  if ( pick.pixel_count > 0 && handler )
101  {
102  InteractiveObjectPtr object = handler->getInteractiveObject().lock();
103  if( object && object->isInteractive() )
104  {
105  new_focused_object = object;
106  }
107  }
108  }
109 
110  // If the mouse has gone from one object to another, defocus the old
111  // and focus the new.
112  InteractiveObjectPtr new_obj = new_focused_object;
113  InteractiveObjectPtr old_obj = focused_object_.lock();
114  if( new_obj != old_obj )
115  {
116  // Only copy the event contents here, once we know we need to use
117  // a modified version of it.
118  ViewportMouseEvent event_copy = event;
119  if( old_obj )
120  {
121  event_copy.type = QEvent::FocusOut;
122  old_obj->handleMouseEvent( event_copy );
123  }
124 
125  if( new_obj )
126  {
127  event_copy.type = QEvent::FocusIn;
128  new_obj->handleMouseEvent( event_copy );
129  }
130  }
131 
132  focused_object_ = new_focused_object;
133 }
134 
136 {
137  int flags = 0;
138 
139  if ( event.panel->contextMenuVisible() )
140  {
141  return flags;
142  }
143 
144  // make sure we let the vis. manager render at least one frame between selection updates
145  bool need_selection_update = context_->getFrameCount() > last_selection_frame_count_;
146 
147  // We are dragging if a button was down and is still down
148  Qt::MouseButtons buttons = event.buttons_down & ( Qt::LeftButton | Qt::RightButton | Qt::MidButton );
149  if ( event.type == QEvent::MouseButtonPress )
150  buttons &= ~event.acting_button;
151  bool dragging = buttons != 0;
152 
153  // unless we're dragging, check if there's a new object under the mouse
154  if( need_selection_update &&
155  !dragging &&
156  event.type != QEvent::MouseButtonRelease )
157  {
158  updateFocus( event );
159  flags = Render;
160  }
161 
162  {
163  InteractiveObjectPtr focused_object = focused_object_.lock();
164  if( focused_object )
165  {
166  focused_object->handleMouseEvent( event );
167  setCursor( focused_object->getCursor() );
168  // this will disable everything but the current interactive object
170  {
172  }
173  }
174  else if( event.panel->getViewController() )
175  {
176  move_tool_.processMouseEvent( event );
179  {
181  }
182  }
183  }
184 
185  if( event.type == QEvent::MouseButtonRelease )
186  {
187  updateFocus( event );
188  }
189 
190  return flags;
191 }
192 
193 int InteractionTool::processKeyEvent( QKeyEvent* event, RenderPanel* panel )
194 {
195  return move_tool_.processKeyEvent( event, panel );
196 }
197 
198 } // end namespace rviz
199 
ViewController * getViewController()
Definition: render_panel.h:88
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:65
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:61
char shortcut_key_
Definition: tool.h:177
virtual int processKeyEvent(QKeyEvent *event, RenderPanel *panel)
Definition: move_tool.cpp:60
const QCursor & getCursor()
Get current cursor of this tool.
Definition: tool.h:160
int pixel_count
Definition: forwards.h:62
virtual bool getBool() const
void enableInteraction(bool enable)
SelectionHandler * getHandler(CollObjectHandle obj)
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
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:54
uint64_t last_selection_frame_count_
virtual int processMouseEvent(ViewportMouseEvent &event)
DisplayContext * context_
Definition: tool.h:175
virtual void onInitialize()
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
BoolProperty * hide_inactive_property_
void setTextureSize(unsigned size)
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition: move_tool.cpp:50
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:69
virtual Property * getPropertyContainer() const
Return the container for properties of this Tool.
Definition: tool.h:75
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual int processKeyEvent(QKeyEvent *event, RenderPanel *panel)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:41