Base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 #ifdef _WIN32
27  // Ensure that Winsock2.h is included before Windows.h, which can get
28  // pulled in by anybody (e.g., Boost).
29  #include <Winsock2.h>
30 #endif
31 
32 #include <boost/enable_shared_from_this.hpp>
33 #include <string>
34 
35 #include <sdf/sdf.hh>
36 
39 #include "gazebo/util/system.hh"
40 
41 namespace gazebo
42 {
44  namespace physics
45  {
48 
50  static std::string EntityTypename[] = {
51  "common",
52  "entity",
53  "model",
54  "actor",
55  "link",
56  "collision",
57  "light",
58  "visual",
59  "joint",
60  "ball",
61  "hinge2",
62  "hinge",
63  "slider",
64  "universal",
65  "shape",
66  "box",
67  "cylinder",
68  "heightmap",
69  "map",
70  "multiray",
71  "ray",
72  "plane",
73  "sphere",
74  "trimesh",
75  "polyline"
76  };
77 
80  class GZ_PHYSICS_VISIBLE Base : public boost::enable_shared_from_this<Base>
81  {
84  public: enum EntityType {
86  BASE = 0x00000000,
88  ENTITY = 0x00000001,
90  MODEL = 0x00000002,
92  LINK = 0x00000004,
94  COLLISION = 0x00000008,
96  ACTOR = 0x00000016,
98  LIGHT = 0x00000010,
100  VISUAL = 0x00000020,
101 
103  JOINT = 0x00000040,
105  BALL_JOINT = 0x00000080,
107  HINGE2_JOINT = 0x00000100,
109  HINGE_JOINT = 0x00000200,
111  SLIDER_JOINT = 0x00000400,
113  SCREW_JOINT = 0x00000800,
115  UNIVERSAL_JOINT = 0x00001000,
117  GEARBOX_JOINT = 0x00002000,
119  FIXED_JOINT = 0x00004000,
120 
122  SHAPE = 0x00010000,
124  BOX_SHAPE = 0x00020000,
126  CYLINDER_SHAPE = 0x00040000,
128  HEIGHTMAP_SHAPE = 0x00080000,
130  MAP_SHAPE = 0x00100000,
132  MULTIRAY_SHAPE = 0x00200000,
134  RAY_SHAPE = 0x00400000,
136  PLANE_SHAPE = 0x00800000,
138  SPHERE_SHAPE = 0x01000000,
140  MESH_SHAPE = 0x02000000,
142  POLYLINE_SHAPE = 0x04000000,
143 
145  SENSOR_COLLISION = 0x10000000
146  };
147 
150  public: explicit Base(BasePtr _parent);
151 
153  public: virtual ~Base();
154 
157  public: virtual void Load(sdf::ElementPtr _sdf);
158 
160  public: virtual void Fini();
161 
163  public: virtual void Init() {}
164 
166  public: virtual void Reset();
167 
170  public: virtual void Reset(Base::EntityType _resetType);
171 
173  public: virtual void Update() {}
174 
178  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
179 
182  public: virtual void SetName(const std::string &_name);
183 
186  public: std::string GetName() const;
187 
190  public: uint32_t GetId() const;
191 
195  public: void SetSaveable(bool _v);
196 
200  public: bool GetSaveable() const;
201 
204  public: int GetParentId() const;
205 
208  public: void SetParent(BasePtr _parent);
209 
212  public: BasePtr GetParent() const;
213 
216  public: void AddChild(BasePtr _child);
217 
220  public: virtual void RemoveChild(unsigned int _id);
221 
223  public: void RemoveChildren();
224 
227  public: unsigned int GetChildCount() const;
228 
234  public: BasePtr GetById(unsigned int _id) const;
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 
259  public: void AddType(EntityType _type);
260 
265  public: bool HasType(const EntityType &_t) const;
266 
269  public: unsigned int GetType() const;
270 
277  public: std::string GetScopedName(bool _prependWorldName = false) const;
278 
281  public: void Print(const std::string &_prefix);
282 
286  public: virtual bool SetSelected(bool _show);
287 
290  public: bool IsSelected() const;
291 
296  public: bool operator ==(const Base &_ent) const;
297 
301  public: void SetWorld(const WorldPtr &_newWorld);
302 
305  public: const WorldPtr &GetWorld() const;
306 
309  public: virtual const sdf::ElementPtr GetSDF();
310 
314  protected: void ComputeScopedName();
315 
317  protected: sdf::ElementPtr sdf;
318 
320  protected: BasePtr parent;
321 
323  protected: Base_V children;
324 
326  protected: WorldPtr world;
327 
329  private: bool saveable;
330 
332  private: uint32_t id;
333 
335  private: unsigned int type;
336 
338  private: bool selected;
339 
341  private: std::string name;
342 
344  private: std::string scopedName;
345 
346  protected: friend class Entity;
347  };
349  }
350 }
351 #endif
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:68
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
Base_V children
Children of this entity.
Definition: Base.hh:323
sdf::ElementPtr sdf
The SDF values for this object.
Definition: Base.hh:317
WorldPtr world
Pointer to the world.
Definition: Base.hh:326
virtual void Update()
Update the object.
Definition: Base.hh:173
BasePtr parent
Parent of this entity.
Definition: Base.hh:320
default namespace for gazebo
virtual void Init()
Initialize the object.
Definition: Base.hh:163
Base class for most physics classes.
Definition: Base.hh:80
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:80
Base class for all physics objects in Gazebo.
Definition: Entity.hh:56
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:84
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:50
std::vector< BasePtr > Base_V
Definition: PhysicsTypes.hh:176