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 {
61  : Tool()
62  , move_tool_(new MoveTool())
63  , selecting_(false)
64  , sel_start_x_(0)
65  , sel_start_y_(0)
66  , moving_(false)
67 {
68  shortcut_key_ = 's';
69  access_all_keys_ = true;
70 }
71 
73 {
74  delete move_tool_;
75 }
76 
78 {
80 }
81 
83 {
84  setStatus("Click and drag to select objects on the screen.");
86  selecting_ = false;
87  moving_ = false;
88  // context_->getSelectionManager()->enableInteraction(true);
89 }
90 
92 {
94 }
95 
96 void SelectionTool::update(float /*wall_dt*/, float /*ros_dt*/)
97 {
99 
100  if (!selecting_)
101  {
102  sel_manager->removeHighlight();
103  }
104 }
105 
107 {
109 
110  int flags = 0;
111 
112  if (event.alt())
113  {
114  moving_ = true;
115  selecting_ = false;
116  }
117  else
118  {
119  moving_ = false;
120 
121  if (event.leftDown())
122  {
123  selecting_ = true;
124 
125  sel_start_x_ = event.x;
126  sel_start_y_ = event.y;
127  }
128  }
129 
130  if (selecting_)
131  {
132  sel_manager->highlight(event.viewport, sel_start_x_, sel_start_y_, event.x, event.y);
133 
134  if (event.leftUp())
135  {
137 
138  M_Picked selection;
139 
140  if (event.shift())
141  {
142  type = SelectionManager::Add;
143  }
144  else if (event.control())
145  {
147  }
148 
149  sel_manager->select(event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type);
150 
151  selecting_ = false;
152  }
153 
154  flags |= Render;
155  }
156  else if (moving_)
157  {
158  sel_manager->removeHighlight();
159 
160  flags = move_tool_->processMouseEvent(event);
161 
162  if (event.type == QEvent::MouseButtonRelease)
163  {
164  moving_ = false;
165  }
166  }
167  else
168  {
169  sel_manager->highlight(event.viewport, event.x, event.y, event.x, event.y);
170  }
171 
172  return flags;
173 }
174 
175 int SelectionTool::processKeyEvent(QKeyEvent* event, RenderPanel* /*panel*/)
176 {
178 
179  if (event->key() == Qt::Key_F)
180  {
181  sel_manager->focusOnSelection();
182  }
183 
184  return Render;
185 }
186 
187 } // end namespace rviz
188 
int processMouseEvent(ViewportMouseEvent &event) override
Definition: move_tool.cpp:49
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition: forwards.h:63
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
char shortcut_key_
Definition: tool.h:209
void highlight(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2)
void activate() override
int processMouseEvent(ViewportMouseEvent &event) override
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:52
DisplayContext * context_
Definition: tool.h:207
void setStatus(const QString &message)
Definition: tool.cpp:101
void onInitialize() override
void setTextureSize(unsigned size)
bool access_all_keys_
Definition: tool.h:210
void update(float wall_dt, float ros_dt) override
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void deactivate() override


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