File: vtk3DWidgetRepresentation.cxx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (253 lines) | stat: -rw-r--r-- 7,971 bytes parent folder | download | duplicates (2)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*=========================================================================

  Program:   ParaView
  Module:    vtk3DWidgetRepresentation.cxx

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtk3DWidgetRepresentation.h"

#include "vtkAbstractWidget.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkPVImplicitPlaneRepresentation.h"
#include "vtkPVRenderView.h"
#include "vtkRenderer.h"
#include "vtkTransform.h"
#include "vtkWidgetRepresentation.h"

vtkStandardNewMacro(vtk3DWidgetRepresentation);
vtkCxxSetObjectMacro(vtk3DWidgetRepresentation, Widget, vtkAbstractWidget);
//----------------------------------------------------------------------------
vtk3DWidgetRepresentation::vtk3DWidgetRepresentation()
{
  this->SetNumberOfInputPorts(0);
  this->Widget = 0;
  this->Representation = 0;
  this->UseNonCompositedRenderer = false;
  this->Enabled = false;

  this->CustomTransform = vtkTransform::New();
  this->CustomTransform->PostMultiply();
  this->CustomTransform->Identity();
  this->RepresentationObserverTag = 0;
  this->ViewObserverTag = 0;
}

//----------------------------------------------------------------------------
vtk3DWidgetRepresentation::~vtk3DWidgetRepresentation()
{
  this->SetWidget(0);
  this->SetRepresentation(0);
  this->CustomTransform->Delete();
}

//-----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::SetRepresentation(vtkWidgetRepresentation* repr)
{
  if (this->Representation == repr)
    {
    return;
    }

  if (this->Representation)
    {
    this->Representation->RemoveObserver(this->RepresentationObserverTag);
    this->RepresentationObserverTag = 0;
    }
  vtkSetObjectBodyMacro(Representation, vtkWidgetRepresentation, repr);
  if (this->Representation)
    {
    this->RepresentationObserverTag = this->Representation->AddObserver(
      vtkCommand::ModifiedEvent,
      this, &vtk3DWidgetRepresentation::OnRepresentationModified);
    }

  this->UpdateEnabled();
  this->UpdateTransform();
}

//----------------------------------------------------------------------------
bool vtk3DWidgetRepresentation::AddToView(vtkView* view)
{
  vtkPVRenderView* pvview = vtkPVRenderView::SafeDownCast(view);
  if (pvview)
    {
    vtkRenderer* activeRenderer = this->UseNonCompositedRenderer?
      pvview->GetNonCompositedRenderer() : pvview->GetRenderer();
    if (this->Widget)
      {
      // If DefaultRenderer is non-null, SetCurrentRenderer() will have no
      // effect.
      this->Widget->SetDefaultRenderer(NULL);
      this->Widget->SetCurrentRenderer(activeRenderer);
      // Set the DefaultRenderer to ensure that it doesn't get overridden by the
      // Widget. The Widget should use the specified renderer. Period.
      this->Widget->SetDefaultRenderer(activeRenderer);
      }
    if (this->Representation)
      {
      this->Representation->SetRenderer(activeRenderer);
      activeRenderer->AddActor(this->Representation);
      }
    if (this->View)
      {
      this->View->RemoveObserver(this->ViewObserverTag);
      this->ViewObserverTag = 0;
      }
    this->View = pvview;
    // observer the view so we know when it gets a new interactor.
    this->ViewObserverTag = this->View->AddObserver(vtkCommand::ModifiedEvent,
      this, &vtk3DWidgetRepresentation::OnViewModified);
    this->UpdateEnabled();
    this->UpdateTransform();
    return true;
    }

  return false;
}

//-----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::SetEnabled(bool enable)
{
  if (this->Enabled != enable)
    {
    this->Enabled = enable;
    this->UpdateEnabled();
    }
}

//-----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::UpdateEnabled()
{
  if (this->Widget == NULL)
    {
    return;
    }

  bool enable_widget = (this->View != NULL)? this->Enabled : false;

  // BUG #14913: Don't enable widget when the representation is missing or not
  // visible.
  if (this->Representation == NULL ||
    this->Representation->GetVisibility() == 0)
    {
    enable_widget = false;
    }

  // Not all processes have the interactor setup. Enable 3D widgets only on
  // those processes that have an interactor.
  if (this->View == NULL || this->View->GetInteractor() == NULL)
    {
    enable_widget = false;
    }

  if (this->Widget->GetEnabled() != (enable_widget? 1 : 0))
    {
    // We do this here, instead of AddToView() since
    // the View may not have the interactor setup when
    // AddToView() is called (which happens when loading state files).
    this->Widget->SetInteractor(this->View->GetInteractor());
    this->Widget->SetEnabled(enable_widget? 1 : 0);
    }
}

//----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::OnRepresentationModified()
{
  // This will be called everytime the representation is modified, but since the
  // work done in this->UpdateEnabled() is minimal, we let it do it.
  this->UpdateEnabled();
}

//----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::OnViewModified()
{
  if (this->View && this->Widget &&
    this->View->GetInteractor() != this->Widget->GetInteractor())
    {
    this->UpdateEnabled();
    }
}
//----------------------------------------------------------------------------
bool vtk3DWidgetRepresentation::RemoveFromView(vtkView* view)
{
  vtkPVRenderView* pvview = vtkPVRenderView::SafeDownCast(view);
  if (pvview)
    {
    this->View = NULL;
    if (this->Widget)
      {
      this->Widget->SetEnabled(0);
      this->Widget->SetDefaultRenderer(0);
      this->Widget->SetCurrentRenderer(0);
      this->Widget->SetInteractor(0);
      }
    if (this->Representation)
      {
      vtkRenderer* renderer = this->Representation->GetRenderer();
      if (renderer)
        {
        renderer->RemoveActor(this->Representation);
        // NOTE: this will modify the Representation and call
        // this->OnRepresentationModified().
        this->Representation->SetRenderer(0);
        }
      }
    this->UpdateTransform();
    return true;
    }
  return false;
}

//----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::SetCustomWidgetTransform(vtkTransform *transform)
{
  if (this->CustomTransform->GetInput () != transform)
    {
    this->CustomTransform->SetInput(transform);
    if (!transform)
      {
      this->CustomTransform->Identity();
      }
    this->UpdateTransform();
    }
}

//----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::UpdateTransform()
{
  if (vtkPVImplicitPlaneRepresentation *plane =
    vtkPVImplicitPlaneRepresentation::SafeDownCast(this->Representation))
    {
    if (this->View)
      {
      plane->SetTransform(this->CustomTransform);
      plane->UpdateTransformLocation();
      }
    else
      {
      plane->ClearTransform();
      }
    }
}

//----------------------------------------------------------------------------
void vtk3DWidgetRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "UseNonCompositedRenderer: " << this->UseNonCompositedRenderer
    << endl;
  os << indent << "Widget: " << this->Widget << endl;
  os << indent << "Representation: " << this->Representation << endl;
  os << indent << "Enabled: " << this->Enabled << endl;
  os << indent << "CustomTransform: ";
  this->CustomTransform->Print(os);
}