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 "interaction_tool.h"
00031
00032 #include "rviz/visualization_manager.h"
00033 #include "rviz/properties/property_manager.h"
00034 #include "rviz/properties/property.h"
00035 #include "rviz/viewport_mouse_event.h"
00036 #include "rviz/render_panel.h"
00037 #include "rviz/view_controller.h"
00038 #include "rviz/viewport_mouse_event.h"
00039 #include "rviz/selection/selection_handler.h"
00040 #include "rviz/selection/selection_manager.h"
00041
00042 #include <OGRE/OgreRay.h>
00043 #include <OGRE/OgrePlane.h>
00044 #include <OGRE/OgreCamera.h>
00045 #include <OGRE/OgreSceneNode.h>
00046 #include <OGRE/OgreViewport.h>
00047
00048 namespace rviz
00049 {
00050
00051
00052 class ViewControllerHandler: public SelectionHandler
00053 {
00054 virtual bool isInteractive() { return true; }
00055 virtual void handleMouseEvent(const Picked& obj, ViewportMouseEvent& event)
00056 {
00057 if ( event.panel->getViewController() )
00058 {
00059 event.panel->getViewController()->handleMouseEvent( event );
00060 }
00061 }
00062 };
00063
00064
00065 InteractionTool::InteractionTool( const std::string& name, char shortcut_key,
00066 VisualizationManager* manager ) : Tool( name, shortcut_key, manager )
00067 , focused_object_(0)
00068 , view_controller_handler_( new ViewControllerHandler() )
00069 , last_selection_frame_count_(manager->getFrameCount())
00070 {
00071 deactivate();
00072
00073 view_controller_handle_ = manager->getSelectionManager()->createHandle();
00074 manager->getSelectionManager()->addObject(view_controller_handle_, view_controller_handler_ );
00075 }
00076
00077 InteractionTool::~InteractionTool()
00078 {
00079 manager_->getSelectionManager()->removeObject( view_controller_handle_ );
00080 }
00081
00082 void InteractionTool::activate()
00083 {
00084 manager_->getSelectionManager()->enableInteraction(true);
00085 manager_->getSelectionManager()->setTextureSize(2);
00086 }
00087
00088 void InteractionTool::deactivate()
00089 {
00090 manager_->getSelectionManager()->enableInteraction(false);
00091 }
00092
00093 void InteractionTool::update(float wall_dt, float ros_dt)
00094 {
00095 }
00096
00097 void InteractionTool::updateSelection( SelectionHandlerPtr &focused_handler, ViewportMouseEvent event )
00098 {
00099 M_Picked results;
00100
00101 manager_->getSelectionManager()->pick( event.viewport,
00102 event.x, event.y,
00103 event.x + 1, event.y + 1,
00104 results, true );
00105
00106 last_selection_frame_count_ = manager_->getFrameCount();
00107
00108 SelectionHandlerPtr new_focused_handler;
00109 Picked new_focused_object;
00110 new_focused_object.pixel_count = 0;
00111
00112
00113 M_Picked::iterator result_it = results.begin();
00114 if( result_it != results.end() )
00115 {
00116 Picked object = result_it->second;
00117 SelectionHandlerPtr handler = manager_->getSelectionManager()->getHandler( object.handle );
00118 if ( object.pixel_count > 0 && handler.get() && handler->isInteractive() )
00119 {
00120 new_focused_object = object;
00121 new_focused_handler = handler;
00122 }
00123 }
00124
00125
00126 if ( !new_focused_handler.get() )
00127 {
00128 new_focused_handler = view_controller_handler_;
00129 new_focused_object.handle = view_controller_handle_;
00130 }
00131
00132
00133
00134 if ( new_focused_handler.get() != focused_handler.get() )
00135 {
00136 if ( focused_handler.get() )
00137 {
00138 event.type = QEvent::FocusOut;
00139 focused_handler->handleMouseEvent( focused_object_, event );
00140 }
00141
00142 ROS_DEBUG( "Switch focus to %d", new_focused_object.handle );
00143 event.type = QEvent::FocusIn;
00144 new_focused_handler->handleMouseEvent( focused_object_, event );
00145 }
00146
00147 focused_handler = new_focused_handler;
00148 focused_object_ = new_focused_object;
00149 }
00150
00151 int InteractionTool::processMouseEvent( ViewportMouseEvent& event )
00152 {
00153 int flags = 0;
00154
00155 SelectionHandlerPtr focused_handler;
00156 focused_handler = manager_->getSelectionManager()->getHandler( focused_object_.handle );
00157
00158
00159 bool need_selection_update = manager_->getFrameCount() > last_selection_frame_count_;
00160
00161
00162 if( need_selection_update && event.type != QEvent::MouseMove && event.type != QEvent::MouseButtonRelease )
00163 {
00164 updateSelection( focused_handler, event );
00165 flags = Render;
00166 }
00167
00168 if( focused_handler.get() )
00169 {
00170 focused_handler->handleMouseEvent( focused_object_, event );
00171 }
00172
00173 if( event.type == QEvent::MouseButtonRelease )
00174 {
00175 updateSelection( focused_handler, event );
00176 }
00177
00178 return flags;
00179 }
00180
00181 void InteractionTool::enumerateProperties(PropertyManager* property_manager, const CategoryPropertyWPtr& parent)
00182 {
00183 }
00184
00185 }
00186