All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Component.h
Go to the documentation of this file.
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 
20 #include <string>
21 #include <memory>
22 
23 #include <boost/uuid/uuid.hpp>
24 
27 
28 namespace SurgSim
29 {
30 namespace Framework
31 {
32 
33 // Forward References
34 class PoseComponent;
35 class Runtime;
36 class Scene;
37 class SceneElement;
38 
43 class Component : public Accessible, public std::enable_shared_from_this<Component>
44 {
45 public:
48  explicit Component(const std::string& name);
50  virtual ~Component();
51 
54  std::string getName() const;
55 
58  void setName(const std::string& name);
59 
61  boost::uuids::uuid getUuid() const;
62 
64  bool isInitialized() const;
65 
72  bool initialize(const std::weak_ptr<Runtime>& runtime);
73 
75  bool isAwake() const;
76 
80  bool wakeUp();
81 
84  void setScene(std::weak_ptr<Scene> scene);
85 
88  std::shared_ptr<Scene> getScene();
89 
92  void setSceneElement(std::weak_ptr<SceneElement> sceneElement);
93 
96  std::shared_ptr<SceneElement> getSceneElement();
97 
100  std::shared_ptr<const SceneElement> getSceneElement() const;
101 
104  std::shared_ptr<Runtime> getRuntime() const;
105 
111  virtual std::string getClassName() const;
112 
114 
116  static FactoryType& getFactory();
117 
120  std::shared_ptr<Component> getSharedPtr();
121 
124  virtual bool doInitialize() = 0;
125 
128  virtual bool doWakeUp() = 0;
129 
132  bool isActive() const;
133 
136  virtual void setLocalActive(bool val);
137 
140  bool isLocalActive() const;
141 
142 protected:
145  virtual std::shared_ptr<PoseComponent> getPoseComponent();
146 
149  virtual std::shared_ptr<const PoseComponent> getPoseComponent() const;
150 
151 private:
153  std::string m_name;
154 
156  boost::uuids::uuid m_uuid;
157 
159  std::weak_ptr<Runtime> m_runtime;
160 
162  std::weak_ptr<Scene> m_scene;
163 
165  std::weak_ptr<SceneElement> m_sceneElement;
166 
168  bool m_didInit;
169 
172 
175 
177  bool m_isAwake;
178 
181 
182 };
183 
184 }; // namespace Framework
185 }; // namespace SurgSim
186 
187 #endif // SURGSIM_FRAMEWORK_COMPONENT_H
std::string m_name
Name of this component.
Definition: Component.h:153
bool isActive() const
Definition: Component.cpp:168
bool m_didInit
Indicates if doInitialize() has been called.
Definition: Component.h:168
bool isAwake() const
Definition: Component.cpp:77
bool wakeUp()
Wakeup this component, this will be called when the component is inserted into the ComponentManager t...
Definition: Component.cpp:82
virtual bool doInitialize()=0
Interface to be implemented by derived classes.
void setScene(std::weak_ptr< Scene > scene)
Sets the scene.
Definition: Component.cpp:94
Component(const std::string &name)
Constructor.
Definition: Component.cpp:34
std::shared_ptr< SceneElement > getSceneElement()
Gets the scene element.
Definition: Component.cpp:109
std::weak_ptr< Scene > m_scene
Scene which contains this component.
Definition: Component.h:162
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:154
bool isInitialized() const
Definition: Component.cpp:61
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:43
virtual std::shared_ptr< PoseComponent > getPoseComponent()
Get the PoseComponent for this component.
Definition: Component.cpp:130
std::weak_ptr< SceneElement > m_sceneElement
SceneElement which contains this component.
Definition: Component.h:165
bool initialize(const std::weak_ptr< Runtime > &runtime)
Initialize this component, this needs to be called before wakeUp() can be called. ...
Definition: Component.cpp:66
bool m_isInitialized
Indicates if this component is initialized.
Definition: Component.h:174
virtual void setLocalActive(bool val)
Set the component's active state.
Definition: Component.cpp:180
bool m_isLocalActive
Indicates if this component is active.
Definition: Component.h:180
std::string getName() const
Gets component name.
Definition: Component.cpp:51
void setName(const std::string &name)
Sets the name of component.
Definition: Component.cpp:56
std::shared_ptr< Runtime > getRuntime() const
Get the runtime which contains this component.
Definition: Component.cpp:119
std::weak_ptr< Runtime > m_runtime
Runtime which contains this component.
Definition: Component.h:159
boost::uuids::uuid getUuid() const
Gets the id of the component.
Definition: Component.cpp:136
bool m_isAwake
Indicates if this component is awake.
Definition: Component.h:177
boost::uuids::uuid m_uuid
Id of this component.
Definition: Component.h:156
bool isLocalActive() const
Definition: Component.cpp:185
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:36
virtual ~Component()
Destructor.
Definition: Component.cpp:47
bool m_didWakeUp
Indicates if doWakeup() has been called.
Definition: Component.h:171
SurgSim::Framework::ObjectFactory1< SurgSim::Framework::Component, std::string > FactoryType
Definition: Component.h:113
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:147
std::shared_ptr< Scene > getScene()
Gets the scene.
Definition: Component.cpp:99
static FactoryType & getFactory()
Definition: Component.cpp:141
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:83
void setSceneElement(std::weak_ptr< SceneElement > sceneElement)
Sets the scene element.
Definition: Component.cpp:104