Base.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 
00018 /* Desc: Base class shared by all classes in Gazebo.
00019  * Author: Nate Koenig
00020  * Date: 09 Sept. 2008
00021  */
00022 
00023 #ifndef GAZEBO_PHYSICS_BASE_HH
00024 #define GAZEBO_PHYSICS_BASE_HH
00025 
00026 #include <boost/enable_shared_from_this.hpp>
00027 
00028 #include <string>
00029 
00030 #include "sdf/sdf.h"
00031 #include "common/CommonTypes.hh"
00032 #include "physics/PhysicsTypes.hh"
00033 
00034 namespace gazebo
00035 {
00036     namespace physics
00037   {
00040 
00041     static std::string EntityTypename[] = { 
00042       "common", 
00043       "entity", 
00044       "model", 
00045       "link", 
00046       "collision",
00047       "light",
00048       "visual",
00049       "joint",
00050       "ball",
00051       "hinge2",
00052       "hinge",
00053       "slider",
00054       "universal",
00055       "shape",
00056       "box",
00057       "cylinder",
00058       "heightmap",  
00059       "map", 
00060       "multiray", 
00061       "ray", 
00062       "plane",
00063       "sphere", 
00064       "trimesh"
00065     };
00066 
00068     class Base : public boost::enable_shared_from_this<Base>
00069     {
00070       public: enum EntityType{
00071                 BASE            = 0x00000000,
00072                 ENTITY          = 0x00000001,
00073                 MODEL           = 0x00000002,
00074                 LINK            = 0x00000004,
00075                 COLLISION       = 0x00000010,
00076                 LIGHT           = 0x00000020,
00077                 VISUAL          = 0x00000040,
00078 
00079                 JOINT           = 0x10000000,
00080                 BALL_JOINT      = 0x10000001,
00081                 HINGE2_JOINT    = 0x10000002,
00082                 HINGE_JOINT     = 0x10000004,
00083                 SLIDER_JOINT    = 0x10000010,
00084                 SCREW_JOINT     = 0x10000020,
00085                 UNIVERSAL_JOINT = 0x10000040,
00086 
00087                 SHAPE           = 0x20000000,
00088                 BOX_SHAPE       = 0x20000001,
00089                 CYLINDER_SHAPE  = 0x20000002,
00090                 HEIGHTMAP_SHAPE = 0x20000004,
00091                 MAP_SHAPE       = 0x20000010,
00092                 MULTIRAY_SHAPE  = 0x20000020,
00093                 RAY_SHAPE       = 0x20000040,
00094                 PLANE_SHAPE     = 0x20000100,
00095                 SPHERE_SHAPE    = 0x20000200,
00096                 TRIMESH_SHAPE   = 0x20000400
00097               };
00098 
00101       public: Base(BasePtr parent);
00102   
00104       public: virtual ~Base();
00105   
00108       public: virtual void Load( sdf::ElementPtr &_sdf );
00109 
00111       public: virtual void Fini();
00112 
00113       public: virtual void Init() {}
00114       public: virtual void Reset();
00115       public: virtual void Update() {}
00116 
00118       public: virtual void UpdateParameters( sdf::ElementPtr &_sdf );
00119 
00122       public: virtual void SetName(const std::string &name);
00123     
00126       public: std::string GetName() const;
00127   
00130       public: unsigned int GetId() const;
00131   
00135       public: void SetSaveable(bool v);
00136   
00140       public: bool GetSaveable() const;
00141   
00144       public: int GetParentId() const;
00145     
00148       public: void SetParent(BasePtr parent);
00149     
00152       public: BasePtr GetParent() const;
00153   
00156       public: void AddChild(BasePtr child);
00157   
00160       public: virtual void RemoveChild(unsigned int id);
00161   
00163       public: void RemoveChildren();
00164 
00167       public: unsigned int GetChildCount() const;
00168 
00170       public: BasePtr GetById(unsigned int _id) const;
00171 
00175       public: BasePtr GetByName(const std::string &name);
00176   
00178       public: BasePtr GetChild(unsigned int i) const;
00179   
00181       public: BasePtr GetChild(const std::string &name );
00182 
00184       public: void RemoveChild( const std::string &_name);
00185   
00187       public: void AddType( EntityType _type );
00188   
00190       public: bool HasType(const EntityType &_t) const;
00191   
00193       public: unsigned int GetType() const;
00194   
00197       public: std::string GetScopedName() const;
00198   
00201       public: std::string GetCompleteScopedName() const;
00202   
00203       public: void Print(std::string prefix);
00204   
00206       public: bool GetShowInGui() const;
00207   
00209       public: void SetShowInGui(bool v);
00210   
00212       //         the gui
00213       public: virtual bool SetSelected( bool s );
00214     
00216       public: bool IsSelected() const;
00217   
00219       public: bool operator==(const Base &ent) const;
00220   
00223       public: void SetWorld(const WorldPtr &_newWorld);
00224     
00226       public: const WorldPtr &GetWorld() const;
00227 
00229       public: virtual const sdf::ElementPtr &GetSDF();
00230 
00231       protected: sdf::ElementPtr sdf;
00232 
00234       protected: BasePtr parent;
00235  
00237       protected: Base_V children;
00238       protected: Base_V::iterator childrenEnd;
00239 
00240       protected: WorldPtr world;
00241 
00243       private: bool saveable;
00244  
00246       private: unsigned int id;
00247     
00249       private: static unsigned int idCounter;
00250    
00251       private: unsigned int type;
00252   
00253       private: bool selected;
00254     };
00256   }
00257 
00258 }
00259 #endif