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