All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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::Device::KeyCode key, std::shared_ptr<SurgSim::Framework::Component> component);
69 
73 
77 
80  virtual void update(double dt) override;
81 
82 protected:
86  virtual bool doInitialize() override;
87 
91  virtual 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
std::shared_ptr< SurgSim::Input::InputComponent > m_inputComponent
Input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.h:98
void setKeyboardRegistry(const KeyboardRegistryType &map)
Set the register map of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:97
std::shared_ptr< SurgSim::Input::InputComponent > getInputComponent() const
Get the input component of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:49
void registerKey(SurgSim::Device::KeyCode key, std::shared_ptr< SurgSim::Framework::Component > component)
Register a key with a component in this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:54
std::unordered_map< int, std::unordered_set< std::shared_ptr< SurgSim::Framework::Component > > > KeyboardRegistryType
Definition: KeyboardTogglesComponentBehavior.h:48
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:43
KeyboardRegistryType m_registry
A mapping between key and the graphical representation(s) it controls.
Definition: KeyboardTogglesComponentBehavior.h:101
virtual void update(double dt) override
Update the behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:60
KeyCode
Definition: KeyCode.h:24
KeyboardTogglesComponentBehavior(const std::string &name)
Constructor.
Definition: KeyboardTogglesComponentBehavior.cpp:30
bool m_keyPressedLastUpdate
Record if any key is pressed in last update() call.
Definition: KeyboardTogglesComponentBehavior.h:95
This behavior is used to control the visibility of registered graphical representation(s) ...
Definition: KeyboardTogglesComponentBehavior.h:44
SURGSIM_CLASSNAME(SurgSim::Blocks::KeyboardTogglesComponentBehavior)
Behaviors perform actions.
Definition: Behavior.h:40
virtual bool doInitialize() override
Initialize this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:80
const KeyboardRegistryType & getKeyboardRegistry() const
Get the register map of this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:103
SURGSIM_STATIC_REGISTRATION(DriveElementFromInputBehavior)
void setInputComponent(std::shared_ptr< SurgSim::Framework::Component > inputComponent)
Set the input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.cpp:40
virtual bool doWakeUp() override
Wakeup this behavior.
Definition: KeyboardTogglesComponentBehavior.cpp:85