iMSTK
Interactive Medical Simulation Toolkit
imstkVTKInteractorStyle.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkVTKInteractorStyle.h"
8 #include "imstkKeyboardDeviceClient.h"
9 #include "imstkMouseDeviceClient.h"
10 
11 #include <vtkObjectFactory.h>
12 #include <vtkRenderWindowInteractor.h>
13 #include <vtkRenderWindow.h>
14 
15 namespace imstk
16 {
17 vtkStandardNewMacro(VTKInteractorStyle);
18 
19 VTKInteractorStyle::VTKInteractorStyle() :
20  m_keyboardDeviceClient(KeyboardDeviceClient::New()),
21  m_mouseDeviceClient(MouseDeviceClient::New())
22 {
23 }
24 
25 VTKInteractorStyle::~VTKInteractorStyle()
26 {
27  this->SetReferenceCount(0);
28 }
29 
30 void
32 {
33  // Submit the change to the keyboard device client
34  m_keyboardDeviceClient->emitKeyDown(this->Interactor->GetKeyCode());
35 }
36 
37 void
39 {
40  // Submit the change to the keyboard device client
41  m_keyboardDeviceClient->emitKeyUp(this->Interactor->GetKeyCode());
42 }
43 
44 void
46 {
47  Vec2i mousePos;
48  this->Interactor->GetEventPosition(mousePos[0], mousePos[1]);
49  Vec2i dim;
50  Interactor->GetSize(dim[0], dim[1]);
51  m_mouseDeviceClient->updateMousePos(mousePos.cast<double>().cwiseQuotient(dim.cast<double>()));
52 }
53 
54 void
56 {
57  m_mouseDeviceClient->emitButtonPress(LEFT_BUTTON);
58 }
59 
60 void
62 {
63  m_mouseDeviceClient->emitButtonRelease(LEFT_BUTTON);
64 }
65 
66 void
68 {
69  m_mouseDeviceClient->emitButtonPress(MIDDLE_BUTTON);
70 }
71 
72 void
74 {
75  m_mouseDeviceClient->emitButtonRelease(MIDDLE_BUTTON);
76 }
77 
78 void
80 {
81  m_mouseDeviceClient->emitButtonPress(RIGHT_BUTTON);
82 }
83 
84 void
86 {
87  m_mouseDeviceClient->emitButtonRelease(RIGHT_BUTTON);
88 }
89 
90 void
92 {
93  // \todo: VTK provides no scroll amount?
94  m_mouseDeviceClient->emitScroll(-0.2);
95 }
96 
97 void
99 {
100  // \todo: VTK provides no scroll amount?
101  m_mouseDeviceClient->emitScroll(0.2);
102 }
103 } // namespace imstk
void OnMouseWheelBackward() override
Slot for mouse wheel rolled backward.
void OnRightButtonDown() override
Slot for mouse right button clicked.
Compound Geometry.
void OnKeyRelease() override
Slot for key released.
void OnMiddleButtonUp() override
Slot for mouse middle button released.
void OnMiddleButtonDown() override
Slot for mouse middle button clicked.
void OnLeftButtonDown() override
Slot for mouse left button clicked.
void OnLeftButtonUp() override
Slot for mouse left button released.
void OnMouseMove() override
Slot for moved mouse cursor.
void OnRightButtonUp() override
Slot for mouse right button released.
void OnMouseWheelForward() override
Slot for mouse wheel rolled forward.
void OnKeyPress() override
Slot for key pressed.