Salome HOME
refs #416: to store the open state of object browser items in the binary array
[modules/gui.git] / src / SVTK / vtkPVAxesWidget.cxx
1 /*=========================================================================
2
3    Program: ParaView
4    Module:    $RCSfile$
5
6    Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7    All rights reserved.
8
9    ParaView is a free software; you can redistribute it and/or modify it
10    under the terms of the ParaView license version 1.2. 
11
12    See License_v1.2.txt for the full ParaView license.
13    A copy of this license can be obtained by contacting
14    Kitware Inc.
15    28 Corporate Drive
16    Clifton Park, NY 12065
17    USA
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 =========================================================================*/
32 #include "vtkPVAxesWidget.h"
33
34 #include "vtkActor2D.h"
35 #include "vtkCallbackCommand.h"
36 #include "vtkCamera.h"
37 #include "vtkCoordinate.h"
38 #include "vtkObjectFactory.h"
39 #include "vtkPoints.h"
40 #include "vtkPolyData.h"
41 #include "vtkPolyDataMapper2D.h"
42 #include "vtkProperty.h"
43 #include "vtkProperty2D.h"
44 #include "vtkPVAxesActor.h"
45 #include "vtkRenderer.h"
46 #include "vtkRenderWindow.h"
47 #include "vtkRenderWindowInteractor.h"
48
49 vtkStandardNewMacro(vtkPVAxesWidget);
50
51 vtkCxxSetObjectMacro(vtkPVAxesWidget, AxesActor, vtkPVAxesActor);
52 vtkCxxSetObjectMacro(vtkPVAxesWidget, ParentRenderer, vtkRenderer);
53
54 //----------------------------------------------------------------------------
55 class vtkPVAxesWidgetObserver : public vtkCommand
56 {
57 public:
58   static vtkPVAxesWidgetObserver *New()
59     {return new vtkPVAxesWidgetObserver;};
60   
61   vtkPVAxesWidgetObserver()
62     {
63       this->AxesWidget = 0;
64     }
65   
66   virtual void Execute(vtkObject* wdg, unsigned long event, void *calldata)
67     {
68       if (this->AxesWidget)
69         {
70         this->AxesWidget->ExecuteEvent(wdg, event, calldata);
71         }
72     }
73   
74   vtkPVAxesWidget *AxesWidget;
75 };
76
77 //----------------------------------------------------------------------------
78 vtkPVAxesWidget::vtkPVAxesWidget()
79 {
80   this->StartEventObserverId = 0;
81
82   this->EventCallbackCommand->SetCallback(vtkPVAxesWidget::ProcessEvents);
83   
84   this->Observer = vtkPVAxesWidgetObserver::New();
85   this->Observer->AxesWidget = this;
86   this->Renderer = vtkRenderer::New();
87   this->Renderer->SetViewport(0.0, 0.0, 0.2, 0.2);
88   this->Renderer->SetLayer(1);
89   this->Renderer->InteractiveOff();
90   this->Priority = 0.55;
91   this->AxesActor = vtkPVAxesActor::New();
92   this->Renderer->AddActor(this->AxesActor);
93   this->AxesActor->AddToRender(this->Renderer); // tmp
94   
95   this->ParentRenderer = NULL;
96   
97   this->Moving = 0;
98   this->MouseCursorState = vtkPVAxesWidget::Outside;
99
100   this->StartTag = 0;
101   
102   this->Interactive = 1;
103   
104   this->Outline = vtkPolyData::New();
105   this->Outline->Allocate();
106   vtkPoints *points = vtkPoints::New();
107   vtkIdType ptIds[5];
108   ptIds[4] = ptIds[0] = points->InsertNextPoint(1, 1, 0);
109   ptIds[1] = points->InsertNextPoint(2, 1, 0);
110   ptIds[2] = points->InsertNextPoint(2, 2, 0);
111   ptIds[3] = points->InsertNextPoint(1, 2, 0);
112   this->Outline->SetPoints(points);
113   this->Outline->InsertNextCell(VTK_POLY_LINE, 5, ptIds);
114   vtkCoordinate *tcoord = vtkCoordinate::New();
115   tcoord->SetCoordinateSystemToDisplay();
116   vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();
117   mapper->SetInputData(this->Outline);
118   mapper->SetTransformCoordinate(tcoord);
119   this->OutlineActor = vtkActor2D::New();
120   this->OutlineActor->SetMapper(mapper);
121   this->OutlineActor->SetPosition(0, 0);
122   this->OutlineActor->SetPosition2(1, 1);
123   
124   points->Delete();
125   mapper->Delete();
126   tcoord->Delete();
127 }
128
129 //----------------------------------------------------------------------------
130 vtkPVAxesWidget::~vtkPVAxesWidget()
131 {
132   this->Observer->Delete();
133   this->AxesActor->Delete();
134   this->OutlineActor->Delete();
135   this->Outline->Delete();
136   this->SetParentRenderer(NULL);
137   this->Renderer->Delete();
138 }
139
140 //----------------------------------------------------------------------------
141 void vtkPVAxesWidget::SetEnabled(int enabling)
142 {
143   if (!this->Interactor)
144     {
145     vtkErrorMacro("The interactor must be set prior to enabling/disabling widget");
146     }
147   
148   if (enabling)
149     {
150     if (this->Enabled)
151       {
152       return;
153       }
154     if (!this->ParentRenderer)
155       {
156       vtkErrorMacro("The parent renderer must be set prior to enabling this widget");
157       return;
158       }
159
160     this->Enabled = 1;
161     
162     if ( this->EventCallbackCommand )
163       {
164       vtkRenderWindowInteractor *i = this->Interactor;
165       i->AddObserver(vtkCommand::MouseMoveEvent,
166         this->EventCallbackCommand, this->Priority);
167       i->AddObserver(vtkCommand::LeftButtonPressEvent,
168         this->EventCallbackCommand, this->Priority);
169       i->AddObserver(vtkCommand::LeftButtonReleaseEvent,
170         this->EventCallbackCommand, this->Priority);
171       }
172     
173     this->ParentRenderer->GetRenderWindow()->AddRenderer(this->Renderer);
174     if (this->ParentRenderer->GetRenderWindow()->GetNumberOfLayers() < 2)
175       {
176       this->ParentRenderer->GetRenderWindow()->SetNumberOfLayers(2);
177       }
178     this->AxesActor->SetVisibility(1);
179     // We need to copy the camera before the compositing observer is called.
180     // Compositing temporarily changes the camera to display an image.
181     this->StartEventObserverId = 
182       this->ParentRenderer->AddObserver(vtkCommand::StartEvent,this->Observer,1);
183     this->InvokeEvent(vtkCommand::EnableEvent, NULL);
184     }
185   else
186     {
187     if (!this->Enabled)
188       {
189       return;
190       }
191     
192     this->Enabled = 0;
193     this->Interactor->RemoveObserver(this->EventCallbackCommand);
194     
195     this->AxesActor->SetVisibility(0);
196     if (this->ParentRenderer)
197       {
198       if (this->ParentRenderer->GetRenderWindow())
199         {
200         this->ParentRenderer->GetRenderWindow()->RemoveRenderer(this->Renderer);
201         this->AxesActor->ReleaseGraphicsResources(this->ParentRenderer->GetRenderWindow());
202         }
203       if (this->StartEventObserverId != 0)
204         {
205         this->ParentRenderer->RemoveObserver(this->StartEventObserverId);
206         }
207       }
208     
209     this->InvokeEvent(vtkCommand::DisableEvent, NULL);
210     }
211 }
212
213 //----------------------------------------------------------------------------
214 void vtkPVAxesWidget::ExecuteEvent(vtkObject *vtkNotUsed(o),
215                                    unsigned long vtkNotUsed(event),
216                                    void *vtkNotUsed(calldata))
217 {
218   if (!this->ParentRenderer)
219     {
220     return;
221     }
222   
223   vtkCamera *cam = this->ParentRenderer->GetActiveCamera();
224   double pos[3], fp[3], viewup[3];
225   cam->GetPosition(pos);
226   cam->GetFocalPoint(fp);
227   cam->GetViewUp(viewup);
228   
229   cam = this->Renderer->GetActiveCamera();
230   cam->SetPosition(pos);
231   cam->SetFocalPoint(fp);
232   cam->SetViewUp(viewup);
233   this->Renderer->ResetCamera();
234   
235   this->SquareRenderer();
236 }
237
238 void vtkPVAxesWidget::UpdateCursorIcon()
239 {
240   if (!this->Enabled)
241     {
242     this->SetMouseCursor(vtkPVAxesWidget::Outside);
243     return;
244     }
245   
246   if (this->Moving)
247     {
248     return;
249     }
250   
251   int *parentSize = this->ParentRenderer->GetSize();
252   
253   int x = this->Interactor->GetEventPosition()[0];
254   int y = this->Interactor->GetEventPosition()[1];
255   double xNorm = x / (double)parentSize[0];
256   double yNorm = y / (double)parentSize[1];
257   
258   double pos[4];
259   this->Renderer->GetViewport(pos);
260   
261   int pState = this->MouseCursorState;
262   
263   if (xNorm > pos[0] && xNorm < pos[2] && yNorm > pos[1] && yNorm < pos[3])
264     {
265     this->MouseCursorState = vtkPVAxesWidget::Inside;
266     }
267   else if (fabs(xNorm-pos[0]) < .02 && fabs(yNorm-pos[3]) < .02)
268     {
269     this->MouseCursorState = vtkPVAxesWidget::TopLeft;
270     }
271   else if (fabs(xNorm-pos[2]) < .02 && fabs(yNorm-pos[3]) < .02)
272     {
273     this->MouseCursorState = vtkPVAxesWidget::TopRight;
274     }
275   else if (fabs(xNorm-pos[0]) < .02 && fabs(yNorm-pos[1]) < .02)
276     {
277     this->MouseCursorState = vtkPVAxesWidget::BottomLeft;
278     }
279   else if (fabs(xNorm-pos[2]) < .02 && fabs(yNorm-pos[1]) < .02)
280     {
281     this->MouseCursorState = vtkPVAxesWidget::BottomRight;
282     }
283   else
284     {
285     this->MouseCursorState = vtkPVAxesWidget::Outside;
286     }
287
288   if (pState == this->MouseCursorState)
289     {
290     return;
291     }
292   
293   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
294     {
295     this->Renderer->RemoveActor(this->OutlineActor);
296     }
297   else
298     {
299     this->Renderer->AddActor(this->OutlineActor);
300     }
301   this->Interactor->Render();
302   
303   this->SetMouseCursor(this->MouseCursorState);
304 }
305
306 //----------------------------------------------------------------------------
307 void vtkPVAxesWidget::SetMouseCursor(int cursorState)
308 {
309   switch (cursorState)
310     {
311     case vtkPVAxesWidget::Outside:
312       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_DEFAULT);
313       break;
314     case vtkPVAxesWidget::Inside:
315       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZEALL);
316       break;
317     case vtkPVAxesWidget::TopLeft:
318       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENW);
319       break;
320     case vtkPVAxesWidget::TopRight:
321       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZENE);
322       break;
323     case vtkPVAxesWidget::BottomLeft:
324       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESW);
325       break;
326     case vtkPVAxesWidget::BottomRight:
327       this->Interactor->GetRenderWindow()->SetCurrentCursor(VTK_CURSOR_SIZESE);
328       break;
329     }
330 }
331
332 //----------------------------------------------------------------------------
333 void vtkPVAxesWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
334                                     unsigned long event,
335                                     void *clientdata,
336                                     void* vtkNotUsed(calldata))
337 {
338   vtkPVAxesWidget *self =
339     reinterpret_cast<vtkPVAxesWidget*>(clientdata);
340
341   if (!self->GetInteractive())
342     {
343     return;
344     }
345   
346   switch (event)
347     {
348     case vtkCommand::LeftButtonPressEvent:
349       self->OnButtonPress();
350       break;
351     case vtkCommand::MouseMoveEvent:
352       self->OnMouseMove();
353       break;
354     case vtkCommand::LeftButtonReleaseEvent:
355       self->OnButtonRelease();
356       break;
357     }
358 }
359
360 //----------------------------------------------------------------------------
361 void vtkPVAxesWidget::OnButtonPress()
362 {
363   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
364     {
365     return;
366     }
367   
368   this->SetMouseCursor(this->MouseCursorState);
369
370   this->StartPosition[0] = this->Interactor->GetEventPosition()[0];
371   this->StartPosition[1] = this->Interactor->GetEventPosition()[1];
372   
373   this->Moving = 1;
374   this->EventCallbackCommand->SetAbortFlag(1);
375   this->StartInteraction();
376   this->InvokeEvent(vtkCommand::StartInteractionEvent, NULL);
377 }
378
379 //----------------------------------------------------------------------------
380 void vtkPVAxesWidget::OnButtonRelease()
381 {
382   if (this->MouseCursorState == vtkPVAxesWidget::Outside)
383     {
384     return;
385     }
386   
387   this->Moving = 0;
388   this->EndInteraction();
389   this->InvokeEvent(vtkCommand::EndInteractionEvent, NULL);
390 }
391
392 //----------------------------------------------------------------------------
393 void vtkPVAxesWidget::OnMouseMove()
394 {
395   if (this->Moving)
396     {
397     switch (this->MouseCursorState)
398       {
399       case vtkPVAxesWidget::Inside:
400         this->MoveWidget();
401         break;
402       case vtkPVAxesWidget::TopLeft:
403         this->ResizeTopLeft();
404         break;
405       case vtkPVAxesWidget::TopRight:
406         this->ResizeTopRight();
407         break;
408       case vtkPVAxesWidget::BottomLeft:
409         this->ResizeBottomLeft();
410         break;
411       case vtkPVAxesWidget::BottomRight:
412         this->ResizeBottomRight();
413         break;
414       }
415     
416     this->UpdateCursorIcon();
417     this->EventCallbackCommand->SetAbortFlag(1);
418     this->InvokeEvent(vtkCommand::InteractionEvent, NULL);
419     }
420   else
421     {
422     this->UpdateCursorIcon();
423     }
424 }
425
426 //----------------------------------------------------------------------------
427 void vtkPVAxesWidget::MoveWidget()
428 {
429   int x = this->Interactor->GetEventPosition()[0];
430   int y = this->Interactor->GetEventPosition()[1];
431   
432   int dx = x - this->StartPosition[0];
433   int dy = y - this->StartPosition[1];
434
435   this->StartPosition[0] = x;
436   this->StartPosition[1] = y;
437
438   int *size = this->ParentRenderer->GetSize();
439   double dxNorm = dx / (double)size[0];
440   double dyNorm = dy / (double)size[1];
441   
442   double *vp = this->Renderer->GetViewport();
443   
444   double newPos[4];
445   newPos[0] = vp[0] + dxNorm;
446   newPos[1] = vp[1] + dyNorm;
447   newPos[2] = vp[2] + dxNorm;
448   newPos[3] = vp[3] + dyNorm;
449
450   if (newPos[0] < 0)
451     {
452     this->StartPosition[0] = 0;
453     newPos[0] = 0;
454     newPos[2] = vp[2] - vp[0];
455     }
456   if (newPos[1] < 0)
457     {
458     this->StartPosition[1] = 0;
459     newPos[1] = 0;
460     newPos[3] = vp[3] - vp[1];
461     }
462   if (newPos[2] > 1)
463     {
464     this->StartPosition[0] = (int)(size[0] - size[0] * (vp[2]-vp[0]));
465     newPos[0] = 1 - (vp[2]-vp[0]);
466     newPos[2] = 1;
467     }
468   if (newPos[3] > 1)
469     {
470     this->StartPosition[1] = (int)(size[1] - size[1]*(vp[3]-vp[1]));
471     newPos[1] = 1 - (vp[3]-vp[1]);
472     newPos[3] = 1;
473     }
474
475   this->Renderer->SetViewport(newPos);
476   this->Interactor->Render();
477 }
478
479 //----------------------------------------------------------------------------
480 void vtkPVAxesWidget::ResizeTopLeft()
481 {
482   int x = this->Interactor->GetEventPosition()[0];
483   int y = this->Interactor->GetEventPosition()[1];
484   
485   int dx = x - this->StartPosition[0];
486   int dy = y - this->StartPosition[1];
487   
488   int *size = this->ParentRenderer->GetSize();
489   double dxNorm = dx / (double)size[0];
490   double dyNorm = dy / (double)size[1];
491   
492   int useX;
493   double change;
494   double absDx = fabs(dxNorm);
495   double absDy = fabs(dyNorm);
496   
497   if (absDx > absDy)
498     {
499     change = dxNorm;
500     useX = 1;
501     }
502   else
503     {
504     change = dyNorm;
505     useX = 0;
506     }
507   
508   double *vp = this->Renderer->GetViewport();
509   
510   this->StartPosition[0] = x;
511   this->StartPosition[1] = y;
512   
513   double newPos[4];
514   newPos[0] = useX ? vp[0] + change : vp[0] - change;
515   newPos[1] = vp[1];
516   newPos[2] = vp[2];
517   newPos[3] = useX ? vp[3] - change : vp[3] + change;
518   
519   if (newPos[0] < 0)
520     {
521     this->StartPosition[0] = 0;
522     newPos[0] = 0;
523     }
524   if (newPos[0] >= newPos[2]-0.01)
525     {
526     newPos[0] = newPos[2] - 0.01;
527     }
528   if (newPos[3] > 1)
529     {
530     this->StartPosition[1] = size[1];
531     newPos[3] = 1;
532     }
533   if (newPos[3] <= newPos[1]+0.01)
534     {
535     newPos[3] = newPos[1] + 0.01;
536     }
537   
538   this->Renderer->SetViewport(newPos);
539   this->Interactor->Render();
540 }
541
542 //----------------------------------------------------------------------------
543 void vtkPVAxesWidget::ResizeTopRight()
544 {
545   int x = this->Interactor->GetEventPosition()[0];
546   int y = this->Interactor->GetEventPosition()[1];
547   
548   int dx = x - this->StartPosition[0];
549   int dy = y - this->StartPosition[1];
550   
551   int *size = this->ParentRenderer->GetSize();
552   double dxNorm = dx / (double)size[0];
553   double dyNorm = dy / (double)size[1];
554
555   double change;
556   double absDx = fabs(dxNorm);
557   double absDy = fabs(dyNorm);
558   
559   if (absDx > absDy)
560     {
561     change = dxNorm;
562     }
563   else
564     {
565     change = dyNorm;
566     }
567   
568   double *vp = this->Renderer->GetViewport();
569   
570   this->StartPosition[0] = x;
571   this->StartPosition[1] = y;
572   
573   double newPos[4];
574   newPos[0] = vp[0];
575   newPos[1] = vp[1];
576   newPos[2] = vp[2] + change;
577   newPos[3] = vp[3] + change;
578   
579   if (newPos[2] > 1)
580     {
581     this->StartPosition[0] = size[0];
582     newPos[2] = 1;
583     }
584   if (newPos[2] <= newPos[0]+0.01)
585     {
586     newPos[2] = newPos[0] + 0.01;
587     }
588   if (newPos[3] > 1)
589     {
590     this->StartPosition[1] = size[1];
591     newPos[3] = 1;
592     }
593   if (newPos[3] <= newPos[1]+0.01)
594     {
595     newPos[3] = newPos[1] + 0.01;
596     }
597   
598   this->Renderer->SetViewport(newPos);
599   this->Interactor->Render();
600 }
601
602 //----------------------------------------------------------------------------
603 void vtkPVAxesWidget::ResizeBottomLeft()
604 {
605   int x = this->Interactor->GetEventPosition()[0];
606   int y = this->Interactor->GetEventPosition()[1];
607   
608   int dx = x - this->StartPosition[0];
609   int dy = y - this->StartPosition[1];
610   
611   int *size = this->ParentRenderer->GetSize();
612   double dxNorm = dx / (double)size[0];
613   double dyNorm = dy / (double)size[1];
614   double *vp = this->Renderer->GetViewport();
615   
616   double change;
617   double absDx = fabs(dxNorm);
618   double absDy = fabs(dyNorm);
619   
620   if (absDx > absDy)
621     {
622     change = dxNorm;
623     }
624   else
625     {
626     change = dyNorm;
627     }
628   
629   this->StartPosition[0] = x;
630   this->StartPosition[1] = y;
631   
632   double newPos[4];
633   newPos[0] = vp[0] + change;
634   newPos[1] = vp[1] + change;
635   newPos[2] = vp[2];
636   newPos[3] = vp[3];
637   
638   if (newPos[0] < 0)
639     {
640     this->StartPosition[0] = 0;
641     newPos[0] = 0;
642     }
643   if (newPos[0] >= newPos[2]-0.01)
644     {
645     newPos[0] = newPos[2] - 0.01;
646     }
647   if (newPos[1] < 0)
648     {
649     this->StartPosition[1] = 0;
650     newPos[1] = 0;
651     }
652   if (newPos[1] >= newPos[3]-0.01)
653     {
654     newPos[1] = newPos[3] - 0.01;
655     }
656   
657   this->Renderer->SetViewport(newPos);
658   this->Interactor->Render();
659 }
660
661 //----------------------------------------------------------------------------
662 void vtkPVAxesWidget::ResizeBottomRight()
663 {
664   int x = this->Interactor->GetEventPosition()[0];
665   int y = this->Interactor->GetEventPosition()[1];
666   
667   int dx = x - this->StartPosition[0];
668   int dy = y - this->StartPosition[1];
669   
670   int *size = this->ParentRenderer->GetSize();
671   double dxNorm = dx / (double)size[0];
672   double dyNorm = dy / (double)size[1];
673   
674   double *vp = this->Renderer->GetViewport();
675   
676   int useX;
677   double change;
678   double absDx = fabs(dxNorm);
679   double absDy = fabs(dyNorm);
680   
681   if (absDx > absDy)
682     {
683     change = dxNorm;
684     useX = 1;
685     }
686   else
687     {
688     change = dyNorm;
689     useX = 0;
690     }
691   
692   this->StartPosition[0] = x;
693   this->StartPosition[1] = y;
694   
695   double newPos[4];
696   newPos[0] = vp[0];
697   newPos[1] = useX ? vp[1] - change : vp[1] + change;
698   newPos[2] = useX ? vp[2] + change : vp[2] - change;
699   newPos[3] = vp[3];
700   
701   if (newPos[2] > 1)
702     {
703     this->StartPosition[0] = size[0];
704     newPos[2] = 1;
705     }
706   if (newPos[2] <= newPos[0]+0.01)
707     {
708     newPos[2] = newPos[0] + 0.01;
709     }
710   if (newPos[1] < 0)
711     {
712     this->StartPosition[1] = 0;
713     newPos[1] = 0;
714     }
715   if (newPos[1] >= newPos[3]-0.01)
716     {
717     newPos[1] = newPos[3]-0.01;
718     }
719   
720   this->Renderer->SetViewport(newPos);
721   this->Interactor->Render();
722 }
723
724 //----------------------------------------------------------------------------
725 void vtkPVAxesWidget::SquareRenderer()
726 {
727   int *size = this->Renderer->GetSize();
728   if (size[0] == 0 || size[1] == 0)
729     {
730     return;
731     }
732   
733   double vp[4];
734   this->Renderer->GetViewport(vp);
735   
736   double deltaX = vp[2] - vp[0];
737   double newDeltaX = size[1] * deltaX / (double)size[0];
738   double deltaY = vp[3] - vp[1];
739   double newDeltaY = size[0] * deltaY / (double)size[1];
740
741   if (newDeltaX > 1)
742     {
743     if (newDeltaY > 1)
744       {
745       if (size[0] > size[1])
746         {
747         newDeltaX = size[1] / (double)size[0];
748         newDeltaY = 1;
749         }
750       else
751         {
752         newDeltaX = 1;
753         newDeltaY = size[0] / (double)size[1];
754         }
755       vp[0] = vp[1] = 0;
756       vp[2] = newDeltaX;
757       vp[3] = newDeltaY;
758       }
759     else
760       {
761       vp[3] = vp[1] + newDeltaY;
762       if (vp[3] > 1)
763         {
764         vp[3] = 1;
765         vp[1] = vp[3] - newDeltaY;
766         }
767       }
768     }
769   else
770     {
771     vp[2] = vp[0] + newDeltaX;
772     if (vp[2] > 1)
773       {
774       vp[2] = 1;
775       vp[0] = vp[2] - newDeltaX;
776       }
777     }
778   
779   this->Renderer->SetViewport(vp);
780   
781   this->Renderer->NormalizedDisplayToDisplay(vp[0], vp[1]);
782   this->Renderer->NormalizedDisplayToDisplay(vp[2], vp[3]);
783   
784   vtkPoints *points = this->Outline->GetPoints();
785   points->SetPoint(0, vp[0]+1, vp[1]+1, 0);
786   points->SetPoint(1, vp[2]-1, vp[1]+1, 0);
787   points->SetPoint(2, vp[2]-1, vp[3]-1, 0);
788   points->SetPoint(3, vp[0]+1, vp[3]-1, 0);
789 }
790
791 //----------------------------------------------------------------------------
792 void vtkPVAxesWidget::SetInteractive(int state)
793 {
794   if (this->Interactive != state)
795     {
796     this->Interactive = state;
797     }
798   
799   if (!state)
800     {
801     this->OnButtonRelease();
802     this->MouseCursorState = vtkPVAxesWidget::Outside;
803     this->Renderer->RemoveActor(this->OutlineActor);
804     if (this->Interactor)
805       {
806       this->SetMouseCursor(this->MouseCursorState);
807       // this->Interactor->Render();
808       }
809     }
810 }
811
812 //----------------------------------------------------------------------------
813 void vtkPVAxesWidget::SetOutlineColor(double r, double g, double b)
814 {
815   this->OutlineActor->GetProperty()->SetColor(r, g, b);
816   if (this->Interactor)
817     {
818 //    this->Interactor->Render();
819     }
820 }
821
822 //----------------------------------------------------------------------------
823 double* vtkPVAxesWidget::GetOutlineColor()
824 {
825   return this->OutlineActor->GetProperty()->GetColor();
826 }
827
828 //----------------------------------------------------------------------------
829 void vtkPVAxesWidget::SetAxisLabelColor(double r, double g, double b)
830 {
831   this->AxesActor->GetXAxisLabelProperty()->SetColor(r, g, b);
832   this->AxesActor->GetYAxisLabelProperty()->SetColor(r, g, b);
833   this->AxesActor->GetZAxisLabelProperty()->SetColor(r, g, b);
834 }
835
836 //----------------------------------------------------------------------------
837 double* vtkPVAxesWidget::GetAxisLabelColor()
838 {
839   return this->AxesActor->GetXAxisLabelProperty()->GetColor();
840 }
841
842 //----------------------------------------------------------------------------
843 vtkRenderer* vtkPVAxesWidget::GetParentRenderer()
844 {
845   return this->ParentRenderer;
846 }
847
848 //----------------------------------------------------------------------------
849 void vtkPVAxesWidget::SetViewport(double minX, double minY,
850                                   double maxX, double maxY)
851 {
852   this->Renderer->SetViewport(minX, minY, maxX, maxY);
853 }
854
855 //----------------------------------------------------------------------------
856 double* vtkPVAxesWidget::GetViewport()
857 {
858   return this->Renderer->GetViewport();
859 }
860
861 //----------------------------------------------------------------------------
862 void vtkPVAxesWidget::PrintSelf(ostream& os, vtkIndent indent)
863 {
864   this->Superclass::PrintSelf(os, indent);
865   
866   os << indent << "AxesActor: " << this->AxesActor << endl;
867   os << indent << "Interactive: " << this->Interactive << endl;
868 }