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 #ifndef GAZEBO_PHYSICS_BASE_HH_
19 #define GAZEBO_PHYSICS_BASE_HH_
20 
21 #ifdef _WIN32
22  // Ensure that Winsock2.h is included before Windows.h, which can get
23  // pulled in by anybody (e.g., Boost).
24  #include <Winsock2.h>
25 #endif
26 
27 #include <boost/enable_shared_from_this.hpp>
28 #include <string>
29 
30 #include <sdf/sdf.hh>
31 
33 #include "gazebo/common/URI.hh"
35 #include "gazebo/util/system.hh"
36 
37 namespace gazebo
38 {
40  namespace physics
41  {
45 
47  static std::string EntityTypename[] = {
48  "common",
49  "entity",
50  "model",
51  "actor",
52  "link",
53  "collision",
54  "light",
55  "visual",
56  "joint",
57  "ball",
58  "hinge2",
59  "hinge",
60  "slider",
61  "universal",
62  "shape",
63  "box",
64  "cylinder",
65  "heightmap",
66  "map",
67  "multiray",
68  "ray",
69  "plane",
70  "sphere",
71  "trimesh",
72  "polyline"
73  };
74 
77  class GZ_PHYSICS_VISIBLE Base : public boost::enable_shared_from_this<Base>
78  {
81  public: enum EntityType {
83  BASE = 0x00000000,
85  ENTITY = 0x00000001,
87  MODEL = 0x00000002,
89  LINK = 0x00000004,
91  COLLISION = 0x00000008,
93  LIGHT = 0x00000010,
95  VISUAL = 0x00000020,
96 
98  JOINT = 0x00000040,
100  BALL_JOINT = 0x00000080,
102  HINGE2_JOINT = 0x00000100,
104  HINGE_JOINT = 0x00000200,
106  SLIDER_JOINT = 0x00000400,
108  SCREW_JOINT = 0x00000800,
110  UNIVERSAL_JOINT = 0x00001000,
112  GEARBOX_JOINT = 0x00002000,
114  FIXED_JOINT = 0x00004000,
115 
117  ACTOR = 0x00008000,
118 
120  SHAPE = 0x00010000,
122  BOX_SHAPE = 0x00020000,
124  CYLINDER_SHAPE = 0x00040000,
126  HEIGHTMAP_SHAPE = 0x00080000,
128  MAP_SHAPE = 0x00100000,
130  MULTIRAY_SHAPE = 0x00200000,
132  RAY_SHAPE = 0x00400000,
134  PLANE_SHAPE = 0x00800000,
136  SPHERE_SHAPE = 0x01000000,
138  MESH_SHAPE = 0x02000000,
140  POLYLINE_SHAPE = 0x04000000,
141 
143  SENSOR_COLLISION = 0x10000000
144  };
145 
148  public: explicit Base(BasePtr _parent);
149 
151  public: virtual ~Base();
152 
155  public: virtual void Load(sdf::ElementPtr _sdf);
156 
158  public: virtual void Fini();
159 
161  public: virtual void Init() {}
162 
164  public: virtual void Reset();
165 
168  public: virtual void Reset(Base::EntityType _resetType);
169 
171  public: virtual void Update() {}
172 
176  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
177 
180  public: virtual void SetName(const std::string &_name);
181 
184  public: std::string GetName() const;
185 
188  public: uint32_t GetId() const;
189 
193  public: void SetSaveable(bool _v);
194 
198  public: bool GetSaveable() const;
199 
202  public: int GetParentId() const;
203 
206  public: void SetParent(BasePtr _parent);
207 
210  public: BasePtr GetParent() const;
211 
214  public: void AddChild(BasePtr _child);
215 
218  public: virtual void RemoveChild(unsigned int _id);
219 
221  public: void RemoveChildren();
222 
225  public: unsigned int GetChildCount() const;
226 
232  public: BasePtr GetById(unsigned int _id) const;
234 
238  public: BasePtr GetByName(const std::string &_name);
239 
243  public: BasePtr GetChild(unsigned int _i) const;
244 
248  public: BasePtr GetChild(const std::string &_name);
249 
252  public: void RemoveChild(const std::string &_name);
253 
257  public: void AddType(EntityType _type);
258 
263  public: bool HasType(const EntityType &_t) const;
264 
267  public: unsigned int GetType() const;
268 
271  public: std::string TypeStr() const;
272 
279  public: std::string GetScopedName(bool _prependWorldName = false) const;
280 
287  public: common::URI URI() const;
288 
291  public: void Print(const std::string &_prefix);
292 
296  public: virtual bool SetSelected(bool _show);
297 
300  public: bool IsSelected() const;
301 
306  public: bool operator ==(const Base &_ent) const;
307 
311  public: void SetWorld(const WorldPtr &_newWorld);
312 
315  public: const WorldPtr &GetWorld() const;
316 
319  public: virtual const sdf::ElementPtr GetSDF();
320 
324  protected: void ComputeScopedName();
325 
327  protected: sdf::ElementPtr sdf;
328 
330  protected: BasePtr parent;
331 
333  protected: Base_V children;
334 
336  protected: WorldPtr world;
337 
339  private: bool saveable;
340 
342  private: uint32_t id;
343 
345  private: unsigned int type;
346 
348  private: std::string typeStr;
349 
351  private: bool selected;
352 
354  private: std::string name;
355 
357  private: std::string scopedName;
358 
359  protected: friend class Entity;
360  };
362  }
363 }
364 #endif
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:47
BasePtr parent
Parent of this entity.
Definition: Base.hh:330
virtual void Update()
Update the object.
Definition: Base.hh:171
default namespace for gazebo
A complete URI.
Definition: URI.hh:170
Base class for most physics classes.
Definition: Base.hh:77
virtual void Init()
Initialize the object.
Definition: Base.hh:161
Base_V children
Children of this entity.
Definition: Base.hh:333
Base class for all physics objects in Gazebo.
Definition: Entity.hh:58
WorldPtr world
Pointer to the world.
Definition: Base.hh:336
std::vector< BasePtr > Base_V
Definition: PhysicsTypes.hh:201
EntityType
Unique identifiers for all entity types.
Definition: Base.hh:81
sdf::ElementPtr sdf
The SDF values for this object.
Definition: Base.hh:327
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77