All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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  };
70 
73  class GAZEBO_VISIBLE Base : public boost::enable_shared_from_this<Base>
74  {
77  public: enum EntityType {
79  BASE = 0x00000000,
81  ENTITY = 0x00000001,
83  MODEL = 0x00000002,
85  LINK = 0x00000004,
87  COLLISION = 0x00000008,
89  ACTOR = 0x00000016,
91  LIGHT = 0x00000010,
93  VISUAL = 0x00000020,
94 
96  JOINT = 0x00000040,
98  BALL_JOINT = 0x00000080,
100  HINGE2_JOINT = 0x00000100,
102  HINGE_JOINT = 0x00000200,
104  SLIDER_JOINT = 0x00000400,
106  SCREW_JOINT = 0x00000800,
108  UNIVERSAL_JOINT = 0x00001000,
110  GEARBOX_JOINT = 0x00002000,
111 
113  SHAPE = 0x00010000,
115  BOX_SHAPE = 0x00020000,
117  CYLINDER_SHAPE = 0x00040000,
119  HEIGHTMAP_SHAPE = 0x00080000,
121  MAP_SHAPE = 0x00100000,
123  MULTIRAY_SHAPE = 0x00200000,
125  RAY_SHAPE = 0x00400000,
127  PLANE_SHAPE = 0x00800000,
129  SPHERE_SHAPE = 0x01000000,
131  MESH_SHAPE = 0x02000000,
132 
134  SENSOR_COLLISION = 0x10000000
135  };
136 
139  public: explicit Base(BasePtr _parent);
140 
142  public: virtual ~Base();
143 
146  public: virtual void Load(sdf::ElementPtr _sdf);
147 
149  public: virtual void Fini();
150 
152  public: virtual void Init() {}
153 
155  public: virtual void Reset();
156 
159  public: virtual void Reset(Base::EntityType _resetType);
160 
162  public: virtual void Update() {}
163 
167  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
168 
171  public: virtual void SetName(const std::string &_name);
172 
175  public: std::string GetName() const;
176 
179  public: uint32_t GetId() const;
180 
184  public: void SetSaveable(bool _v);
185 
189  public: bool GetSaveable() const;
190 
193  public: int GetParentId() const;
194 
197  public: void SetParent(BasePtr _parent);
198 
201  public: BasePtr GetParent() const;
202 
205  public: void AddChild(BasePtr _child);
206 
209  public: virtual void RemoveChild(unsigned int _id);
210 
212  public: void RemoveChildren();
213 
216  public: unsigned int GetChildCount() const;
217 
223  public: BasePtr GetById(unsigned int _id) const;
225 
229  public: BasePtr GetByName(const std::string &_name);
230 
234  public: BasePtr GetChild(unsigned int _i) const;
235 
239  public: BasePtr GetChild(const std::string &_name);
240 
243  public: void RemoveChild(const std::string &_name);
244 
248  public: void AddType(EntityType _type);
249 
254  public: bool HasType(const EntityType &_t) const;
255 
258  public: unsigned int GetType() const;
259 
263  public: std::string GetScopedName() const;
264 
267  public: void Print(const std::string &_prefix);
268 
272  public: virtual bool SetSelected(bool _show);
273 
276  public: bool IsSelected() const;
277 
282  public: bool operator ==(const Base &_ent) const;
283 
287  public: void SetWorld(const WorldPtr &_newWorld);
288 
291  public: const WorldPtr &GetWorld() const;
292 
295  public: virtual const sdf::ElementPtr GetSDF();
296 
300  protected: void ComputeScopedName();
301 
303  protected: sdf::ElementPtr sdf;
304 
306  protected: BasePtr parent;
307 
309  protected: Base_V children;
310 
312  protected: WorldPtr world;
313 
315  private: bool saveable;
316 
318  private: uint32_t id;
319 
321  private: unsigned int type;
322 
324  private: bool selected;
325 
327  private: std::string name;
328 
330  private: std::string scopedName;
331 
332  protected: friend class Entity;
333  };
335  }
336 }
337 #endif