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 "selection_tool.h"
00031 #include "move_tool.h"
00032 #include "selection/selection_manager.h"
00033 #include "visualization_manager.h"
00034 #include "render_panel.h"
00035 #include "display.h"
00036 #include "viewport_mouse_event.h"
00037
00038 #include "ogre_tools/camera_base.h"
00039 #include "ogre_tools/wx_ogre_render_window.h"
00040
00041 #include <wx/event.h>
00042
00043 #include <OGRE/OgreRay.h>
00044 #include <OGRE/OgreSceneManager.h>
00045 #include <OGRE/OgreCamera.h>
00046 #include <OGRE/OgreMovableObject.h>
00047 #include <OGRE/OgreRectangle2D.h>
00048 #include <OGRE/OgreSceneNode.h>
00049 #include <OGRE/OgreViewport.h>
00050 #include <OGRE/OgreMaterialManager.h>
00051 #include <OGRE/OgreTexture.h>
00052 #include <OGRE/OgreTextureManager.h>
00053
00054 #include <btBulletCollisionCommon.h>
00055
00056 #include <ros/time.h>
00057
00058 namespace rviz
00059 {
00060
00061 SelectionTool::SelectionTool( const std::string& name, char shortcut_key, VisualizationManager* manager )
00062 : Tool( name, shortcut_key, manager )
00063 , move_tool_(new MoveTool("SelectionTool Fake MoveTool", 0, manager))
00064 , selecting_(false)
00065 , sel_start_x_(0)
00066 , sel_start_y_(0)
00067 , moving_(false)
00068 {
00069
00070 }
00071
00072 SelectionTool::~SelectionTool()
00073 {
00074 delete move_tool_;
00075 }
00076
00077 void SelectionTool::activate()
00078 {
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 event.viewport->setMaterialScheme("test");
00103
00104 int flags = 0;
00105
00106 if (event.event.AltDown())
00107 {
00108 moving_ = true;
00109 selecting_ = false;
00110 }
00111 else
00112 {
00113 moving_ = false;
00114
00115 if (event.event.LeftDown())
00116 {
00117 selecting_ = true;
00118
00119 sel_start_x_ = event.event.GetX();
00120 sel_start_y_ = event.event.GetY();
00121 }
00122 }
00123
00124 if (selecting_)
00125 {
00126 sel_manager->highlight(event.viewport, sel_start_x_, sel_start_y_, event.event.GetX(), event.event.GetY());
00127
00128 if (event.event.LeftUp())
00129 {
00130 SelectionManager::SelectType type = SelectionManager::Replace;
00131
00132 M_Picked selection;
00133
00134 if (event.event.ShiftDown())
00135 {
00136 type = SelectionManager::Add;
00137 }
00138 else if (event.event.ControlDown())
00139 {
00140 type = SelectionManager::Remove;
00141 }
00142
00143 sel_manager->select(event.viewport, sel_start_x_, sel_start_y_, event.event.GetX(), event.event.GetY(), type);
00144
00145 selecting_ = false;
00146 }
00147
00148 flags |= Render;
00149 }
00150 else if (moving_)
00151 {
00152 sel_manager->removeHighlight();
00153
00154 flags = move_tool_->processMouseEvent(event);
00155
00156 if (event.event.LeftUp() || event.event.RightUp() || event.event.MiddleUp())
00157 {
00158 moving_ = false;
00159 }
00160 }
00161 else
00162 {
00163 sel_manager->highlight(event.viewport, event.event.GetX(), event.event.GetY(), event.event.GetX(), event.event.GetY());
00164 }
00165
00166 return flags;
00167 }
00168
00169 int SelectionTool::processKeyEvent( wxKeyEvent& event )
00170 {
00171 SelectionManager* sel_manager = manager_->getSelectionManager();
00172 char key = event.GetKeyCode();
00173
00174 switch (key)
00175 {
00176 case 'f':
00177 case 'F':
00178 sel_manager->focusOnSelection();
00179 break;
00180 }
00181
00182 return Render;
00183 }
00184
00185 }
00186