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 InteractionTool::InteractionTool( const std::string& name, char shortcut_key, VisualizationManager* manager )
00052 : MoveTool( name, shortcut_key, manager )
00053 , last_selection_frame_count_(manager->getFrameCount())
00054 {
00055 deactivate();
00056 }
00057
00058 InteractionTool::~InteractionTool()
00059 {
00060 }
00061
00062 void InteractionTool::activate()
00063 {
00064 manager_->getSelectionManager()->enableInteraction(true);
00065 manager_->getSelectionManager()->setTextureSize(2);
00066 }
00067
00068 void InteractionTool::deactivate()
00069 {
00070 manager_->getSelectionManager()->enableInteraction(false);
00071 }
00072
00073 void InteractionTool::update(float wall_dt, float ros_dt)
00074 {
00075 }
00076
00077 void InteractionTool::updateFocus( const ViewportMouseEvent& event )
00078 {
00079 M_Picked results;
00080
00081 manager_->getSelectionManager()->pick( event.viewport,
00082 event.x, event.y,
00083 event.x + 1, event.y + 1,
00084 results, true );
00085
00086 last_selection_frame_count_ = manager_->getFrameCount();
00087
00088 InteractiveObjectPtr new_focused_object;
00089
00090
00091 M_Picked::iterator result_it = results.begin();
00092 if( result_it != results.end() )
00093 {
00094 Picked pick = result_it->second;
00095 SelectionHandlerPtr handler = manager_->getSelectionManager()->getHandler( pick.handle );
00096 if ( pick.pixel_count > 0 && handler.get() )
00097 {
00098 InteractiveObjectPtr object = handler->getInteractiveObject().lock();
00099 if( object && object->isInteractive() )
00100 {
00101 new_focused_object = object;
00102 }
00103 }
00104 }
00105
00106
00107
00108 InteractiveObjectPtr new_obj = new_focused_object;
00109 InteractiveObjectPtr old_obj = focused_object_.lock();
00110 if( new_obj != old_obj )
00111 {
00112
00113
00114 ViewportMouseEvent event_copy = event;
00115 if( old_obj )
00116 {
00117 event_copy.type = QEvent::FocusOut;
00118 old_obj->handleMouseEvent( event_copy );
00119 }
00120
00121 if( new_obj )
00122 {
00123 event_copy.type = QEvent::FocusIn;
00124 new_obj->handleMouseEvent( event_copy );
00125 }
00126 }
00127
00128 focused_object_ = new_focused_object;
00129 }
00130
00131 int InteractionTool::processMouseEvent( ViewportMouseEvent& event )
00132 {
00133 int flags = 0;
00134
00135
00136 bool need_selection_update = manager_->getFrameCount() > last_selection_frame_count_;
00137 bool dragging = (event.type == QEvent::MouseMove && event.buttons_down != Qt::NoButton);
00138
00139
00140 if( need_selection_update &&
00141 !dragging &&
00142 event.type != QEvent::MouseButtonRelease )
00143 {
00144 updateFocus( event );
00145 flags = Render;
00146 }
00147
00148 {
00149 InteractiveObjectPtr focused_object = focused_object_.lock();
00150 if( focused_object )
00151 {
00152 focused_object->handleMouseEvent( event );
00153 }
00154 else if( event.panel->getViewController() )
00155 {
00156 event.panel->getViewController()->handleMouseEvent( event );
00157 }
00158 }
00159
00160 if( event.type == QEvent::MouseButtonRelease )
00161 {
00162 updateFocus( event );
00163 }
00164
00165 return flags;
00166 }
00167
00168 }
00169