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 #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 #include <vector>
30 
31 #include <sdf/sdf.hh>
32 
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 
256  public: void RemoveChild(physics::BasePtr _child);
257 
261  public: void AddType(EntityType _type);
262 
267  public: bool HasType(const EntityType &_t) const;
268 
271  public: unsigned int GetType() const;
272 
275  public: std::string TypeStr() const;
276 
283  public: std::string GetScopedName(bool _prependWorldName = false) const;
284 
291  public: common::URI URI() const;
292 
295  public: void Print(const std::string &_prefix);
296 
300  public: virtual bool SetSelected(bool _show);
301 
304  public: bool IsSelected() const;
305 
310  public: bool operator ==(const Base &_ent) const;
311 
315  public: void SetWorld(const WorldPtr &_newWorld);
316 
319  public: const WorldPtr &GetWorld() const;
320 
323  public: virtual const sdf::ElementPtr GetSDF();
324 
326  protected: virtual void RegisterIntrospectionItems();
327 
329  protected: virtual void UnregisterIntrospectionItems();
330 
334  protected: void ComputeScopedName();
335 
337  protected: sdf::ElementPtr sdf;
338 
340  protected: BasePtr parent;
341 
343  protected: Base_V children;
344 
346  protected: WorldPtr world;
347 
349  protected: std::vector<common::URI> introspectionItems;
350 
352  private: bool saveable;
353 
355  private: uint32_t id;
356 
358  private: unsigned int type;
359 
361  private: std::string typeStr;
362 
364  private: bool selected;
365 
367  private: std::string name;
368 
370  private: std::string scopedName;
371 
372  protected: friend class Entity;
373  };
375  }
376 }
377 #endif
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:89
Forward declarations for the common classes.
Definition: Animation.hh:26
static std::string EntityTypename[]
String names for the different entity types.
Definition: Base.hh:47
BasePtr parent
Parent of this entity.
Definition: Base.hh:340
virtual void Update()
Update the object.
Definition: Base.hh:171
default namespace for gazebo
A complete URI.
Definition: URI.hh:176
std::vector< common::URI > introspectionItems
All the introspection items regsitered for this.
Definition: Base.hh:349
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:343
Base class for all physics objects in Gazebo.
Definition: Entity.hh:52
WorldPtr world
Pointer to the world.
Definition: Base.hh:346
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:337
boost::shared_ptr< Base > BasePtr
Definition: PhysicsTypes.hh:77