vtkSMContextViewProxy.cxx 7.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*=========================================================================

  Program:   ParaView
  Module:    vtkSMContextViewProxy.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 "vtkSMContextViewProxy.h"

17
#include "vtkAxis.h"
18
#include "vtkChartXY.h"
19
#include "vtkClientServerStream.h"
20
21
#include "vtkCommand.h"
#include "vtkContextInteractorStyle.h"
22
#include "vtkContextView.h"
23
#include "vtkErrorCode.h"
24
#include "vtkEventForwarderCommand.h"
25
#include "vtkNew.h"
26
#include "vtkObjectFactory.h"
27
28
#include "vtkPVContextView.h"
#include "vtkRenderWindow.h"
29
30
#include "vtkRenderWindowInteractor.h"
#include "vtkSMPropertyHelper.h"
31
#include "vtkSMUtilities.h"
32
#include "vtkWeakPointer.h"
33
#include "vtkWindowToImageFilter.h"
34
#include "vtkProcessModule.h"
35

36
37
38
39
40
41
42
//****************************************************************************
// vtkSMContextViewInteractorStyle makes it possible for us to call
// StillRender() as the user interacts with the chart views on the client side
// instead of directly calling Render() on the render-window. This makes no
// difference in general, except in tile-display mode, where the StillRender()
// ensures that the server-side views are updated as well.
class vtkSMContextViewInteractorStyle : public vtkContextInteractorStyle
43
44
{
public:
45
46
  static vtkSMContextViewInteractorStyle*New();
  vtkTypeMacro(vtkSMContextViewInteractorStyle, vtkContextInteractorStyle);
47

48
49
50
51
  void SetView(vtkSMContextViewProxy* view)
    { this->ViewProxy = view; }
protected:
  virtual void RenderNow()
52
    {
53
    if (this->ViewProxy)
54
      {
55
      this->ViewProxy->StillRender();
56
57
58
59
      }
    }

private:
60
61
62
  vtkSMContextViewInteractorStyle() {}
  ~vtkSMContextViewInteractorStyle() {}
  vtkWeakPointer<vtkSMContextViewProxy> ViewProxy;
63
64
};

65
66
67
68
vtkStandardNewMacro(vtkSMContextViewInteractorStyle);
//****************************************************************************


69
vtkStandardNewMacro(vtkSMContextViewProxy);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//----------------------------------------------------------------------------
vtkSMContextViewProxy::vtkSMContextViewProxy()
{
  this->ChartView = NULL;
}

//----------------------------------------------------------------------------
vtkSMContextViewProxy::~vtkSMContextViewProxy()
{
}

//----------------------------------------------------------------------------
void vtkSMContextViewProxy::CreateVTKObjects()
{
  if (this->ObjectsCreated)
    {
    return;
    }
88
  this->Superclass::CreateVTKObjects();
Sebastien Jourdain's avatar
Sebastien Jourdain committed
89
90
91
92
93
94
95

  // If prototype, no need to go thurther...
  if(this->Location == 0)
    {
    return;
    }

96
97
98
99
  if (!this->ObjectsCreated)
    {
    return;
    }
100

101
102
103
  vtkPVContextView* pvview = vtkPVContextView::SafeDownCast(
    this->GetClientSideObject());
  this->ChartView = pvview->GetContextView();
104

105
106
107
108
109
110
111
112
113
114
115
116
117
118
  // if user interacts with the chart, we need to ensure that we set the axis
  // behaviors to "FIXED" so that the user chosen axis ranges are preserved in
  // state files, etc.
  this->GetContextItem()->AddObserver(
    vtkCommand::InteractionEvent, this,
    &vtkSMContextViewProxy::OnInteractionEvent);

  // update the interactor style.
  vtkSMContextViewInteractorStyle* style =
    vtkSMContextViewInteractorStyle::New();
  style->SetScene(this->ChartView->GetScene());
  style->SetView(this);
  this->ChartView->GetInteractor()->SetInteractorStyle(style);
  style->Delete();
119
120
}

121
122
123
124
125
126
//----------------------------------------------------------------------------
vtkRenderWindow* vtkSMContextViewProxy::GetRenderWindow()
{
  return this->ChartView->GetRenderWindow();
}

127
//----------------------------------------------------------------------------
Kyle Lutz's avatar
Kyle Lutz committed
128
vtkContextView* vtkSMContextViewProxy::GetContextView()
129
130
131
132
{
  return this->ChartView;
}

