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 2011 Nate Koenig
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: 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 
214  public: BasePtr GetById(unsigned int _id) const;
215 
219  public: BasePtr GetByName(const std::string &_name);
220 
224  public: BasePtr GetChild(unsigned int _i) const;
225 
229  public: BasePtr GetChild(const std::string &_name);
230 
233  public: void RemoveChild(const std::string &_name);
234 
238  public: void AddType(EntityType _type);
239 
244  public: bool HasType(const EntityType &_t) const;
245 
248  public: unsigned int GetType() const;
249 
253  public: std::string GetScopedName() const;
254 
257  public: void Print(const std::string &_prefix);
258 
262  public: virtual bool SetSelected(bool _show);
263 
266  public: bool IsSelected() const;
267 
272  public: bool operator ==(const Base &_ent) const;
273 
277  public: void SetWorld(const WorldPtr &_newWorld);
278 
281  public: const WorldPtr &GetWorld() const;
282 
285  public: virtual const sdf::ElementPtr GetSDF();
286 
288  protected: sdf::ElementPtr sdf;
289 
291  protected: BasePtr parent;
292 
294  protected: Base_V children;
295 
297  protected: Base_V::iterator childrenEnd;
298 
300  protected: WorldPtr world;
301 
303  private: bool saveable;
304 
306  private: unsigned int id;
307 
309  private: static unsigned int idCounter;
310 
312  private: unsigned int type;
313 
315  private: bool selected;
316  };
318  }
319 }
320 #endif