$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 #ifndef RVIZ_SELECTION_HANDLER_H 00031 #define RVIZ_SELECTION_HANDLER_H 00032 00033 #include "forwards.h" 00034 #include "selection_handler.h" 00035 #include "rviz/properties/forwards.h" 00036 #include "rviz/viewport_mouse_event.h" 00037 00038 #include <boost/shared_ptr.hpp> 00039 #include <boost/unordered_map.hpp> 00040 00041 #include <OGRE/OgreMovableObject.h> 00042 00043 #include <vector> 00044 #include <set> 00045 00046 namespace Ogre 00047 { 00048 class WireBoundingBox; 00049 class SceneNode; 00050 class MovableObject; 00051 } 00052 00053 namespace rviz 00054 { 00055 00056 class ViewportMouseEvent; 00057 class VisualizationManager; 00058 class PropertyManager; 00059 00060 typedef std::vector<Ogre::AxisAlignedBox> V_AABB; 00061 00062 00063 00064 class SelectionHandler 00065 { 00066 public: 00067 typedef std::vector<PropertyBaseWPtr> V_Property; 00068 00069 SelectionHandler(); 00070 virtual ~SelectionHandler(); 00071 00072 void initialize(VisualizationManager* manager); 00073 void addTrackedObject(Ogre::MovableObject* object); 00074 void removeTrackedObject(Ogre::MovableObject* object); 00075 00076 virtual void updateTrackedBoxes(); 00077 00078 virtual void createProperties(const Picked& obj, PropertyManager* property_manager) {} 00079 virtual void destroyProperties(const Picked& obj, PropertyManager* property_manager); 00080 virtual void updateProperties(); 00081 00082 virtual bool needsAdditionalRenderPass(uint32_t pass) 00083 { 00084 return false; 00085 } 00086 00087 virtual void preRenderPass(uint32_t pass); 00088 virtual void postRenderPass(uint32_t pass); 00089 00090 virtual void getAABBs(const Picked& obj, V_AABB& aabbs); 00091 00092 virtual void onSelect(const Picked& obj); 00093 virtual void onDeselect(const Picked& obj); 00094 00095 // interface for interactive mode //// 00096 00097 // called when interactive mode is globally switched on/off 00098 virtual void enableInteraction(bool enable) {} 00099 00100 // @return true if this handler is ready to receive mouse events 00101 virtual bool isInteractive() { return false; } 00102 00103 // will receive all mouse events while the handler has focus (incl. set/kill focus events) 00104 virtual void handleMouseEvent(const Picked& obj, ViewportMouseEvent& event) {} 00105 00106 protected: 00107 void createBox(const std::pair<CollObjectHandle, uint64_t>& handles, const Ogre::AxisAlignedBox& aabb, const std::string& material_name); 00108 void destroyBox(const std::pair<CollObjectHandle, uint64_t>& handles); 00109 00110 V_Property properties_; 00111 00112 typedef std::map<std::pair<CollObjectHandle, uint64_t>, std::pair<Ogre::SceneNode*, Ogre::WireBoundingBox*> > M_HandleToBox; 00113 M_HandleToBox boxes_; 00114 00115 VisualizationManager* manager_; 00116 00117 typedef std::set<Ogre::MovableObject*> S_Movable; 00118 S_Movable tracked_objects_; 00119 00120 class Listener : public Ogre::MovableObject::Listener 00121 { 00122 public: 00123 Listener(SelectionHandler* handler) 00124 : handler_(handler) 00125 {} 00126 virtual void objectMoved(Ogre::MovableObject* object) 00127 { 00128 handler_->updateTrackedBoxes(); 00129 } 00130 00131 virtual void objectDestroyed(Ogre::MovableObject* object) 00132 { 00133 handler_->removeTrackedObject(object); 00134 } 00135 00136 SelectionHandler* handler_; 00137 }; 00138 typedef boost::shared_ptr<Listener> ListenerPtr; 00139 ListenerPtr listener_; 00140 00141 friend class SelectionManager; 00142 }; 00143 00144 typedef boost::shared_ptr<SelectionHandler> SelectionHandlerPtr; 00145 typedef std::vector<SelectionHandlerPtr> V_SelectionHandler; 00146 typedef std::set<SelectionHandlerPtr> S_SelectionHandler; 00147 00148 } 00149 00150 #endif