Salome HOME
Merge remote branch 'origin/hydro/imps_2015'
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 //  SALOME VTKViewer : build VTK viewer into Salome desktop
24 //  File   : 
25 //  Author : 
26
27 #include "SVTK_InteractorStyle.h"
28
29 #include "VTKViewer_Algorithm.h"
30 #include "VTKViewer_Utilities.h"
31 #include "SVTK_GenericRenderWindowInteractor.h"
32
33 #include "SVTK_Selection.h"
34 #include "SVTK_Event.h" 
35 #include "SVTK_Selector.h"
36 #include "SVTK_Functor.h"
37 #include "SVTK_Actor.h"
38
39 #include "VTKViewer_Algorithm.h"
40 #include "SVTK_Functor.h"
41
42 #include "SUIT_Tools.h"
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 <vtkPointPicker.h>
51 #include <vtkCellPicker.h>
52 #include <vtkRenderWindow.h>
53 #include <vtkRenderWindowInteractor.h>
54 #include <vtkCallbackCommand.h>
55 #include <vtkRendererCollection.h>
56 #include <vtkDataSet.h>
57 #include <vtkPerspectiveTransform.h> 
58 #include <vtkMatrix4x4.h>
59
60 #include <QtxRubberBand.h>
61
62 #include <QPixmap>
63 #include <QWidget>
64 #include <QPolygon>
65
66 #include <algorithm>
67 #include <iostream>
68
69 namespace
70 {
71   inline void 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
81 vtkStandardNewMacro(SVTK_InteractorStyle);
82
83
84 /*!
85   Constructor
86 */
87 SVTK_InteractorStyle::SVTK_InteractorStyle():
88   mySelectionEvent(new SVTK_SelectionEvent()),
89   myPointPicker(vtkPointPicker::New()),
90   myLastHighlitedActor(NULL),
91   myLastPreHighlitedActor(NULL),
92   myControllerIncrement(SVTK_ControllerIncrement::New()),
93   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
94   myHighlightSelectionPointActor(SVTK_Actor::New()),
95   myRectBand(0),
96   myPolygonBand(0),
97   myIsAdvancedZoomingEnabled(false),
98   myPoligonState( Disable )
99 {
100   myPointPicker->Delete();
101
102   myPointPicker->SetTolerance(0.025);
103
104   this->MotionFactor = 10.0;
105   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
106   this->RadianToDegree = 180.0 / vtkMath::Pi();
107   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
108
109   loadCursors();
110
111   // set custom event handling function (to handle 3d space mouse events)
112   EventCallbackCommand->SetCallback( SVTK_InteractorStyle::ProcessEvents );
113
114   // set default values of properties.  user may edit them in preferences.
115   mySMDecreaseSpeedBtn = 1;
116   mySMIncreaseSpeedBtn = 2;
117   mySMDominantCombinedSwitchBtn = 9;
118   //
119   myControllerIncrement->Delete();
120   myControllerOnKeyDown->Delete();
121
122   myCurrRotationPointType = SVTK::SetRotateGravity;
123   myPrevRotationPointType = myCurrRotationPointType;
124
125   myCurrFocalPointType = SVTK::SetFocalPointSelected;
126   myPrevFocalPointType = myCurrFocalPointType;
127
128   myHighlightSelectionPointActor->Delete();
129   myHighlightSelectionPointActor->Initialize();
130   myHighlightSelectionPointActor->PickableOff();
131   myHighlightSelectionPointActor->SetVisibility( false );
132   
133   myHighlightSelectionPointActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE+2);
134   myHighlightSelectionPointActor->GetProperty()->SetLineWidth(SALOME_LINE_WIDTH+2);
135   myHighlightSelectionPointActor->GetProperty()->SetRepresentationToPoints();
136
137   myBBFirstCheck = true;
138 }
139
140 /*!
141   Destructor
142 */
143 SVTK_InteractorStyle::~SVTK_InteractorStyle() 
144 {
145   endDrawRect();
146   endDrawPolygon();
147 }
148
149 /*!
150   \return widget for rendering
151 */
152 QWidget* SVTK_InteractorStyle::GetRenderWidget()
153 {
154   return myInteractor->GetRenderWidget();
155 }
156
157 /*!
158   \return selector
159 */
160 SVTK_Selector* SVTK_InteractorStyle::GetSelector() 
161 {
162   return myInteractor->GetSelector();
163 }
164
165 /*!
166   Realeaze actors
167 */
168 void SVTK_InteractorStyle::FreeActors()
169 {
170   myLastHighlitedActor = NULL;
171   myLastPreHighlitedActor = NULL;
172 }
173
174 /*!
175   Generate special SVTK_SelectionEvent
176 */
177 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEvent()
178 {
179   mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
180
181   mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
182   mySelectionEvent->myIsShift = Interactor->GetShiftKey();
183
184   mySelectionEvent->myLastX = mySelectionEvent->myX;
185   mySelectionEvent->myLastY = mySelectionEvent->myY;
186
187   GetEventPosition( this->Interactor, mySelectionEvent->myX, mySelectionEvent->myY );
188
189   return mySelectionEvent.get();
190 }
191
192 /*!
193   Generate special SVTK_SelectionEvent with flipped Y coordinate
194 */
195 SVTK_SelectionEvent* SVTK_InteractorStyle::GetSelectionEventFlipY()
196 {
197   mySelectionEvent->mySelectionMode = GetSelector()->SelectionMode();
198
199   mySelectionEvent->myIsCtrl = Interactor->GetControlKey();
200   mySelectionEvent->myIsShift = Interactor->GetShiftKey();
201
202   mySelectionEvent->myLastX = mySelectionEvent->myX;
203   mySelectionEvent->myLastY = mySelectionEvent->myY;
204
205   this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
206
207   return mySelectionEvent.get();
208 }
209
210 void SVTK_InteractorStyle::RotateXY(int dx, int dy)
211 {
212   /*   if(GetCurrentRenderer() == NULL)
213     return;
214   
215   int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
216   double aDeltaElevation = -20.0 / size[1];
217   double aDeltaAzimuth = -20.0 / size[0];
218   
219   double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
220   double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
221   
222   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
223   cam->Azimuth(rxf);
224   cam->Elevation(ryf);
225   cam->OrthogonalizeViewUp();
226
227   GetCurrentRenderer()->ResetCameraClippingRange(); 
228
229   this->Render();*/
230
231   if(GetCurrentRenderer() == NULL)
232     return;
233   
234   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
235
236   double viewFP[3], viewPos[3];
237   cam->GetFocalPoint(viewFP);
238   cam->GetPosition(viewPos);
239
240   if ( myCurrRotationPointType == SVTK::SetRotateGravity )
241   {
242     double aCenter[3];
243     if ( ComputeBBCenter(GetCurrentRenderer(),aCenter) ) 
244     {
245       myRotationPointX = aCenter[0];
246       myRotationPointY = aCenter[1];
247       myRotationPointZ = aCenter[2];
248     }
249   }
250
251   // Calculate corresponding transformation
252   vtkPerspectiveTransform* aTransform = vtkPerspectiveTransform::New();
253   aTransform->Identity();
254   aTransform->Translate(+myRotationPointX, +myRotationPointY, +myRotationPointZ);
255
256   // Azimuth transformation
257   int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize();
258   double aDeltaAzimuth = -20.0 / size[0];
259   
260   double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor;
261   aTransform->RotateWXYZ(rxf, cam->GetViewUp());
262
263   // Elevation transformation
264   double aDeltaElevation = -20.0 / size[1];
265
266   double ryf = double(dy) * aDeltaElevation * this->MotionFactor;
267   vtkMatrix4x4* aMatrix = cam->GetViewTransformMatrix();
268   const double anAxis[3] = {-aMatrix->GetElement(0,0), // mkr : 27.11.2006 : PAL14011 - Strange behaviour in rotation in VTK Viewer.
269                             -aMatrix->GetElement(0,1), 
270                             -aMatrix->GetElement(0,2)};
271   
272   aTransform->RotateWXYZ(ryf, anAxis);
273             
274   aTransform->Translate(-myRotationPointX, -myRotationPointY, -myRotationPointZ);
275
276   // To apply the transformation
277   cam->SetPosition(aTransform->TransformPoint(viewPos));
278   cam->SetFocalPoint(aTransform->TransformPoint(viewFP));
279   aTransform->Delete();
280
281   cam->OrthogonalizeViewUp();
282
283   GetCurrentRenderer()->ResetCameraClippingRange(); 
284
285   this->Render();
286   this->InvokeEvent(SVTK::OperationFinished,NULL);
287 }
288
289 void SVTK_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
290 {
291   TranslateView(x, y, oldX, oldY);   
292   this->Render();
293   this->InvokeEvent(SVTK::OperationFinished,NULL);
294 }
295
296 void SVTK_InteractorStyle::DollyXY(int dx, int dy)
297 {
298   if (GetCurrentRenderer() == NULL) 
299     return;
300
301   double dxf = this->MotionFactor * (double)(dx) / (double)(GetCurrentRenderer()->GetCenter()[1]);
302   double dyf = this->MotionFactor * (double)(dy) / (double)(GetCurrentRenderer()->GetCenter()[1]);
303
304   double zoomFactor = pow((double)1.1, dxf + dyf);
305   
306   vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
307   if (aCam->GetParallelProjection()) {
308     int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
309     if( IsAdvancedZoomingEnabled() ) { // zoom relatively to the cursor
310       int* aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
311       int w = aSize[0];
312       int h = aSize[1];
313       x0 = w / 2;
314       y0 = h / 2;
315       x1 = myOtherPoint.x();
316       y1 = h - myOtherPoint.y();
317       TranslateView( x0, y0, x1, y1 );
318     }
319     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
320     if( IsAdvancedZoomingEnabled() )
321       TranslateView( x1, y1, x0, y0 );
322   }
323   else{
324     aCam->Dolly(zoomFactor); // Move camera in/out along projection direction
325     GetCurrentRenderer()->ResetCameraClippingRange(); 
326   }
327
328   this->Render();
329   this->InvokeEvent(SVTK::OperationFinished,NULL);
330 }
331
332 void SVTK_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
333 {
334   vtkCamera *cam;
335
336   if (GetCurrentRenderer() == NULL)
337     return;
338
339   double newAngle = atan2((double)(y - GetCurrentRenderer()->GetCenter()[1]),
340                           (double)(x - GetCurrentRenderer()->GetCenter()[0]));
341   double oldAngle = atan2((double)(oldY -GetCurrentRenderer()->GetCenter()[1]),
342                           (double)(oldX - GetCurrentRenderer()->GetCenter()[0]));
343   
344   newAngle *= this->RadianToDegree;
345   oldAngle *= this->RadianToDegree;
346
347   cam = GetCurrentRenderer()->GetActiveCamera();
348   cam->Roll(newAngle - oldAngle);
349   cam->OrthogonalizeViewUp();
350       
351   this->Render();
352   this->InvokeEvent(SVTK::OperationFinished,NULL);
353 }
354
355
356 /*!
357   To reset reset view
358 */
359 void SVTK_InteractorStyle::OnConfigure() 
360 {
361   this->FindPokedRenderer(0,0);
362   this->GetCurrentRenderer()->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
363 }
364
365 /*!
366   To handle mouse move event
367 */
368 void SVTK_InteractorStyle::OnMouseMove() 
369 {
370   int x, y;
371   GetEventPosition( this->Interactor, x, y );
372   this->OnMouseMove( this->Interactor->GetControlKey(),
373                      this->Interactor->GetShiftKey(),
374                      x, y );
375 }
376
377 /*!
378   To handle left mouse button down event (reimplemented from vtkInteractorStyle)
379 */
380 void SVTK_InteractorStyle::OnLeftButtonDown()
381 {
382   int x, y;
383   GetEventPosition( this->Interactor, x, y );
384   this->OnLeftButtonDown( this->Interactor->GetControlKey(),
385                           this->Interactor->GetShiftKey(),
386                           x, y );
387 }
388
389 /*!
390   To handle left mouse button up event (reimplemented from vtkInteractorStyle)
391 */
392 void SVTK_InteractorStyle::OnLeftButtonUp()
393 {
394   int x, y;
395   GetEventPosition( this->Interactor, x, y );
396   this->OnLeftButtonUp( this->Interactor->GetControlKey(),
397                         this->Interactor->GetShiftKey(),
398                         x, y );
399 }
400
401 /*!
402   To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
403 */
404 void SVTK_InteractorStyle::OnMiddleButtonDown() 
405 {
406   int x, y;
407   GetEventPosition( this->Interactor, x, y );
408   this->OnMiddleButtonDown( this->Interactor->GetControlKey(),
409                             this->Interactor->GetShiftKey(),
410                             x, y );
411 }
412
413 /*!
414   To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
415 */
416 void SVTK_InteractorStyle::OnMiddleButtonUp()
417 {
418   int x, y;
419   GetEventPosition( this->Interactor, x, y );
420   this->OnMiddleButtonUp( this->Interactor->GetControlKey(),
421                           this->Interactor->GetShiftKey(),
422                           x, y );
423 }
424
425 /*!
426   To handle right mouse button down event (reimplemented from vtkInteractorStyle)
427 */
428 void SVTK_InteractorStyle::OnRightButtonDown() 
429 {
430   int x, y;
431   GetEventPosition( this->Interactor, x, y );
432   this->OnRightButtonDown( this->Interactor->GetControlKey(),
433                            this->Interactor->GetShiftKey(),
434                            x, y );
435 }
436
437 /*!
438   To handle right mouse button up event (reimplemented from vtkInteractorStyle)
439 */
440 void SVTK_InteractorStyle::OnRightButtonUp()
441 {
442   int x, y;
443   GetEventPosition( this->Interactor, x, y );
444   this->OnRightButtonUp( this->Interactor->GetControlKey(),
445                          this->Interactor->GetShiftKey(),
446                          x, y );
447 }
448
449 /*!
450   To handle mouse wheel forward event (reimplemented from #vtkInteractorStyle)
451 */
452 void SVTK_InteractorStyle::OnMouseWheelForward()
453 {
454   int x, y;
455   GetEventPosition( this->Interactor, x, y );
456   myOtherPoint = QPoint(x, y);
457 }
458
459 /*!
460   To handle mouse wheel backward event (reimplemented from #vtkInteractorStyle)
461 */
462 void SVTK_InteractorStyle::OnMouseWheelBackward()
463 {
464   int x, y;
465   GetEventPosition( this->Interactor, x, y );
466   myOtherPoint = QPoint(x, y);
467 }
468
469 /*!
470   To handle mouse double click event
471 */
472 void SVTK_InteractorStyle::OnMouseButtonDoubleClick()
473 {
474   if( myPoligonState == InProcess ) {
475     onFinishOperation();
476     myPoligonState = Finished;
477   }
478 }
479
480 /*!
481   To handle mouse move event
482 */
483 void SVTK_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl), 
484                                        int shift,
485                                        int x, int y) 
486 {
487   if ( myPoligonState == Start ) {
488     // if right button was pressed and mouse is moved
489     // we can to draw a polygon for polygonal selection
490     myPoligonState = InProcess;
491     startOperation( VTK_INTERACTOR_STYLE_CAMERA_SELECT );
492   }
493   myShiftState = shift;
494   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
495     onOperation(QPoint(x, y));
496   else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
497     onCursorMove(QPoint(x, y));
498 }
499
500 /*!
501   To handle left mouse button down event (reimplemented from vtkInteractorStyle)
502 */
503 void SVTK_InteractorStyle::OnLeftButtonDown(int ctrl, int shift, 
504                                             int x, int y) 
505 {
506   this->FindPokedRenderer(x, y);
507   if(GetCurrentRenderer() == NULL)
508     return;
509
510   if ( myPoligonState != Disable )
511     return;
512
513   myShiftState = shift;
514   // finishing current viewer operation
515   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
516     onFinishOperation();
517     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
518   }
519   myOtherPoint = myPoint = QPoint(x, y);
520   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
521     startOperation(ForcedState);
522   } else {
523     if (ctrl)
524       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
525     else if ( myCurrRotationPointType == SVTK::StartPointSelection ||
526               myCurrFocalPointType == SVTK::StartFocalPointSelection )
527     {
528       SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
529
530       bool isPicked = false;
531       vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
532       
533       if( anActorCollection )
534       {
535         anActorCollection->InitTraversal();
536         while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
537         {
538           if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
539           {
540                 Selection_Mode aSelectionMode = GetSelector()->SelectionMode();
541                 double* aCoords;
542                 int aVtkId;
543                 bool isTrueType = false;
544                 
545                 if( myCurrFocalPointType == SVTK::StartFocalPointSelection ||
546                         ( myCurrRotationPointType == SVTK::StartPointSelection && aSelectionMode == NodeSelection ) )
547                 {
548               SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
549               myPointPicker->Pick( aSelectionEvent->myX,
550                                    aSelectionEvent->myY,
551                                    0.0,
552                                    GetCurrentRenderer() );
553               aVtkId = myPointPicker->GetPointId();
554               if ( aVtkId >= 0 )
555               {
556                 int anObjId = anActor->GetNodeObjId( aVtkId );
557                 aCoords = anActor->GetNodeCoord(anObjId);
558                 isTrueType = true;
559               }
560                 }
561
562                 if( aSelectionMode == EdgeSelection || aSelectionMode == FaceSelection ||  aSelectionMode == VolumeSelection )
563                 {
564               vtkSmartPointer<vtkCellPicker> aCellPicker = vtkCellPicker::New();
565               aCellPicker->SetTolerance( 0.005 );
566               SVTK::TPickLimiter aPickLimiter( aCellPicker, anActor );
567               aCellPicker->Pick( aSelectionEvent->myX,
568                                  aSelectionEvent->myY,
569                                  0.0,
570                                  GetCurrentRenderer() );
571               aVtkId = aCellPicker->GetCellId();
572               int aCellId = anActor->GetElemObjId( aVtkId );
573
574               if( aSelectionMode == EdgeSelection )
575                 isTrueType = anActor->GetObjDimension( aCellId ) == 1;
576               else if( aSelectionMode == FaceSelection )
577                 isTrueType = anActor->GetObjDimension( aCellId ) == 2;
578               else if( aSelectionMode == VolumeSelection )
579                 isTrueType = anActor->GetObjDimension( aCellId ) == 3;
580
581               if ( aVtkId >= 0 && isTrueType )
582                 aCoords = anActor->GetGravityCenter( aCellId );
583                 }
584
585                 if( aVtkId >= 0 )
586                 {
587               if (myCurrRotationPointType == SVTK::StartPointSelection) {
588                 myCurrRotationPointType = SVTK::SetRotateSelected;
589                 // invoke event for update coordinates in SVTK_SetRotationPointDlg
590                 if( isTrueType )
591                   InvokeEvent(SVTK::RotationPointChanged,(void*)aCoords);
592                 else
593                   InvokeEvent(SVTK::RotationPointChanged);
594                 GetSelector()->SetSelectionMode(ActorSelection);
595               }
596               else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
597                 myCurrFocalPointType = SVTK::SetFocalPointSelected;
598                 
599                 // invoke event for update coordinates in SVTK_ViewParameterDlg
600                 InvokeEvent(SVTK::FocalPointChanged,(void*)aCoords);
601               }
602
603               isPicked = true;
604               break;
605             }
606           }
607         }
608       }
609
610       if( !isPicked )
611       {
612         if (myCurrRotationPointType == SVTK::StartPointSelection) {
613           // invoke event with no data (for SVTK_SetRotationPointDlg)
614           InvokeEvent(SVTK::RotationPointChanged,0);
615           myCurrRotationPointType = myPrevRotationPointType;
616           GetSelector()->SetSelectionMode(ActorSelection);
617         }
618         else if (myCurrFocalPointType == SVTK::StartFocalPointSelection) {
619           // invoke event with no data (for SVTK_ViewParameterDlg)
620           InvokeEvent(SVTK::FocalPointChanged,0);
621           myCurrFocalPointType = myPrevFocalPointType;
622         }
623       }
624     
625       myHighlightSelectionPointActor->SetVisibility( false );
626       if(GetCurrentRenderer() != NULL)
627         GetCurrentRenderer()->RemoveActor( myHighlightSelectionPointActor.GetPointer() );
628
629       GetRenderWidget()->setCursor(myDefCursor); 
630     }
631     else
632       startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
633   }
634   
635   return;
636 }
637
638 /*!
639   To handle left mouse button up event (reimplemented from vtkInteractorStyle)
640 */
641 void SVTK_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
642                                           int shift, 
643                                           int x,
644                                           int y)
645 {
646   myShiftState = shift;
647   if( myPoligonState == InProcess ) { // add a new point of polygon
648     myPolygonPoints.append( QPoint( x, y ) );
649     this->Interactor->GetEventPosition( mySelectionEvent->myX, mySelectionEvent->myY );
650     mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY ) );
651     return;
652   }
653   else if ( myPoligonState == Closed ) { // close polygon and apply a selection
654     onFinishOperation();
655     myPoligonState = Finished;
656     return;
657   }
658   else if( myPoligonState == Finished || myPoligonState == NotValid )
659     return;
660   // finishing current viewer operation
661   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
662     onFinishOperation();
663     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
664   }
665 }
666
667 /*!
668   To handle middle mouse button down event (reimplemented from vtkInteractorStyle)
669 */
670 void SVTK_InteractorStyle::OnMiddleButtonDown(int ctrl,
671                                               int shift, 
672                                               int x, int y) 
673 {
674   this->FindPokedRenderer(x, y);
675   if(GetCurrentRenderer() == NULL)
676     return;
677
678   if ( myPoligonState != Disable )
679     return;
680
681   myShiftState = shift;
682   // finishing current viewer operation
683   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
684     onFinishOperation();
685     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
686   }
687   myOtherPoint = myPoint = QPoint(x, y);
688   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
689     startOperation(ForcedState);
690   }
691   else {
692     if (ctrl)
693       startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
694   }
695 }
696
697
698 /*!
699   To handle middle mouse button up event (reimplemented from vtkInteractorStyle)
700 */
701 void SVTK_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
702                                             int shift, 
703                                             int vtkNotUsed(x),
704                                             int vtkNotUsed(y))
705 {
706   if( myPoligonState == InProcess ) { // delete a point of polygon
707     if ( myPolygonPoints.size() > 2 ) {
708       myPolygonPoints.remove( myPolygonPoints.size() - 1 );
709       mySelectionEvent->myPolygonPoints.remove( mySelectionEvent->myPolygonPoints.size() - 1 );
710     }
711     return;
712   }
713   myShiftState = shift;
714   // finishing current viewer operation
715   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
716     onFinishOperation();
717     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
718   }
719 }
720
721
722 /*!
723   To handle right mouse button down event (reimplemented from vtkInteractorStyle)
724 */
725 void SVTK_InteractorStyle::OnRightButtonDown(int ctrl,
726                                              int shift, 
727                                              int x, int y) 
728 {
729   this->FindPokedRenderer(x, y);
730   if(GetCurrentRenderer() == NULL)
731     return;
732
733   myShiftState = shift;
734
735   if ( !ctrl ) {
736     myPoligonState = Start;
737     this->Interactor->GetEventPosition(mySelectionEvent->myX, mySelectionEvent->myY);
738     mySelectionEvent->myPolygonPoints.append( QPoint( mySelectionEvent->myX, mySelectionEvent->myY) );
739   }
740   // finishing current viewer operation
741   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
742     onFinishOperation();
743     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
744   }
745   myOtherPoint = myPoint = QPoint(x, y);
746   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
747     startOperation(ForcedState);
748   }
749   else {
750     if (ctrl)
751       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);  
752   }
753 }
754
755 /*!
756   To handle right mouse button up event (reimplemented from vtkInteractorStyle)
757 */
758 void SVTK_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
759                                            int shift, 
760                                            int vtkNotUsed(x),
761                                            int vtkNotUsed(y))
762 {
763   if( myPoligonState == Start ) { // if right button was pressed but mouse is not moved
764     myPoligonState = Disable;
765     mySelectionEvent->myPolygonPoints.clear();
766   }
767
768   if( myPoligonState != Disable ) {
769     endDrawPolygon();
770     myPoligonState = Finished;
771     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
772     return;
773   }
774
775   myShiftState = shift;
776   // finishing current viewer operation
777   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
778     onFinishOperation();
779     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
780   }
781 }
782
783 /* XPM */
784 const char* imageZoomCursor[] = { 
785 "32 32 3 1",
786 ". c None",
787 "a c #000000",
788 "# c #ffffff",
789 "................................",
790 "................................",
791 ".#######........................",
792 "..aaaaaaa.......................",
793 "................................",
794 ".............#####..............",
795 "...........##.aaaa##............",
796 "..........#.aa.....a#...........",
797 ".........#.a.........#..........",
798 ".........#a..........#a.........",
799 "........#.a...........#.........",
800 "........#a............#a........",
801 "........#a............#a........",
802 "........#a............#a........",
803 "........#a............#a........",
804 ".........#...........#.a........",
805 ".........#a..........#a.........",
806 ".........##.........#.a.........",
807 "........#####.....##.a..........",
808 ".......###aaa#####.aa...........",
809 "......###aa...aaaaa.......#.....",
810 ".....###aa................#a....",
811 "....###aa.................#a....",
812 "...###aa...............#######..",
813 "....#aa.................aa#aaaa.",
814 ".....a....................#a....",
815 "..........................#a....",
816 "...........................a....",
817 "................................",
818 "................................",
819 "................................",
820 "................................"};
821
822 const char* imageRotateCursor[] = { 
823 "32 32 3 1",
824 ". c None",
825 "a c #000000",
826 "# c #ffffff",
827 "................................",
828 "................................",
829 "................................",
830 "................................",
831 "........#.......................",
832 ".......#.a......................",
833 "......#######...................",
834 ".......#aaaaa#####..............",
835 "........#..##.a#aa##........##..",
836 ".........a#.aa..#..a#.....##.aa.",
837 ".........#.a.....#...#..##.aa...",
838 ".........#a.......#..###.aa.....",
839 "........#.a.......#a..#aa.......",
840 "........#a.........#..#a........",
841 "........#a.........#a.#a........",
842 "........#a.........#a.#a........",
843 "........#a.........#a.#a........",
844 ".........#.........#a#.a........",
845 "........##a........#a#a.........",
846 "......##.a#.......#.#.a.........",
847 "....##.aa..##.....##.a..........",
848 "..##.aa.....a#####.aa...........",
849 "...aa.........aaa#a.............",
850 "................#.a.............",
851 "...............#.a..............",
852 "..............#.a...............",
853 "...............a................",
854 "................................",
855 "................................",
856 "................................",
857 "................................",
858 "................................"};
859
860
861 /*!
862   loads cursors for viewer operations - zoom, pan, etc...
863 */
864 void SVTK_InteractorStyle::loadCursors()
865 {
866   myDefCursor       = QCursor(Qt::ArrowCursor);
867   myHandCursor      = QCursor(Qt::PointingHandCursor);
868   myPanCursor       = QCursor(Qt::SizeAllCursor);
869   myZoomCursor      = QCursor(QPixmap(imageZoomCursor));
870   myRotateCursor    = QCursor(QPixmap(imageRotateCursor));
871   mySpinCursor      = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
872   myGlobalPanCursor = QCursor(Qt::CrossCursor);
873   myCursorState     = false;
874 }
875
876
877 /*!
878   Starts Zoom operation (e.g. through menu command)
879 */
880 void SVTK_InteractorStyle::startZoom()
881 {
882   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
883   {
884     onFinishOperation();
885     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
886   }
887   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
888   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
889 }
890
891
892 /*!
893   Starts Pan operation (e.g. through menu command)
894 */
895 void SVTK_InteractorStyle::startPan()
896 {
897   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
898   {
899     onFinishOperation();
900     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
901   }
902   setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
903   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
904 }
905
906 /*!
907   Starts Rotate operation (e.g. through menu command)
908 */
909 void SVTK_InteractorStyle::startRotate()
910 {
911   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
912   {
913     onFinishOperation();
914     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
915   }
916   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
917   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
918 }
919
920 /*!
921   Set rotation point selected by user
922 */
923 void SVTK_InteractorStyle::startPointSelection()
924 {
925   myCurrRotationPointType = SVTK::StartPointSelection;
926
927   if(GetCurrentRenderer() != NULL) {
928     GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
929     double aColor[3];
930     GetCurrentRenderer()->GetBackground( aColor );
931     myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
932                                                             1. - aColor[1],
933                                                             1. - aColor[2]);
934   }
935
936   setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
937 }
938
939 /*!
940   Set focal point selected by user
941 */
942 void SVTK_InteractorStyle::startFocalPointSelection()
943 {
944   myCurrFocalPointType = SVTK::StartFocalPointSelection;
945
946   if(GetCurrentRenderer() != NULL) {
947     GetCurrentRenderer()->AddActor( myHighlightSelectionPointActor.GetPointer() );
948     double aColor[3];
949     GetCurrentRenderer()->GetBackground( aColor );
950     myHighlightSelectionPointActor->GetProperty()->SetColor(1. - aColor[0],
951                                                             1. - aColor[1],
952                                                             1. - aColor[2]);
953   }
954
955   setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
956 }
957
958 /*! 
959   Starts Spin operation (e.g. through menu command)
960 */
961 void SVTK_InteractorStyle::startSpin()
962 {
963   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
964   {
965     onFinishOperation();
966     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
967   }
968   setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
969   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
970 }
971
972
973
974 /*!
975   Starts Fit Area operation (e.g. through menu command)
976 */
977 void SVTK_InteractorStyle::startFitArea()
978 {
979   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
980   {
981     onFinishOperation();
982     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
983   }
984   setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
985   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
986 }
987
988
989 /*!
990   Starts Global Panning operation (e.g. through menu command)
991 */
992 void SVTK_InteractorStyle::startGlobalPan()
993 {
994   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
995   {
996     onFinishOperation();
997     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
998   }
999   setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
1000   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
1001
1002   // store current zoom scale
1003   myScale = GetCurrentRenderer()->GetActiveCamera()->GetParallelScale();
1004
1005   GetCurrentRenderer()->ResetCamera();
1006
1007   this->Render();
1008 }
1009
1010
1011 /*!
1012   Fits viewer contents to rect
1013 */
1014 void SVTK_InteractorStyle::fitRect(const int left, 
1015                                    const int top, 
1016                                    const int right, 
1017                                    const int bottom)
1018 {
1019   if (GetCurrentRenderer() == NULL) 
1020     return;
1021  
1022   // move camera
1023   int x = (left + right)/2;
1024   int y = (top + bottom)/2;
1025   int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1026   int oldX = aSize[0]/2;
1027   int oldY = aSize[1]/2;
1028   TranslateView(oldX, oldY, x, y);
1029
1030   // zoom camera
1031   double dxf = right == left ? 1.0 : (double)(aSize[0]) / (double)(abs(right - left));
1032   double dyf = bottom == top ? 1.0 : (double)(aSize[1]) / (double)(abs(bottom - top));
1033   double zoomFactor = (dxf + dyf)/2 ;
1034
1035   vtkCamera *aCam = GetCurrentRenderer()->GetActiveCamera();
1036   if(aCam->GetParallelProjection())
1037     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
1038   else{
1039     aCam->Dolly(zoomFactor);
1040     GetCurrentRenderer()->ResetCameraClippingRange();
1041   }
1042   
1043   this->Render();
1044 }
1045
1046
1047 /*!
1048   Starts viewer operation (!internal usage!)
1049 */
1050 void SVTK_InteractorStyle::startOperation(int operation)
1051 {
1052   switch(operation)
1053   { 
1054   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1055   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1056   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1057   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1058   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1059   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1060   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1061     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
1062       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1063     State = operation;
1064     if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
1065       setCursor(operation);
1066     onStartOperation();
1067     break;
1068   case VTK_INTERACTOR_STYLE_CAMERA_NONE:
1069   default:
1070     setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1071     State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
1072     break;
1073   }
1074 }
1075
1076
1077 /*!
1078   Sets proper cursor for window when viewer operation is activated
1079 */
1080 void SVTK_InteractorStyle::setCursor(const int operation)
1081 {
1082   if (!GetRenderWidget()) return;
1083   switch (operation)
1084   {
1085     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1086       GetRenderWidget()->setCursor(myZoomCursor); 
1087       myCursorState = true;
1088       break;
1089     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1090       GetRenderWidget()->setCursor(myPanCursor); 
1091       myCursorState = true;
1092       break;
1093     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1094       GetRenderWidget()->setCursor(myRotateCursor); 
1095       myCursorState = true;
1096       break;
1097     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1098       GetRenderWidget()->setCursor(mySpinCursor); 
1099       myCursorState = true;
1100       break;
1101     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1102       GetRenderWidget()->setCursor(myGlobalPanCursor); 
1103       myCursorState = true;
1104       break;
1105     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1106     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1107       GetRenderWidget()->setCursor(myHandCursor); 
1108       myCursorState = true;
1109       break;
1110     case VTK_INTERACTOR_STYLE_CAMERA_NONE:
1111     default:
1112       if ( myCurrRotationPointType == SVTK::StartPointSelection ||
1113            myCurrFocalPointType == SVTK::StartFocalPointSelection )
1114         GetRenderWidget()->setCursor(myHandCursor);
1115       else
1116         GetRenderWidget()->setCursor(myDefCursor); 
1117       myCursorState = false;
1118       break;
1119   }
1120 }
1121
1122
1123 /*!
1124   Called when viewer operation started (!put necessary initialization here!)
1125 */
1126 void SVTK_InteractorStyle::onStartOperation()
1127 {
1128   if (!GetRenderWidget()) 
1129     return;
1130
1131   vtkRenderWindowInteractor *aRWI = this->Interactor;
1132   vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
1133   aRenWin->SetDesiredUpdateRate(aRWI->GetDesiredUpdateRate());
1134
1135   switch (State) {
1136     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1137     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1138     {
1139       if ( myPoligonState == InProcess )
1140         drawPolygon();
1141       else
1142         drawRect();
1143       break;
1144     }
1145     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1146     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1147     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1148     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1149     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1150       break;
1151   }
1152 }
1153
1154
1155 /*!
1156   Called when viewer operation finished (!put necessary post-processing here!)
1157 */
1158 void SVTK_InteractorStyle::onFinishOperation() 
1159 {
1160   if (!GetRenderWidget()) 
1161     return;
1162
1163   vtkRenderWindowInteractor *aRWI = this->Interactor;
1164   vtkRenderWindow *aRenWin = aRWI->GetRenderWindow();
1165   aRenWin->SetDesiredUpdateRate(aRWI->GetStillUpdateRate());
1166
1167   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1168
1169   switch (State) {
1170     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1171     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1172     {
1173       endDrawRect();
1174       QRect aRect(myPoint, myOtherPoint);
1175       aRect = aRect.normalized();
1176
1177       if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
1178         // making fit rect opeation 
1179         int w, h;
1180         Interactor->GetSize(w, h);
1181         int x1 = aRect.left(); 
1182         int y1 = h - aRect.top() - 1;
1183         int x2 = aRect.right(); 
1184         int y2 = h - aRect.bottom() - 1;
1185         fitRect(x1, y1, x2, y2);
1186       }
1187       else {
1188         if (myPoint == myOtherPoint)
1189         {
1190           // process point selection
1191           this->FindPokedRenderer(aSelectionEvent->myX, aSelectionEvent->myY);
1192           Interactor->StartPickCallback();
1193             
1194           SALOME_Actor* aHighlightedActor = NULL;
1195           vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1196
1197           aSelectionEvent->myIsRectangle = false;
1198           aSelectionEvent->myIsPolygon = false;
1199           if(!myShiftState)
1200             GetSelector()->ClearIObjects();
1201
1202           if( anActorCollection )
1203           {
1204             if( !myShiftState && 
1205                 anActorCollection->GetNumberOfItems () > 1 && 
1206                 myLastHighlitedActor.GetPointer() ) {
1207               anActorCollection->RemoveItem ( myLastHighlitedActor.GetPointer() );
1208             }
1209             anActorCollection->InitTraversal();
1210             while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1211             {
1212               if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1213               {
1214                 if( anActor->Highlight( this, aSelectionEvent, true ) )
1215                 {
1216                   aHighlightedActor = anActor;
1217                   break;
1218                 }
1219               }
1220             }
1221           }
1222
1223           if( !aHighlightedActor )
1224           {
1225             if(myLastHighlitedActor.GetPointer() && myLastHighlitedActor.GetPointer() != aHighlightedActor)
1226               myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
1227           }
1228           myLastHighlitedActor = aHighlightedActor;
1229         }
1230         else
1231         {
1232           if ( myPoligonState == InProcess || myPoligonState == Closed )
1233             aSelectionEvent->myIsPolygon = true;
1234           else
1235             aSelectionEvent->myIsRectangle = true;
1236
1237           //processing polygonal selection
1238           Interactor->StartPickCallback();
1239           GetSelector()->StartPickCallback();
1240
1241           if(!myShiftState)
1242             GetSelector()->ClearIObjects();
1243
1244           VTK::ActorCollectionCopy aCopy(GetCurrentRenderer()->GetActors());
1245           vtkActorCollection* aListActors = aCopy.GetActors();
1246           aListActors->InitTraversal();
1247           while(vtkActor* aActor = aListActors->GetNextActor())
1248           {
1249             if(aActor->GetVisibility())
1250             {
1251               if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor))
1252               {
1253                 if(aSActor->hasIO())
1254                   aSActor->Highlight( this, aSelectionEvent, true );
1255               }
1256             }
1257           }
1258         }
1259         aSelectionEvent->myIsRectangle = false;
1260         aSelectionEvent->myIsPolygon = false;
1261         aSelectionEvent->myPolygonPoints.clear();
1262         endDrawPolygon();
1263         Interactor->EndPickCallback();
1264         GetSelector()->EndPickCallback();
1265       } 
1266       break;
1267     }
1268     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
1269     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
1270     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
1271     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
1272       break;
1273     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
1274     {
1275       int w, h, x, y;
1276       Interactor->GetSize(w, h);
1277       x = myPoint.x(); 
1278       y = h - myPoint.y() - 1;
1279       Place(x, y);
1280     }
1281     break;
1282   }
1283
1284   this->Render();
1285 }
1286
1287
1288 /*!
1289   Called during viewer operation when user moves mouse (!put necessary processing here!)
1290 */
1291 void SVTK_InteractorStyle::onOperation(QPoint mousePos) 
1292 {
1293   if (!GetRenderWidget()) 
1294     return;
1295
1296   switch (State) {
1297   case VTK_INTERACTOR_STYLE_CAMERA_PAN: 
1298     {
1299       this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
1300       myPoint = mousePos;
1301       break;
1302     }
1303   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: 
1304     {    
1305       this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
1306       myPoint = mousePos;
1307       break;
1308     }
1309   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: 
1310     {
1311       this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
1312       myPoint = mousePos;
1313       break;
1314     }
1315   case VTK_INTERACTOR_STYLE_CAMERA_SPIN: 
1316     {
1317       this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
1318       myPoint = mousePos;
1319       break;
1320     }
1321   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
1322     {    
1323       break;
1324     }
1325   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
1326     {
1327       if (!myCursorState)
1328         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1329     }
1330   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
1331     {
1332       myOtherPoint = mousePos;
1333       if ( myPoligonState == InProcess || myPoligonState == Closed || myPoligonState == NotValid )
1334         drawPolygon();
1335       else if ( myPoligonState != Finished )
1336         drawRect();
1337       break;
1338     }
1339   }
1340 }
1341
1342 /*!
1343   Called when user moves mouse inside viewer window and there is no active viewer operation 
1344   (!put necessary processing here!)
1345 */
1346 void SVTK_InteractorStyle::onCursorMove(QPoint mousePos) 
1347 {
1348   if ( !GetSelector()->IsPreSelectionEnabled() ) 
1349     return;
1350
1351   // processing highlighting
1352   SVTK_SelectionEvent* aSelectionEvent = GetSelectionEventFlipY();
1353   this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
1354
1355   bool anIsChanged = false;
1356
1357   SALOME_Actor* aPreHighlightedActor = NULL;
1358   vtkActorCollection* anActorCollection = GetSelector()->Pick(aSelectionEvent, GetCurrentRenderer());
1359
1360   if ( myCurrFocalPointType == SVTK::StartFocalPointSelection )
1361   {
1362     myHighlightSelectionPointActor->SetVisibility( false );
1363
1364     if( anActorCollection )
1365     {
1366       anActorCollection->InitTraversal();
1367       while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1368       {
1369         if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1370         {
1371           SVTK::TPickLimiter aPickLimiter( myPointPicker, anActor );
1372           myPointPicker->Pick( aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer() );
1373           int aVtkId = myPointPicker->GetPointId();
1374           if ( aVtkId >= 0 ) {
1375             int anObjId = anActor->GetNodeObjId( aVtkId );
1376
1377             TColStd_IndexedMapOfInteger aMapIndex;
1378             aMapIndex.Add( anObjId );
1379             myHighlightSelectionPointActor->MapPoints( anActor, aMapIndex );
1380
1381             myHighlightSelectionPointActor->SetVisibility( true );
1382             anIsChanged = true;
1383             break;
1384           }
1385         }
1386       }
1387     }
1388   }
1389   else {
1390     if( anActorCollection )
1391     {
1392       anActorCollection->InitTraversal();
1393       while( vtkActor* aVTKActor = anActorCollection->GetNextActor() )
1394       {
1395         if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( aVTKActor ) )
1396         {
1397           anIsChanged = anActor->PreHighlight( this, aSelectionEvent, true );
1398           if( anActor->isPreselected() )
1399           {
1400             aPreHighlightedActor = anActor;
1401             break;
1402           }
1403         }
1404       }
1405     }
1406
1407     if(myLastPreHighlitedActor.GetPointer() && myLastPreHighlitedActor.GetPointer() != aPreHighlightedActor)
1408       anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );   
1409
1410   }
1411   
1412   myLastPreHighlitedActor = aPreHighlightedActor;
1413
1414   if(anIsChanged)
1415     this->Render();
1416 }
1417
1418 /*!
1419   Called on finsh GlobalPan operation 
1420 */
1421 void SVTK_InteractorStyle::Place(const int theX, const int theY) 
1422 {
1423   if (GetCurrentRenderer() == NULL)
1424     return;
1425
1426   //translate view
1427   int *aSize = GetCurrentRenderer()->GetRenderWindow()->GetSize();
1428   int centerX = aSize[0]/2;
1429   int centerY = aSize[1]/2;
1430
1431   TranslateView(centerX, centerY, theX, theY);
1432
1433   // restore zoom scale
1434   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1435   cam->SetParallelScale(myScale);
1436   GetCurrentRenderer()->ResetCameraClippingRange();
1437
1438   this->Render();
1439 }
1440
1441
1442
1443 /*!
1444   Translates view from Point to Point
1445 */
1446 void SVTK_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
1447 {
1448   if (GetCurrentRenderer() == NULL)
1449     return;
1450
1451   vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera();
1452   double viewFocus[4], focalDepth, viewPoint[3];
1453   double newPickPoint[4], oldPickPoint[4], motionVector[3];
1454   cam->GetFocalPoint(viewFocus);
1455
1456   this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
1457                               viewFocus[2], viewFocus);
1458   focalDepth = viewFocus[2];
1459
1460   this->ComputeDisplayToWorld(double(toX), double(toY),
1461                               focalDepth, newPickPoint);
1462   this->ComputeDisplayToWorld(double(fromX),double(fromY),
1463                               focalDepth, oldPickPoint);
1464   
1465   // camera motion is reversed
1466   motionVector[0] = oldPickPoint[0] - newPickPoint[0];
1467   motionVector[1] = oldPickPoint[1] - newPickPoint[1];
1468   motionVector[2] = oldPickPoint[2] - newPickPoint[2];
1469   
1470   cam->GetFocalPoint(viewFocus);
1471   cam->GetPosition(viewPoint);
1472   cam->SetFocalPoint(motionVector[0] + viewFocus[0],
1473                      motionVector[1] + viewFocus[1],
1474                      motionVector[2] + viewFocus[2]);
1475   cam->SetPosition(motionVector[0] + viewPoint[0],
1476                    motionVector[1] + viewPoint[1],
1477                    motionVector[2] + viewPoint[2]);
1478 }
1479
1480 void SVTK_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
1481 {
1482   this->PanXY( incrX, incrY, 0, 0 );
1483 }
1484
1485 void SVTK_InteractorStyle::IncrementalZoom( const int incr )
1486 {
1487   this->DollyXY( incr, incr );
1488 }
1489
1490 void SVTK_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
1491 {
1492   this->RotateXY( incrX, -incrY );
1493 }
1494
1495 /*!
1496   Redefined in order to add an observer (callback) for custorm event (space mouse event)
1497 */
1498 void SVTK_InteractorStyle::SetInteractor( vtkRenderWindowInteractor* theInteractor )
1499 {
1500   // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
1501   Superclass::SetInteractor( theInteractor );
1502  
1503   myInteractor = dynamic_cast<SVTK_GenericRenderWindowInteractor*>(theInteractor);
1504
1505   if(theInteractor) { 
1506     // register EventCallbackCommand as observer of custorm event (3d space mouse event)
1507     theInteractor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority );
1508     theInteractor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority );
1509     theInteractor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority );
1510     theInteractor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority );
1511     theInteractor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority );
1512     theInteractor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority );
1513     theInteractor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority );
1514     theInteractor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority );
1515     theInteractor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority );
1516     theInteractor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority );
1517     theInteractor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority );
1518     theInteractor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority );
1519     theInteractor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority );
1520     theInteractor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority );
1521     theInteractor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority );
1522
1523     theInteractor->AddObserver( SVTK::SetSMDecreaseSpeedEvent, EventCallbackCommand, Priority );
1524     theInteractor->AddObserver( SVTK::SetSMIncreaseSpeedEvent, EventCallbackCommand, Priority );
1525     theInteractor->AddObserver( SVTK::SetSMDominantCombinedSwitchEvent, EventCallbackCommand, Priority );
1526
1527     theInteractor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority );
1528     theInteractor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority );
1529     theInteractor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority );
1530     theInteractor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority );
1531     theInteractor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority );
1532
1533     theInteractor->AddObserver( SVTK::SetRotateGravity, EventCallbackCommand, Priority );
1534     theInteractor->AddObserver( SVTK::StartPointSelection, EventCallbackCommand, Priority );
1535
1536     theInteractor->AddObserver( SVTK::ChangeRotationPoint, EventCallbackCommand, Priority );
1537
1538     theInteractor->AddObserver( SVTK::SetFocalPointGravity, EventCallbackCommand, Priority );
1539     theInteractor->AddObserver( SVTK::StartFocalPointSelection, EventCallbackCommand, Priority );
1540     theInteractor->AddObserver( SVTK::SetFocalPointSelected, EventCallbackCommand, Priority );
1541   }
1542 }
1543
1544 /*!
1545   To implement cached rendering
1546 */
1547 void SVTK_InteractorStyle::OnTimer() 
1548 {
1549   //vtkInteractorStyle::OnTimer();
1550   this->Interactor->Render();
1551   // check if bounding box was changed
1552   if ( GetCurrentRenderer() )
1553   {
1554     double aCurrBBCenter[3];
1555     if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
1556     {
1557       if ( !myBBFirstCheck )
1558       {
1559         if ( fabs(aCurrBBCenter[0]-myBBCenter[0]) > 1e-38 ||
1560              fabs(aCurrBBCenter[1]-myBBCenter[1]) > 1e-38 ||
1561              fabs(aCurrBBCenter[2]-myBBCenter[2]) > 1e-38 ) {
1562           // bounding box was changed => send SVTK::RotationPointChanged event
1563           // invoke event for update coordinates in SVTK_SetRotationPointDlg
1564           InvokeEvent(SVTK::BBCenterChanged,(void*)aCurrBBCenter);
1565           for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1566         }
1567       }
1568       else 
1569       {
1570         for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1571         myBBFirstCheck = false;
1572       }
1573     }
1574   }
1575 }
1576
1577 /*!
1578   To invoke #vtkRenderWindowInteractor::CreateTimer
1579 */
1580 void SVTK_InteractorStyle::Render() 
1581 {
1582   this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1583 }
1584
1585 void SVTK_InteractorStyle::onSpaceMouseMove( double* data )
1586 {
1587   // general things, do SetCurrentRenderer() within FindPokedRenderer() 
1588   int x, y;
1589   GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1590   FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1591   
1592   IncrementalZoom( (int)data[2] );        // 1. push toward / pull backward = zoom out / zoom in
1593   IncrementalPan(  (int)data[0],  (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1594   IncrementalRotate( 0,  (int)data[4] );   // 4. twist the control = rotate around Y axis
1595   IncrementalRotate( (int)data[3], 0  );   // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1596 }
1597
1598 void SVTK_InteractorStyle::onSpaceMouseButton( int button )
1599 {
1600   if( mySMDecreaseSpeedBtn == button ) {   
1601     ControllerIncrement()->Decrease();
1602   }
1603   if( mySMIncreaseSpeedBtn == button ) {    
1604     ControllerIncrement()->Increase();
1605   }
1606   if( mySMDominantCombinedSwitchBtn == button )    
1607     DominantCombinedSwitch();
1608 }
1609
1610 void SVTK_InteractorStyle::DominantCombinedSwitch()
1611 {
1612   printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1613 }
1614
1615 /*!
1616   Draws rectangle by starting and current points
1617 */
1618 void SVTK_InteractorStyle::drawRect()
1619 {
1620   if ( !myRectBand )
1621     myRectBand = new QtxRectRubberBand( GetRenderWidget() );
1622
1623   myRectBand->setUpdatesEnabled ( false );
1624   QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
1625   myRectBand->initGeometry( aRect );
1626
1627   if ( !myRectBand->isVisible() )
1628     myRectBand->show();
1629
1630   myRectBand->setUpdatesEnabled ( true );
1631 }
1632
1633 /*!
1634   \brief Delete rubber band on the end on the dragging operation.
1635 */
1636 void SVTK_InteractorStyle::endDrawRect()
1637 {
1638   if ( myRectBand ) {
1639     myRectBand->clearGeometry();
1640     myRectBand->hide();
1641   }
1642 }
1643
1644 bool isIntersect( const QPoint& theStart1, const QPoint& theEnd1,
1645                   const QPoint& theStart2, const QPoint& theEnd2 )
1646 {
1647   if ( ( theStart1 == theStart2 && theEnd1 == theEnd2 ) ||
1648        ( theStart1 == theEnd2 && theEnd1 == theStart2 ) )
1649     return true;
1650
1651   if ( theStart1 == theStart2 || theStart2 == theEnd1 ||
1652       theStart1 == theEnd2 || theEnd1 == theEnd2 )
1653     return false;
1654
1655   double x11 = theStart1.x() * 1.0;
1656   double x12 = theEnd1.x() * 1.0;
1657   double y11 = theStart1.y() * 1.0;
1658   double y12 = theEnd1.y() * 1.0;
1659
1660   double x21 = theStart2.x() * 1.0;
1661   double x22 = theEnd2.x() * 1.0;
1662   double y21 = theStart2.y() * 1.0;
1663   double y22 = theEnd2.y() * 1.0;
1664
1665   double k1 = x12 == x11 ? 0 : ( y12 - y11 ) / ( x12 - x11 );
1666   double k2 = x22 == x21 ? 0 : ( y22 - y21 ) / ( x22 - x21 );
1667
1668   double b1 = y11 - k1 * x11;
1669   double b2 = y21 - k2 * x21;
1670
1671   if ( k1 == k2 )
1672   {
1673     if ( b1 != b2 )
1674       return false;
1675     else
1676       return !( ( qMax( x11, x12 ) <= qMin( x21, x22 ) ||
1677                   qMin( x11, x12 ) >= qMax( x21, x22 ) ) &&
1678                 ( qMax( y11, y12 ) <= qMin( y21, y22 ) ||
1679                   qMin( y11, y12 ) >= qMax( y21, y22 ) ) );
1680   }
1681   else
1682   {
1683     double x0 = ( b2 - b1 ) / ( k1 - k2 );
1684     double y0 = ( k1 * b2 - k2 * b1 ) / ( k1 - k2 );
1685
1686     if ( qMin( x11, x12 ) < x0 && x0 < qMax( x11, x12 ) &&
1687          qMin( y11, y12 ) < y0 && y0 < qMax( y11, y12 ) &&
1688          qMin( x21, x22 ) < x0 && x0 < qMax( x21, x22 ) &&
1689          qMin( y21, y22 ) < y0 && y0 < qMax( y21, y22 ) )
1690       return true;
1691   }
1692   return false;
1693 }
1694
1695 bool isValid( const QPolygon* thePoints, const QPoint& theCurrent )
1696 {
1697   if ( !thePoints->count() )
1698     return true;
1699
1700   if ( thePoints->count() == 1 && thePoints->point( 0 ) == theCurrent )
1701     return false;
1702
1703   const QPoint& aLast = thePoints->point( thePoints->count() - 1 );
1704
1705   if ( aLast == theCurrent )
1706     return true;
1707
1708   bool res = true;
1709   for ( uint i = 0; i < thePoints->count() - 1 && res; i++ )
1710   {
1711     const QPoint& aStart = thePoints->point( i );
1712     const QPoint& anEnd  = thePoints->point( i + 1 );
1713     res = !isIntersect( aStart, anEnd, theCurrent, aLast );
1714   }
1715   return res;
1716 }
1717
1718 /*!
1719   Draws polygon
1720 */
1721 void SVTK_InteractorStyle::drawPolygon()
1722 {
1723   QSize aToler( 5, 5 );
1724   if ( !myPolygonBand ) {
1725     myPolygonBand = new QtxPolyRubberBand( GetRenderWidget() );
1726     QPalette palette;
1727     palette.setColor( myPolygonBand->foregroundRole(), Qt::white );
1728     myPolygonBand->setPalette( palette );
1729     myPolygonPoints.append( QPoint( myPoint.x(), myPoint.y() ) );
1730   }
1731   myPolygonBand->hide();
1732
1733   bool closed = false;
1734   bool valid = GetRenderWidget()->rect().contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1735   if ( !myPolygonPoints.at(0).isNull() )
1736   {
1737     QRect aRect( myPolygonPoints.at(0).x() - aToler.width(), myPolygonPoints.at(0).y() - aToler.height(),
1738                  2 * aToler.width(), 2 * aToler.height() );
1739     closed = aRect.contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1740   }
1741
1742   QPolygon* points = new QPolygon( myPolygonPoints );
1743   valid = valid && isValid( points, QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1744   myPoligonState = valid ? InProcess : NotValid;
1745   delete points;
1746   if ( closed && !valid )
1747     closed = false;
1748
1749   if ( closed && myPolygonPoints.size() > 2 ) {
1750     GetRenderWidget()->setCursor( Qt::CrossCursor );
1751     myPoligonState = Closed;
1752   }
1753   else if ( valid )
1754     GetRenderWidget()->setCursor( Qt::PointingHandCursor );
1755   else
1756     GetRenderWidget()->setCursor( Qt::ForbiddenCursor );
1757
1758   myPolygonPoints.append( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1759
1760   QPolygon aPolygon( myPolygonPoints );
1761   myPolygonBand->initGeometry( aPolygon );
1762   myPolygonBand->setVisible( true );
1763
1764   if ( myPolygonPoints.size() > 1 ) {
1765     myPolygonPoints.remove( myPolygonPoints.size() - 1 );
1766   }
1767 }
1768
1769 /*!
1770   \brief Delete rubber band on the end on the dragging operation.
1771 */
1772 void SVTK_InteractorStyle::endDrawPolygon()
1773 {
1774   if ( myPolygonBand ) myPolygonBand->hide();
1775
1776   delete myPolygonBand;
1777   myPolygonBand = 0;
1778
1779   myPolygonPoints.clear();
1780 }
1781
1782 /*!
1783   Main process event method (reimplemented from #vtkInteractorStyle)
1784 */
1785 void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
1786                                           unsigned long event,
1787                                           void* clientData, 
1788                                           void* callData )
1789 {
1790   if ( clientData ) {
1791     vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1792     SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1793     int aSpeedIncrement=self->ControllerIncrement()->Current();
1794     double aCenter[3];
1795     double* aSelectedPoint;
1796     if ( self ) {
1797       switch ( event ) {
1798       case SVTK::SpaceMouseMoveEvent : 
1799         self->onSpaceMouseMove( (double*)callData ); 
1800         return;
1801       case SVTK::SpaceMouseButtonEvent : 
1802         self->onSpaceMouseButton( *((int*)callData) ); 
1803         return;
1804       case SVTK::PanLeftEvent: 
1805         self->IncrementalPan(-aSpeedIncrement, 0);
1806         return;
1807       case SVTK::PanRightEvent:
1808         self->IncrementalPan(aSpeedIncrement, 0);
1809         return;
1810       case SVTK::PanUpEvent:
1811         self->IncrementalPan(0, aSpeedIncrement);
1812         return;
1813       case SVTK::PanDownEvent:
1814         self->IncrementalPan(0, -aSpeedIncrement);
1815         return;
1816       case SVTK::ZoomInEvent:
1817         self->IncrementalZoom(aSpeedIncrement);
1818         return;
1819       case SVTK::ZoomOutEvent:
1820         self->IncrementalZoom(-aSpeedIncrement);
1821         return;
1822       case SVTK::RotateLeftEvent: 
1823         self->IncrementalRotate(-aSpeedIncrement, 0);
1824         return;
1825       case SVTK::RotateRightEvent:
1826         self->IncrementalRotate(aSpeedIncrement, 0);
1827         return;
1828       case SVTK::RotateUpEvent:
1829         self->IncrementalRotate(0, -aSpeedIncrement);
1830         return;
1831       case SVTK::RotateDownEvent:
1832         self->IncrementalRotate(0, aSpeedIncrement);
1833         return;
1834       case SVTK::PlusSpeedIncrementEvent:
1835         self->ControllerIncrement()->Increase();
1836         return;
1837       case SVTK::MinusSpeedIncrementEvent:
1838         self->ControllerIncrement()->Decrease();
1839         return;
1840       case SVTK::SetSpeedIncrementEvent:
1841         self->ControllerIncrement()->SetStartValue(*((int*)callData));
1842         return;
1843
1844       case SVTK::SetSMDecreaseSpeedEvent:
1845         self->mySMDecreaseSpeedBtn = *((int*)callData);
1846         return;
1847       case SVTK::SetSMIncreaseSpeedEvent:
1848         self->mySMIncreaseSpeedBtn = *((int*)callData);
1849         return;
1850       case SVTK::SetSMDominantCombinedSwitchEvent:
1851         self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1852         return;
1853
1854       case SVTK::StartZoom:
1855         self->startZoom();
1856         return;
1857       case SVTK::StartPan:
1858         self->startPan();
1859         return;
1860       case SVTK::StartRotate:
1861         self->startRotate();
1862         return;
1863       case SVTK::StartGlobalPan:
1864         self->startGlobalPan();
1865         return;
1866       case SVTK::StartFitArea:
1867         self->startFitArea();
1868         return;
1869
1870       case SVTK::SetRotateGravity:
1871         if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1872         {
1873           self->myHighlightSelectionPointActor->SetVisibility( false );
1874           if( self->GetCurrentRenderer() != NULL )
1875             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1876           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1877         }
1878         self->myPrevRotationPointType = self->myCurrRotationPointType;
1879         self->myCurrRotationPointType = SVTK::SetRotateGravity;
1880         if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) 
1881           // invoke event for update coordinates in SVTK_SetRotationPointDlg
1882           self->InvokeEvent(SVTK::BBCenterChanged,(void*)aCenter);
1883         return;
1884       case SVTK::StartPointSelection:
1885         self->startPointSelection();
1886         return;
1887
1888       case SVTK::ChangeRotationPoint:
1889         if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1890         {
1891           self->myHighlightSelectionPointActor->SetVisibility( false );
1892           if( self->GetCurrentRenderer() != NULL )
1893             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1894           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1895         }
1896         self->myPrevRotationPointType = self->myCurrRotationPointType;
1897         self->myCurrRotationPointType = SVTK::SetRotateSelected;
1898         aSelectedPoint = (double*)callData;
1899         self->myRotationPointX = aSelectedPoint[0];
1900         self->myRotationPointY = aSelectedPoint[1];
1901         self->myRotationPointZ = aSelectedPoint[2];
1902         return;
1903
1904       case SVTK::SetFocalPointGravity:
1905         if ( self->myCurrFocalPointType == SVTK::StartPointSelection )
1906         {
1907           self->myHighlightSelectionPointActor->SetVisibility( false );
1908           if( self->GetCurrentRenderer() != NULL )
1909             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1910           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1911         }
1912         self->myCurrFocalPointType = SVTK::SetFocalPointGravity;
1913         if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) {
1914           // invoke event for update coordinates in SVTK_ViewParameterDlg
1915           self->InvokeEvent(SVTK::FocalPointChanged,(void*)aCenter);
1916         }
1917         return;
1918       case SVTK::StartFocalPointSelection:
1919         self->startFocalPointSelection();
1920         return;
1921
1922       case SVTK::SetFocalPointSelected:
1923         if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
1924         {
1925           self->myHighlightSelectionPointActor->SetVisibility( false );
1926           if( self->GetCurrentRenderer() != NULL )
1927             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1928           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1929         }
1930         self->myPrevFocalPointType = self->myCurrFocalPointType;
1931         self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
1932         return;
1933       }
1934     }
1935   }
1936
1937   Superclass::ProcessEvents( object, event, clientData, callData );
1938 }
1939
1940 /*!
1941   To handle keyboard event (reimplemented from #vtkInteractorStyle)
1942 */
1943 void SVTK_InteractorStyle::OnChar()
1944 {
1945   char key = GetInteractor()->GetKeyCode();
1946   switch ( key ) {
1947   case '+': ControllerIncrement()->Increase(); break;
1948   case '-': ControllerIncrement()->Decrease(); break;
1949   }
1950 }
1951
1952 /*!
1953   Redefined vtkInteractorStyle::OnKeyDown
1954 */
1955 void SVTK_InteractorStyle::OnKeyDown()
1956 {
1957   bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1958   if (bInvokeSuperclass){
1959     Superclass::OnKeyDown();
1960   }
1961 }
1962
1963 /*!
1964   Provide instructions for Picking
1965 */
1966 void SVTK_InteractorStyle::ActionPicking()
1967 {
1968   int x, y;
1969   Interactor->GetEventPosition( x, y ); 
1970   FindPokedRenderer( x, y ); 
1971   
1972   myOtherPoint = myPoint = QPoint(x, y);
1973   
1974   startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1975   onFinishOperation();
1976   startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1977 }
1978
1979 /*!
1980   To set current increment controller 
1981 */
1982 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1983 {
1984   myControllerOnKeyDown=theController;
1985 }
1986
1987 /*!
1988   To get current OnKeyDown controller 
1989 */
1990 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1991 {
1992   return myControllerOnKeyDown.GetPointer();
1993 }
1994
1995 /*!
1996   To set current increment controller
1997 */
1998 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
1999 {
2000   myControllerIncrement=theController;
2001 }
2002
2003 /*!
2004   To modify current increment controller
2005 */
2006 void SVTK_InteractorStyle::SetIncrementSpeed(const int theValue, const int theMode)
2007 {
2008   SVTK_ControllerIncrement* c = 0;
2009   switch (theMode) {
2010   case 0: c = SVTK_ControllerIncrement::New(); break;
2011   case 1: c = SVTK_GeomControllerIncrement::New(); break;
2012   }
2013   c->SetStartValue(theValue);
2014
2015   SetControllerIncrement(c);
2016   c->Delete();
2017 }
2018
2019 /*!
2020   To get current increment controller 
2021 */
2022 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
2023 {
2024   return myControllerIncrement.GetPointer();
2025 }
2026
2027 vtkStandardNewMacro(SVTK_ControllerIncrement);
2028 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
2029 {
2030   myIncrement=10;
2031 }
2032 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
2033 {
2034 }
2035 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
2036 {
2037   myIncrement=theValue;
2038 }
2039 int SVTK_ControllerIncrement::Current()const
2040 {
2041   return myIncrement;
2042 }
2043 int SVTK_ControllerIncrement::Increase()
2044 {
2045   ++myIncrement;
2046   return myIncrement;
2047 }
2048 int SVTK_ControllerIncrement::Decrease()
2049 {
2050   if (myIncrement>1){
2051     --myIncrement;
2052   }
2053   return myIncrement;
2054 }
2055
2056 vtkStandardNewMacro(SVTK_GeomControllerIncrement);
2057 SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
2058 {
2059 }
2060 SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement()
2061 {
2062 }
2063 int SVTK_GeomControllerIncrement::Increase()
2064 {
2065   myIncrement*=2;
2066   return myIncrement;
2067 }
2068 int SVTK_GeomControllerIncrement::Decrease()
2069 {
2070   myIncrement/=2;
2071   if (myIncrement<1){
2072     myIncrement=1;
2073   }
2074   return myIncrement;
2075 }
2076
2077 vtkStandardNewMacro(SVTK_ControllerOnKeyDown);
2078
2079 /*!
2080   Constructor
2081 */
2082 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
2083 {
2084 }
2085
2086 /*!
2087   Destructor
2088 */
2089 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
2090 {
2091 }
2092
2093 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS)
2094 {
2095   return true;
2096 }