All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 /* Desc: Base class shared by all classes in Gazebo.
19  * Author: Nate Koenig
20  * Date: 09 Sept. 2008
21  */
22 
23 #ifndef _GAZEBO_PHYSICS_BASE_HH_
24 #define _GAZEBO_PHYSICS_BASE_HH_
25 
26 #include <boost/enable_shared_from_this.hpp>
27 #include <string>
28 
29 #include <sdf/sdf.hh>
30 
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
38  namespace physics
39  {
42 
44  static std::string EntityTypename[] = {
45  "common",
46  "entity",
47  "model",
48  "actor",
49  "link",
50  "collision",
51  "light",
52  "visual",
53  "joint",
54  "ball",
55  "hinge2",
56  "hinge",
57  "slider",
58  "universal",
59  "shape",
60  "box",
61  "cylinder",
62  "heightmap",
63  "map",
64  "multiray",
65  "ray",
66  "plane",
67  "sphere",
68  "trimesh",
69  "polyline"
70  };
71 
74  class GAZEBO_VISIBLE Base : public boost::enable_shared_from_this<Base>
75  {
78  public: enum EntityType {
80  BASE = 0x00000000,
82  ENTITY = 0x00000001,
84  MODEL = 0x00000002,
86  LINK = 0x00000004,
88  COLLISION = 0x00000008,
90  ACTOR = 0x00000016,
92  LIGHT = 0x00000010,
94  VISUAL = 0x00000020,
95 
97  JOINT = 0x00000040,
99  BALL_JOINT = 0x00000080,
101  HINGE2_JOINT = 0x00000100,
103  HINGE_JOINT = 0x00000200,
105  SLIDER_JOINT = 0x00000400,
107  SCREW_JOINT = 0x00000800,
109  UNIVERSAL_JOINT = 0x00001000,
111  GEARBOX_JOINT = 0x00002000,
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 
251  public: void AddType(EntityType _type);
252 
257  public: bool HasType(const EntityType &_t) const;
258 
261  public: unsigned int GetType() const;
262 
269  public: std::string GetScopedName(bool _prependWorldName = false) const;
270 
273  public: void Print(const std::string &_prefix);
274 
278  public: virtual bool SetSelected(bool _show);
279 
282  public: bool IsSelected() const;
283 
288  public: bool operator ==(const Base &_ent) const;
289 
293  public: void SetWorld(const WorldPtr &_newWorld);
294 
297  public: const WorldPtr &GetWorld() const;
298 
301  public: virtual const sdf::ElementPtr GetSDF();
302 
306  protected: void ComputeScopedName();
307 
309  protected: sdf::ElementPtr sdf;
310 
312  protected: BasePtr parent;
313 
315  protected: Base_V children;
316 
318  protected: WorldPtr world;
319 
321  private: bool saveable;
322 
324  private: uint32_t id;
325 
327  private: unsigned int type;
328 
330  private: bool selected;
331 
333  private: std::string name;
334 
336  private: std::string scopedName;
337 
338  protected: friend class Entity;
339  };
341  }
342 }
343 #endif
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:66
Base_V children
Children of this entity.
Definition: Base.hh:315
sdf::ElementPtr sdf
The SDF values for this object.
Definition: Base.hh:309
WorldPtr world
Pointer to the world.
Definition: Base.hh:318
virtual void Update()
Update the object.
Definition: Base.hh:165
BasePtr parent
Parent of this entity.
Definition: Base.hh:312
default namespace for gazebo
virtual void Init()
Initialize the object.
Definition: Base.hh:155
Base class for most physics classes.
Definition: Base.hh:74
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:78
Base class for all physics objects in Gazebo.
Definition: Entity.hh:56
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:78
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:44
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
std::vector< BasePtr > Base_V
Definition: PhysicsTypes.hh:162