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