KeyboardTogglesComponentBehavior.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_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
17 #define SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
18 
19 #include <unordered_map>
20 #include <unordered_set>
21 
25 
26 namespace SurgSim
27 {
28 
29 namespace Framework
30 {
31 class Component;
32 }
33 
34 namespace Input
35 {
36 class InputComponent;
37 }
38 
39 namespace Blocks
40 {
41 SURGSIM_STATIC_REGISTRATION(KeyboardTogglesComponentBehavior);
42 
45 {
46 public:
47  typedef std::unordered_map<int, std::unordered_set<std::shared_ptr<SurgSim::Framework::Component>>>
49 
52  explicit KeyboardTogglesComponentBehavior(const std::string& name);
53 
55 
58  void setInputComponent(std::shared_ptr<SurgSim::Framework::Component> inputComponent);
59 
62  std::shared_ptr<SurgSim::Input::InputComponent> getInputComponent() const;
63 
68  void registerKey(SurgSim::Devices::KeyCode key, std::shared_ptr<SurgSim::Framework::Component> component);
69 
73 
77 
80  void update(double dt) override;
81 
82 protected:
86  bool doInitialize() override;
87 
91  bool doWakeUp() override;
92 
93 private:
96 
98  std::shared_ptr<SurgSim::Input::InputComponent> m_inputComponent;
99 
102 };
103 
104 }; // namespace Blocks
105 }; // namespace SurgSim
106 
107 #endif //SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
Macros.h
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_inputComponent
std::shared_ptr< SurgSim::Input::InputComponent > m_inputComponent
Input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.h:98
SurgSim::Blocks::KeyboardTogglesComponentBehavior::KeyboardTogglesComponentBehavior
KeyboardTogglesComponentBehavior(const std::string &name)
Constructor.
Definition: KeyboardTogglesComponentBehavior.cpp:32
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:41
SurgSim::Blocks::KeyboardTogglesComponentBehavior::setInputComponent
void setInputComponent(std::shared_ptr< SurgSim::Framework::Component > inputComponent)
Set the input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.cpp:42
SurgSim::Blocks::KeyboardTogglesComponentBehavior
This behavior is used to control the activity of registered components.
Definition: KeyboardTogglesComponentBehavior.h:45
SurgSim::Blocks::KeyboardTogglesComponentBehavior::doInitialize
bool doInitialize() override
Initialize this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:81
SurgSim::Blocks::KeyboardTogglesComponentBehavior::doWakeUp
bool doWakeUp() override
Wakeup this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:86
SurgSim::Blocks::KeyboardTogglesComponentBehavior::KeyboardRegistryType
std::unordered_map< int, std::unordered_set< std::shared_ptr< SurgSim::Framework::Component > > > KeyboardRegistryType
Definition: KeyboardTogglesComponentBehavior.h:48
SurgSim::Devices::KeyCode
KeyCode
Definition: KeyCode.h:25
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Blocks::KeyboardTogglesComponentBehavior::update
void update(double dt) override
Update the behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:61
KeyCode.h
SurgSim::Blocks::KeyboardTogglesComponentBehavior::getInputComponent
std::shared_ptr< SurgSim::Input::InputComponent > getInputComponent() const
Get the input component of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:50
SurgSim::Blocks::KeyboardTogglesComponentBehavior::getKeyboardRegistry
const KeyboardRegistryType & getKeyboardRegistry() const
Get the register map of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:104
SurgSim::Blocks::KeyboardTogglesComponentBehavior::setKeyboardRegistry
void setKeyboardRegistry(const KeyboardRegistryType &map)
Set the register map of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:98
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_registry
KeyboardRegistryType m_registry
A mapping between key and the graphical representation(s) it controls.
Definition: KeyboardTogglesComponentBehavior.h:101
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
Behavior.h
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_keyPressedLastUpdate
bool m_keyPressedLastUpdate
Record if any key is pressed in last update() call.
Definition: KeyboardTogglesComponentBehavior.h:95
SurgSim::Blocks::KeyboardTogglesComponentBehavior::registerKey
void registerKey(SurgSim::Devices::KeyCode key, std::shared_ptr< SurgSim::Framework::Component > component)
Register a key with a component in this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:55
SurgSim::Blocks::KeyboardTogglesComponentBehavior::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Blocks::KeyboardTogglesComponentBehavior)