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 "gazebo/sdf/sdf.hh"
32 
33 namespace gazebo
34 {
36  namespace physics
37  {
40 
42  static std::string EntityTypename[] = {
43  "common",
44  "entity",
45  "model",
46  "actor",
47  "link",
48  "collision",
49  "light",
50  "visual",
51  "joint",
52  "ball",
53  "hinge2",
54  "hinge",
55  "slider",
56  "universal",
57  "shape",
58  "box",
59  "cylinder",
60  "heightmap",
61  "map",
62  "multiray",
63  "ray",
64  "plane",
65  "sphere",
66  "trimesh"
67  };
68 
71  class Base : public boost::enable_shared_from_this<Base>
72  {
75  public: enum EntityType {
77  BASE = 0x00000000,
79  ENTITY = 0x00000001,
81  MODEL = 0x00000002,
83  LINK = 0x00000004,
85  COLLISION = 0x00000008,
87  ACTOR = 0x00000016,
89  LIGHT = 0x00000010,
91  VISUAL = 0x00000020,
92 
94  JOINT = 0x00000040,
96  BALL_JOINT = 0x00000080,
98  HINGE2_JOINT = 0x00000100,
100  HINGE_JOINT = 0x00000200,
102  SLIDER_JOINT = 0x00000400,
104  SCREW_JOINT = 0x00000800,
106  UNIVERSAL_JOINT = 0x00001000,
107 
109  SHAPE = 0x00002000,
111  BOX_SHAPE = 0x00004000,
113  CYLINDER_SHAPE = 0x00008000,
115  HEIGHTMAP_SHAPE = 0x00010000,
117  MAP_SHAPE = 0x00020000,
119  MULTIRAY_SHAPE = 0x00040000,
121  RAY_SHAPE = 0x00080000,
123  PLANE_SHAPE = 0x00100000,
125  SPHERE_SHAPE = 0x00200000,
127  TRIMESH_SHAPE = 0x00400000
128  };
129 
132  public: explicit Base(BasePtr _parent);
133 
135  public: virtual ~Base();
136 
139  public: virtual void Load(sdf::ElementPtr _sdf);
140 
142  public: virtual void Fini();
143 
145  public: virtual void Init() {}
146 
148  public: virtual void Reset();
149 
152  public: virtual void Reset(Base::EntityType _resetType);
153 
155  public: virtual void Update() {}
156 
160  public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
161 
164  public: virtual void SetName(const std::string &_name);
165 
168  public: std::string GetName() const;
169 
172  public: unsigned int GetId() const;
173 
177  public: void SetSaveable(bool _v);
178 
182  public: bool GetSaveable() const;
183 
186  public: int GetParentId() const;
187 
190  public: void SetParent(BasePtr _parent);
191 
194  public: BasePtr GetParent() const;
195 
198  public: void AddChild(BasePtr _child);
199 
202  public: virtual void RemoveChild(unsigned int _id);
203 
205  public: void RemoveChildren();
206 
209  public: unsigned int GetChildCount() const;
210 
216  public: BasePtr GetById(unsigned int _id) const;
218 
222  public: BasePtr GetByName(const std::string &_name);
223 
227  public: BasePtr GetChild(unsigned int _i) const;
228 
232  public: BasePtr GetChild(const std::string &_name);
233 
236  public: void RemoveChild(const std::string &_name);
237 
241  public: void AddType(EntityType _type);
242 
247  public: bool HasType(const EntityType &_t) const;
248 
251  public: unsigned int GetType() const;
252 
256  public: std::string GetScopedName() const;
257 
260  public: void Print(const std::string &_prefix);
261 
265  public: virtual bool SetSelected(bool _show);
266 
269  public: bool IsSelected() const;
270 
275  public: bool operator ==(const Base &_ent) const;
276 
280  public: void SetWorld(const WorldPtr &_newWorld);
281 
284  public: const WorldPtr &GetWorld() const;
285 
288  public: virtual const sdf::ElementPtr GetSDF();
289 
291  protected: sdf::ElementPtr sdf;
292 
294  protected: BasePtr parent;
295 
297  protected: Base_V children;
298 
300  protected: Base_V::iterator childrenEnd;
301 
303  protected: WorldPtr world;
304 
306  private: bool saveable;
307 
309  private: unsigned int id;
310 
312  private: static unsigned int idCounter;
313 
315  private: unsigned int type;
316 
318  private: bool selected;
319 
320  protected: friend class Entity;
321  };
323  }
324 }
325 #endif