forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkContinuousValueWidget.cxx
216 lines (182 loc) · 7.04 KB
/
vtkContinuousValueWidget.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*=========================================================================
Program: Visualization Toolkit
Module: vtkContinuousValueWidget.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.
=========================================================================*/
/*-------------------------------------------------------------------------
Copyright 2008 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
#include "vtkCallbackCommand.h"
#include "vtkCommand.h"
#include "vtkContinuousValueWidget.h"
#include "vtkContinuousValueWidgetRepresentation.h"
#include "vtkEvent.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkWidgetEvent.h"
#include "vtkWidgetEventTranslator.h"
//------------------------------------------------------------
vtkContinuousValueWidget::vtkContinuousValueWidget()
{
// Set the initial state
this->WidgetState = vtkContinuousValueWidget::Start;
this->Value = 0;
// Okay, define the events
this->CallbackMapper->SetCallbackMethod
(vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Select,
this, vtkContinuousValueWidget::SelectAction);
this->CallbackMapper->SetCallbackMethod
(vtkCommand::MouseMoveEvent,
vtkWidgetEvent::Move,
this, vtkContinuousValueWidget::MoveAction);
this->CallbackMapper->SetCallbackMethod
(vtkCommand::LeftButtonReleaseEvent,
vtkWidgetEvent::EndSelect,
this, vtkContinuousValueWidget::EndSelectAction);
}
//-----------------------------------------------------------------
double vtkContinuousValueWidget::GetValue()
{
vtkContinuousValueWidgetRepresentation *slider =
vtkContinuousValueWidgetRepresentation::SafeDownCast(this->WidgetRep);
return slider->GetValue();
}
//-----------------------------------------------------------------
void vtkContinuousValueWidget::SetValue(double value)
{
vtkContinuousValueWidgetRepresentation *slider =
vtkContinuousValueWidgetRepresentation::SafeDownCast(this->WidgetRep);
slider->SetValue(value);
}
//-------------------------------------------------------------
void vtkContinuousValueWidget::SelectAction(vtkAbstractWidget *w)
{
vtkContinuousValueWidget *self =
reinterpret_cast<vtkContinuousValueWidget*>(w);
double eventPos[2];
eventPos[0] = self->Interactor->GetEventPosition()[0];
eventPos[1] = self->Interactor->GetEventPosition()[1];
// Okay, make sure that the pick is in the current renderer
if (!self->CurrentRenderer ||
!self->CurrentRenderer->IsInViewport(static_cast<int>(eventPos[0]),
static_cast<int>(eventPos[1])))
{
return;
}
// See if the widget has been selected. StartWidgetInteraction records the
// starting point of the motion.
self->WidgetRep->StartWidgetInteraction(eventPos);
int interactionState = self->WidgetRep->GetInteractionState();
if (interactionState != vtkContinuousValueWidgetRepresentation::Adjusting)
{
return;
}
// We are definitely selected
self->GrabFocus(self->EventCallbackCommand);
self->EventCallbackCommand->SetAbortFlag(1);
if ( interactionState == vtkContinuousValueWidgetRepresentation::Adjusting )
{
self->WidgetState = vtkContinuousValueWidget::Adjusting;
// Highlight as necessary
self->WidgetRep->Highlight(1);
// start the interaction
self->StartInteraction();
self->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
self->Render();
return;
}
}
//---------------------------------------------------------------
void vtkContinuousValueWidget::MoveAction(vtkAbstractWidget *w)
{
vtkContinuousValueWidget *self =
reinterpret_cast<vtkContinuousValueWidget*>(w);
// do we need to change highlight state?
int interactionState = self->WidgetRep->ComputeInteractionState
(self->Interactor->GetEventPosition()[0],
self->Interactor->GetEventPosition()[1]);
// if we are outside and in the start state then return
if (interactionState == vtkContinuousValueWidgetRepresentation::Outside &&
self->WidgetState == vtkContinuousValueWidget::Start)
{
return;
}
// if we are not outside and in the highlighting state then return
if (interactionState != vtkContinuousValueWidgetRepresentation::Outside &&
self->WidgetState == vtkContinuousValueWidget::Highlighting)
{
return;
}
// if we are not outside and in the Start state highlight
if ( interactionState != vtkContinuousValueWidgetRepresentation::Outside &&
self->WidgetState == vtkContinuousValueWidget::Start)
{
self->WidgetRep->Highlight(1);
self->WidgetState = vtkContinuousValueWidget::Highlighting;
self->Render();
return;
}
// if we are outside but in the highlight state then stop highlighting
if ( self->WidgetState == vtkContinuousValueWidget::Highlighting &&
interactionState == vtkContinuousValueWidgetRepresentation::Outside)
{
self->WidgetRep->Highlight(0);
self->WidgetState = vtkContinuousValueWidget::Start;
self->Render();
return;
}
// Definitely moving the slider, get the updated position
double eventPos[2];
eventPos[0] = self->Interactor->GetEventPosition()[0];
eventPos[1] = self->Interactor->GetEventPosition()[1];
self->WidgetRep->WidgetInteraction(eventPos);
self->InvokeEvent(vtkCommand::InteractionEvent,NULL);
self->Render();
// Interact, if desired
self->EventCallbackCommand->SetAbortFlag(1);
}
//-----------------------------------------------------------------
void vtkContinuousValueWidget::EndSelectAction(vtkAbstractWidget *w)
{
vtkContinuousValueWidget *self =
reinterpret_cast<vtkContinuousValueWidget*>(w);
if ( self->WidgetState != vtkContinuousValueWidget::Adjusting )
{
return;
}
int interactionState = self->WidgetRep->ComputeInteractionState
(self->Interactor->GetEventPosition()[0],
self->Interactor->GetEventPosition()[1]);
if ( interactionState == vtkContinuousValueWidgetRepresentation::Outside)
{
self->WidgetRep->Highlight(0);
self->WidgetState = vtkContinuousValueWidget::Start;
}
else
{
self->WidgetState = vtkContinuousValueWidget::Highlighting;
}
// The state returns to unselected
self->ReleaseFocus();
// Complete interaction
self->EventCallbackCommand->SetAbortFlag(1);
self->EndInteraction();
self->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
self->Render();
}
//-----------------------------------------------------------------
void vtkContinuousValueWidget::PrintSelf(ostream& os, vtkIndent indent)
{
//Superclass typedef defined in vtkTypeMacro() found in vtkSetGet.h
this->Superclass::PrintSelf(os,indent);
}