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 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 /* 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 
34 namespace gazebo
35 {
37  namespace physics
38  {
41 
43  static std::string EntityTypename[] = {
44  "common",
45  "entity",
46  "model",
47  "actor",
48  "link",
49  "collision",
50  "light",
51  "visual",
52  "joint",
53  "ball",
54  "hinge2",
55  "hinge",
56  "slider",
57  "universal",
58  "shape",
59  "box",
60  "cylinder",
61  "heightmap",
62  "map",
63  "multiray",
64  "ray",
65  "plane",
66  "sphere",
67  "trimesh"
68  };
69 
72  class Base : public boost::enable_shared_from_this<Base>
73  {
76  public: enum EntityType {
78  BASE = 0x00000000,
80  ENTITY = 0x00000001,
82  MODEL = 0x00000002,
84  LINK = 0x00000004,
86  COLLISION = 0x00000008,
88  ACTOR = 0x00000016,
90  LIGHT = 0x00000010,
92  VISUAL = 0x00000020,
93 
95  JOINT = 0x00000040,
97  BALL_JOINT = 0x00000080,
99  HINGE2_JOINT = 0x00000100,
101  HINGE_JOINT = 0x00000200,
103  SLIDER_JOINT = 0x00000400,
105  SCREW_JOINT = 0x00000800,
107  UNIVERSAL_JOINT = 0x00001000,
108 
110  SHAPE = 0x00002000,
112  BOX_SHAPE = 0x00004000,
114  CYLINDER_SHAPE = 0x00008000,
116  HEIGHTMAP_SHAPE = 0x00010000,
118  MAP_SHAPE = 0x00020000,
120  MULTIRAY_SHAPE = 0x00040000,
122  RAY_SHAPE = 0x00080000,
124  PLANE_SHAPE = 0x00100000,
126  SPHERE_SHAPE = 0x00200000,
128  MESH_SHAPE = 0x00400000,
129 
131  SENSOR_COLLISION = 0x00800000
132  };
133 
136  public: explicit Base(BasePtr _parent);
137 
139  public: virtual ~Base();
140 
143  public: virtual void Load(sdf::ElementPtr _sdf);
144 
146  public: virtual void Fini();
147 
149  public: virtual void Init() {}
150 
152  public: virtual void Reset();
153 
156  public: virtual void Reset(Base::EntityType _resetType);
157 
159  public: virtual void Update() {}
160 
164  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
165 
168  public: virtual void SetName(const std::string &_name);
169 
172  public: std::string GetName() const;
173 
176  public: uint32_t GetId() const;
177 
181  public: void SetSaveable(bool _v);
182 
186  public: bool GetSaveable() const;
187 
190  public: int GetParentId() const;
191 
194  public: void SetParent(BasePtr _parent);
195 
198  public: BasePtr GetParent() const;
199 
202  public: void AddChild(BasePtr _child);
203 
206  public: virtual void RemoveChild(unsigned int _id);
207 
209  public: void RemoveChildren();
210 
213  public: unsigned int GetChildCount() const;
214 
220  public: BasePtr GetById(unsigned int _id) const;
222 
226  public: BasePtr GetByName(const std::string &_name);
227 
231  public: BasePtr GetChild(unsigned int _i) const;
232 
236  public: BasePtr GetChild(const std::string &_name);
237 
240  public: void RemoveChild(const std::string &_name);
241 
245  public: void AddType(EntityType _type);
246 
251  public: bool HasType(const EntityType &_t) const;
252 
255  public: unsigned int GetType() const;
256 
260  public: std::string GetScopedName() const;
261 
264  public: void Print(const std::string &_prefix);
265 
269  public: virtual bool SetSelected(bool _show);
270 
273  public: bool IsSelected() const;
274 
279  public: bool operator ==(const Base &_ent) const;
280 
284  public: void SetWorld(const WorldPtr &_newWorld);
285 
288  public: const WorldPtr &GetWorld() const;
289 
292  public: virtual const sdf::ElementPtr GetSDF();
293 
297  protected: void ComputeScopedName();
298 
300  protected: sdf::ElementPtr sdf;
301 
303  protected: BasePtr parent;
304 
306  protected: Base_V children;
307 
309  protected: Base_V::iterator childrenEnd;
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