forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkMagnifierWidget.cxx
145 lines (120 loc) · 4.75 KB
/
vtkMagnifierWidget.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMagnifierWidget.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkMagnifierWidget.h"
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
#include "vtkEvent.h"
#include "vtkMagnifierRepresentation.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkWidgetEvent.h"
#include "vtkWidgetEventTranslator.h"
vtkStandardNewMacro(vtkMagnifierWidget);
//------------------------------------------------------------------------------
vtkMagnifierWidget::vtkMagnifierWidget()
{
// Change activation value inherited from superclass
this->KeyPressActivationValue = 'm';
// Define increase and decrease keystrokes
this->KeyPressIncreaseValue = '+';
this->KeyPressDecreaseValue = '-';
this->WidgetState = vtkMagnifierWidget::Invisible;
this->CallbackMapper->SetCallbackMethod(
vtkCommand::MouseMoveEvent, vtkWidgetEvent::Move, this, vtkMagnifierWidget::MoveAction);
this->CallbackMapper->SetCallbackMethod(
vtkCommand::CharEvent, vtkWidgetEvent::Up, this, vtkMagnifierWidget::CharAction);
this->CallbackMapper->SetCallbackMethod(
vtkCommand::CharEvent, vtkWidgetEvent::Down, this, vtkMagnifierWidget::CharAction);
}
//------------------------------------------------------------------------------
vtkMagnifierWidget::~vtkMagnifierWidget() = default;
//------------------------------------------------------------------------------
void vtkMagnifierWidget::CreateDefaultRepresentation()
{
if (!this->WidgetRep)
{
this->WidgetRep = vtkMagnifierRepresentation::New();
}
}
//------------------------------------------------------------------------------
void vtkMagnifierWidget::SetEnabled(int enabling)
{
int enabled = this->Enabled;
// We do this step first because it sets the CurrentRenderer
this->Superclass::SetEnabled(enabling);
// Activate the representation
if (enabling && !enabled)
{
this->WidgetState = Visible;
static_cast<vtkMagnifierRepresentation*>(this->WidgetRep)->SetInteractionState(Visible);
}
else if (!enabling && enabled)
{
this->WidgetState = Invisible;
static_cast<vtkMagnifierRepresentation*>(this->WidgetRep)->SetInteractionState(Invisible);
}
// Bring everything up to date
double eventPos[2];
eventPos[0] = static_cast<double>(this->Interactor->GetEventPosition()[0]);
eventPos[1] = static_cast<double>(this->Interactor->GetEventPosition()[1]);
static_cast<vtkMagnifierRepresentation*>(this->WidgetRep)->WidgetInteraction(eventPos);
this->Render();
}
//------------------------------------------------------------------------------
void vtkMagnifierWidget::MoveAction(vtkAbstractWidget* w)
{
vtkMagnifierWidget* self = reinterpret_cast<vtkMagnifierWidget*>(w);
// Return if not active
if (self->WidgetState == vtkMagnifierWidget::Invisible)
{
return;
}
// Note current mouse location
int X = self->Interactor->GetEventPosition()[0];
int Y = self->Interactor->GetEventPosition()[1];
// Forward the event to the representation
double eventPos[2];
eventPos[0] = static_cast<double>(X);
eventPos[1] = static_cast<double>(Y);
self->WidgetRep->WidgetInteraction(eventPos);
self->Render();
}
//------------------------------------------------------------------------------
void vtkMagnifierWidget::CharAction(vtkAbstractWidget* w)
{
vtkMagnifierWidget* self = reinterpret_cast<vtkMagnifierWidget*>(w);
// Return if not active
if (self->WidgetState == vtkMagnifierWidget::Invisible)
{
return;
}
if (self->Interactor->GetKeyCode() == self->KeyPressIncreaseValue ||
self->Interactor->GetKeyCode() == self->KeyPressDecreaseValue)
{
int X = self->Interactor->GetEventPosition()[0];
int Y = self->Interactor->GetEventPosition()[1];
// Forward the event to the representation
self->InvokeEvent(vtkCommand::WidgetValueChangedEvent, nullptr);
double eventPos[2];
eventPos[0] = static_cast<double>(X);
eventPos[1] = static_cast<double>(Y);
self->WidgetRep->WidgetInteraction(eventPos);
self->Render();
}
}
//------------------------------------------------------------------------------
void vtkMagnifierWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}