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 <OgreCamera.h>
00031 #include <OgrePlane.h>
00032 #include <OgreRay.h>
00033 #include <OgreSceneNode.h>
00034 #include <OgreViewport.h>
00035
00036 #include "rviz/render_panel.h"
00037 #include "rviz/selection/selection_handler.h"
00038 #include "rviz/selection/selection_manager.h"
00039 #include "rviz/view_controller.h"
00040 #include "rviz/viewport_mouse_event.h"
00041 #include "rviz/viewport_mouse_event.h"
00042 #include "rviz/visualization_manager.h"
00043 #include "rviz/load_resource.h"
00044 #include "rviz/properties/bool_property.h"
00045
00046 #include "rviz/default_plugin/tools/interaction_tool.h"
00047
00048 namespace rviz
00049 {
00050
00051 InteractionTool::InteractionTool()
00052 {
00053 shortcut_key_ = 'i';
00054 hide_inactive_property_ = new BoolProperty("Hide Inactive Objects", true,
00055 "While holding down a mouse button, hide all other Interactive Objects.",
00056 getPropertyContainer(), SLOT( hideInactivePropertyChanged() ), this );
00057 }
00058
00059 InteractionTool::~InteractionTool()
00060 {
00061 }
00062
00063 void InteractionTool::onInitialize()
00064 {
00065 move_tool_.initialize( context_ );
00066 last_selection_frame_count_ = context_->getFrameCount();
00067 deactivate();
00068 }
00069
00070 void InteractionTool::activate()
00071 {
00072 context_->getSelectionManager()->enableInteraction(true);
00073 context_->getSelectionManager()->setTextureSize(1);
00074 }
00075
00076 void InteractionTool::deactivate()
00077 {
00078 context_->getSelectionManager()->enableInteraction(false);
00079 }
00080
00081 void InteractionTool::updateFocus( const ViewportMouseEvent& event )
00082 {
00083 M_Picked results;
00084
00085 context_->getSelectionManager()->pick( event.viewport,
00086 event.x, event.y,
00087 event.x + 1, event.y + 1,
00088 results, true );
00089
00090 last_selection_frame_count_ = context_->getFrameCount();
00091
00092 InteractiveObjectPtr new_focused_object;
00093
00094
00095 M_Picked::iterator result_it = results.begin();
00096 if( result_it != results.end() )
00097 {
00098 Picked pick = result_it->second;
00099 SelectionHandler* handler = context_->getSelectionManager()->getHandler( pick.handle );
00100 if ( pick.pixel_count > 0 && handler )
00101 {
00102 InteractiveObjectPtr object = handler->getInteractiveObject().lock();
00103 if( object && object->isInteractive() )
00104 {
00105 new_focused_object = object;
00106 }
00107 }
00108 }
00109
00110
00111
00112 InteractiveObjectPtr new_obj = new_focused_object;
00113 InteractiveObjectPtr old_obj = focused_object_.lock();
00114 if( new_obj != old_obj )
00115 {
00116
00117
00118 ViewportMouseEvent event_copy = event;
00119 if( old_obj )
00120 {
00121 event_copy.type = QEvent::FocusOut;
00122 old_obj->handleMouseEvent( event_copy );
00123 }
00124
00125 if( new_obj )
00126 {
00127 event_copy.type = QEvent::FocusIn;
00128 new_obj->handleMouseEvent( event_copy );
00129 }
00130 }
00131
00132 focused_object_ = new_focused_object;
00133 }
00134
00135 int InteractionTool::processMouseEvent( ViewportMouseEvent& event )
00136 {
00137 int flags = 0;
00138
00139 if ( event.panel->contextMenuVisible() )
00140 {
00141 return flags;
00142 }
00143
00144
00145 bool need_selection_update = context_->getFrameCount() > last_selection_frame_count_;
00146
00147
00148 Qt::MouseButtons buttons = event.buttons_down & ( Qt::LeftButton | Qt::RightButton | Qt::MidButton );
00149 if ( event.type == QEvent::MouseButtonPress )
00150 buttons &= ~event.acting_button;
00151 bool dragging = buttons != 0;
00152
00153
00154 if( need_selection_update &&
00155 !dragging &&
00156 event.type != QEvent::MouseButtonRelease )
00157 {
00158 updateFocus( event );
00159 flags = Render;
00160 }
00161
00162 {
00163 InteractiveObjectPtr focused_object = focused_object_.lock();
00164 if( focused_object )
00165 {
00166 focused_object->handleMouseEvent( event );
00167 setCursor( focused_object->getCursor() );
00168
00169 if ( hide_inactive_property_->getBool() )
00170 {
00171 context_->getSelectionManager()->enableInteraction(!dragging);
00172 }
00173 }
00174 else if( event.panel->getViewController() )
00175 {
00176 move_tool_.processMouseEvent( event );
00177 setCursor( move_tool_.getCursor() );
00178 if ( hide_inactive_property_->getBool() )
00179 {
00180 context_->getSelectionManager()->enableInteraction(true);
00181 }
00182 }
00183 }
00184
00185 if( event.type == QEvent::MouseButtonRelease )
00186 {
00187 updateFocus( event );
00188 }
00189
00190 return flags;
00191 }
00192
00193 int InteractionTool::processKeyEvent( QKeyEvent* event, RenderPanel* panel )
00194 {
00195 return move_tool_.processKeyEvent( event, panel );
00196 }
00197
00198 }
00199
00200 #include <pluginlib/class_list_macros.h>
00201 PLUGINLIB_EXPORT_CLASS( rviz::InteractionTool, rviz::Tool )