Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
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
61
SelectionTool::SelectionTool
()
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
73
SelectionTool::~SelectionTool
()
74
{
75
delete
move_tool_
;
76
}
77
78
void
SelectionTool::onInitialize
()
79
{
80
move_tool_
->
initialize
(
context_
);
81
}
82
83
void
SelectionTool::activate
()
84
{
85
setStatus
(
"Click and drag to select objects on the screen."
);
86
context_
->
getSelectionManager
()->
setTextureSize
(512);
87
selecting_
=
false
;
88
moving_
=
false
;
89
// context_->getSelectionManager()->enableInteraction(true);
90
}
91
92
void
SelectionTool::deactivate
()
93
{
94
context_
->
getSelectionManager
()->
removeHighlight
();
95
}
96
97
void
SelectionTool::update
(
float
wall_dt,
float
ros_dt)
98
{
99
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
100
101
if
(!
selecting_
)
102
{
103
sel_manager->
removeHighlight
();
104
}
105
}
106
107
int
SelectionTool::processMouseEvent
(
ViewportMouseEvent
& event )
108
{
109
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
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
{
137
SelectionManager::SelectType
type =
SelectionManager::Replace
;
138
139
M_Picked
selection;
140
141
if
( event.
shift
() )
142
{
143
type =
SelectionManager::Add
;
144
}
145
else
if
( event.
control
() )
146
{
147
type =
SelectionManager::Remove
;
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
{
178
SelectionManager
* sel_manager =
context_
->
getSelectionManager
();
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
190
#include <
pluginlib/class_list_macros.hpp
>
191
PLUGINLIB_EXPORT_CLASS
(
rviz::SelectionTool
,
rviz::Tool
)
selection_manager.h
rviz::SelectionManager::Add
Definition:
selection_manager.h:86
rviz::ViewportMouseEvent::leftDown
bool leftDown()
Definition:
viewport_mouse_event.h:103
rviz::SelectionManager::focusOnSelection
void focusOnSelection()
Definition:
selection_manager.cpp:1228
rviz::Tool
Definition:
tool.h:55
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition:
viewport_mouse_event.h:108
time.h
rviz::SelectionManager::removeHighlight
void removeHighlight()
Definition:
selection_manager.cpp:521
rviz::M_Picked
boost::unordered_map< CollObjectHandle, Picked > M_Picked
Definition:
forwards.h:65
rviz::SelectionTool::processKeyEvent
virtual int processKeyEvent(QKeyEvent *event, RenderPanel *panel)
Definition:
selection_tool.cpp:176
rviz::RenderPanel
Definition:
render_panel.h:75
move_tool.h
rviz::SelectionTool::~SelectionTool
virtual ~SelectionTool()
Definition:
selection_tool.cpp:73
rviz::Tool::shortcut_key_
char shortcut_key_
Definition:
tool.h:177
load_resource.h
rviz::SelectionTool::activate
virtual void activate()
Definition:
selection_tool.cpp:83
rviz
Definition:
add_display_dialog.cpp:54
rviz::ViewportMouseEvent::x
int x
Definition:
viewport_mouse_event.h:110
rviz::SelectionManager::highlight
void highlight(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2)
Definition:
selection_manager.cpp:508
rviz::SelectionTool::deactivate
virtual void deactivate()
Definition:
selection_tool.cpp:92
rviz::Tool::Render
Definition:
tool.h:91
display.h
class_list_macros.hpp
rviz::SelectionManager::Replace
Definition:
selection_manager.h:88
rviz::ViewportMouseEvent::control
bool control()
Definition:
viewport_mouse_event.h:94
rviz::SelectionTool::move_tool_
MoveTool * move_tool_
Definition:
selection_tool.h:66
rviz::SelectionTool::processMouseEvent
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition:
selection_tool.cpp:107
rviz::SelectionTool::sel_start_x_
int sel_start_x_
Definition:
selection_tool.h:69
viewport_mouse_event.h
rviz::SelectionManager
Definition:
selection_manager.h:80
rviz::ViewportMouseEvent::shift
bool shift()
Definition:
viewport_mouse_event.h:93
rviz::SelectionManager::select
void select(Ogre::Viewport *viewport, int x1, int y1, int x2, int y2, SelectType type)
Definition:
selection_manager.cpp:528
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition:
viewport_mouse_event.h:99
camera_base.h
visualization_manager.h
rviz::SelectionTool
Definition:
selection_tool.h:48
rviz::SelectionTool::moving_
bool moving_
Definition:
selection_tool.h:74
rviz::Tool::initialize
void initialize(DisplayContext *context)
Definition:
tool.cpp:54
rviz::SelectionManager::SelectType
SelectType
Definition:
selection_manager.h:84
rviz::ViewportMouseEvent::type
QEvent::Type type
Definition:
viewport_mouse_event.h:109
render_panel.h
rviz::SelectionTool::sel_start_y_
int sel_start_y_
Definition:
selection_tool.h:70
rviz::Tool::context_
DisplayContext * context_
Definition:
tool.h:175
rviz::Tool::setStatus
void setStatus(const QString &message)
Definition:
tool.cpp:97
selection_tool.h
rviz::ViewportMouseEvent::y
int y
Definition:
viewport_mouse_event.h:111
rviz::SelectionManager::setTextureSize
void setTextureSize(unsigned size)
Definition:
selection_manager.cpp:364
rviz::MoveTool::processMouseEvent
virtual int processMouseEvent(ViewportMouseEvent &event)
Definition:
move_tool.cpp:50
rviz::ViewportMouseEvent::alt
bool alt()
Definition:
viewport_mouse_event.h:95
rviz::SelectionTool::update
virtual void update(float wall_dt, float ros_dt)
Definition:
selection_tool.cpp:97
rviz::MoveTool
Definition:
move_tool.h:40
rviz::ViewportMouseEvent
Definition:
viewport_mouse_event.h:46
rviz::Tool::access_all_keys_
bool access_all_keys_
Definition:
tool.h:178
qt_ogre_render_window.h
rviz::SelectionTool::SelectionTool
SelectionTool()
Definition:
selection_tool.cpp:61
rviz::SelectionTool::selecting_
bool selecting_
Definition:
selection_tool.h:68
rviz::SelectionManager::Remove
Definition:
selection_manager.h:87
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::SelectionTool::onInitialize
virtual void onInitialize()
Definition:
selection_tool.cpp:78
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42