Base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_PHYSICS_BASE_HH_
19 #define GAZEBO_PHYSICS_BASE_HH_
20 
21 #include <boost/enable_shared_from_this.hpp>
22 #include <string>
23 #include <vector>
24 
25 #include <sdf/sdf.hh>
26 
27 #include "gazebo/common/URI.hh"
29 #include "gazebo/util/system.hh"
30 
31 namespace gazebo
32 {
34  namespace physics
35  {
39 
41  static std::string EntityTypename[] = {
42  "common",
43  "entity",
44  "model",
45  "actor",
46  "link",
47  "collision",
48  "light",
49  "visual",
50  "joint",
51  "ball",
52  "hinge2",
53  "hinge",
54  "slider",
55  "universal",
56  "shape",
57  "box",
58  "cylinder",
59  "heightmap",
60  "map",
61  "multiray",
62  "ray",
63  "plane",
64  "sphere",
65  "trimesh",
66  "polyline"
67  };
68 
71  class GZ_PHYSICS_VISIBLE Base : public boost::enable_shared_from_this<Base>
72  {
75  public: enum EntityType {
77  BASE = 0x00000000,
79  ENTITY = 0x00000001,
81  MODEL = 0x00000002,
83  LINK = 0x00000004,
85  COLLISION = 0x00000008,
87  LIGHT = 0x00000010,
89  VISUAL = 0x00000020,
90 
92  JOINT = 0x00000040,
94  BALL_JOINT = 0x00000080,
96  HINGE2_JOINT = 0x00000100,
98  HINGE_JOINT = 0x00000200,
100  SLIDER_JOINT = 0x00000400,
102  SCREW_JOINT = 0x00000800,
104  UNIVERSAL_JOINT = 0x00001000,
106  GEARBOX_JOINT = 0x00002000,
108  FIXED_JOINT = 0x00004000,
109 
111  ACTOR = 0x00008000,
112 
114  SHAPE = 0x00010000,
116  BOX_SHAPE = 0x00020000,
118  CYLINDER_SHAPE = 0x00040000,
120  HEIGHTMAP_SHAPE = 0x00080000,
122  MAP_SHAPE = 0x00100000,
124  MULTIRAY_SHAPE = 0x00200000,
126  RAY_SHAPE = 0x00400000,
128  PLANE_SHAPE = 0x00800000,
130  SPHERE_SHAPE = 0x01000000,
132  MESH_SHAPE = 0x02000000,
134  POLYLINE_SHAPE = 0x04000000,
135 
137  SENSOR_COLLISION = 0x10000000
138  };
139 
142  public: explicit Base(BasePtr _parent);
143 
145  public: virtual ~Base();
146 
149  public: virtual void Load(sdf::ElementPtr _sdf);
150 
152  public: virtual void Fini();
153 
155  public: virtual void Init() {}
156 
158  public: virtual void Reset();
159 
162  public: virtual void Reset(Base::EntityType _resetType);
163 
165  public: virtual void Update() {}
166 
170  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
171 
174  public: virtual void SetName(const std::string &_name);
175 
178  public: std::string GetName() const;
179 
182  public: uint32_t GetId() const;
183 
187  public: void SetSaveable(bool _v);
188 
192  public: bool GetSaveable() const;
193 
196  public: int GetParentId() const;
197 
200  public: void SetParent(BasePtr _parent);
201 
204  public: BasePtr GetParent() const;
205 
208  public: void AddChild(BasePtr _child);
209 
212  public: virtual void RemoveChild(unsigned int _id);
213 
215  public: void RemoveChildren();
216 
219  public: unsigned int GetChildCount() const;
220 
226  public: BasePtr GetById(unsigned int _id) const;
228 
232  public: BasePtr GetByName(const std::string &_name);
233 
237  public: BasePtr GetChild(unsigned int _i) const;
238 
242  public: BasePtr GetChild(const std::string &_name);
243 
246  public: void RemoveChild(const std::string &_name);
247 
250  public: void RemoveChild(physics::BasePtr _child);
251 
255  public: void AddType(EntityType _type);
256 
261  public: bool HasType(const EntityType &_t) const;
262 
265  public: unsigned int GetType() const;
266 
269  public: std::string TypeStr() const;
270 
277  public: std::string GetScopedName(bool _prependWorldName = false) const;
278 
285  public: common::URI URI() const;
286 
289  public: void Print(const std::string &_prefix);
290 
294  public: virtual bool SetSelected(bool _show);
295 
298  public: bool IsSelected() const;
299 
304  public: bool operator ==(const Base &_ent) const;
305 
309  public: void SetWorld(const WorldPtr &_newWorld);
310 
313  public: const WorldPtr &GetWorld() const;
314 
317  public: virtual const sdf::ElementPtr GetSDF();
318 
320  protected: virtual void RegisterIntrospectionItems();
321 
323  protected: virtual void UnregisterIntrospectionItems();
324 
328  protected: void ComputeScopedName();
329 
331  protected: sdf::ElementPtr sdf;
332 
334  protected: BasePtr parent;
335 
337  protected: Base_V children;
338 
340  protected: WorldPtr world;
341 
343  protected: std::vector<common::URI> introspectionItems;
344 
346  private: bool saveable;
347 
349  private: uint32_t id;
350 
352  private: unsigned int type;
353 
355  private: std::string typeStr;
356 
358  private: bool selected;
359 
361  private: std::string name;
362 
364  private: std::string scopedName;
365 
366  protected: friend class Entity;
367  };
369  }
370 }
371 #endif
void ComputeScopedName()
Compute the scoped name of this object based on its parents.
@ RAY_SHAPE
RayShape type.
Definition: Base.hh:126
@ MULTIRAY_SHAPE
MultiRayShape type.
Definition: Base.hh:124
virtual void Update()
Update the object.
Definition: Base.hh:165
unsigned int GetChildCount() const
Get the number of children.
A complete URI.
Definition: URI.hh:176
virtual void Fini()
Finialize the object.
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
BasePtr GetByName(const std::string &_name)
Get by name.
common::URI URI() const
Return the common::URI of this entity.
@ SCREW_JOINT
ScrewJoint type.
Definition: Base.hh:102
bool operator==(const Base &_ent) const
Returns true if the entities are the same.
void Print(const std::string &_prefix)
Print this object to screen via gzmsg.
Forward declarations for the common classes.
Definition: Animation.hh:26
@ BASE
Base type.
Definition: Base.hh:77
@ ACTOR
Actor type.
Definition: Base.hh:111
@ GEARBOX_JOINT
GearboxJoint type.
Definition: Base.hh:106
@ MODEL
Model type.
Definition: Base.hh:81
BasePtr GetParent() const
Get the parent.
@ BALL_JOINT
BallJoint type.
Definition: Base.hh:94
@ MESH_SHAPE
MeshShape type.
Definition: Base.hh:132
virtual void SetName(const std::string &_name)
Set the name of the entity.
int GetParentId() const
Return the ID of the parent.
bool IsSelected() const
True if the entity is selected by the user.
@ MAP_SHAPE
MapShape type.
Definition: Base.hh:122
default namespace for gazebo
@ HINGE_JOINT
HingeJoint type.
Definition: Base.hh:98
uint32_t GetId() const
Return the ID of this entity.
@ JOINT
Joint type.
Definition: Base.hh:92
std::string TypeStr() const
Get the string name for the entity type.
BasePtr parent
Parent of this entity.
Definition: Base.hh:334
virtual void Reset()
Reset the object.
const WorldPtr & GetWorld() const
Get the World this object is in.
virtual void Load(sdf::ElementPtr _sdf)
Load.
virtual void UnregisterIntrospectionItems()
Unregister items in the introspection service.
virtual void Init()
Initialize the object.
Definition: Base.hh:155
@ FIXED_JOINT
FixedJoint type.
Definition: Base.hh:108
std::string GetScopedName(bool _prependWorldName=false) const
Return the name of this entity with the model scope model1::...::modelN::entityName.
Base class for most physics classes.
Definition: Base.hh:71
@ COLLISION
Collision type.
Definition: Base.hh:85
std::string GetName() const
Return the name of the entity.
void RemoveChildren()
Remove all children.
@ UNIVERSAL_JOINT
UniversalJoint type.
Definition: Base.hh:104
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
@ LIGHT
Light type.
Definition: Base.hh:87
Base_V children
Children of this entity.
Definition: Base.hh:337
virtual const sdf::ElementPtr GetSDF()
Get the SDF values for the object.
void AddChild(BasePtr _child)
Add a child to this entity.
@ LINK
Link type.
Definition: Base.hh:83
@ HINGE2_JOINT
Hing2Joint type.
Definition: Base.hh:96
@ HEIGHTMAP_SHAPE
HeightmapShape type.
Definition: Base.hh:120
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77
void SetSaveable(bool _v)
Set whether the object should be "saved", when the user selects to save the world to xml.
@ SLIDER_JOINT
SliderJoint type.
Definition: Base.hh:100
sdf::ElementPtr sdf
The SDF values for this object.
Definition: Base.hh:331
@ CYLINDER_SHAPE
CylinderShape type.
Definition: Base.hh:118
@ VISUAL
Visual type.
Definition: Base.hh:89
unsigned int GetType() const
Get the full type definition.
@ BOX_SHAPE
BoxShape type.
Definition: Base.hh:116
void AddType(EntityType _type)
Add a type specifier.
Base(BasePtr _parent)
Constructor.
@ ENTITY
Entity type.
Definition: Base.hh:79
@ SPHERE_SHAPE
SphereShape type.
Definition: Base.hh:130
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
std::vector< common::URI > introspectionItems
All the introspection items regsitered for this.
Definition: Base.hh:343
@ SHAPE
Shape type.
Definition: Base.hh:114
void SetWorld(const WorldPtr &_newWorld)
Set the world this object belongs to.
@ POLYLINE_SHAPE
PolylineShape type.
Definition: Base.hh:134
@ PLANE_SHAPE
PlaneShape type.
Definition: Base.hh:128
bool HasType(const EntityType &_t) const
Returns true if this object's type definition has the given type.
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:75
virtual void RegisterIntrospectionItems()
Register items in the introspection service.
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
void SetParent(BasePtr _parent)
Set the parent.
virtual ~Base()
Destructor.
bool GetSaveable() const
Get whether the object should be "saved", when the user selects to save the world to xml.
virtual bool SetSelected(bool _show)
Set whether this entity has been selected by the user through the gui.
std::vector< BasePtr > Base_V
Definition: PhysicsTypes.hh:201
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:41
BasePtr GetChild(unsigned int _i) const
Get a child by index.
@ SENSOR_COLLISION
Indicates a collision shape used for sensing.
Definition: Base.hh:137
WorldPtr world
Pointer to the world.
Definition: Base.hh:340