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 <OGRE/OgreRay.h>
00033 #include <OGRE/OgreSceneManager.h>
00034 #include <OGRE/OgreCamera.h>
00035 #include <OGRE/OgreMovableObject.h>
00036 #include <OGRE/OgreRectangle2D.h>
00037 #include <OGRE/OgreSceneNode.h>
00038 #include <OGRE/OgreViewport.h>
00039 #include <OGRE/OgreMaterialManager.h>
00040 #include <OGRE/OgreTexture.h>
00041 #include <OGRE/OgreTextureManager.h>
00042
00043 #include <ros/time.h>
00044
00045 #include "ogre_tools/camera_base.h"
00046 #include "ogre_tools/qt_ogre_render_window.h"
00047
00048 #include "move_tool.h"
00049 #include "selection/selection_manager.h"
00050 #include "visualization_manager.h"
00051 #include "render_panel.h"
00052 #include "display.h"
00053 #include "viewport_mouse_event.h"
00054
00055 #include "selection_tool.h"
00056
00057 namespace rviz
00058 {
00059
00060 SelectionTool::SelectionTool( const std::string& name, char shortcut_key, VisualizationManager* manager )
00061 : Tool( name, shortcut_key, manager )
00062 , move_tool_(new MoveTool("SelectionTool Fake MoveTool", 0, manager))
00063 , selecting_(false)
00064 , sel_start_x_(0)
00065 , sel_start_y_(0)
00066 , moving_(false)
00067 {
00068
00069 }
00070
00071 SelectionTool::~SelectionTool()
00072 {
00073 delete move_tool_;
00074 }
00075
00076 void SelectionTool::activate()
00077 {
00078 manager_->getSelectionManager()->setTextureSize(512);
00079 selecting_ = false;
00080 moving_ = false;
00081 }
00082
00083 void SelectionTool::deactivate()
00084 {
00085 manager_->getSelectionManager()->removeHighlight();
00086 }
00087
00088 void SelectionTool::update(float wall_dt, float ros_dt)
00089 {
00090 SelectionManager* sel_manager = manager_->getSelectionManager();
00091
00092 if (!selecting_)
00093 {
00094 sel_manager->removeHighlight();
00095 }
00096 }
00097
00098 int SelectionTool::processMouseEvent( ViewportMouseEvent& event )
00099 {
00100 SelectionManager* sel_manager = manager_->getSelectionManager();
00101
00102 int flags = 0;
00103
00104 if( event.alt() )
00105 {
00106 moving_ = true;
00107 selecting_ = false;
00108 }
00109 else
00110 {
00111 moving_ = false;
00112
00113 if( event.leftDown() )
00114 {
00115 selecting_ = true;
00116
00117 sel_start_x_ = event.x;
00118 sel_start_y_ = event.y;
00119 }
00120 }
00121
00122 if( selecting_ )
00123 {
00124 sel_manager->highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );
00125
00126 if( event.leftUp() )
00127 {
00128 SelectionManager::SelectType type = SelectionManager::Replace;
00129
00130 M_Picked selection;
00131
00132 if( event.shift() )
00133 {
00134 type = SelectionManager::Add;
00135 }
00136 else if( event.control() )
00137 {
00138 type = SelectionManager::Remove;
00139 }
00140
00141 sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );
00142
00143 selecting_ = false;
00144 }
00145
00146 flags |= Render;
00147 }
00148 else if( moving_ )
00149 {
00150 sel_manager->removeHighlight();
00151
00152 flags = move_tool_->processMouseEvent( event );
00153
00154 if( event.type == QEvent::MouseButtonRelease )
00155 {
00156 moving_ = false;
00157 }
00158 }
00159 else
00160 {
00161 sel_manager->highlight( event.viewport, event.x, event.y, event.x, event.y );
00162 }
00163
00164 return flags;
00165 }
00166
00167 int SelectionTool::processKeyEvent( QKeyEvent* event )
00168 {
00169 SelectionManager* sel_manager = manager_->getSelectionManager();
00170
00171 if( event->key() == Qt::Key_F )
00172 {
00173 sel_manager->focusOnSelection();
00174 }
00175
00176 return Render;
00177 }
00178
00179 }
00180