selection_handler.h
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 #ifndef RVIZ_SELECTION_HANDLER_H
00031 #define RVIZ_SELECTION_HANDLER_H
00032 
00033 #include <vector>
00034 #include <set>
00035 
00036 #include <boost/shared_ptr.hpp>
00037 #include <boost/unordered_map.hpp>
00038 
00039 #include <OGRE/OgreMovableObject.h>
00040 
00041 #include "rviz/selection/forwards.h"
00042 #include "rviz/selection/selection_handler.h"
00043 #include "rviz/viewport_mouse_event.h"
00044 #include "rviz/interactive_object.h"
00045 
00046 namespace Ogre
00047 {
00048 class WireBoundingBox;
00049 class SceneNode;
00050 class MovableObject;
00051 }
00052 
00053 namespace rviz
00054 {
00055 
00056 class DisplayContext;
00057 class Property;
00058 class ViewportMouseEvent;
00059 
00060 typedef std::vector<Ogre::AxisAlignedBox> V_AABB;
00061 
00062 class SelectionHandler
00063 {
00064 public:
00065   SelectionHandler( DisplayContext* context );
00066   virtual ~SelectionHandler();
00067 
00068   void addTrackedObjects( Ogre::SceneNode* node );
00069   void addTrackedObject(Ogre::MovableObject* object);
00070   void removeTrackedObject(Ogre::MovableObject* object);
00071 
00072   virtual void updateTrackedBoxes();
00073 
00081   virtual void createProperties( const Picked& obj, Property* parent_property ) {}
00082 
00090   virtual void destroyProperties( const Picked& obj, Property* parent_property );
00091 
00101   virtual void updateProperties() {}
00102 
00103   virtual bool needsAdditionalRenderPass(uint32_t pass)
00104   {
00105     return false;
00106   }
00107 
00108   virtual void preRenderPass(uint32_t pass);
00109   virtual void postRenderPass(uint32_t pass);
00110 
00111   virtual void getAABBs(const Picked& obj, V_AABB& aabbs);
00112 
00113   virtual void onSelect(const Picked& obj);
00114   virtual void onDeselect(const Picked& obj);
00115 
00118   virtual void setInteractiveObject( InteractiveObjectWPtr object );
00119 
00127   virtual InteractiveObjectWPtr getInteractiveObject();
00128 
00129   CollObjectHandle getHandle() const { return pick_handle_; }
00130 
00131 protected:
00133   void createBox(const std::pair<CollObjectHandle, uint64_t>& handles, const Ogre::AxisAlignedBox& aabb, const std::string& material_name);
00134 
00136   void destroyBox(const std::pair<CollObjectHandle, uint64_t>& handles);
00137 
00138   QList<Property*> properties_;
00139 
00140   typedef std::map<std::pair<CollObjectHandle, uint64_t>, std::pair<Ogre::SceneNode*, Ogre::WireBoundingBox*> > M_HandleToBox;
00141   M_HandleToBox boxes_;
00142 
00143   DisplayContext* context_;
00144 
00145   typedef std::set<Ogre::MovableObject*> S_Movable;
00146   S_Movable tracked_objects_;
00147 
00148   class Listener : public Ogre::MovableObject::Listener
00149   {
00150   public:
00151     Listener(SelectionHandler* handler)
00152     : handler_(handler)
00153     {}
00154     virtual void objectMoved(Ogre::MovableObject* object)
00155     {
00156       handler_->updateTrackedBoxes();
00157     }
00158 
00159     virtual void objectDestroyed(Ogre::MovableObject* object)
00160     {
00161       handler_->removeTrackedObject(object);
00162     }
00163 
00164     SelectionHandler* handler_;
00165   };
00166   typedef boost::shared_ptr<Listener> ListenerPtr;
00167   ListenerPtr listener_;
00168 
00169   InteractiveObjectWPtr interactive_object_;
00170 
00171 private:
00172   // pick_handle_ must never be changed, otherwise the destructor will
00173   // call removeObject() with the wrong handle.  Use getHandle() to
00174   // access the value.
00175   CollObjectHandle pick_handle_;
00176 
00177   friend class SelectionManager;
00178 };
00179 
00180 typedef boost::shared_ptr<SelectionHandler> SelectionHandlerPtr;
00181 typedef std::vector<SelectionHandlerPtr> V_SelectionHandler;
00182 typedef std::set<SelectionHandlerPtr> S_SelectionHandler;
00183 
00184 }
00185 
00186 #endif


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