$search
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 "selection_tool.h" 00031 #include "move_tool.h" 00032 #include "selection/selection_manager.h" 00033 #include "visualization_manager.h" 00034 #include "render_panel.h" 00035 #include "display.h" 00036 #include "viewport_mouse_event.h" 00037 00038 #include "ogre_tools/camera_base.h" 00039 #include "ogre_tools/wx_ogre_render_window.h" 00040 00041 #include <wx/event.h> 00042 00043 #include <OGRE/OgreRay.h> 00044 #include <OGRE/OgreSceneManager.h> 00045 #include <OGRE/OgreCamera.h> 00046 #include <OGRE/OgreMovableObject.h> 00047 #include <OGRE/OgreRectangle2D.h> 00048 #include <OGRE/OgreSceneNode.h> 00049 #include <OGRE/OgreViewport.h> 00050 #include <OGRE/OgreMaterialManager.h> 00051 #include <OGRE/OgreTexture.h> 00052 #include <OGRE/OgreTextureManager.h> 00053 00054 #include <btBulletCollisionCommon.h> 00055 00056 #include <ros/time.h> 00057 00058 namespace rviz 00059 { 00060 00061 SelectionTool::SelectionTool( const std::string& name, char shortcut_key, VisualizationManager* manager ) 00062 : Tool( name, shortcut_key, manager ) 00063 , move_tool_(new MoveTool("SelectionTool Fake MoveTool", 0, manager)) 00064 , selecting_(false) 00065 , sel_start_x_(0) 00066 , sel_start_y_(0) 00067 , moving_(false) 00068 { 00069 00070 } 00071 00072 SelectionTool::~SelectionTool() 00073 { 00074 delete move_tool_; 00075 } 00076 00077 void SelectionTool::activate() 00078 { 00079 manager_->getSelectionManager()->setTextureSize(512); 00080 selecting_ = false; 00081 moving_ = false; 00082 } 00083 00084 void SelectionTool::deactivate() 00085 { 00086 manager_->getSelectionManager()->removeHighlight(); 00087 } 00088 00089 void SelectionTool::update(float wall_dt, float ros_dt) 00090 { 00091 SelectionManager* sel_manager = manager_->getSelectionManager(); 00092 00093 if (!selecting_) 00094 { 00095 sel_manager->removeHighlight(); 00096 } 00097 } 00098 00099 int SelectionTool::processMouseEvent( ViewportMouseEvent& event ) 00100 { 00101 SelectionManager* sel_manager = manager_->getSelectionManager(); 00102 00103 int flags = 0; 00104 00105 if (event.event.AltDown()) 00106 { 00107 moving_ = true; 00108 selecting_ = false; 00109 } 00110 else 00111 { 00112 moving_ = false; 00113 00114 if (event.event.LeftDown()) 00115 { 00116 selecting_ = true; 00117 00118 sel_start_x_ = event.event.GetX(); 00119 sel_start_y_ = event.event.GetY(); 00120 } 00121 } 00122 00123 if (selecting_) 00124 { 00125 sel_manager->highlight(event.viewport, sel_start_x_, sel_start_y_, event.event.GetX(), event.event.GetY()); 00126 00127 if (event.event.LeftUp()) 00128 { 00129 SelectionManager::SelectType type = SelectionManager::Replace; 00130 00131 M_Picked selection; 00132 00133 if (event.event.ShiftDown()) 00134 { 00135 type = SelectionManager::Add; 00136 } 00137 else if (event.event.ControlDown()) 00138 { 00139 type = SelectionManager::Remove; 00140 } 00141 00142 sel_manager->select(event.viewport, sel_start_x_, sel_start_y_, event.event.GetX(), event.event.GetY(), type); 00143 00144 selecting_ = false; 00145 } 00146 00147 flags |= Render; 00148 } 00149 else if (moving_) 00150 { 00151 sel_manager->removeHighlight(); 00152 00153 flags = move_tool_->processMouseEvent(event); 00154 00155 if (event.event.LeftUp() || event.event.RightUp() || event.event.MiddleUp()) 00156 { 00157 moving_ = false; 00158 } 00159 } 00160 else 00161 { 00162 sel_manager->highlight(event.viewport, event.event.GetX(), event.event.GetY(), event.event.GetX(), event.event.GetY()); 00163 } 00164 00165 return flags; 00166 } 00167 00168 int SelectionTool::processKeyEvent( wxKeyEvent& event ) 00169 { 00170 SelectionManager* sel_manager = manager_->getSelectionManager(); 00171 char key = event.GetKeyCode(); 00172 00173 switch (key) 00174 { 00175 case 'f': 00176 case 'F': 00177 sel_manager->focusOnSelection(); 00178 break; 00179 } 00180 00181 return Render; 00182 } 00183 00184 } 00185