selection_tool.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <QKeyEvent>
00031 
00032 #include <OGRE/OgreRay.h>
00033 #include <OGRE/OgreSceneManager.h>
00034 #include <OGRE/OgreCamera.h>
00035 #include <OGRE/OgreMovableObject.h>
00036 #include <OGRE/OgreRectangle2D.h>
00037 #include <OGRE/OgreSceneNode.h>
00038 #include <OGRE/OgreViewport.h>
00039 #include <OGRE/OgreMaterialManager.h>
00040 #include <OGRE/OgreTexture.h>
00041 #include <OGRE/OgreTextureManager.h>
00042 
00043 #include <ros/time.h>
00044 
00045 #include "move_tool.h"
00046 
00047 #include "rviz/ogre_helpers/camera_base.h"
00048 #include "rviz/ogre_helpers/qt_ogre_render_window.h"
00049 #include "rviz/selection/selection_manager.h"
00050 #include "rviz/visualization_manager.h"
00051 #include "rviz/render_panel.h"
00052 #include "rviz/display.h"
00053 #include "rviz/viewport_mouse_event.h"
00054 #include "rviz/load_resource.h"
00055 
00056 #include "selection_tool.h"
00057 
00058 namespace rviz
00059 {
00060 
00061 SelectionTool::SelectionTool()
00062   : Tool()
00063   , move_tool_( new MoveTool() )
00064   , selecting_( false )
00065   , sel_start_x_( 0 )
00066   , sel_start_y_( 0 )
00067   , moving_( false )
00068 {
00069   shortcut_key_ = 's';
00070 }
00071 
00072 SelectionTool::~SelectionTool()
00073 {
00074   delete move_tool_;
00075 }
00076 
00077 void SelectionTool::onInitialize()
00078 {
00079   move_tool_->initialize( context_ );
00080 }
00081 
00082 void SelectionTool::activate()
00083 {
00084   setStatus( "Click and drag to select objects on the screen." );
00085   context_->getSelectionManager()->setTextureSize(512);
00086   selecting_ = false;
00087   moving_ = false;
00088 //  context_->getSelectionManager()->enableInteraction(true);
00089 }
00090 
00091 void SelectionTool::deactivate()
00092 {
00093   context_->getSelectionManager()->removeHighlight();
00094 }
00095 
00096 void SelectionTool::update(float wall_dt, float ros_dt)
00097 {
00098   SelectionManager* sel_manager = context_->getSelectionManager();
00099 
00100   if (!selecting_)
00101   {
00102     sel_manager->removeHighlight();
00103   }
00104 }
00105 
00106 int SelectionTool::processMouseEvent( ViewportMouseEvent& event )
00107 {
00108   SelectionManager* sel_manager = context_->getSelectionManager();
00109 
00110   int flags = 0;
00111 
00112   if( event.alt() )
00113   {
00114     moving_ = true;
00115     selecting_ = false;
00116   }
00117   else
00118   {
00119     moving_ = false;
00120 
00121     if( event.leftDown() )
00122     {
00123       selecting_ = true;
00124 
00125       sel_start_x_ = event.x;
00126       sel_start_y_ = event.y;
00127     }
00128   }
00129 
00130   if( selecting_ )
00131   {
00132     sel_manager->highlight( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y );
00133 
00134     if( event.leftUp() )
00135     {
00136       SelectionManager::SelectType type = SelectionManager::Replace;
00137 
00138       M_Picked selection;
00139 
00140       if( event.shift() )
00141       {
00142         type = SelectionManager::Add;
00143       }
00144       else if( event.control() )
00145       {
00146         type = SelectionManager::Remove;
00147       }
00148 
00149       sel_manager->select( event.viewport, sel_start_x_, sel_start_y_, event.x, event.y, type );
00150 
00151       selecting_ = false;
00152     }
00153 
00154     flags |= Render;
00155   }
00156   else if( moving_ )
00157   {
00158     sel_manager->removeHighlight();
00159 
00160     flags = move_tool_->processMouseEvent( event );
00161 
00162     if( event.type == QEvent::MouseButtonRelease )
00163     {
00164       moving_ = false;
00165     }
00166   }
00167   else
00168   {
00169     sel_manager->highlight( event.viewport, event.x, event.y, event.x, event.y );
00170   }
00171 
00172   return flags;
00173 }
00174 
00175 int SelectionTool::processKeyEvent( QKeyEvent* event, RenderPanel* panel )
00176 {
00177   SelectionManager* sel_manager = context_->getSelectionManager();
00178 
00179   if( event->key() == Qt::Key_F )
00180   {
00181     sel_manager->focusOnSelection();
00182   }
00183 
00184   return Render;
00185 }
00186 
00187 } // end namespace rviz
00188 
00189 #include <pluginlib/class_list_macros.h>
00190 PLUGINLIB_EXPORT_CLASS( rviz::SelectionTool, rviz::Tool )


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:36