133
//----------------------------------------------------------------------------
Kyle Lutz's avatar
Kyle Lutz committed
134
vtkAbstractContextItem* vtkSMContextViewProxy::GetContextItem()
135
{
136
137
  vtkPVContextView* pvview = vtkPVContextView::SafeDownCast(
    this->GetClientSideObject());
Kyle Lutz's avatar
Kyle Lutz committed
138
  return pvview? pvview->GetContextItem() : NULL;
139
140
}

141
//-----------------------------------------------------------------------------
142
vtkImageData* vtkSMContextViewProxy::CaptureWindowInternal(int magnification)
143
{
144
145
146
147
148
149
150
151
152
153
  vtkRenderWindow* window = this->GetRenderWindow();

  // Offscreen rendering is not functioning properly on the mac.
  // Do not use it.
#if !defined(__APPLE__)
  int prevOffscreen = window->GetOffScreenRendering();
  window->SetOffScreenRendering(1);
#endif

  window->SwapBuffersOff();
154

155
  this->StillRender();
Kyle Lutz's avatar
Kyle Lutz committed
156
  this->GetContextView()->Render();
157

158
159
160
  vtkSmartPointer<vtkWindowToImageFilter> w2i =
    vtkSmartPointer<vtkWindowToImageFilter>::New();
  w2i->SetInput(window);
161
162
163
  w2i->SetMagnification(magnification);
  w2i->ReadFrontBufferOff();
  w2i->ShouldRerenderOff();
164
165
166
167
168
169
170
171
172
173
174
175
176
  w2i->FixBoundaryOff();

  // BUG #8715: We go through this indirection since the active connection needs
  // to be set during update since it may request re-renders if magnification >1.
  vtkClientServerStream stream;
  stream << vtkClientServerStream::Invoke
         << w2i.GetPointer() << "Update"
         << vtkClientServerStream::End;
  this->ExecuteStream(stream, false, vtkProcessModule::CLIENT);

  window->SwapBuffersOn();
#if !defined(__APPLE__)
  window->SetOffScreenRendering(prevOffscreen);
177
#endif
178
179
180

  vtkImageData* capture = vtkImageData::New();
  capture->ShallowCopy(w2i->GetOutput());
181
  window->Frame();
182
183
184
  return capture;
}

185
static void update_property(vtkAxis* axis, vtkSMProperty* prop)
186
{
187
188
189
190
191
192
193
  if (axis && prop)
    {
    double range[2];
    axis->GetRange(range);
    vtkSMPropertyHelper(prop).SetNumberOfElements(2);
    vtkSMPropertyHelper(prop).Set(range, 2);
    }
194
}
195
196

//----------------------------------------------------------------------------
197
void vtkSMContextViewProxy::OnInteractionEvent()
198
{
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  vtkChartXY *chartXY = vtkChartXY::SafeDownCast(this->GetContextItem());
  if (chartXY)
    {
    // FIXME: Generalize to support charts with zero to many axes.
    update_property(
      chartXY->GetAxis(vtkAxis::LEFT), this->GetProperty("LeftAxisRange"));
    update_property(
      chartXY->GetAxis(vtkAxis::RIGHT), this->GetProperty("RightAxisRange"));
    update_property(
      chartXY->GetAxis(vtkAxis::TOP), this->GetProperty("TopAxisRange"));
    update_property(
      chartXY->GetAxis(vtkAxis::BOTTOM), this->GetProperty("BottomAxisRange"));
    this->UpdateVTKObjects();
    this->InvokeEvent(vtkCommand::InteractionEvent);
    }
214
215
}

216
217
//-----------------------------------------------------------------------------
void vtkSMContextViewProxy::ResetDisplay()
218
{
219
220
221
222
  vtkSMPropertyHelper(this, "LeftAxisRange", true).SetNumberOfElements(0);
  vtkSMPropertyHelper(this, "RightAxisRange", true).SetNumberOfElements(0);
  vtkSMPropertyHelper(this, "TopAxisRange", true).SetNumberOfElements(0);
  vtkSMPropertyHelper(this, "BottomAxisRange", true).SetNumberOfElements(0);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
223
224
225
226
  this->UpdateProperty("LeftAxisRange", 1);
  this->UpdateProperty("RightAxisRange", 1);
  this->UpdateProperty("TopAxisRange", 1);
  this->UpdateProperty("BottomAxisRange", 1);
227
228
  this->StillRender();
}
229

230
231
232
233
//----------------------------------------------------------------------------
void vtkSMContextViewProxy::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
234
}