forked from Kitware/VTK
/
vtkScalarBarWidget.cxx
133 lines (112 loc) · 4.07 KB
/
vtkScalarBarWidget.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkScalarBarWidget.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 "vtkScalarBarWidget.h"
#include "vtkCallbackCommand.h"
#include "vtkCoordinate.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkScalarBarActor.h"
#include "vtkScalarBarRepresentation.h"
#include "vtkWidgetCallbackMapper.h"
#include "vtkWidgetEvent.h"
vtkStandardNewMacro(vtkScalarBarWidget);
//-------------------------------------------------------------------------
vtkScalarBarWidget::vtkScalarBarWidget()
{
this->Selectable = 0;
this->Repositionable = 1;
// Override the subclasses callback to handle the Repositionable flag.
this->CallbackMapper->SetCallbackMethod(vtkCommand::MouseMoveEvent,
vtkWidgetEvent::Move,
this, vtkScalarBarWidget::MoveAction);
}
//-------------------------------------------------------------------------
vtkScalarBarWidget::~vtkScalarBarWidget()
{
}
//-----------------------------------------------------------------------------
void vtkScalarBarWidget::SetRepresentation(vtkScalarBarRepresentation *rep)
{
this->SetWidgetRepresentation(rep);
}
//-----------------------------------------------------------------------------
void vtkScalarBarWidget::SetScalarBarActor(vtkScalarBarActor *actor)
{
vtkScalarBarRepresentation *rep = this->GetScalarBarRepresentation();
if (!rep)
{
this->CreateDefaultRepresentation();
rep = this->GetScalarBarRepresentation();
}
if (rep->GetScalarBarActor() != actor)
{
rep->SetScalarBarActor(actor);
this->Modified();
}
}
//-----------------------------------------------------------------------------
vtkScalarBarActor *vtkScalarBarWidget::GetScalarBarActor()
{
vtkScalarBarRepresentation *rep = this->GetScalarBarRepresentation();
if (!rep)
{
this->CreateDefaultRepresentation();
rep = this->GetScalarBarRepresentation();
}
return rep->GetScalarBarActor();
}
//-----------------------------------------------------------------------------
void vtkScalarBarWidget::CreateDefaultRepresentation()
{
if (!this->WidgetRep)
{
vtkScalarBarRepresentation *rep = vtkScalarBarRepresentation::New();
this->SetRepresentation(rep);
rep->Delete();
}
}
//-------------------------------------------------------------------------
void vtkScalarBarWidget::SetCursor(int cState)
{
if ( !this->Repositionable && !this->Selectable
&& cState == vtkBorderRepresentation::Inside)
{
// Don't have a special cursor for the inside if we cannot reposition.
this->RequestCursorShape(VTK_CURSOR_DEFAULT);
}
else
{
this->Superclass::SetCursor(cState);
}
}
//-------------------------------------------------------------------------
void vtkScalarBarWidget::MoveAction(vtkAbstractWidget *w)
{
// The the superclass handle most stuff.
vtkScalarBarWidget::Superclass::MoveAction(w);
vtkScalarBarWidget *self = reinterpret_cast<vtkScalarBarWidget*>(w);
vtkScalarBarRepresentation *representation = self->GetScalarBarRepresentation();
// Handle the case where we suppress widget translation.
if ( !self->Repositionable
&& ( representation->GetInteractionState()
== vtkBorderRepresentation::Inside ) )
{
representation->MovingOff();
}
}
//-------------------------------------------------------------------------
void vtkScalarBarWidget::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Repositionable: " << this->Repositionable << endl;
}