Salome HOME
#18963 Minimize compiler warnings
[modules/gui.git] / src / SVTK / SVTK_InteractorStyle.cxx
1 // Copyright (C) 2007-2020  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   myLastHighlitedActor(NULL),
89   myLastPreHighlitedActor(NULL),
90   myControllerIncrement(SVTK_ControllerIncrement::New()),
91   myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()),
92   mySelectionEvent(new SVTK_SelectionEvent()),
93   myHighlightSelectionPointActor(SVTK_Actor::New()),
94   myPointPicker(vtkPointPicker::New()),
95   myRectBand(0),
96   myPolygonBand(0),
97   myPoligonState(Disable),
98   myIsAdvancedZoomingEnabled(false)
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 = NULL;
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     } // fall through!
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 #ifdef VGL_WORKAROUND
1555     GetCurrentRenderer()->Render();
1556 #endif
1557     double aCurrBBCenter[3];
1558     if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) )
1559     {
1560       if ( !myBBFirstCheck )
1561       {
1562         if ( fabs(aCurrBBCenter[0]-myBBCenter[0]) > 1e-38 ||
1563              fabs(aCurrBBCenter[1]-myBBCenter[1]) > 1e-38 ||
1564              fabs(aCurrBBCenter[2]-myBBCenter[2]) > 1e-38 ) {
1565           // bounding box was changed => send SVTK::RotationPointChanged event
1566           // invoke event for update coordinates in SVTK_SetRotationPointDlg
1567           InvokeEvent(SVTK::BBCenterChanged,(void*)aCurrBBCenter);
1568           for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1569         }
1570       }
1571       else 
1572       {
1573         for ( int i =0; i < 3; i++) myBBCenter[i] = aCurrBBCenter[i];
1574         myBBFirstCheck = false;
1575       }
1576     }
1577   }
1578 }
1579
1580 /*!
1581   To invoke #vtkRenderWindowInteractor::CreateTimer
1582 */
1583 void SVTK_InteractorStyle::Render() 
1584 {
1585   this->Interactor->CreateTimer(VTKI_TIMER_FIRST);
1586 }
1587
1588 void SVTK_InteractorStyle::onSpaceMouseMove( double* data )
1589 {
1590   // general things, do SetCurrentRenderer() within FindPokedRenderer() 
1591   int x, y;
1592   GetEventPosition( this->Interactor, x, y ); // current mouse position (from last mouse move event or any other event)
1593   FindPokedRenderer( x, y ); // calls SetCurrentRenderer
1594   
1595   IncrementalZoom( (int)data[2] );        // 1. push toward / pull backward = zoom out / zoom in
1596   IncrementalPan(  (int)data[0],  (int)data[1] );// 2. pull up / push down = pan up / down, 3. move left / right = pan left / right
1597   IncrementalRotate( 0,  (int)data[4] );   // 4. twist the control = rotate around Y axis
1598   IncrementalRotate( (int)data[3], 0  );   // 5. tilt the control forward/backward = rotate around X axis (Z axis of local coordinate system of space mouse)
1599 }
1600
1601 void SVTK_InteractorStyle::onSpaceMouseButton( int button )
1602 {
1603   if( mySMDecreaseSpeedBtn == button ) {   
1604     ControllerIncrement()->Decrease();
1605   }
1606   if( mySMIncreaseSpeedBtn == button ) {    
1607     ControllerIncrement()->Increase();
1608   }
1609   if( mySMDominantCombinedSwitchBtn == button )    
1610     DominantCombinedSwitch();
1611 }
1612
1613 void SVTK_InteractorStyle::DominantCombinedSwitch()
1614 {
1615   printf( "\n--DominantCombinedSwitch() NOT IMPLEMENTED--\n" );
1616 }
1617
1618 /*!
1619   Draws rectangle by starting and current points
1620 */
1621 void SVTK_InteractorStyle::drawRect()
1622 {
1623   if ( !myRectBand )
1624     myRectBand = new QtxRectRubberBand( GetRenderWidget() );
1625
1626   myRectBand->setUpdatesEnabled ( false );
1627   QRect aRect = SUIT_Tools::makeRect(myPoint.x(), myPoint.y(), myOtherPoint.x(), myOtherPoint.y());
1628   myRectBand->initGeometry( aRect );
1629
1630   if ( !myRectBand->isVisible() )
1631     myRectBand->show();
1632
1633   myRectBand->setUpdatesEnabled ( true );
1634 }
1635
1636 /*!
1637   \brief Delete rubber band on the end on the dragging operation.
1638 */
1639 void SVTK_InteractorStyle::endDrawRect()
1640 {
1641   if ( myRectBand ) {
1642     myRectBand->clearGeometry();
1643     myRectBand->hide();
1644   }
1645 }
1646
1647 bool isIntersect( const QPoint& theStart1, const QPoint& theEnd1,
1648                   const QPoint& theStart2, const QPoint& theEnd2 )
1649 {
1650   if ( ( theStart1 == theStart2 && theEnd1 == theEnd2 ) ||
1651        ( theStart1 == theEnd2 && theEnd1 == theStart2 ) )
1652     return true;
1653
1654   if ( theStart1 == theStart2 || theStart2 == theEnd1 ||
1655       theStart1 == theEnd2 || theEnd1 == theEnd2 )
1656     return false;
1657
1658   double x11 = theStart1.x() * 1.0;
1659   double x12 = theEnd1.x() * 1.0;
1660   double y11 = theStart1.y() * 1.0;
1661   double y12 = theEnd1.y() * 1.0;
1662
1663   double x21 = theStart2.x() * 1.0;
1664   double x22 = theEnd2.x() * 1.0;
1665   double y21 = theStart2.y() * 1.0;
1666   double y22 = theEnd2.y() * 1.0;
1667
1668   double k1 = x12 == x11 ? 0 : ( y12 - y11 ) / ( x12 - x11 );
1669   double k2 = x22 == x21 ? 0 : ( y22 - y21 ) / ( x22 - x21 );
1670
1671   double b1 = y11 - k1 * x11;
1672   double b2 = y21 - k2 * x21;
1673
1674   if ( k1 == k2 )
1675   {
1676     if ( b1 != b2 )
1677       return false;
1678     else
1679       return !( ( qMax( x11, x12 ) <= qMin( x21, x22 ) ||
1680                   qMin( x11, x12 ) >= qMax( x21, x22 ) ) &&
1681                 ( qMax( y11, y12 ) <= qMin( y21, y22 ) ||
1682                   qMin( y11, y12 ) >= qMax( y21, y22 ) ) );
1683   }
1684   else
1685   {
1686     double x0 = ( b2 - b1 ) / ( k1 - k2 );
1687     double y0 = ( k1 * b2 - k2 * b1 ) / ( k1 - k2 );
1688
1689     if ( qMin( x11, x12 ) < x0 && x0 < qMax( x11, x12 ) &&
1690          qMin( y11, y12 ) < y0 && y0 < qMax( y11, y12 ) &&
1691          qMin( x21, x22 ) < x0 && x0 < qMax( x21, x22 ) &&
1692          qMin( y21, y22 ) < y0 && y0 < qMax( y21, y22 ) )
1693       return true;
1694   }
1695   return false;
1696 }
1697
1698 bool isValid( const QPolygon* thePoints, const QPoint& theCurrent )
1699 {
1700   if ( !thePoints->count() )
1701     return true;
1702
1703   if ( thePoints->count() == 1 && thePoints->point( 0 ) == theCurrent )
1704     return false;
1705
1706   const QPoint& aLast = thePoints->point( thePoints->count() - 1 );
1707
1708   if ( aLast == theCurrent )
1709     return true;
1710
1711   bool res = true;
1712   for ( int i = 0; i < thePoints->count() - 1 && res; i++ )
1713   {
1714     const QPoint& aStart = thePoints->point( i );
1715     const QPoint& anEnd  = thePoints->point( i + 1 );
1716     res = !isIntersect( aStart, anEnd, theCurrent, aLast );
1717   }
1718   return res;
1719 }
1720
1721 /*!
1722   Draws polygon
1723 */
1724 void SVTK_InteractorStyle::drawPolygon()
1725 {
1726   QSize aToler( 5, 5 );
1727   if ( !myPolygonBand ) {
1728     myPolygonBand = new QtxPolyRubberBand( GetRenderWidget() );
1729     QPalette palette;
1730     palette.setColor( myPolygonBand->foregroundRole(), Qt::white );
1731     myPolygonBand->setPalette( palette );
1732     myPolygonPoints.append( QPoint( myPoint.x(), myPoint.y() ) );
1733   }
1734   myPolygonBand->hide();
1735
1736   bool closed = false;
1737   bool valid = GetRenderWidget()->rect().contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1738   if ( !myPolygonPoints.at(0).isNull() )
1739   {
1740     QRect aRect( myPolygonPoints.at(0).x() - aToler.width(), myPolygonPoints.at(0).y() - aToler.height(),
1741                  2 * aToler.width(), 2 * aToler.height() );
1742     closed = aRect.contains( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1743   }
1744
1745   QPolygon* points = new QPolygon( myPolygonPoints );
1746   valid = valid && isValid( points, QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1747   myPoligonState = valid ? InProcess : NotValid;
1748   delete points;
1749   if ( closed && !valid )
1750     closed = false;
1751
1752   if ( closed && myPolygonPoints.size() > 2 ) {
1753     GetRenderWidget()->setCursor( Qt::CrossCursor );
1754     myPoligonState = Closed;
1755   }
1756   else if ( valid )
1757     GetRenderWidget()->setCursor( Qt::PointingHandCursor );
1758   else
1759     GetRenderWidget()->setCursor( Qt::ForbiddenCursor );
1760
1761   myPolygonPoints.append( QPoint( myOtherPoint.x(), myOtherPoint.y() ) );
1762
1763   QPolygon aPolygon( myPolygonPoints );
1764   myPolygonBand->initGeometry( aPolygon );
1765   myPolygonBand->setVisible( true );
1766
1767   if ( myPolygonPoints.size() > 1 ) {
1768     myPolygonPoints.remove( myPolygonPoints.size() - 1 );
1769   }
1770 }
1771
1772 /*!
1773   \brief Delete rubber band on the end on the dragging operation.
1774 */
1775 void SVTK_InteractorStyle::endDrawPolygon()
1776 {
1777   if ( myPolygonBand ) myPolygonBand->hide();
1778
1779   // RNV fix for : #19204 [CEA][Windows] VTK Viewer - Access violation while right clicking
1780   //delete myPolygonBand;
1781   myPolygonBand->deleteLater();
1782   myPolygonBand = 0;
1783
1784   myPolygonPoints.clear();
1785 }
1786
1787 /*!
1788   Main process event method (reimplemented from #vtkInteractorStyle)
1789 */
1790 void SVTK_InteractorStyle::ProcessEvents( vtkObject* object,
1791                                           unsigned long event,
1792                                           void* clientData, 
1793                                           void* callData )
1794 {
1795   if ( clientData ) {
1796     vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
1797     SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
1798     int aSpeedIncrement=self->ControllerIncrement()->Current();
1799     double aCenter[3];
1800     double* aSelectedPoint;
1801     if ( self ) {
1802       switch ( event ) {
1803       case SVTK::SpaceMouseMoveEvent : 
1804         self->onSpaceMouseMove( (double*)callData ); 
1805         return;
1806       case SVTK::SpaceMouseButtonEvent : 
1807         self->onSpaceMouseButton( *((int*)callData) ); 
1808         return;
1809       case SVTK::PanLeftEvent: 
1810         self->IncrementalPan(-aSpeedIncrement, 0);
1811         return;
1812       case SVTK::PanRightEvent:
1813         self->IncrementalPan(aSpeedIncrement, 0);
1814         return;
1815       case SVTK::PanUpEvent:
1816         self->IncrementalPan(0, aSpeedIncrement);
1817         return;
1818       case SVTK::PanDownEvent:
1819         self->IncrementalPan(0, -aSpeedIncrement);
1820         return;
1821       case SVTK::ZoomInEvent:
1822         self->IncrementalZoom(aSpeedIncrement);
1823         return;
1824       case SVTK::ZoomOutEvent:
1825         self->IncrementalZoom(-aSpeedIncrement);
1826         return;
1827       case SVTK::RotateLeftEvent: 
1828         self->IncrementalRotate(-aSpeedIncrement, 0);
1829         return;
1830       case SVTK::RotateRightEvent:
1831         self->IncrementalRotate(aSpeedIncrement, 0);
1832         return;
1833       case SVTK::RotateUpEvent:
1834         self->IncrementalRotate(0, -aSpeedIncrement);
1835         return;
1836       case SVTK::RotateDownEvent:
1837         self->IncrementalRotate(0, aSpeedIncrement);
1838         return;
1839       case SVTK::PlusSpeedIncrementEvent:
1840         self->ControllerIncrement()->Increase();
1841         return;
1842       case SVTK::MinusSpeedIncrementEvent:
1843         self->ControllerIncrement()->Decrease();
1844         return;
1845       case SVTK::SetSpeedIncrementEvent:
1846         self->ControllerIncrement()->SetStartValue(*((int*)callData));
1847         return;
1848
1849       case SVTK::SetSMDecreaseSpeedEvent:
1850         self->mySMDecreaseSpeedBtn = *((int*)callData);
1851         return;
1852       case SVTK::SetSMIncreaseSpeedEvent:
1853         self->mySMIncreaseSpeedBtn = *((int*)callData);
1854         return;
1855       case SVTK::SetSMDominantCombinedSwitchEvent:
1856         self->mySMDominantCombinedSwitchBtn = *((int*)callData);
1857         return;
1858
1859       case SVTK::StartZoom:
1860         self->startZoom();
1861         return;
1862       case SVTK::StartPan:
1863         self->startPan();
1864         return;
1865       case SVTK::StartRotate:
1866         self->startRotate();
1867         return;
1868       case SVTK::StartGlobalPan:
1869         self->startGlobalPan();
1870         return;
1871       case SVTK::StartFitArea:
1872         self->startFitArea();
1873         return;
1874
1875       case SVTK::SetRotateGravity:
1876         if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1877         {
1878           self->myHighlightSelectionPointActor->SetVisibility( false );
1879           if( self->GetCurrentRenderer() != NULL )
1880             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1881           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1882         }
1883         self->myPrevRotationPointType = self->myCurrRotationPointType;
1884         self->myCurrRotationPointType = SVTK::SetRotateGravity;
1885         if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) 
1886           // invoke event for update coordinates in SVTK_SetRotationPointDlg
1887           self->InvokeEvent(SVTK::BBCenterChanged,(void*)aCenter);
1888         return;
1889       case SVTK::StartPointSelection:
1890         self->startPointSelection();
1891         return;
1892
1893       case SVTK::ChangeRotationPoint:
1894         if ( self->myCurrRotationPointType == SVTK::StartPointSelection )
1895         {
1896           self->myHighlightSelectionPointActor->SetVisibility( false );
1897           if( self->GetCurrentRenderer() != NULL )
1898             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1899           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1900         }
1901         self->myPrevRotationPointType = self->myCurrRotationPointType;
1902         self->myCurrRotationPointType = SVTK::SetRotateSelected;
1903         aSelectedPoint = (double*)callData;
1904         self->myRotationPointX = aSelectedPoint[0];
1905         self->myRotationPointY = aSelectedPoint[1];
1906         self->myRotationPointZ = aSelectedPoint[2];
1907         return;
1908
1909       case SVTK::SetFocalPointGravity:
1910         if ( self->myCurrFocalPointType == SVTK::StartPointSelection )
1911         {
1912           self->myHighlightSelectionPointActor->SetVisibility( false );
1913           if( self->GetCurrentRenderer() != NULL )
1914             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1915           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1916         }
1917         self->myCurrFocalPointType = SVTK::SetFocalPointGravity;
1918         if ( ComputeBBCenter(self->GetCurrentRenderer(),aCenter) ) {
1919           // invoke event for update coordinates in SVTK_ViewParameterDlg
1920           self->InvokeEvent(SVTK::FocalPointChanged,(void*)aCenter);
1921         }
1922         return;
1923       case SVTK::StartFocalPointSelection:
1924         self->startFocalPointSelection();
1925         return;
1926
1927       case SVTK::SetFocalPointSelected:
1928         if ( self->myCurrFocalPointType == SVTK::StartFocalPointSelection )
1929         {
1930           self->myHighlightSelectionPointActor->SetVisibility( false );
1931           if( self->GetCurrentRenderer() != NULL )
1932             self->GetCurrentRenderer()->RemoveActor( self->myHighlightSelectionPointActor.GetPointer() );
1933           self->GetRenderWidget()->setCursor(self->myDefCursor); 
1934         }
1935         self->myPrevFocalPointType = self->myCurrFocalPointType;
1936         self->myCurrFocalPointType = SVTK::SetFocalPointSelected;
1937         return;
1938       }
1939     }
1940   }
1941
1942   Superclass::ProcessEvents( object, event, clientData, callData );
1943 }
1944
1945 /*!
1946   To handle keyboard event (reimplemented from #vtkInteractorStyle)
1947 */
1948 void SVTK_InteractorStyle::OnChar()
1949 {
1950   char key = GetInteractor()->GetKeyCode();
1951   switch ( key ) {
1952   case '+': ControllerIncrement()->Increase(); break;
1953   case '-': ControllerIncrement()->Decrease(); break;
1954   }
1955 }
1956
1957 /*!
1958   Redefined vtkInteractorStyle::OnKeyDown
1959 */
1960 void SVTK_InteractorStyle::OnKeyDown()
1961 {
1962   bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this);
1963   if (bInvokeSuperclass){
1964     Superclass::OnKeyDown();
1965   }
1966 }
1967
1968 /*!
1969   Provide instructions for Picking
1970 */
1971 void SVTK_InteractorStyle::ActionPicking()
1972 {
1973   int x, y;
1974   Interactor->GetEventPosition( x, y ); 
1975   FindPokedRenderer( x, y ); 
1976   
1977   myOtherPoint = myPoint = QPoint(x, y);
1978   
1979   startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
1980   onFinishOperation();
1981   startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
1982 }
1983
1984 /*!
1985   To set current increment controller 
1986 */
1987 void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController)
1988 {
1989   myControllerOnKeyDown=theController;
1990 }
1991
1992 /*!
1993   To get current OnKeyDown controller 
1994 */
1995 SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown()
1996 {
1997   return myControllerOnKeyDown.GetPointer();
1998 }
1999
2000 /*!
2001   To set current increment controller
2002 */
2003 void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController)
2004 {
2005   myControllerIncrement=theController;
2006 }
2007
2008 /*!
2009   To modify current increment controller
2010 */
2011 void SVTK_InteractorStyle::SetIncrementSpeed(const int theValue, const int theMode)
2012 {
2013   SVTK_ControllerIncrement* c = 0;
2014   switch (theMode) {
2015   case 0: c = SVTK_ControllerIncrement::New(); break;
2016   case 1: c = SVTK_GeomControllerIncrement::New(); break;
2017   }
2018   c->SetStartValue(theValue);
2019
2020   SetControllerIncrement(c);
2021   c->Delete();
2022 }
2023
2024 /*!
2025   To get current increment controller 
2026 */
2027 SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement()
2028 {
2029   return myControllerIncrement.GetPointer();
2030 }
2031
2032 vtkStandardNewMacro(SVTK_ControllerIncrement)
2033 SVTK_ControllerIncrement::SVTK_ControllerIncrement()
2034 {
2035   myIncrement=10;
2036 }
2037 SVTK_ControllerIncrement::~SVTK_ControllerIncrement()
2038 {
2039 }
2040 void SVTK_ControllerIncrement::SetStartValue(const int theValue)
2041 {
2042   myIncrement=theValue;
2043 }
2044 int SVTK_ControllerIncrement::Current()const
2045 {
2046   return myIncrement;
2047 }
2048 int SVTK_ControllerIncrement::Increase()
2049 {
2050   ++myIncrement;
2051   return myIncrement;
2052 }
2053 int SVTK_ControllerIncrement::Decrease()
2054 {
2055   if (myIncrement>1){
2056     --myIncrement;
2057   }
2058   return myIncrement;
2059 }
2060
2061 vtkStandardNewMacro(SVTK_GeomControllerIncrement)
2062 SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement()
2063 {
2064 }
2065 SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement()
2066 {
2067 }
2068 int SVTK_GeomControllerIncrement::Increase()
2069 {
2070   myIncrement*=2;
2071   return myIncrement;
2072 }
2073 int SVTK_GeomControllerIncrement::Decrease()
2074 {
2075   myIncrement/=2;
2076   if (myIncrement<1){
2077     myIncrement=1;
2078   }
2079   return myIncrement;
2080 }
2081
2082 vtkStandardNewMacro(SVTK_ControllerOnKeyDown)
2083
2084 /*!
2085   Constructor
2086 */
2087 SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown()
2088 {
2089 }
2090
2091 /*!
2092   Destructor
2093 */
2094 SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown()
2095 {
2096 }
2097
2098 bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* /*theIS*/)
2099 {
2100   return true;
2101 }