]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_RenderWindowInteractor.cxx
Salome HOME
[bos #42871] Clipping plane remains applied after being deleted
[modules/gui.git] / src / SVTK / SVTK_RenderWindowInteractor.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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_RenderWindowInteractor.h"
28
29 #include "SVTK_InteractorStyle.h"
30 #include "SVTK_Renderer.h"
31 #include "SVTK_Functor.h"
32 #include "SALOME_Actor.h"
33 #include "ViewerTools_ScreenScaling.h"
34
35 // QT Includes
36 // Put Qt includes before the X11 includes which #define the symbol None
37 // (see SVTK_SpaceMouse.h) to avoid the compilation error.
38 #if !defined(WIN32) && !defined(__APPLE__)
39 #include <xcb/xcb.h>
40 #include <QX11Info>
41 #endif
42 #include <QMouseEvent>
43
44 #include "SVTK_SpaceMouse.h" 
45 #include "SVTK_Event.h" 
46
47 #include "VTKViewer_Algorithm.h"
48
49 // VTK Includes
50 #include <vtkObjectFactory.h>
51 #include <vtkRendererCollection.h>
52 #include <vtkRenderWindow.h>
53 #include <vtkGenericRenderWindowInteractor.h>
54 #include <vtkCallbackCommand.h>
55 #include <vtkCommand.h>
56 #include <vtkPicker.h>
57 #include <vtkCamera.h>
58
59 static bool GENERATE_SUIT_EVENTS = true;
60 static bool FOCUS_UNDER_MOUSE = false;
61
62 // workaround about the bug in vtkImplicitPlaneWidget class
63 // that eats mouse button release event
64 // causing clipping plane preview in SMESH sticking up
65 #define Fix_Of_vtkImplicitPlaneWidget_bug
66
67 /*!
68   Constructor
69 */
70 QVTK_RenderWindowInteractor
71 ::QVTK_RenderWindowInteractor(QWidget* theParent, 
72                               const char* theName):
73   QWidget(theParent),
74   myRenderWindow(vtkRenderWindow::New())
75 {
76   setAttribute( Qt::WA_PaintOnScreen );
77   setAttribute( Qt::WA_NoSystemBackground );
78
79   setObjectName(theName);
80
81   setMouseTracking(true);
82
83   myRenderWindow->Delete();
84   myRenderWindow->DoubleBufferOn();
85
86 #if !defined WIN32 && !defined __APPLE__
87   myRenderWindow->SetDisplayId((void*)QX11Info::display());
88 #endif
89   myRenderWindow->SetWindowId((void*)winId());
90 }
91
92 /*!
93   To initialize by vtkGenericRenderWindowInteractor instance
94 */
95 void 
96 QVTK_RenderWindowInteractor
97 ::Initialize(vtkGenericRenderWindowInteractor* theDevice)
98 {
99   if ( GetDevice() )
100     myDevice->SetRenderWindow( NULL );
101
102   myDevice = theDevice;
103
104   if ( theDevice )
105     theDevice->SetRenderWindow( getRenderWindow() );
106 }
107
108 /*!
109   Destructor
110 */
111 QVTK_RenderWindowInteractor
112 ::~QVTK_RenderWindowInteractor() 
113 {
114 #if !defined WIN32 && !defined __APPLE__
115   SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
116   if ( aSpaceMouse && aSpaceMouse->isSpaceMouseOn() )
117     aSpaceMouse->close( QX11Info::connection() );
118 #endif
119 }
120
121
122 /*!
123   \return corresponding render window interactor
124 */
125 vtkGenericRenderWindowInteractor* 
126 QVTK_RenderWindowInteractor
127 ::GetDevice()
128 {
129   return myDevice.GetPointer();
130 }
131
132 /*!
133   \return corresponding render window
134 */
135 vtkRenderWindow*
136 QVTK_RenderWindowInteractor
137 ::getRenderWindow()
138 {
139   return myRenderWindow.GetPointer();
140 }
141
142 /*!
143   Just to simplify usage of its device (vtkGenericRenderWindowInteractor)
144 */
145 void
146 QVTK_RenderWindowInteractor
147 ::InvokeEvent(unsigned long theEvent, void* theCallData)
148 {
149   GetDevice()->InvokeEvent(theEvent,theCallData);
150 }
151
152 /*!
153   Get paint engine for the scene
154 */
155 QPaintEngine* QVTK_RenderWindowInteractor::paintEngine() const
156 {
157   return 0;
158 }
159
160 /*!
161   Need for initial contents display on Win32
162 */
163 void
164 QVTK_RenderWindowInteractor
165 ::show()
166 {
167   QWidget::show();
168   update(); // needed for initial contents display on Win32
169 }
170
171 /*!
172   To implement final initialization, just before the widget is displayed
173 */
174 void
175 QVTK_RenderWindowInteractor
176 ::polish()
177 {
178   // Final initialization just before the widget is displayed
179   const double pixelRatio = ViewerTools_ScreenScaling::getPR();
180   GetDevice()->SetSize(width() * pixelRatio, height() * pixelRatio);
181   if(!GetDevice()->GetInitialized() && GetDevice()->GetRenderWindow()){
182     GetDevice()->Initialize();
183     GetDevice()->ConfigureEvent();
184   }
185 }
186
187 /*!
188   To adjust widget and vtkRenderWindow size
189 */
190 void
191 QVTK_RenderWindowInteractor
192 ::resize(int w, int h) 
193 {
194   GetDevice()->UpdateSize(w,h);
195 }
196
197 /*!
198   Custom paint event handler
199 */
200 void
201 QVTK_RenderWindowInteractor
202 ::paintEvent( QPaintEvent* /*theEvent*/ ) 
203 {
204   GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
205 }
206
207
208 /*!
209   Custom resize event handler
210 */
211 void
212 QVTK_RenderWindowInteractor
213 ::resizeEvent( QResizeEvent* /* theEvent */ )
214 {
215
216   int* aSize = getRenderWindow()->GetSize();
217   int aWidth = aSize[0];
218   int aHeight = aSize[1];
219
220   const double pixelRatio = ViewerTools_ScreenScaling::getPR();
221   GetDevice()->UpdateSize(width() * pixelRatio, height() * pixelRatio);
222
223   if(isVisible() && aWidth && aHeight){
224     if( aWidth != width() || aHeight != height() ) {
225       vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers();
226       aRenderers->InitTraversal();
227       double aCoeff = 1.0;
228       if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) {
229         vtkCamera *aCamera = aRenderer->GetActiveCamera();
230         double aScale = aCamera->GetParallelScale();
231         if((aWidth - width())*(aHeight - height()) > 0)
232           aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
233         else
234           aCoeff = double(aWidth)/double(width());
235         aCamera->SetParallelScale(aScale*aCoeff);
236       }
237     }
238   }
239
240   update(); 
241 }
242
243
244
245 /*!
246   Custom context menu event handler
247 */
248 void
249 QVTK_RenderWindowInteractor
250 ::contextMenuEvent( QContextMenuEvent* /*event*/ )
251 {}
252
253 /*!
254   Custom mouse move event handler
255 */
256 void
257 QVTK_RenderWindowInteractor
258 ::mouseMoveEvent( QMouseEvent* event ) 
259 {
260   GetDevice()->SetEventInformationFlipY(event->x(), 
261                                         event->y(),
262                                         event->modifiers() & Qt::ControlModifier,
263                                         event->modifiers() & Qt::ShiftModifier);
264   GetDevice()->MouseMoveEvent();
265 }
266
267
268 /*!
269   Custom mouse press event handler
270 */
271 void
272 QVTK_RenderWindowInteractor
273 ::mousePressEvent( QMouseEvent* event ) 
274 {
275   GetDevice()->SetEventInformationFlipY(event->x(), 
276                                         event->y(),
277                                         event->modifiers() & Qt::ControlModifier,
278                                         event->modifiers() & Qt::ShiftModifier);
279   if( event->button() & Qt::LeftButton )
280     GetDevice()->LeftButtonPressEvent();
281   else if( event->button() & Qt::MidButton )
282     GetDevice()->MiddleButtonPressEvent();
283   else if( event->button() & Qt::RightButton )
284     GetDevice()->RightButtonPressEvent();
285 }
286
287
288 /*!
289   Custom mouse release event handler
290 */
291 void
292 QVTK_RenderWindowInteractor
293 ::mouseReleaseEvent( QMouseEvent *event )
294 {
295   GetDevice()->SetEventInformationFlipY(event->x(), 
296                                         event->y(),
297                                         event->modifiers() & Qt::ControlModifier,
298                                         event->modifiers() & Qt::ShiftModifier);
299
300   if( event->button() & Qt::LeftButton )
301     GetDevice()->LeftButtonReleaseEvent();
302   else if( event->button() & Qt::MidButton )
303     GetDevice()->MiddleButtonReleaseEvent();
304   else if( event->button() & Qt::RightButton ) {
305 #if defined(Fix_Of_vtkImplicitPlaneWidget_bug)
306     GetDevice()->SetEventInformationFlipY( -99999, -99999,
307                                            event->modifiers() & Qt::ControlModifier,
308                                            event->modifiers() & Qt::ShiftModifier);
309     bool blocked = blockSignals( true );
310     GetDevice()->LeftButtonPressEvent();
311     GetDevice()->LeftButtonReleaseEvent();
312     blockSignals( blocked );
313     GetDevice()->SetEventInformationFlipY(event->x(),
314                                           event->y(),
315                                           event->modifiers() & Qt::ControlModifier,
316                                           event->modifiers() & Qt::ShiftModifier);
317 #endif
318     GetDevice()->RightButtonReleaseEvent();
319   }
320 }
321
322
323 /*!
324   Custom mouse double click event handler
325 */
326 void
327 QVTK_RenderWindowInteractor
328 ::mouseDoubleClickEvent( QMouseEvent* /*event*/ )
329 {}
330
331
332 /*!
333   Custom mouse wheel event handler
334 */
335 void
336 QVTK_RenderWindowInteractor
337 ::wheelEvent( QWheelEvent* event )
338 {
339   activateWindow();
340   setFocus();
341   GetDevice()->SetEventInformationFlipY(event->x(), 
342                                         event->y(),
343                                         event->modifiers() & Qt::ControlModifier,
344                                         event->modifiers() & Qt::ShiftModifier);
345   if ( event->delta()>0)
346     GetDevice()->MouseWheelForwardEvent();
347   else
348     GetDevice()->MouseWheelBackwardEvent();
349 }
350
351
352 /*!
353   Custom key press event handler
354 */
355 void
356 QVTK_RenderWindowInteractor
357 ::keyPressEvent( QKeyEvent* event ) 
358 {
359   GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier,
360                                       event->modifiers() & Qt::ShiftModifier,
361                                       event->key());
362   GetDevice()->KeyPressEvent();
363   GetDevice()->CharEvent();
364 }
365
366 /*!
367   Custom key release event handler
368 */
369 void
370 QVTK_RenderWindowInteractor
371 ::keyReleaseEvent( QKeyEvent * event ) 
372 {
373   GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier,
374                                       event->modifiers() & Qt::ShiftModifier,
375                                       event->key());
376   GetDevice()->KeyReleaseEvent();
377 }
378
379
380 /*!
381   Custom enter event handler
382 */
383 void  
384 QVTK_RenderWindowInteractor
385 ::enterEvent( QEvent* /*event*/ )
386 {
387   if(FOCUS_UNDER_MOUSE){
388     activateWindow();
389     setFocus();
390   }
391   GetDevice()->EnterEvent();
392 }
393
394 /*!
395   Custom leave event handler
396 */
397 void  
398 QVTK_RenderWindowInteractor
399 ::leaveEvent( QEvent * )
400 {
401   GetDevice()->LeaveEvent();
402 }
403
404 /*!
405   Reimplemented from QWidget in order to set window - receiver
406   of space mouse events. 
407 */
408 void  
409 QVTK_RenderWindowInteractor
410 ::focusInEvent( QFocusEvent* event )
411 {
412   QWidget::focusInEvent( event );
413
414 #if !defined WIN32 && !defined __APPLE__
415   // register set space mouse events receiver
416   SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
417   if ( aSpaceMouse )
418   {
419     if ( !aSpaceMouse->isSpaceMouseOn() )
420       // initialize 3D space mouse driver
421       aSpaceMouse->initialize( QX11Info::connection(), winId() );
422     else
423       aSpaceMouse->setWindow( QX11Info::connection(), winId() );
424   }
425 #endif
426 }
427
428 /*!
429   Reimplemented from QWidget in order to set window - receiver
430   of space mouse events. 
431 */
432 void  
433 QVTK_RenderWindowInteractor
434 ::focusOutEvent ( QFocusEvent* event )
435 {
436   QWidget::focusOutEvent( event );
437
438 #if !defined WIN32 && !defined __APPLE__
439   SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
440   if ( aSpaceMouse && aSpaceMouse->isSpaceMouseOn() )
441     aSpaceMouse->setWindow( QX11Info::connection(), 0 );
442 #endif
443 }
444
445 bool QVTK_RenderWindowInteractor
446 ::nativeEvent(const QByteArray& eventType, void* message, long* result)
447 {
448 #if defined(WIN32)
449   // TODO: WIN32-related implementation
450 #elif !defined(__APPLE__)
451   if ( eventType == "xcb_generic_event_t" )
452   {
453     xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message);
454     if ( SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance() )
455     {
456       if ( aSpaceMouse->isSpaceMouseOn() && ev->response_type == XCB_CLIENT_MESSAGE )
457       {
458         SVTK_SpaceMouse::MoveEvent anEvent;
459         int type = aSpaceMouse->translateEvent( QX11Info::connection(), (xcb_client_message_event_t*)ev, &anEvent, 1.0, 1.0 );
460         switch ( type )
461         {
462         case SVTK_SpaceMouse::SpaceMouseMove:
463                 GetDevice()->InvokeEvent( SVTK::SpaceMouseMoveEvent, anEvent.data );
464                 break;
465         case SVTK_SpaceMouse::SpaceButtonPress:
466                 GetDevice()->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button );
467                 break;
468         case SVTK_SpaceMouse::SpaceButtonRelease:
469                 break;
470         }
471         return true; // stop handling the event
472       }
473     }
474   }
475 #endif
476  return QWidget::nativeEvent( eventType, message, result );
477 }
478
479 /*!
480   Constructor
481 */
482 SVTK_RenderWindowInteractor
483 ::SVTK_RenderWindowInteractor(QWidget* theParent, 
484                                const char* theName):
485   QVTK_RenderWindowInteractor(theParent,theName),
486   myEventCallbackCommand(vtkCallbackCommand::New())
487 {
488   myEventCallbackCommand->Delete();
489
490   myEventCallbackCommand->SetClientData(this); 
491   myPriority = 0.0;
492
493   myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents);
494 }
495
496 /*!
497   To initialize properly the class
498 */
499 void
500 SVTK_RenderWindowInteractor
501 ::Initialize(vtkGenericRenderWindowInteractor* theDevice,
502              SVTK_Renderer* theRenderer,
503              SVTK_Selector* theSelector)
504 {
505   QVTK_RenderWindowInteractor::Initialize(theDevice);
506   SetRenderer(theRenderer);
507   SetSelector(theSelector);
508 }
509
510 /*!
511   Destructor
512 */
513 SVTK_RenderWindowInteractor
514 ::~SVTK_RenderWindowInteractor() 
515 {
516   // Sequence of the destruction call are fixed and should be changed.
517   // vtkRenderWindow instance should be destroyed after all vtkRenderer's
518   GetDevice()->SetInteractorStyle(NULL); 
519   while(!myInteractorStyles.empty()){
520     const PInteractorStyle& aStyle = myInteractorStyles.top();
521     aStyle->SetInteractor(NULL);
522     myInteractorStyles.pop();
523   }
524 }
525
526 /*!
527   To get corresponding SVTK_Renderer instance
528 */
529 SVTK_Renderer* 
530 SVTK_RenderWindowInteractor
531 ::GetRenderer()
532 {
533   return myRenderer.GetPointer();
534 }
535
536 /*!
537   To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
538 */
539 vtkRenderer* 
540 SVTK_RenderWindowInteractor
541 ::getRenderer()
542 {
543   return GetRenderer()->GetDevice();
544 }
545
546 /*!
547   Changes renderer
548   \param theRenderer - new renderer
549 */
550 void
551 SVTK_RenderWindowInteractor
552 ::SetRenderer(SVTK_Renderer* theRenderer)
553 {
554   if(theRenderer == myRenderer.GetPointer())
555     return;
556
557   if(GetRenderer())
558     myRenderWindow->RemoveRenderer(getRenderer());
559
560   myRenderer = theRenderer;
561
562   if(GetRenderer())
563     myRenderWindow->AddRenderer(getRenderer());
564 }
565
566
567 /*!
568   Changes interactor style
569   \param theStyle - new interactor style
570 */
571 void
572 SVTK_RenderWindowInteractor
573 ::InitInteractorStyle(vtkInteractorStyle* theStyle)
574 {
575   GetDevice()->SetInteractorStyle(theStyle); 
576 }
577
578 /*!
579   To change current interactor style by pushing the new one into the container
580 */
581 void
582 SVTK_RenderWindowInteractor
583 ::PushInteractorStyle(vtkInteractorStyle* theStyle)
584 {
585   myInteractorStyles.push(PInteractorStyle(theStyle));
586   InitInteractorStyle(theStyle);
587 }
588
589 /*!
590   To restore previous interactor style
591 */
592 void
593 SVTK_RenderWindowInteractor
594 ::PopInteractorStyle()
595 {
596   if(GetInteractorStyle())
597     myInteractorStyles.pop();
598   
599   if(GetInteractorStyle()) 
600     InitInteractorStyle(GetInteractorStyle());
601 }
602
603 /*!
604   To get current interactor style
605 */
606 vtkInteractorStyle* 
607 SVTK_RenderWindowInteractor
608 ::GetInteractorStyle()
609 {
610   return myInteractorStyles.empty() ? 0 : myInteractorStyles.top().GetPointer();
611 }
612
613
614 /*!
615   To get current selector
616 */
617 SVTK_Selector* 
618 SVTK_RenderWindowInteractor
619 ::GetSelector() 
620
621   return mySelector.GetPointer(); 
622 }
623
624
625 /*!
626   Changes selector
627   \param theSelector - new selector
628 */
629 void
630 SVTK_RenderWindowInteractor
631 ::SetSelector(SVTK_Selector* theSelector)
632
633   if(mySelector.GetPointer())
634     mySelector->RemoveObserver(myEventCallbackCommand.GetPointer());
635
636   mySelector = theSelector; 
637
638   if(mySelector.GetPointer())
639     mySelector->AddObserver(vtkCommand::EndPickEvent, 
640                             myEventCallbackCommand.GetPointer(), 
641                             myPriority);
642 }
643
644 /*!
645   Main process VTK event method
646 */
647 void 
648 SVTK_RenderWindowInteractor
649 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
650                 unsigned long theEvent,
651                 void* theClientData, 
652                 void* vtkNotUsed(theCallData))
653 {
654   SVTK_RenderWindowInteractor* self = reinterpret_cast<SVTK_RenderWindowInteractor*>(theClientData);
655
656   switch(theEvent){
657   case vtkCommand::EndPickEvent:
658     self->onEmitSelectionChanged();
659     break;
660   }
661 }
662
663 /*!
664   To change selection mode (just to simplify collobaration with SVTK_Selector)
665 */
666 void
667 SVTK_RenderWindowInteractor
668 ::SetSelectionMode(Selection_Mode theMode)
669 {
670   mySelector->SetSelectionMode(theMode);
671 }
672
673 /*!
674   To get current selection mode (just to simplify collobaration with SVTK_Selector)
675 */
676 Selection_Mode
677 SVTK_RenderWindowInteractor
678 ::SelectionMode() const
679 {
680   return mySelector->SelectionMode();
681 }
682
683
684 /*!
685   Emits signal selectionChanged()
686 */
687 void
688 SVTK_RenderWindowInteractor
689 ::onEmitSelectionChanged()
690 {
691   return emit selectionChanged();
692 }
693
694
695 /*!
696   Custom mouse move event handler
697 */
698 void
699 SVTK_RenderWindowInteractor
700 ::mouseMoveEvent( QMouseEvent* event ) 
701 {
702   event = static_cast<QMouseEvent*>(ViewerTools_ScreenScaling::getDpiAwareEvent(event));
703   QVTK_RenderWindowInteractor::mouseMoveEvent(event);
704
705   if(GENERATE_SUIT_EVENTS)
706     emit MouseMove( event );
707 }
708
709
710 /*!
711   Custom mouse press event handler
712 */
713 void
714 SVTK_RenderWindowInteractor
715 ::mousePressEvent( QMouseEvent* event ) 
716 {
717   event = static_cast<QMouseEvent*>(ViewerTools_ScreenScaling::getDpiAwareEvent(event));
718   QVTK_RenderWindowInteractor::mousePressEvent(event);
719
720   if(GENERATE_SUIT_EVENTS)
721     emit MouseButtonPressed( event );
722 }
723
724
725 /*!
726   Custom mouse release event handler
727 */
728 void
729 SVTK_RenderWindowInteractor
730 ::mouseReleaseEvent( QMouseEvent *event )
731 {
732   SVTK_InteractorStyle* style = 0;
733   bool aRightBtn = event->button() == Qt::RightButton;
734   bool isOperation = false;
735   bool isPolygonalSelection = false;
736   if( aRightBtn && GetInteractorStyle()) {
737     style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
738     if ( style )
739       isOperation = style->CurrentState() != VTK_INTERACTOR_STYLE_CAMERA_NONE;
740   }
741
742   event = static_cast<QMouseEvent*>(ViewerTools_ScreenScaling::getDpiAwareEvent(event));
743   QVTK_RenderWindowInteractor::mouseReleaseEvent(event);
744
745   if ( style ) {
746     isPolygonalSelection = style->GetPolygonState() == Finished;
747     style->SetPolygonState( Disable );
748   }
749
750   if ( aRightBtn && !isOperation && !isPolygonalSelection &&
751        !( event->modifiers() & Qt::ControlModifier ) &&
752        !( event->modifiers() & Qt::ShiftModifier ) ) {
753     // We need to pass unscaled coordinates to get a menu painted in a right place.
754     const double pixelRatio = ViewerTools_ScreenScaling::getPR();
755     QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
756                               event->pos() / pixelRatio, event->globalPos() / pixelRatio);
757     emit contextMenuRequested( &aEvent );
758   }
759   if(GENERATE_SUIT_EVENTS)
760     emit MouseButtonReleased( event );
761 }
762
763
764 /*!
765   Custom mouse double click event handler
766 */
767 void
768 SVTK_RenderWindowInteractor
769 ::mouseDoubleClickEvent( QMouseEvent* event )
770 {
771   event = static_cast<QMouseEvent*>(ViewerTools_ScreenScaling::getDpiAwareEvent(event));
772
773   if( GetInteractorStyle() && event->button() == Qt::LeftButton ) {
774     SVTK_InteractorStyle* style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
775     if ( style )
776       style->OnMouseButtonDoubleClick();
777   }
778
779   QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event);
780
781   if(GENERATE_SUIT_EVENTS)
782     emit MouseDoubleClicked( event );
783 }
784
785
786 /*!
787   Custom mouse wheel event handler
788 */
789 void
790 SVTK_RenderWindowInteractor
791 ::wheelEvent( QWheelEvent* event )
792 {
793   event = static_cast<QWheelEvent*>(ViewerTools_ScreenScaling::getDpiAwareEvent(event));
794
795   QVTK_RenderWindowInteractor::wheelEvent(event);
796
797   if(event->delta() > 0)
798     GetDevice()->InvokeEvent(SVTK::ZoomInEvent,NULL);
799   else
800     GetDevice()->InvokeEvent(SVTK::ZoomOutEvent,NULL);
801
802   if(GENERATE_SUIT_EVENTS)
803     emit WheelMoved( event );
804 }
805
806 /*!
807   Custom key press event handler
808 */
809 void
810 SVTK_RenderWindowInteractor
811 ::keyPressEvent( QKeyEvent* event ) 
812 {
813   QVTK_RenderWindowInteractor::keyPressEvent(event);
814
815   if(GENERATE_SUIT_EVENTS)
816     emit KeyPressed( event );
817 }
818
819 /*!
820   Custom key release event handler
821 */
822 void
823 SVTK_RenderWindowInteractor
824 ::keyReleaseEvent( QKeyEvent * event ) 
825 {
826   QVTK_RenderWindowInteractor::keyReleaseEvent(event);
827
828   if(GENERATE_SUIT_EVENTS)
829     emit KeyReleased( event );
830 }
831