selection_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 <QKeyEvent>
31 
32 #include <OgreRay.h>
33 #include <OgreSceneManager.h>
34 #include <OgreCamera.h>
35 #include <OgreMovableObject.h>
36 #include <OgreRectangle2D.h>
37 #include <OgreSceneNode.h>
38 #include <OgreViewport.h>
39 #include <OgreMaterialManager.h>
40 #include <OgreTexture.h>
41 #include <OgreTextureManager.h>
42 
43 #include <ros/time.h>
44 
45 #include "move_tool.h"
46 
51 #include "rviz/render_panel.h"
52 #include "rviz/display.h"
54 #include "rviz/load_resource.h"
55 
56 #include "selection_tool.h"
57 
58 namespace rviz
59 {
60 
62  : Tool()
63  , move_tool_( new MoveTool() )
64  , selecting_( false )
65  , sel_start_x_( 0 )
66  , sel_start_y_( 0 )
67  , moving_( false )
68 {
69  shortcut_key_ = 's';
70  access_all_keys_ = true;
71 }
72 
74 {
75  delete move_tool_;
76 }
77 
79 {
81 }
82 
84 {
85  setStatus( "Click and drag to select objects on the screen." );
87  selecting_ = false;
88  moving_ = false;
89 // context_->getSelectionManager()->enableInteraction(true);
90 }
91 
93 {
95 }
96 
97 void SelectionTool::update(float wall_dt, float ros_dt)
98 {
100 
101  if (!selecting_)
102  {
103  sel_manager->removeHighlight();
104  }
105 }
106 
108 {
110 
111  int flags = 0;
112 
113  if( event.alt() )
114  {
115  moving_ = true;
116  selecting_ = false;
117  }
118  else
119  {
120  moving_ = false;
121 
122  if( event.leftDown() )
123  {
124  selecting_ = true;
125 
126  sel_start_x_ = event.x;
127  sel_start_y_ = event.y;
128  }
129  }
130 
131  if( selecting_ )
132  {
133  sel_manager->highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );
134 
135  if( event.leftUp() )
136  {
138 
139  M_Picked selection;
140 
141  if( event.shift() )
142  {
143  type = SelectionManager::Add;
144  }
145  else if( event.control() )
146  {
148  }
149 
150  sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );
151 
152  selecting_ = false;
153  }
154 
155  flags |= Render;
156  }
157  else if( moving_ )
158  {
159  sel_manager->removeHighlight();
160 
161  flags = move_tool_->processMouseEvent( event );
162 
163  if( event.type == QEvent::MouseButtonRelease )
164  {
165  moving_ = false;
166  }
167  }
168  else
169  {
170  sel_manager->highlight( event.viewport, event.x, event.y, event.x, event.y );
171  }
172 
173  return flags;
174 }
175 
176 int SelectionTool::processKeyEvent( QKeyEvent* event, RenderPanel* panel )
177 {
179 
180  if( event->key() == Qt::Key_F )
181  {
182  sel_manager->focusOnSelection();
183  }
184 
185  return Render;
186 }
187 
188 } // end namespace rviz
189 
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:65
virtual int processKeyEvent(QKeyEvent *event, RenderPanel *panel)
char shortcut_key_
Definition: tool.h:177
virtual void activate()
void highlight(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2)
virtual void deactivate()
virtual int processMouseEvent(ViewportMouseEvent &event)
void select(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2, SelectType type)
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
void initialize(DisplayContext *context)
Definition: tool.cpp:54
DisplayContext * context_
Definition: tool.h:175
void setStatus(const QString &message)
Definition: tool.cpp:97
void setTextureSize(unsigned size)
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition: move_tool.cpp:50
virtual void update(float wall_dt, float ros_dt)
bool access_all_keys_
Definition: tool.h:178
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void onInitialize()


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