Base.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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  {
49 
51  static std::string EntityTypename[] = {
52  "common",
53  "entity",
54  "model",
55  "actor",
56  "link",
57  "collision",
58  "light",
59  "visual",
60  "joint",
61  "ball",
62  "hinge2",
63  "hinge",
64  "slider",
65  "universal",
66  "shape",
67  "box",
68  "cylinder",
69  "heightmap",
70  "map",
71  "multiray",
72  "ray",
73  "plane",
74  "sphere",
75  "trimesh",
76  "polyline"
77  };
78 
81  class GZ_PHYSICS_VISIBLE Base : public boost::enable_shared_from_this<Base>
82  {
85  public: enum EntityType {
87  BASE = 0x00000000,
89  ENTITY = 0x00000001,
91  MODEL = 0x00000002,
93  LINK = 0x00000004,
95  COLLISION = 0x00000008,
97  ACTOR = 0x00000016,
99  LIGHT = 0x00000010,
101  VISUAL = 0x00000020,
102 
104  JOINT = 0x00000040,
106  BALL_JOINT = 0x00000080,
108  HINGE2_JOINT = 0x00000100,
110  HINGE_JOINT = 0x00000200,
112  SLIDER_JOINT = 0x00000400,
114  SCREW_JOINT = 0x00000800,
116  UNIVERSAL_JOINT = 0x00001000,
118  GEARBOX_JOINT = 0x00002000,
120  FIXED_JOINT = 0x00004000,
121 
123  SHAPE = 0x00010000,
125  BOX_SHAPE = 0x00020000,
127  CYLINDER_SHAPE = 0x00040000,
129  HEIGHTMAP_SHAPE = 0x00080000,
131  MAP_SHAPE = 0x00100000,
133  MULTIRAY_SHAPE = 0x00200000,
135  RAY_SHAPE = 0x00400000,
137  PLANE_SHAPE = 0x00800000,
139  SPHERE_SHAPE = 0x01000000,
141  MESH_SHAPE = 0x02000000,
143  POLYLINE_SHAPE = 0x04000000,
144 
146  SENSOR_COLLISION = 0x10000000
147  };
148 
151  public: explicit Base(BasePtr _parent);
152 
154  public: virtual ~Base();
155 
158  public: virtual void Load(sdf::ElementPtr _sdf);
159 
161  public: virtual void Fini();
162 
164  public: virtual void Init() {}
165 
167  public: virtual void Reset();
168 
171  public: virtual void Reset(Base::EntityType _resetType);
172 
174  public: virtual void Update() {}
175 
179  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
180 
183  public: virtual void SetName(const std::string &_name);
184 
187  public: std::string GetName() const;
188 
191  public: uint32_t GetId() const;
192 
196  public: void SetSaveable(bool _v);
197 
201  public: bool GetSaveable() const;
202 
205  public: int GetParentId() const;
206 
209  public: void SetParent(BasePtr _parent);
210 
213  public: BasePtr GetParent() const;
214 
217  public: void AddChild(BasePtr _child);
218 
221  public: virtual void RemoveChild(unsigned int _id);
222 
224  public: void RemoveChildren();
225 
228  public: unsigned int GetChildCount() const;
229 
235  public: BasePtr GetById(unsigned int _id) const;
237 
241  public: BasePtr GetByName(const std::string &_name);
242 
246  public: BasePtr GetChild(unsigned int _i) const;
247 
251  public: BasePtr GetChild(const std::string &_name);
252 
255  public: void RemoveChild(const std::string &_name);
256 
259  public: void RemoveChild(physics::BasePtr _child);
260 
264  public: void AddType(EntityType _type);
265 
270  public: bool HasType(const EntityType &_t) const;
271 
274  public: unsigned int GetType() const;
275 
282  public: std::string GetScopedName(bool _prependWorldName = false) const;
283 
286  public: void Print(const std::string &_prefix);
287 
291  public: virtual bool SetSelected(bool _show);
292 
295  public: bool IsSelected() const;
296 
301  public: bool operator ==(const Base &_ent) const;
302 
306  public: void SetWorld(const WorldPtr &_newWorld);
307 
310  public: const WorldPtr &GetWorld() const;
311 
314  public: virtual const sdf::ElementPtr GetSDF();
315 
319  protected: void ComputeScopedName();
320 
322  protected: sdf::ElementPtr sdf;
323 
325  protected: BasePtr parent;
326 
328  protected: Base_V children;
329 
331  protected: WorldPtr world;
332 
334  private: bool saveable;
335 
337  private: uint32_t id;
338 
340  private: unsigned int type;
341 
343  private: bool selected;
344 
346  private: std::string name;
347 
349  private: std::string scopedName;
350 
351  protected: friend class Entity;
352  };
354  }
355 }
356 #endif
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:84
Forward declarations for the common classes.
Definition: Animation.hh:33
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:51
BasePtr parent
Parent of this entity.
Definition: Base.hh:325
virtual void Update()
Update the object.
Definition: Base.hh:174
default namespace for gazebo
Base class for most physics classes.
Definition: Base.hh:81
virtual void Init()
Initialize the object.
Definition: Base.hh:164
Base_V children
Children of this entity.
Definition: Base.hh:328
Base class for all physics objects in Gazebo.
Definition: Entity.hh:58
WorldPtr world
Pointer to the world.
Definition: Base.hh:331
std::vector< BasePtr > Base_V
Definition: PhysicsTypes.hh:192
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:85
sdf::ElementPtr sdf
The SDF values for this object.
Definition: Base.hh:322
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:72