src
rviz
default_plugin
tools
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
47
#include "
rviz/ogre_helpers/camera_base.h
"
48
#include "
rviz/ogre_helpers/qt_ogre_render_window.h
"
49
#include "
rviz/selection/selection_manager.h
"
50
#include "
rviz/visualization_manager.h
"
51
#include "
rviz/render_panel.h
"
52
#include "
rviz/display.h
"
53
#include "
rviz/viewport_mouse_event.h
"
54
#include "
rviz/load_resource.h
"
55
56
#include "
selection_tool.h
"
57
58
namespace
rviz
59
{
60
SelectionTool::SelectionTool
()
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
72
SelectionTool::~SelectionTool
()
73
{
74
delete
move_tool_
;
75
}
76
77
void
SelectionTool::onInitialize
()
78
{
79
move_tool_
->
initialize
(
context_
);
80
}
81
82
void
SelectionTool::activate
()
83
{
84
setStatus
(
"Click and drag to select objects on the screen."
);
85
context_
->
getSelectionManager
()->
setTextureSize
(512);
86
selecting_
=
false
;
87
moving_
=
false
;
88
// context_->getSelectionManager()->enableInteraction(true);
89
}
90
91
void
SelectionTool::deactivate
()
92
{
93
context_
->
getSelectionManager
()->
removeHighlight
();
94
}
95
96
void
SelectionTool::update
(
float
/*wall_dt*/
,
float
/*ros_dt*/
)
97
{
98
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
99
100
if
(!
selecting_
)
101
{
102
sel_manager->
removeHighlight
();
103
}
104
}
105
106
int
SelectionTool::processMouseEvent
(
ViewportMouseEvent
& event)
107
{
108
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
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
{
136
SelectionManager::SelectType
type =
SelectionManager::Replace
;
137
138
M_Picked
selection;
139
140
if
(event.
shift
())
141
{
142
type =
SelectionManager::Add
;
143
}
144
else
if
(event.
control
())
145
{
146
type =
SelectionManager::Remove
;
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
{
177
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
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
189
#include <
pluginlib/class_list_macros.hpp
>
190
PLUGINLIB_EXPORT_CLASS
(
rviz::SelectionTool
,
rviz::Tool
)
selection_manager.h
rviz::SelectionManager::Add
Definition:
selection_manager.h:89
rviz::ViewportMouseEvent::leftDown
bool leftDown()
Definition:
viewport_mouse_event.h:131
rviz::SelectionManager::focusOnSelection
void focusOnSelection()
Definition:
selection_manager.cpp:1285
rviz::Tool
Definition:
tool.h:56
rviz::MoveTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition:
move_tool.cpp:49
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:145
time.h
rviz::SelectionManager::removeHighlight
void removeHighlight()
Definition:
selection_manager.cpp:532
rviz::M_Picked
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition:
forwards.h:63
rviz::RenderPanel
Definition:
render_panel.h:74
move_tool.h
rviz::SelectionTool::processKeyEvent
int processKeyEvent(QKeyEvent *event, RenderPanel *panel) override
Definition:
selection_tool.cpp:175
rviz::Tool::shortcut_key_
char shortcut_key_
Definition:
tool.h:209
load_resource.h
rviz
Definition:
add_display_dialog.cpp:54
rviz::ViewportMouseEvent::x
int x
Definition:
viewport_mouse_event.h:147
rviz::SelectionManager::highlight
void highlight(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2)
Definition:
selection_manager.cpp:519
rviz::Tool::Render
Definition:
tool.h:102
rviz::SelectionTool::activate
void activate() override
Definition:
selection_tool.cpp:82
display.h
class_list_macros.hpp
rviz::SelectionManager::Replace
Definition:
selection_manager.h:91
rviz::ViewportMouseEvent::control
bool control()
Definition:
viewport_mouse_event.h:107
rviz::SelectionTool::move_tool_
MoveTool * move_tool_
Definition:
selection_tool.h:64
rviz::SelectionTool::sel_start_x_
int sel_start_x_
Definition:
selection_tool.h:67
viewport_mouse_event.h
rviz::SelectionTool::~SelectionTool
~SelectionTool() override
Definition:
selection_tool.cpp:72
rviz::SelectionTool::processMouseEvent
int processMouseEvent(ViewportMouseEvent &event) override
Definition:
selection_tool.cpp:106
rviz::SelectionManager
Definition:
selection_manager.h:81
rviz::ViewportMouseEvent::shift
bool shift()
Definition:
viewport_mouse_event.h:103
rviz::SelectionManager::select
void select(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2, SelectType type)
Definition:
selection_manager.cpp:539
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition:
viewport_mouse_event.h:118
camera_base.h
visualization_manager.h
rviz::SelectionTool
Definition:
selection_tool.h:47
rviz::SelectionTool::moving_
bool moving_
Definition:
selection_tool.h:72
rviz::Tool::initialize
void initialize(DisplayContext *context)
Definition:
tool.cpp:52
rviz::SelectionManager::SelectType
SelectType
Definition:
selection_manager.h:87
rviz::ViewportMouseEvent::type
QEvent::Type type
Definition:
viewport_mouse_event.h:146
render_panel.h
rviz::SelectionTool::sel_start_y_
int sel_start_y_
Definition:
selection_tool.h:68
rviz::Tool::context_
DisplayContext * context_
Definition:
tool.h:207
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:101
selection_tool.h
rviz::ViewportMouseEvent::y
int y
Definition:
viewport_mouse_event.h:148
rviz::SelectionTool::onInitialize
void onInitialize() override
Definition:
selection_tool.cpp:77
rviz::SelectionManager::setTextureSize
void setTextureSize(unsigned size)
Definition:
selection_manager.cpp:374
rviz::ViewportMouseEvent::alt
bool alt()
Definition:
viewport_mouse_event.h:111
rviz::MoveTool
Definition:
move_tool.h:39
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:45
rviz::Tool::access_all_keys_
bool access_all_keys_
Definition:
tool.h:210
qt_ogre_render_window.h
rviz::SelectionTool::SelectionTool
SelectionTool()
Definition:
selection_tool.cpp:60
rviz::SelectionTool::selecting_
bool selecting_
Definition:
selection_tool.h:66
rviz::SelectionManager::Remove
Definition:
selection_manager.h:90
rviz::SelectionTool::update
void update(float wall_dt, float ros_dt) override
Definition:
selection_tool.cpp:96
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::SelectionTool::deactivate
void deactivate() override
Definition:
selection_tool.cpp:91
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25