forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkCaptionWidget.cxx
184 lines (161 loc) · 5.95 KB
/
vtkCaptionWidget.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCaptionWidget.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 "vtkCaptionWidget.h"
#include "vtkCaptionRepresentation.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkHandleWidget.h"
#include "vtkPointHandleRepresentation3D.h"
#include "vtkCallbackCommand.h"
#include "vtkRenderWindow.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkWidgetEvent.h"
vtkStandardNewMacro(vtkCaptionWidget);
// The point widget invokes events that we watch for. Basically
// the attachment/anchor point is moved with the point widget.
class vtkCaptionAnchorCallback : public vtkCommand
{
public:
static vtkCaptionAnchorCallback *New()
{ return new vtkCaptionAnchorCallback; }
void Execute(vtkObject*, unsigned long eventId, void*) VTK_OVERRIDE
{
switch (eventId)
{
case vtkCommand::StartInteractionEvent:
this->CaptionWidget->StartAnchorInteraction();
break;
case vtkCommand::InteractionEvent:
this->CaptionWidget->AnchorInteraction();
break;
case vtkCommand::EndInteractionEvent:
this->CaptionWidget->EndAnchorInteraction();
break;
}
}
vtkCaptionAnchorCallback():CaptionWidget(0) {}
vtkCaptionWidget *CaptionWidget;
};
//-------------------------------------------------------------------------
vtkCaptionWidget::vtkCaptionWidget()
{
// The priority of the point widget is set a little higher than me.
// This is so Enable/Disable events are caught by the anchor and then
// dispatched to the BorderWidget.
this->HandleWidget = vtkHandleWidget::New();
this->HandleWidget->SetPriority(this->Priority+0.01);
this->HandleWidget->KeyPressActivationOff();
// over ride the call back mapper on the border widget superclass to move
// the caption widget using the left mouse button (still moves on middle
// mouse button press). Release is already mapped to end select action
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent,
vtkWidgetEvent::Select,
this, vtkBorderWidget::TranslateAction);
this->AnchorCallback = vtkCaptionAnchorCallback::New();
this->AnchorCallback->CaptionWidget = this;
this->HandleWidget->AddObserver(vtkCommand::StartInteractionEvent, this->AnchorCallback, 1.0);
this->HandleWidget->AddObserver(vtkCommand::InteractionEvent, this->AnchorCallback, 1.0);
this->HandleWidget->AddObserver(vtkCommand::EndInteractionEvent, this->AnchorCallback, 1.0);
}
//-------------------------------------------------------------------------
vtkCaptionWidget::~vtkCaptionWidget()
{
this->HandleWidget->Delete();
this->AnchorCallback->Delete();
}
//----------------------------------------------------------------------
void vtkCaptionWidget::SetEnabled(int enabling)
{
if ( this->Interactor )
{
this->Interactor->Disable(); //avoid extra renders
}
if ( enabling )
{
this->CreateDefaultRepresentation();
this->HandleWidget->SetRepresentation(reinterpret_cast<vtkCaptionRepresentation*>
(this->WidgetRep)->GetAnchorRepresentation());
this->HandleWidget->SetInteractor(this->Interactor);
this->HandleWidget->SetEnabled(1);
}
else
{
this->HandleWidget->SetEnabled(0);
}
if ( this->Interactor )
{
this->Interactor->Enable();
}
this->Superclass::SetEnabled(enabling);
}
//----------------------------------------------------------------------
void vtkCaptionWidget::CreateDefaultRepresentation()
{
if ( ! this->WidgetRep )
{
this->WidgetRep = vtkCaptionRepresentation::New();
}
}
//-------------------------------------------------------------------------
void vtkCaptionWidget::SetCaptionActor2D(vtkCaptionActor2D *capActor)
{
vtkCaptionRepresentation *capRep = reinterpret_cast<vtkCaptionRepresentation*>(this->WidgetRep);
if ( ! capRep )
{
this->CreateDefaultRepresentation();
capRep = reinterpret_cast<vtkCaptionRepresentation*>(this->WidgetRep);
}
if ( capRep->GetCaptionActor2D() != capActor )
{
capRep->SetCaptionActor2D(capActor);
this->Modified();
}
}
//-------------------------------------------------------------------------
vtkCaptionActor2D *vtkCaptionWidget::GetCaptionActor2D()
{
vtkCaptionRepresentation *capRep = reinterpret_cast<vtkCaptionRepresentation*>(this->WidgetRep);
if ( ! capRep )
{
return NULL;
}
else
{
return capRep->GetCaptionActor2D();
}
}
//----------------------------------------------------------------------
void vtkCaptionWidget::StartAnchorInteraction()
{
this->Superclass::StartInteraction();
this->InvokeEvent(vtkCommand::StartInteractionEvent,NULL);
}
//----------------------------------------------------------------------
void vtkCaptionWidget::AnchorInteraction()
{
vtkCaptionRepresentation *rep= reinterpret_cast<vtkCaptionRepresentation*>(this->WidgetRep);
double pos[3];
rep->GetAnchorRepresentation()->GetWorldPosition(pos);
rep->SetAnchorPosition(pos);
this->InvokeEvent(vtkCommand::InteractionEvent,NULL);
}
//----------------------------------------------------------------------
void vtkCaptionWidget::EndAnchorInteraction()
{
this->Superclass::EndInteraction();
this->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
}
//-------------------------------------------------------------------------
void vtkCaptionWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}