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 <optional>
23#include <string>
24#include <vector>
25
26#include <sdf/sdf.hh>
27
28#include "gazebo/common/URI.hh"
30#include "gazebo/util/system.hh"
31
32namespace gazebo
33{
35 namespace physics
36 {
40
42 static std::string EntityTypename[] = {
43 "common",
44 "entity",
45 "model",
46 "actor",
47 "link",
48 "collision",
49 "light",
50 "visual",
51 "joint",
52 "ball",
53 "hinge2",
54 "hinge",
55 "slider",
56 "universal",
57 "shape",
58 "box",
59 "cylinder",
60 "heightmap",
61 "map",
62 "multiray",
63 "ray",
64 "plane",
65 "sphere",
66 "trimesh",
67 "polyline"
68 };
69
72 class GZ_PHYSICS_VISIBLE Base : public boost::enable_shared_from_this<Base>
73 {
76 public: enum EntityType {
78 BASE = 0x00000000,
80 ENTITY = 0x00000001,
82 MODEL = 0x00000002,
84 LINK = 0x00000004,
86 COLLISION = 0x00000008,
88 LIGHT = 0x00000010,
90 VISUAL = 0x00000020,
91
93 JOINT = 0x00000040,
95 BALL_JOINT = 0x00000080,
97 HINGE2_JOINT = 0x00000100,
99 HINGE_JOINT = 0x00000200,
101 SLIDER_JOINT = 0x00000400,
103 SCREW_JOINT = 0x00000800,
105 UNIVERSAL_JOINT = 0x00001000,
107 GEARBOX_JOINT = 0x00002000,
109 FIXED_JOINT = 0x00004000,
110
112 ACTOR = 0x00008000,
113
115 SHAPE = 0x00010000,
117 BOX_SHAPE = 0x00020000,
119 CYLINDER_SHAPE = 0x00040000,
121 HEIGHTMAP_SHAPE = 0x00080000,
123 MAP_SHAPE = 0x00100000,
125 MULTIRAY_SHAPE = 0x00200000,
127 RAY_SHAPE = 0x00400000,
129 PLANE_SHAPE = 0x00800000,
131 SPHERE_SHAPE = 0x01000000,
133 MESH_SHAPE = 0x02000000,
135 POLYLINE_SHAPE = 0x04000000,
136
138 SENSOR_COLLISION = 0x10000000
139 };
140
143 public: explicit Base(BasePtr _parent);
144
146 public: virtual ~Base();
147
150 public: virtual void Load(sdf::ElementPtr _sdf);
151
153 public: virtual void Fini();
154
156 public: virtual void Init() {}
157
159 public: virtual void Reset();
160
163 public: virtual void Reset(Base::EntityType _resetType);
164
166 public: virtual void Update() {}
167
171 public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
172
175 public: virtual void SetName(const std::string &_name);
176
179 public: std::string GetName() const;
180
183 public: uint32_t GetId() const;
184
188 public: void SetSaveable(bool _v);
189
193 public: bool GetSaveable() const;
194
197 public: int GetParentId() const;
198
201 public: void SetParent(BasePtr _parent);
202
205 public: BasePtr GetParent() const;
206
209 public: void AddChild(BasePtr _child);
210
213 public: virtual void RemoveChild(unsigned int _id);
214
216 public: void RemoveChildren();
217
220 public: unsigned int GetChildCount() const;
221
227 public: BasePtr GetById(unsigned int _id) const;
229
234 public: BasePtr GetByIdRecursive(unsigned int _id);
235
236
240 public: BasePtr GetByName(const std::string &_name);
241
245 public: BasePtr GetChild(unsigned int _i) const;
246
250 public: BasePtr GetChild(const std::string &_name);
251
254 public: void RemoveChild(const std::string &_name);
255
258 public: void RemoveChild(physics::BasePtr _child);
259
263 public: void AddType(EntityType _type);
264
269 public: bool HasType(const EntityType &_t) const;
270
273 public: unsigned int GetType() const;
274
277 public: std::string TypeStr() const;
278
285 public: std::string GetScopedName(bool _prependWorldName = false) const;
286
291 public: std::string StripScopedName(const std::string &_name) const;
292
297 public: std::string StripParentScopedName(const std::string &_name) const;
298
305 public: common::URI URI() const;
306
309 public: void Print(const std::string &_prefix);
310
314 public: virtual bool SetSelected(bool _show);
315
318 public: bool IsSelected() const;
319
324 public: bool operator ==(const Base &_ent) const;
325
329 public: void SetWorld(const WorldPtr &_newWorld);
330
333 public: const WorldPtr &GetWorld() const;
334
337 public: virtual const sdf::ElementPtr GetSDF();
338
342 public: virtual std::optional<sdf::SemanticPose> SDFSemanticPose() const;
343
350 public: ignition::math::Pose3d SDFPoseRelativeToParent() const;
351
353 protected: virtual void RegisterIntrospectionItems();
354
356 protected: virtual void UnregisterIntrospectionItems();
357
361 protected: void ComputeScopedName();
362
364 protected: sdf::ElementPtr sdf;
365
367 protected: BasePtr parent;
368
370 protected: Base_V children;
371
373 protected: WorldPtr world;
374
376 protected: std::vector<common::URI> introspectionItems;
377
379 private: bool saveable;
380
382 private: uint32_t id;
383
385 private: unsigned int type;
386
388 private: std::string typeStr;
389
391 private: bool selected;
392
394 private: std::string name;
395
397 private: std::string scopedName;
398
399 protected: friend class Entity;
400 };
402 }
403}
404#endif
default namespace for gazebo
A complete URI.
Definition URI.hh:177
Base class for most physics classes.
Definition Base.hh:73
unsigned int GetType() const
Get the full type definition.
BasePtr parent
Parent of this entity.
Definition Base.hh:367
virtual bool SetSelected(bool _show)
Set whether this entity has been selected by the user through the gui.
bool IsSelected() const
True if the entity is selected by the user.
std::string GetScopedName(bool _prependWorldName=false) const
Return the name of this entity with the model scope model1::...::modelN::entityName.
std::vector< common::URI > introspectionItems
All the introspection items regsitered for this.
Definition Base.hh:376
virtual void Fini()
Finialize the object.
BasePtr GetByName(const std::string &_name)
Get by name.
void AddType(EntityType _type)
Add a type specifier.
void Print(const std::string &_prefix)
Print this object to screen via gzmsg.
virtual void Init()
Initialize the object.
Definition Base.hh:156
BasePtr GetChild(unsigned int _i) const
Get a child by index.
void AddChild(BasePtr _child)
Add a child to this entity.
virtual void Reset()
Reset the object.
Base_V children
Children of this entity.
Definition Base.hh:370
Base(BasePtr _parent)
Constructor.
virtual void SetName(const std::string &_name)
Set the name of the entity.
virtual void RemoveChild(unsigned int _id)
Remove a child from this entity.
virtual const sdf::ElementPtr GetSDF()
Get the SDF values for the object.
void RemoveChild(const std::string &_name)
Remove a child by name.
BasePtr GetByIdRecursive(unsigned int _id)
This is an internal function.
bool HasType(const EntityType &_t) const
Returns true if this object's type definition has the given type.
common::URI URI() const
Return the common::URI of this entity.
void SetParent(BasePtr _parent)
Set the parent.
void SetWorld(const WorldPtr &_newWorld)
Set the world this object belongs to.
virtual void RegisterIntrospectionItems()
Register items in the introspection service.
const WorldPtr & GetWorld() const
Get the World this object is in.
unsigned int GetChildCount() const
Get the number of children.
std::string GetName() const
Return the name of the entity.
sdf::ElementPtr sdf
The SDF values for this object.
Definition Base.hh:364
ignition::math::Pose3d SDFPoseRelativeToParent() const
Get the SDF pose of the object according to the sdf 1.6 convention.
void RemoveChildren()
Remove all children.
void SetSaveable(bool _v)
Set whether the object should be "saved", when the user selects to save the world to xml.
BasePtr GetChild(const std::string &_name)
Get a child by name.
virtual ~Base()
Destructor.
int GetParentId() const
Return the ID of the parent.
void ComputeScopedName()
Compute the scoped name of this object based on its parents.
WorldPtr world
Pointer to the world.
Definition Base.hh:373
std::string StripScopedName(const std::string &_name) const
Return a short version of the name with "ScopedName::" removed.
virtual void Load(sdf::ElementPtr _sdf)
Load.
virtual void UnregisterIntrospectionItems()
Unregister items in the introspection service.
virtual std::optional< sdf::SemanticPose > SDFSemanticPose() const
Get the SDF SemanticPose object associated with the pose of this object.
uint32_t GetId() const
Return the ID of this entity.
bool operator==(const Base &_ent) const
Returns true if the entities are the same.
std::string StripParentScopedName(const std::string &_name) const
Return a short version of the name with "ParentScopedName::" removed.
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
EntityType
Unique identifiers for all entity types.
Definition Base.hh:76
@ SENSOR_COLLISION
Indicates a collision shape used for sensing.
Definition Base.hh:138
@ SLIDER_JOINT
SliderJoint type.
Definition Base.hh:101
@ ENTITY
Entity type.
Definition Base.hh:80
@ PLANE_SHAPE
PlaneShape type.
Definition Base.hh:129
@ SCREW_JOINT
ScrewJoint type.
Definition Base.hh:103
@ SHAPE
Shape type.
Definition Base.hh:115
@ HEIGHTMAP_SHAPE
HeightmapShape type.
Definition Base.hh:121
@ CYLINDER_SHAPE
CylinderShape type.
Definition Base.hh:119
@ UNIVERSAL_JOINT
UniversalJoint type.
Definition Base.hh:105
@ ACTOR
Actor type.
Definition Base.hh:112
@ MODEL
Model type.
Definition Base.hh:82
@ SPHERE_SHAPE
SphereShape type.
Definition Base.hh:131
@ HINGE_JOINT
HingeJoint type.
Definition Base.hh:99
@ RAY_SHAPE
RayShape type.
Definition Base.hh:127
@ BASE
Base type.
Definition Base.hh:78
@ VISUAL
Visual type.
Definition Base.hh:90
@ JOINT
Joint type.
Definition Base.hh:93
@ MULTIRAY_SHAPE
MultiRayShape type.
Definition Base.hh:125
@ GEARBOX_JOINT
GearboxJoint type.
Definition Base.hh:107
@ COLLISION
Collision type.
Definition Base.hh:86
@ MESH_SHAPE
MeshShape type.
Definition Base.hh:133
@ POLYLINE_SHAPE
PolylineShape type.
Definition Base.hh:135
@ BOX_SHAPE
BoxShape type.
Definition Base.hh:117
@ FIXED_JOINT
FixedJoint type.
Definition Base.hh:109
@ LINK
Link type.
Definition Base.hh:84
@ LIGHT
Light type.
Definition Base.hh:88
@ BALL_JOINT
BallJoint type.
Definition Base.hh:95
@ MAP_SHAPE
MapShape type.
Definition Base.hh:123
@ HINGE2_JOINT
Hing2Joint type.
Definition Base.hh:97
void RemoveChild(physics::BasePtr _child)
Remove a child by pointer.
std::string TypeStr() const
Get the string name for the entity type.
virtual void Reset(Base::EntityType _resetType)
Calls recursive Reset on one of the Base::EntityType's.
bool GetSaveable() const
Get whether the object should be "saved", when the user selects to save the world to xml.
BasePtr GetParent() const
Get the parent.
virtual void Update()
Update the object.
Definition Base.hh:166
Base class for all physics objects in Gazebo.
Definition Entity.hh:53
static std::string EntityTypename[]
String names for the different entity types.
Definition Base.hh:42
std::vector< BasePtr > Base_V
Definition PhysicsTypes.hh:202
boost::shared_ptr< Base > BasePtr
Definition PhysicsTypes.hh:78
boost::shared_ptr< World > WorldPtr
Definition PhysicsTypes.hh:90
Forward declarations for the common classes.
Definition Animation.hh:27