selection_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef RVIZ_SELECTION_HANDLER_H
31 #define RVIZ_SELECTION_HANDLER_H
32 
33 #include <vector>
34 #include <set>
35 
36 #ifndef Q_MOC_RUN
37 #include <boost/shared_ptr.hpp>
38 #include <boost/unordered_map.hpp>
39 
40 #include <OgreMovableObject.h>
41 #endif
42 
47 #include "rviz/rviz_export.h"
48 
49 namespace Ogre
50 {
51 class WireBoundingBox;
52 class SceneNode;
53 class MovableObject;
54 } // namespace Ogre
55 
56 namespace rviz
57 {
58 class DisplayContext;
59 class Property;
61 
62 typedef std::vector<Ogre::AxisAlignedBox> V_AABB;
63 
64 class RVIZ_EXPORT SelectionHandler
65 {
66 public:
68  virtual ~SelectionHandler();
69 
70  void addTrackedObjects(Ogre::SceneNode* node);
71  void addTrackedObject(Ogre::MovableObject* object);
72  void removeTrackedObject(Ogre::MovableObject* object);
73 
74  virtual void updateTrackedBoxes();
75 
83  virtual void createProperties(const Picked& /*obj*/, Property* /*parent_property*/)
84  {
85  }
86 
94  virtual void destroyProperties(const Picked& obj, Property* parent_property);
95 
105  virtual void updateProperties()
106  {
107  }
108 
109  virtual bool needsAdditionalRenderPass(uint32_t /*pass*/)
110  {
111  return false;
112  }
113 
114  virtual void preRenderPass(uint32_t pass);
115  virtual void postRenderPass(uint32_t pass);
116 
117  virtual void getAABBs(const Picked& obj, V_AABB& aabbs);
118 
119  virtual void onSelect(const Picked& obj);
120  virtual void onDeselect(const Picked& obj);
121 
124  virtual void setInteractiveObject(InteractiveObjectWPtr object);
125 
133  virtual InteractiveObjectWPtr getInteractiveObject();
134 
136  {
137  return pick_handle_;
138  }
139 
140 protected:
142  void createBox(const std::pair<CollObjectHandle, uint64_t>& handles,
143  const Ogre::AxisAlignedBox& aabb,
144  const std::string& material_name);
145 
147  void destroyBox(const std::pair<CollObjectHandle, uint64_t>& handles);
148 
149  QList<Property*> properties_;
150 
151  typedef std::map<std::pair<CollObjectHandle, uint64_t>,
152  std::pair<Ogre::SceneNode*, Ogre::WireBoundingBox*> >
155 
157 
158  typedef std::set<Ogre::MovableObject*> S_Movable;
159  S_Movable tracked_objects_;
160 
161  class Listener : public Ogre::MovableObject::Listener
162  {
163  public:
164  Listener(SelectionHandler* handler) : handler_(handler)
165  {
166  }
167  void objectMoved(Ogre::MovableObject* /*object*/) override
168  {
169  handler_->updateTrackedBoxes();
170  }
171 
172  void objectDestroyed(Ogre::MovableObject* object) override
173  {
174  handler_->removeTrackedObject(object);
175  }
176 
178  };
180  ListenerPtr listener_;
181 
183 
184 private:
185  // pick_handle_ must never be changed, otherwise the destructor will
186  // call removeObject() with the wrong handle. Use getHandle() to
187  // access the value.
189 
190  friend class SelectionManager;
191 };
192 
194 typedef std::vector<SelectionHandlerPtr> V_SelectionHandler;
195 typedef std::set<SelectionHandlerPtr> S_SelectionHandler;
196 
197 } // namespace rviz
198 
199 #endif
boost::shared_ptr< Listener > ListenerPtr
std::set< SelectionHandlerPtr > S_SelectionHandler
CollObjectHandle getHandle() const
void objectDestroyed(Ogre::MovableObject *object) override
virtual void updateProperties()
Override to update property values.
std::vector< SelectionHandlerPtr > V_SelectionHandler
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
std::set< Ogre::MovableObject * > S_Movable
virtual bool needsAdditionalRenderPass(uint32_t)
Pure-virtual base class for objects which give Display subclasses context in which to work...
std::vector< Ogre::AxisAlignedBox > V_AABB
Listener(SelectionHandler *handler)
DisplayContext * context_
InteractiveObjectWPtr interactive_object_
virtual void createProperties(const Picked &, Property *)
Override to create properties of the given picked object(s).
boost::weak_ptr< InteractiveObject > InteractiveObjectWPtr
void objectMoved(Ogre::MovableObject *) override
std::map< std::pair< CollObjectHandle, uint64_t >, std::pair< Ogre::SceneNode *, Ogre::WireBoundingBox * > > M_HandleToBox
CollObjectHandle pick_handle_
QList< Property * > properties_
boost::shared_ptr< SelectionHandler > SelectionHandlerPtr
uint32_t CollObjectHandle
Definition: forwards.h:45


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25