Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <QKeyEvent>
00031
00032 #include <OgreRay.h>
00033 #include <OgreSceneManager.h>
00034 #include <OgreCamera.h>
00035 #include <OgreMovableObject.h>
00036 #include <OgreRectangle2D.h>
00037 #include <OgreSceneNode.h>
00038 #include <OgreViewport.h>
00039 #include <OgreMaterialManager.h>
00040 #include <OgreTexture.h>
00041 #include <OgreTextureManager.h>
00042
00043 #include <ros/time.h>
00044
00045 #include "move_tool.h"
00046
00047 #include "rviz/ogre_helpers/camera_base.h"
00048 #include "rviz/ogre_helpers/qt_ogre_render_window.h"
00049 #include "rviz/selection/selection_manager.h"
00050 #include "rviz/visualization_manager.h"
00051 #include "rviz/render_panel.h"
00052 #include "rviz/display.h"
00053 #include "rviz/viewport_mouse_event.h"
00054 #include "rviz/load_resource.h"
00055
00056 #include "selection_tool.h"
00057
00058 namespace rviz
00059 {
00060
00061 SelectionTool::SelectionTool()
00062 : Tool()
00063 , move_tool_( new MoveTool() )
00064 , selecting_( false )
00065 , sel_start_x_( 0 )
00066 , sel_start_y_( 0 )
00067 , moving_( false )
00068 {
00069 shortcut_key_ = 's';
00070 access_all_keys_ = true;
00071 }
00072
00073 SelectionTool::~SelectionTool()
00074 {
00075 delete move_tool_;
00076 }
00077
00078 void SelectionTool::onInitialize()
00079 {
00080 move_tool_->initialize( context_ );
00081 }
00082
00083 void SelectionTool::activate()
00084 {
00085 setStatus( "Click and drag to select objects on the screen." );
00086 context_->getSelectionManager()->setTextureSize(512);
00087 selecting_ = false;
00088 moving_ = false;
00089
00090 }
00091
00092 void SelectionTool::deactivate()
00093 {
00094 context_->getSelectionManager()->removeHighlight();
00095 }
00096
00097 void SelectionTool::update(float wall_dt, float ros_dt)
00098 {
00099 SelectionManager* sel_manager = context_->getSelectionManager();
00100
00101 if (!selecting_)
00102 {
00103 sel_manager->removeHighlight();
00104 }
00105 }
00106
00107 int SelectionTool::processMouseEvent( ViewportMouseEvent& event )
00108 {
00109 SelectionManager* sel_manager = context_->getSelectionManager();
00110
00111 int flags = 0;
00112
00113 if( event.alt() )
00114 {
00115 moving_ = true;
00116 selecting_ = false;
00117 }
00118 else
00119 {
00120 moving_ = false;
00121
00122 if( event.leftDown() )
00123 {
00124 selecting_ = true;
00125
00126 sel_start_x_ = event.x;
00127 sel_start_y_ = event.y;
00128 }
00129 }
00130
00131 if( selecting_ )
00132 {
00133 sel_manager->highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );
00134
00135 if( event.leftUp() )
00136 {
00137 SelectionManager::SelectType type = SelectionManager::Replace;
00138
00139 M_Picked selection;
00140
00141 if( event.shift() )
00142 {
00143 type = SelectionManager::Add;
00144 }
00145 else if( event.control() )
00146 {
00147 type = SelectionManager::Remove;
00148 }
00149
00150 sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );
00151
00152 selecting_ = false;
00153 }
00154
00155 flags |= Render;
00156 }
00157 else if( moving_ )
00158 {
00159 sel_manager->removeHighlight();
00160
00161 flags = move_tool_->processMouseEvent( event );
00162
00163 if( event.type == QEvent::MouseButtonRelease )
00164 {
00165 moving_ = false;
00166 }
00167 }
00168 else
00169 {
00170 sel_manager->highlight( event.viewport, event.x, event.y, event.x, event.y );
00171 }
00172
00173 return flags;
00174 }
00175
00176 int SelectionTool::processKeyEvent( QKeyEvent* event, RenderPanel* panel )
00177 {
00178 SelectionManager* sel_manager = context_->getSelectionManager();
00179
00180 if( event->key() == Qt::Key_F )
00181 {
00182 sel_manager->focusOnSelection();
00183 }
00184
00185 return Render;
00186 }
00187
00188 }
00189
00190 #include <pluginlib/class_list_macros.h>
00191 PLUGINLIB_EXPORT_CLASS( rviz::SelectionTool, rviz::Tool )