Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : SALOME
27 //  $Header$
28
29
30 #include "SVTK_InteractorStyle.h"
31
32 #include "VTKViewer_Utilities.h"
33 #include "SVTK_GenericRenderWindowInteractor.h"
34
35 #include "SVTK_Selection.h"
36 #include "SVTK_Event.h" 
37 #include "SVTK_Selector.h"
38 #include "SVTK_Functor.h"
39
40 #include "VTKViewer_Algorithm.h"
41 #include "SVTK_Functor.h"
42
43 #include "SALOME_Actor.h"
44
45 #include <vtkObjectFactory.h>
46 #include <vtkMath.h>
47 #include <vtkCommand.h>
48 #include <vtkCamera.h>
49 #include <vtkRenderer.h>
50 #include <vtkPicker.h>
51 #include <vtkRenderWindow.h>
52 #include <vtkRenderWindowInteractor.h>
53 #include <vtkCallbackCommand.h>
54 #include <vtkRendererCollection.h>
55
56 #include <qapplication.h>
57 #include <qpixmap.h>
58 //VRV: porting on Qt 3.0.5
59 #if QT_VERSION >= 0x030005
60 #include <qpainter.h>
61 #endif
62 //VRV: porting on Qt 3.0.5
63 #include <algorithm>
64
65 using namespace std;
66
67 namespace
68 {
69   inline 
70   void
71   GetEventPosition(vtkRenderWindowInteractor* theInteractor,
72                    int& theX, 
73                    int& theY)
74   {
75     theInteractor->GetEventPosition(theX,theY);
76     theY = theInteractor->GetSize()[1] - theY - 1;
77   }
78
79   //==================================================================
80   // function : GetFirstSALOMEActor
81   // purpose  :
82   //==================================================================
83   struct THaveIO
84   {
85     bool
86     operator()(SALOME_Actor* theActor)
87     {
88       return theActor->hasIO();
89     }
90   };
91
92   inline
93   SALOME_Actor* 
94   GetFirstSALOMEActor(vtkPicker *thePicker)
95   {
96     return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
97   }
98 }
99
100
101 vtkStandardNewMacro(SVTK_InteractorStyle);
102
103 /*!
104   Constructor
105 */
106 SVTK_InteractorStyle
107 ::SVTK_InteractorStyle():
108   mySelectionEvent(new SVTK_SelectionEvent()),
109   myPicker(vtkPicker::New()),
110   myLastHighlitedActor(NULL),
111   myLastPreHighlitedActor(NULL),
112   myControllerIncrement(SVTK_ControllerIncrement::New()),
113   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New())
114 {
115   myPicker->Delete();
116
117   this->MotionFactor = 10.0;
118   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
119   this->RadianToDegree = 180.0 / vtkMath::Pi();
120   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
121
122   loadCursors();
123
124   // set custom event handling function (to handle 3d space mouse events)
125   EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
126
127   // set default values of properties.  user may edit them in preferences.
128   mySMDecreaseSpeedBtn = 1;
129   mySMIncreaseSpeedBtn = 2;
130   mySMDominantCombinedSwitchBtn = 9;
131   //
132   myControllerIncrement->Delete();
133   myControllerOnKeyDown->Delete();
134 }
135
136 /*!
137   Destructor
138 */
139 SVTK_InteractorStyle
140 ::~SVTK_InteractorStyle() 
141 {
142 }
143
144 /*!
145   \return widget for rendering
146 */
147 QWidget*
148 SVTK_InteractorStyle
149 ::GetRenderWidget()
150 {
151   return myInteractor->GetRenderWidget();
152 }
153
154 /*!
155   \return selector
156 */
157 SVTK_Selector*
158 SVTK_InteractorStyle
159 ::GetSelector() 
160 {
161   return myInteractor->GetSelector();
162 }
163
164 /*!
165   Generate special SVTK_SelectionEvent
166 */
167 SVTK_SelectionEvent*
168 SVTK_InteractorStyle
169 ::GetSelectionEvent()
170 {
171   mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
172
173   mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
174   mySelectionEvent->myIsShift = Interactor->GetShiftKey();
175
176   mySelectionEvent->myLastX = mySelectionEvent->myX;
177   mySelectionEvent->myLastY = mySelectionEvent->myY;
178
179   GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
180
181   return mySelectionEvent.get();
182 }
183
184 /*!
185   Generate special SVTK_SelectionEvent with flipped Y coordinate
186 */
187 SVTK_SelectionEvent*
188 SVTK_InteractorStyle
189 ::GetSelectionEventFlipY()
190 {
191   mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
192
193   mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
194   mySelectionEvent->myIsShift = Interactor->GetShiftKey();
195
196   mySelectionEvent->myLastX = mySelectionEvent->myX;
197   mySelectionEvent->myLastY = mySelectionEvent->myY;
198
199   this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
200
201   return mySelectionEvent.get();
202 }
203
204 void
205 SVTK_InteractorStyle
206 ::RotateXY(int dx, int dy)
207 {
208   if(GetCurrentRenderer() == NULL)
209     return;
210   
211   int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
212   double aDeltaElevation = -20.0 / size[1];
213   double aDeltaAzimuth = -20.0 / size[0];
214   
215   double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
216   double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
217   
218   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
219   cam->Azimuth(rxf);
220   cam->Elevation(ryf);
221   cam->OrthogonalizeViewUp();
222
223   GetCurrentRenderer()->ResetCameraClippingRange(); 
224
225   this->Render();
226 }
227
228 void
229 SVTK_InteractorStyle
230 ::PanXY(int x, int y, int oldX, int oldY)
231 {
232   TranslateView(x, y, oldX, oldY);   
233   this->Render();
234 }
235
236
237 void 
238 SVTK_InteractorStyle
239 ::DollyXY(int dx, int dy)
240 {
241   if (GetCurrentRenderer() == NULL) 
242     return;
243
244   double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
245   double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
246
247   double zoomFactor = pow((double)1.1, dxf + dyf);
248   
249   vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
250   if (aCam->GetParallelProjection())
251     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
252   else{
253     aCam->Dolly(zoomFactor);
254     GetCurrentRenderer()->ResetCameraClippingRange(); 
255   }
256
257   this->Render();
258 }
259
260 void 
261 SVTK_InteractorStyle
262 ::SpinXY(int x, int y, int oldX, int oldY)
263 {
264   vtkCamera *cam;
265
266   if (GetCurrentRenderer() == NULL)
267     return;
268
269   double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
270                           (double)(x - GetCurrentRenderer()->GetCenter()[0]));
271   double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
272                           (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
273   
274   newAngle *= this->RadianToDegree;
275   oldAngle *= this->RadianToDegree;
276
277   cam = GetCurrentRenderer()->GetActiveCamera();
278   cam->Roll(newAngle - oldAngle);
279   cam->OrthogonalizeViewUp();
280       
281   this->Render();
282 }
283
284
285 /*!
286   To reset reset view
287 */
288 void
289 SVTK_InteractorStyle
290 ::OnConfigure() 
291 {
292   this->FindPokedRenderer(0,0);
293   this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
294 }
295
296 /*!
297   To handle mouse move event
298 */
299 void
300 SVTK_InteractorStyle
301 ::OnMouseMove() 
302 {
303   int x, y;
304   GetEventPosition( this->Interactor, x, y );
305   this->OnMouseMove( this->Interactor->GetControlKey(),
306                      this->Interactor->GetShiftKey(),
307                      x, y );
308 }
309
310 /*!
311   To handle left mouse button down event (reimplemented from vtkInteractorStyle)
312 */
313 void
314 SVTK_InteractorStyle
315 ::OnLeftButtonDown()
316 {
317   int x, y;
318   GetEventPosition( this->Interactor, x, y );
319   this->OnLeftButtonDown( this->Interactor->GetControlKey(),
320                           this->Interactor->GetShiftKey(),
321                           x, y );
322 }
323
324 /*!
325   To handle left mouse button up event (reimplemented from vtkInteractorStyle)
326 */
327 void
328 SVTK_InteractorStyle
329 ::OnLeftButtonUp()
330 {
331   int x, y;
332   GetEventPosition( this->Interactor, x, y );
333   this->OnLeftButtonUp( this->Interactor->GetControlKey(),
334                         this->Interactor->GetShiftKey(),
335                         x, y );
336 }
337
338 /*!
339   To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
340 */
341 void
342 SVTK_InteractorStyle
343 ::OnMiddleButtonDown() 
344 {
345   int x, y;
346   GetEventPosition( this->Interactor, x, y );
347   this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
348                             this->Interactor->GetShiftKey(),
349                             x, y );
350 }
351
352 /*!
353   To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
354 */
355 void
356 SVTK_InteractorStyle
357 ::OnMiddleButtonUp()
358 {
359   int x, y;
360   GetEventPosition( this->Interactor, x, y );
361   this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
362                           this->Interactor->GetShiftKey(),
363                           x, y );
364 }
365
366 /*!
367   To handle right mouse button down event (reimplemented from vtkInteractorStyle)
368 */
369 void
370 SVTK_InteractorStyle
371 ::OnRightButtonDown() 
372 {
373   int x, y;
374   GetEventPosition( this->Interactor, x, y );
375   this->OnRightButtonDown( this->Interactor->GetControlKey(),
376                            this->Interactor->GetShiftKey(),
377                            x, y );
378 }
379
380 /*!
381   To handle right mouse button up event (reimplemented from vtkInteractorStyle)
382 */
383 void
384 SVTK_InteractorStyle
385 ::OnRightButtonUp()
386 {
387   int x, y;
388   GetEventPosition( this->Interactor, x, y );
389   this->OnRightButtonUp( this->Interactor->GetControlKey(),
390                          this->Interactor->GetShiftKey(),
391                          x, y );
392 }
393
394 /*!
395   To handle mouse move event
396 */
397 void
398 SVTK_InteractorStyle
399 ::OnMouseMove(int vtkNotUsed(ctrl), 
400               int shift,
401               int x, int y) 
402 {
403   myShiftState = shift;
404   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
405     onOperation(QPoint(x, y));
406   else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
407     onCursorMove(QPoint(x, y));
408 }
409
410 /*!
411   To handle left mouse button down event (reimplemented from vtkInteractorStyle)
412 */
413 void
414 SVTK_InteractorStyle
415 ::OnLeftButtonDown(int ctrl, int shift, 
416                    int x, int y) 
417 {
418   this->FindPokedRenderer(x, y);
419   if(GetCurrentRenderer() == NULL)
420     return;
421
422   myShiftState = shift;
423   // finishing current viewer operation
424   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
425     onFinishOperation();
426     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
427   }
428   myOtherPoint = myPoint = QPoint(x, y);
429   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
430     startOperation(ForcedState);
431   } else {
432     if (ctrl)
433       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
434     else
435       startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
436   }
437   return;
438 }
439
440 /*!
441   To handle left mouse button up event (reimplemented from vtkInteractorStyle)
442 */
443 void
444 SVTK_InteractorStyle
445 ::OnLeftButtonUp(int vtkNotUsed(ctrl),
446                  int shift, 
447                  int vtkNotUsed(x),
448                  int vtkNotUsed(y))
449 {
450   myShiftState = shift;
451   // finishing current viewer operation
452   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
453     onFinishOperation();
454     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
455   }
456 }
457
458 /*!
459   To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
460 */
461 void
462 SVTK_InteractorStyle
463 ::OnMiddleButtonDown(int ctrl,
464                      int shift, 
465                      int x, int y) 
466 {
467   this->FindPokedRenderer(x, y);
468   if(GetCurrentRenderer() == NULL)
469     return;
470
471   myShiftState = shift;
472   // finishing current viewer operation
473   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
474     onFinishOperation();
475     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
476   }
477   myOtherPoint = myPoint = QPoint(x, y);
478   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
479     startOperation(ForcedState);
480   }
481   else {
482     if (ctrl)
483       startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
484   }
485 }
486
487
488 /*!
489   To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
490 */
491 void
492 SVTK_InteractorStyle
493 ::OnMiddleButtonUp(int vtkNotUsed(ctrl),
494                    int shift, 
495                    int vtkNotUsed(x),
496                    int vtkNotUsed(y))
497 {
498   myShiftState = shift;
499   // finishing current viewer operation
500   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
501     onFinishOperation();
502     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
503   }
504 }
505
506
507 /*!
508   To handle right mouse button down event (reimplemented from vtkInteractorStyle)
509 */
510 void
511 SVTK_InteractorStyle
512 ::OnRightButtonDown(int ctrl,
513                     int shift, 
514                     int x, int y) 
515 {
516   this->FindPokedRenderer(x, y);
517   if(GetCurrentRenderer() == NULL)
518     return;
519
520   myShiftState = shift;
521   // finishing current viewer operation
522   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
523     onFinishOperation();
524     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
525   }
526   myOtherPoint = myPoint = QPoint(x, y);
527   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
528     startOperation(ForcedState);
529   }
530   else {
531     if (ctrl)
532       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);  
533   }
534 }
535
536 /*!
537   To handle right mouse button up event (reimplemented from vtkInteractorStyle)
538 */
539 void
540 SVTK_InteractorStyle
541 ::OnRightButtonUp(int vtkNotUsed(ctrl),
542                   int shift, 
543                   int vtkNotUsed(x),
544                   int vtkNotUsed(y))
545 {
546   myShiftState = shift;
547   // finishing current viewer operation
548   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
549     onFinishOperation();
550     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
551   }
552 }
553
554 /* XPM */
555 const char* imageZoomCursor[] = { 
556 "32 32 3 1",
557 ". c None",
558 "a c #000000",
559 "# c #ffffff",
560 "................................",
561 "................................",
562 ".#######........................",
563 "..aaaaaaa.......................",
564 "................................",
565 ".............#####..............",
566 "...........##.aaaa##............",
567 "..........#.aa.....a#...........",
568 ".........#.a.........#..........",
569 ".........#a..........#a.........",
570 "........#.a...........#.........",
571 "........#a............#a........",
572 "........#a............#a........",
573 "........#a............#a........",
574 "........#a............#a........",
575 ".........#...........#.a........",
576 ".........#a..........#a.........",
577 ".........##.........#.a.........",
578 "........#####.....##.a..........",
579 ".......###aaa#####.aa...........",
580 "......###aa...aaaaa.......#.....",
581 ".....###aa................#a....",
582 "....###aa.................#a....",
583 "...###aa...............#######..",
584 "....#aa.................aa#aaaa.",
585 ".....a....................#a....",
586 "..........................#a....",
587 "...........................a....",
588 "................................",
589 "................................",
590 "................................",
591 "................................"};
592
593 const char* imageRotateCursor[] = { 
594 "32 32 3 1",
595 ". c None",
596 "a c #000000",
597 "# c #ffffff",
598 "................................",
599 "................................",
600 "................................",
601 "................................",
602 "........#.......................",
603 ".......#.a......................",
604 "......#######...................",
605 ".......#aaaaa#####..............",
606 "........#..##.a#aa##........##..",
607 ".........a#.aa..#..a#.....##.aa.",
608 ".........#.a.....#...#..##.aa...",
609 ".........#a.......#..###.aa.....",
610 "........#.a.......#a..#aa.......",
611 "........#a.........#..#a........",
612 "........#a.........#a.#a........",
613 "........#a.........#a.#a........",
614 "........#a.........#a.#a........",
615 ".........#.........#a#.a........",
616 "........##a........#a#a.........",
617 "......##.a#.......#.#.a.........",
618 "....##.aa..##.....##.a..........",
619 "..##.aa.....a#####.aa...........",
620 "...aa.........aaa#a.............",
621 "................#.a.............",
622 "...............#.a..............",
623 "..............#.a...............",
624 "...............a................",
625 "................................",
626 "................................",
627 "................................",
628 "................................",
629 "................................"};
630
631
632 /*!
633   loads cursors for viewer operations - zoom, pan, etc...
634 */
635 void
636 SVTK_InteractorStyle
637 ::loadCursors()
638 {
639   myDefCursor       = QCursor(Qt::ArrowCursor);
640   myHandCursor      = QCursor(Qt::PointingHandCursor);
641   myPanCursor       = QCursor(Qt::SizeAllCursor);
642   myZoomCursor      = QCursor(QPixmap(imageZoomCursor));
643   myRotateCursor    = QCursor(QPixmap(imageRotateCursor));
644   mySpinCursor      = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
645   myGlobalPanCursor = QCursor(Qt::CrossCursor);
646   myCursorState     = false;
647 }
648
649
650 /*!
651   Starts Zoom operation (e.g. through menu command)
652 */
653 void
654 SVTK_InteractorStyle
655 ::startZoom()
656 {
657   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
658   {
659     onFinishOperation();
660     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
661   }
662   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
663   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
664 }
665
666
667 /*!
668   Starts Pan operation (e.g. through menu command)
669 */
670 void
671 SVTK_InteractorStyle
672 ::startPan()
673 {
674   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
675   {
676     onFinishOperation();
677     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
678   }
679   setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
680   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
681 }
682
683 /*!
684   Starts Rotate operation (e.g. through menu command)
685 */
686 void 
687 SVTK_InteractorStyle
688 ::startRotate()
689 {
690   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
691   {
692     onFinishOperation();
693     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
694   }
695   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
696   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
697 }
698
699
700 /*! 
701   Starts Spin operation (e.g. through menu command)
702 */
703 void
704 SVTK_InteractorStyle
705 ::startSpin()
706 {
707   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
708   {
709     onFinishOperation();
710     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
711   }
712   setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
713   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
714 }
715
716
717
718 /*!
719   Starts Fit Area operation (e.g. through menu command)
720 */
721 void
722 SVTK_InteractorStyle
723 ::startFitArea()
724 {
725   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
726   {
727     onFinishOperation();
728     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
729   }
730   setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
731   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
732 }
733
734
735 /*!
736   Starts Global Panning operation (e.g. through menu command)
737 */
738 void
739 SVTK_InteractorStyle
740 ::startGlobalPan()
741 {
742   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
743   {
744     onFinishOperation();
745     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
746   }
747   setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
748   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
749
750   // store current zoom scale
751   myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
752
753   GetCurrentRenderer()->ResetCamera();
754
755   this->Render();
756 }
757
758
759 /*!
760   Fits viewer contents to rect
761 */
762 void
763 SVTK_InteractorStyle
764 ::fitRect(const int left, 
765           const int top, 
766           const int right, 
767           const int bottom)
768 {
769   if (GetCurrentRenderer() == NULL) 
770     return;
771  
772   // move camera
773   int x = (left + right)/2;
774   int y = (top + bottom)/2;
775   int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
776   int oldX = aSize[0]/2;
777   int oldY = aSize[1]/2;
778   TranslateView(oldX, oldY, x, y);
779
780   // zoom camera
781   double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
782   double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
783   double zoomFactor = (dxf + dyf)/2 ;
784
785   vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
786   if(aCam->GetParallelProjection())
787     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
788   else{
789     aCam->Dolly(zoomFactor);
790     GetCurrentRenderer()->ResetCameraClippingRange();
791   }
792   
793   this->Render();
794 }
795
796
797 /*!
798   Starts viewer operation (!internal usage!)
799 */
800 void
801 SVTK_InteractorStyle
802 ::startOperation(int operation)
803 {
804   switch(operation)
805   { 
806   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
807   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
808   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
809   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
810   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
811   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
812   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
813     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
814       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
815     State = operation;
816     if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
817       setCursor(operation);
818     onStartOperation();
819     break;
820   case VTK_INTERACTOR_STYLE_CAMERA_NONE:
821   default:
822     setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
823     State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
824     break;
825   }
826 }
827
828
829 /*!
830   Sets proper cursor for window when viewer operation is activated
831 */
832 void
833 SVTK_InteractorStyle
834 ::setCursor(const int operation)
835 {
836   if (!GetRenderWidget()) return;
837   switch (operation)
838   {
839     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
840       GetRenderWidget()->setCursor(myZoomCursor); 
841       myCursorState = true;
842       break;
843     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
844       GetRenderWidget()->setCursor(myPanCursor); 
845       myCursorState = true;
846       break;
847     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
848       GetRenderWidget()->setCursor(myRotateCursor); 
849       myCursorState = true;
850       break;
851     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
852       GetRenderWidget()->setCursor(mySpinCursor); 
853       myCursorState = true;
854       break;
855     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
856       GetRenderWidget()->setCursor(myGlobalPanCursor); 
857       myCursorState = true;
858       break;
859     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
860     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
861       GetRenderWidget()->setCursor(myHandCursor); 
862       myCursorState = true;
863       break;
864     case VTK_INTERACTOR_STYLE_CAMERA_NONE:
865     default:
866       GetRenderWidget()->setCursor(myDefCursor); 
867       myCursorState = false;
868       break;
869   }
870 }
871
872
873 /*!
874   Called when viewer operation started (!put necessary initialization here!)
875 */
876 void
877 SVTK_InteractorStyle
878 ::onStartOperation()
879 {
880   if (!GetRenderWidget()) 
881     return;
882
883   vtkRenderWindowInteractor *aRWI = this->Interactor;
884   vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
885   aRenWin->SetDesiredUpdateRate(aRWI->GetDesiredUpdateRate());
886
887   switch (State) {
888     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
889     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
890     {
891       QPainter p(GetRenderWidget());
892       p.setPen(Qt::lightGray);
893       p.setRasterOp(Qt::XorROP);
894       p.drawRect(QRect(myPoint, myOtherPoint));
895       break;
896     }
897     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
898     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
899     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
900     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
901     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
902       break;
903   }
904 }
905
906
907 /*!
908   Called when viewer operation finished (!put necessary post-processing here!)
909 */
910 void
911 SVTK_InteractorStyle
912 ::onFinishOperation() 
913 {
914   if (!GetRenderWidget()) 
915     return;
916
917   vtkRenderWindowInteractor *aRWI = this->Interactor;
918   vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
919   aRenWin->SetDesiredUpdateRate(aRWI->GetStillUpdateRate());
920
921   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
922
923   switch (State) {
924     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
925     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
926     {
927       QPainter aPainter(GetRenderWidget());
928       aPainter.setPen(Qt::lightGray);
929       aPainter.setRasterOp(Qt::XorROP);
930       QRect aRect(myPoint, myOtherPoint);
931       aPainter.drawRect(aRect);
932       aRect = aRect.normalize();
933
934       if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
935         // making fit rect opeation 
936         int w, h;
937         Interactor->GetSize(w, h);
938         int x1 = aRect.left(); 
939         int y1 = h - aRect.top() - 1;
940         int x2 = aRect.right(); 
941         int y2 = h - aRect.bottom() - 1;
942         fitRect(x1, y1, x2, y2);
943       }
944       else {
945         if (myPoint == myOtherPoint) {
946           // process point selection
947           this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
948           Interactor->StartPickCallback();
949
950           myPicker->Pick(aSelectionEvent->myX, 
951                          aSelectionEvent->myY, 
952                          0.0, 
953                          GetCurrentRenderer());
954           //
955           SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
956           aSelectionEvent->myIsRectangle = false;
957
958           if(!myShiftState)
959             GetSelector()->ClearIObjects();
960
961           if(anActor){
962             anActor->Highlight( this, aSelectionEvent, true );
963           }else{
964             if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != anActor)
965               myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
966           }
967           myLastHighlitedActor = anActor;
968         } 
969         else {
970           //processing rectangle selection
971           Interactor->StartPickCallback();
972           GetSelector()->StartPickCallback();
973           aSelectionEvent->myIsRectangle = true;
974
975           if(!myShiftState)
976             GetSelector()->ClearIObjects();
977
978           vtkActorCollection* aListActors = GetCurrentRenderer()->GetActors();
979           aListActors->InitTraversal();
980           while(vtkActor* aActor = aListActors->GetNextActor()){
981             if(aActor->GetVisibility()){
982               if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){
983                 if(aSActor->hasIO()){
984                   aSActor->Highlight( this, aSelectionEvent, true );
985                 }
986               }
987             }
988           }
989         }
990         Interactor->EndPickCallback();
991         GetSelector()->EndPickCallback();
992       } 
993     } 
994     break;
995   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
996   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
997   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
998   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
999     break;
1000   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
1001     {
1002       int w, h, x, y;
1003       Interactor->GetSize(w, h);
1004       x = myPoint.x(); 
1005       y = h - myPoint.y() - 1;
1006       Place(x, y);
1007     }
1008     break;
1009   }
1010
1011   this->Render();
1012 }
1013
1014
1015 /*!
1016   Called during viewer operation when user moves mouse (!put necessary processing here!)
1017 */
1018 void
1019 SVTK_InteractorStyle
1020 ::onOperation(QPoint mousePos) 
1021 {
1022   if (!GetRenderWidget()) 
1023     return;
1024
1025   switch (State) {
1026   case VTK_INTERACTOR_STYLE_CAMERA_PAN: 
1027     {
1028       this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1029       myPoint = mousePos;
1030       break;
1031     }
1032   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: 
1033     {    
1034       this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1035       myPoint = mousePos;
1036       break;
1037     }
1038   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: 
1039     {
1040       this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1041       myPoint = mousePos;
1042       break;
1043     }
1044   case VTK_INTERACTOR_STYLE_CAMERA_SPIN: 
1045     {
1046       this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1047       myPoint = mousePos;
1048       break;
1049     }
1050   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
1051     {    
1052       break;
1053     }
1054   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1055     {
1056       if (!myCursorState)
1057         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1058     }
1059   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1060     {
1061       QPainter p(GetRenderWidget());
1062       p.setPen(Qt::lightGray);
1063       p.setRasterOp(Qt::XorROP);
1064       p.drawRect(QRect(myPoint, myOtherPoint));
1065       myOtherPoint = mousePos;
1066       p.drawRect(QRect(myPoint, myOtherPoint));
1067       break;
1068     }
1069   }
1070 }
1071
1072 /*!
1073   Called when user moves mouse inside viewer window and there is no active viewer operation 
1074   (!put necessary processing here!)
1075 */
1076 void
1077 SVTK_InteractorStyle
1078 ::onCursorMove(QPoint mousePos) 
1079 {
1080   // processing highlighting
1081   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1082   this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1083
1084   bool anIsChanged = false;
1085
1086   myPicker->Pick(aSelectionEvent->myX, 
1087                  aSelectionEvent->myY, 
1088                  0.0, 
1089                  GetCurrentRenderer());
1090   
1091   SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
1092   if (anActor){
1093     anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
1094   }
1095
1096   if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != anActor)
1097     anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );   
1098
1099   myLastPreHighlitedActor = anActor;
1100
1101   if(anIsChanged)
1102     this->Render();
1103 }
1104
1105 /*!
1106   Called on finsh GlobalPan operation 
1107 */
1108 void
1109 SVTK_InteractorStyle
1110 ::Place(const int theX, const int theY) 
1111 {
1112   if (GetCurrentRenderer() == NULL)
1113     return;
1114
1115   //translate view
1116   int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1117   int centerX = aSize[0]/2;
1118   int centerY = aSize[1]/2;
1119
1120   TranslateView(centerX, centerY, theX, theY);
1121
1122   // restore zoom scale
1123   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1124   cam->SetParallelScale(myScale);
1125   GetCurrentRenderer()->ResetCameraClippingRange();
1126
1127   this->Render();
1128 }
1129
1130
1131
1132 /*!
1133   Translates view from Point to Point
1134 */
1135 void
1136 SVTK_InteractorStyle
1137 ::TranslateView(int toX, int toY, int fromX, int fromY)
1138 {
1139   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1140   double viewFocus[4], focalDepth, viewPoint[3];
1141   vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
1142   cam->GetFocalPoint(viewFocus);
1143
1144   this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1145                               viewFocus[2], viewFocus);
1146   focalDepth = viewFocus[2];
1147
1148   this->ComputeDisplayToWorld(double(toX), double(toY),
1149                               focalDepth, newPickPoint);
1150   this->ComputeDisplayToWorld(double(fromX),double(fromY),
1151                               focalDepth, oldPickPoint);
1152   
1153   // camera motion is reversed
1154   motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1155   motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1156   motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1157   
1158   cam->GetFocalPoint(viewFocus);
1159   cam->GetPosition(viewPoint);
1160   cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1161                      motionVector[1] + viewFocus[1],
1162                      motionVector[2] + viewFocus[2]);
1163   cam->SetPosition(motionVector[0] + viewPoint[0],
1164                    motionVector[1] + viewPoint[1],
1165                    motionVector[2] + viewPoint[2]);
1166 }
1167
1168 void
1169 SVTK_InteractorStyle
1170 ::IncrementalPan( const int incrX, const int incrY )
1171 {
1172   this->PanXY( incrX, incrY, 0, 0 );
1173 }
1174
1175 void
1176 SVTK_InteractorStyle
1177 ::IncrementalZoom( const int incr )
1178 {
1179   this->DollyXY( incr, incr );
1180 }
1181
1182 void
1183 SVTK_InteractorStyle
1184 ::IncrementalRotate( const int incrX, const int incrY )
1185 {
1186   this->RotateXY( incrX, -incrY );
1187 }
1188
1189 /*!
1190   Redefined in order to add an observer (callback) for custorm event (space mouse event)
1191 */
1192 void
1193 SVTK_InteractorStyle
1194 ::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1195 {
1196   // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1197   Superclass::SetInteractor( theInteractor );
1198  
1199   myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1200
1201   if(theInteractor) { 
1202     // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1203     theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1204     theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1205     theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1206     theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1207     theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1208     theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1209     theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1210     theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1211     theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1212     theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1213     theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1214     theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1215     theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1216     theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1217     theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1218
1219     theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1220     theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1221     theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1222
1223     theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1224     theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1225     theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1226     theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1227     theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1228   }
1229 }
1230
1231 /*!
1232   To implement cached rendering
1233 */
1234 void
1235 SVTK_InteractorStyle
1236 ::OnTimer() 
1237 {
1238   //vtkInteractorStyle::OnTimer();
1239   this->Interactor->Render();
1240 }
1241
1242 /*!
1243   To invoke #vtkRenderWindowInteractor::CreateTimer
1244 */
1245 void
1246 SVTK_InteractorStyle
1247 ::Render() 
1248 {
1249   this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1250 }
1251
1252 void
1253 SVTK_InteractorStyle
1254 ::onSpaceMouseMove( double* data )
1255 {
1256   // general things, do SetCurrentRenderer() within FindPokedRenderer() 
1257   int x, y;
1258   GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1259   FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1260   
1261   IncrementalZoom( (int)data[2] );        // 1. push toward / pull backward = zoom out / zoom in
1262   IncrementalPan(  (int)data[0],  (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1263   IncrementalRotate( 0,  (int)data[4] );   // 4. twist the control = rotate around Y axis
1264   IncrementalRotate( (int)data[3], 0  );   // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1265 }
1266
1267 void
1268 SVTK_InteractorStyle
1269 ::onSpaceMouseButton( int button )
1270 {
1271   if( mySMDecreaseSpeedBtn == button ) {   
1272     ControllerIncrement()->Decrease();
1273   }
1274   if( mySMIncreaseSpeedBtn == button ) {    
1275     ControllerIncrement()->Increase();
1276   }
1277   if( mySMDominantCombinedSwitchBtn == button )    
1278     DominantCombinedSwitch();
1279 }
1280
1281 void
1282 SVTK_InteractorStyle
1283 ::DominantCombinedSwitch()
1284 {
1285   printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1286 }
1287
1288 /*!
1289   Main process event method (reimplemented from #vtkInteractorStyle)
1290 */
1291 void
1292 SVTK_InteractorStyle
1293 ::ProcessEvents( vtkObject* object,
1294                  unsigned long event,
1295                  void* clientData, 
1296                  void* callData )
1297 {
1298   if ( clientData ) {
1299     vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1300     SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1301     int aSpeedIncrement=self->ControllerIncrement()->Current();
1302     if ( self ) {
1303       switch ( event ) {
1304       case SVTK::SpaceMouseMoveEvent : 
1305         self->onSpaceMouseMove( (double*)callData ); 
1306         return;
1307       case SVTK::SpaceMouseButtonEvent : 
1308         self->onSpaceMouseButton( *((int*)callData) ); 
1309         return;
1310       case SVTK::PanLeftEvent: 
1311         self->IncrementalPan(-aSpeedIncrement, 0);
1312         return;
1313       case SVTK::PanRightEvent:
1314         self->IncrementalPan(aSpeedIncrement, 0);
1315         return;
1316       case SVTK::PanUpEvent:
1317         self->IncrementalPan(0, aSpeedIncrement);
1318         return;
1319       case SVTK::PanDownEvent:
1320         self->IncrementalPan(0, -aSpeedIncrement);
1321         return;
1322       case SVTK::ZoomInEvent:
1323         self->IncrementalZoom(aSpeedIncrement);
1324         return;
1325       case SVTK::ZoomOutEvent:
1326         self->IncrementalZoom(-aSpeedIncrement);
1327         return;
1328       case SVTK::RotateLeftEvent: 
1329         self->IncrementalRotate(-aSpeedIncrement, 0);
1330         return;
1331       case SVTK::RotateRightEvent:
1332         self->IncrementalRotate(aSpeedIncrement, 0);
1333         return;
1334       case SVTK::RotateUpEvent:
1335         self->IncrementalRotate(0, -aSpeedIncrement);
1336         return;
1337       case SVTK::RotateDownEvent:
1338         self->IncrementalRotate(0, aSpeedIncrement);
1339         return;
1340       case SVTK::PlusSpeedIncrementEvent:
1341         self->ControllerIncrement()->Increase();
1342         return;
1343       case SVTK::MinusSpeedIncrementEvent:
1344         self->ControllerIncrement()->Decrease();
1345         return;
1346       case SVTK::SetSpeedIncrementEvent:
1347         self->ControllerIncrement()->SetStartValue(*((int*)callData));
1348         return;
1349
1350       case SVTK::SetSMDecreaseSpeedEvent:
1351         self->mySMDecreaseSpeedBtn = *((int*)callData);
1352         return;
1353       case SVTK::SetSMIncreaseSpeedEvent:
1354         self->mySMIncreaseSpeedBtn = *((int*)callData);
1355         return;
1356       case SVTK::SetSMDominantCombinedSwitchEvent:
1357         self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1358         return;
1359
1360       case SVTK::StartZoom:
1361         self->startZoom();
1362         return;
1363       case SVTK::StartPan:
1364         self->startPan();
1365         return;
1366       case SVTK::StartRotate:
1367         self->startRotate();
1368         return;
1369       case SVTK::StartGlobalPan:
1370         self->startGlobalPan();
1371         return;
1372       case SVTK::StartFitArea:
1373         self->startFitArea();
1374         return;
1375       }
1376     }
1377   }
1378
1379   Superclass::ProcessEvents( object, event, clientData, callData );
1380 }
1381
1382 /*!
1383   To handle keyboard event (reimplemented from #vtkInteractorStyle)
1384 */
1385 void SVTK_InteractorStyle::OnChar()
1386 {
1387 }
1388
1389 /*!
1390   Redefined vtkInteractorStyle::OnKeyDown
1391 */
1392 void SVTK_InteractorStyle::OnKeyDown()
1393 {
1394   bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1395   if (bInvokeSuperclass){
1396     Superclass::OnKeyDown();
1397   }
1398 }
1399
1400 /*!
1401   Provide instructions for Picking
1402 */
1403 void SVTK_InteractorStyle::ActionPicking()
1404 {
1405   int x, y;
1406   Interactor->GetEventPosition( x, y ); 
1407   FindPokedRenderer( x, y ); 
1408   
1409   myOtherPoint = myPoint = QPoint(x, y);
1410   
1411   startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1412   onFinishOperation();
1413   startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1414 }
1415
1416 /*!
1417   To set current increment controller 
1418 */
1419 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1420 {
1421   myControllerOnKeyDown=theController;
1422 }
1423
1424 /*!
1425   To get current OnKeyDown controller 
1426 */
1427 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1428 {
1429   return myControllerOnKeyDown.GetPointer();
1430 }
1431
1432 /*!
1433   To get current increment controller
1434 */
1435 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1436 {
1437   myControllerIncrement=theController;
1438 }
1439
1440 /*!
1441   To get current increment controller 
1442 */
1443 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
1444 {
1445   return myControllerIncrement.GetPointer();
1446 }
1447
1448 vtkStandardNewMacro(SVTK_ControllerIncrement);
1449 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
1450 {
1451   myIncrement=10;
1452 }
1453 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
1454 {
1455 }
1456 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
1457 {
1458   myIncrement=theValue;
1459 }
1460 int SVTK_ControllerIncrement::Current()const
1461 {
1462   return myIncrement;
1463 }
1464 int SVTK_ControllerIncrement::Increase()
1465 {
1466   ++myIncrement;
1467   return myIncrement;
1468 }
1469 int SVTK_ControllerIncrement::Decrease()
1470 {
1471   if (myIncrement>1){
1472     --myIncrement;
1473   }
1474   return myIncrement;
1475 }
1476
1477 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
1478
1479 /*!
1480   Constructor
1481 */
1482 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
1483 {
1484 }
1485
1486 /*!
1487   Destructor
1488 */
1489 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
1490 {
1491 }
1492
1493 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
1494 {
1495   return true;
1496 }