opensurgsim
Component.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
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 #ifndef SURGSIM_FRAMEWORK_COMPONENT_H
17 #define SURGSIM_FRAMEWORK_COMPONENT_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include <boost/uuid/uuid.hpp>
23 
24 #include "SurgSim/Framework/Accessible.h"
25 #include "SurgSim/Framework/ObjectFactory.h"
26 
27 namespace SurgSim
28 {
29 namespace Framework
30 {
31 
32 // Forward References
33 class PoseComponent;
34 class Runtime;
35 class Scene;
36 class SceneElement;
37 
42 class Component :
43  public Accessible,
44  public std::enable_shared_from_this<Component>,
45  public FactoryBase1<Component, std::string>
46 {
47 public:
50  explicit Component(const std::string& name);
52  virtual ~Component();
53 
56  std::string getName() const;
57 
60  std::string getFullName() const;
61 
64  void setName(const std::string& name);
65 
67  boost::uuids::uuid getUuid() const;
68 
70  bool isInitialized() const;
71 
78  bool initialize(const std::weak_ptr<Runtime>& runtime);
79 
81  bool isAwake() const;
82 
86  bool wakeUp();
87 
90  void retire();
91 
94  void setScene(std::weak_ptr<Scene> scene);
95 
98  std::shared_ptr<Scene> getScene();
99 
102  void setSceneElement(std::weak_ptr<SceneElement> sceneElement);
103 
106  std::shared_ptr<SceneElement> getSceneElement();
107 
110  std::shared_ptr<const SceneElement> getSceneElement() const;
111 
114  std::shared_ptr<Runtime> getRuntime() const;
115 
121  virtual std::string getClassName() const;
122 
125  std::shared_ptr<Component> getSharedPtr();
126 
129  virtual bool doInitialize() = 0;
130 
133  virtual bool doWakeUp() = 0;
134 
137  virtual void doRetire();
138 
141  bool isActive() const;
142 
145  virtual void setLocalActive(bool val);
146 
149  bool isLocalActive() const;
150 
151 protected:
154  virtual std::shared_ptr<PoseComponent> getPoseComponent();
155 
158  virtual std::shared_ptr<const PoseComponent> getPoseComponent() const;
159 
160 
161 private:
162 
163 
165  std::string m_name;
166 
168  boost::uuids::uuid m_uuid;
169 
171  std::weak_ptr<Runtime> m_runtime;
172 
174  std::weak_ptr<Scene> m_scene;
175 
177  std::weak_ptr<SceneElement> m_sceneElement;
178 
180  bool m_didInit;
181 
183  bool m_didWakeUp;
184 
186  bool m_isInitialized;
187 
189  bool m_isAwake;
190 
192  bool m_isLocalActive;
193 
194 };
195 
206 template <class Target, class Source>
207 std::shared_ptr<Target> checkAndConvert(std::shared_ptr<Source> incoming, const std::string& expectedTypeName);
208 
209 }; // namespace Framework
210 }; // namespace SurgSim
211 
212 #include "SurgSim/Framework/Component-inl.h"
213 
214 #endif // SURGSIM_FRAMEWORK_COMPONENT_H
std::shared_ptr< Runtime > getRuntime() const
Get the runtime which contains this component.
Definition: Component.cpp:141
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
bool wakeUp()
Wakeup this component, this will be called when the component is inserted into the ComponentManager t...
Definition: Component.cpp:93
virtual bool doInitialize()=0
Interface to be implemented by derived classes.
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:140
void setScene(std::weak_ptr< Scene > scene)
Sets the scene.
Definition: Component.cpp:116
Component(const std::string &name)
Constructor.
Definition: Component.cpp:34
std::shared_ptr< SceneElement > getSceneElement()
Gets the scene element.
Definition: Component.cpp:131
virtual void doRetire()
Interface to be implemented by derived classes Has a default implementation, does nothing...
Definition: Component.cpp:111
virtual bool doWakeUp()=0
Interface to be implemented by derived classes.
std::shared_ptr< Component > getSharedPtr()
Gets a shared pointer to this component.
Definition: Component.cpp:170
void retire()
Retire this component, this will be called when the component is removed from the ComponentManager th...
Definition: Component.cpp:105
boost::uuids::uuid getUuid() const
Gets the id of the component.
Definition: Component.cpp:158
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:42
virtual std::shared_ptr< PoseComponent > getPoseComponent()
Get the PoseComponent for this component.
Definition: Component.cpp:152
bool initialize(const std::weak_ptr< Runtime > &runtime)
Initialize this component, this needs to be called before wakeUp() can be called. ...
Definition: Component.cpp:77
std::string getName() const
Gets component name.
Definition: Component.cpp:51
bool isActive() const
Definition: Component.cpp:184
virtual void setLocalActive(bool val)
Set the component&#39;s active state.
Definition: Component.cpp:196
void setName(const std::string &name)
Sets the name of component.
Definition: Component.cpp:67
virtual std::string getClassName() const
The class name for this class, this being the base class it should return SurgSim::Framework::Compone...
Definition: Component.cpp:163
bool isInitialized() const
Definition: Component.cpp:72
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:37
bool isLocalActive() const
Definition: Component.cpp:201
std::string getFullName() const
Gets a string containing the name of the Component and (if it has one) its SceneElement.
Definition: Component.cpp:56
virtual ~Component()
Destructor.
Definition: Component.cpp:47
bool isAwake() const
Definition: Component.cpp:88
std::shared_ptr< Scene > getScene()
Gets the scene.
Definition: Component.cpp:121
void setSceneElement(std::weak_ptr< SceneElement > sceneElement)
Sets the scene element.
Definition: Component.cpp:126