Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_RenderWindowInteractor.cxx
index 55dd794e7f4c20a6a7fa06daf95f9df5cf4af139..3406d70136202bcad7bf040d7a5a3b9b7864e3dc 100644 (file)
-//  SALOME VTKViewer : build VTK viewer into Salome desktop
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  File   : VTKViewer_RenderWindowInteractor.cxx
-//  Author : Nicolas REJNERI
-//  Module : SALOME
-//  $Header$
+
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//  File   : 
+//  Author : 
 
 #include "SVTK_RenderWindowInteractor.h"
 
 #include "SVTK_InteractorStyle.h"
-#include "SVTK_RenderWindow.h"
-#include "SVTK_ViewWindow.h"
-
-#include "VTKViewer_Algorithm.h"
+#include "SVTK_Renderer.h"
 #include "SVTK_Functor.h"
-#include "SVTK_Actor.h"
+#include "SALOME_Actor.h"
+
+// QT Includes
+// Put Qt includes before the X11 includes which #define the symbol None
+// (see SVTK_SpaceMouse.h) to avoid the compilation error.
+#if !defined(WIN32) && !defined(__APPLE__)
+#include <xcb/xcb.h>
+#include <QX11Info>
+#endif
+#include <QMouseEvent>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
+#include "SVTK_SpaceMouse.h" 
+#include "SVTK_Event.h" 
+
+#include "VTKViewer_Algorithm.h"
 
 // VTK Includes
 #include <vtkObjectFactory.h>
-#include <vtkPicker.h>
-#include <vtkCellPicker.h>
-#include <vtkPointPicker.h>
 #include <vtkRendererCollection.h>
 #include <vtkRenderWindow.h>
+#include <vtkGenericRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCommand.h>
+#include <vtkPicker.h>
+#include <vtkCamera.h>
 
-// QT Includes
-#include <qkeycode.h>
-
-#include <TColStd_IndexedMapOfInteger.hxx>
+static bool GENERATE_SUIT_EVENTS = true;
+static bool FOCUS_UNDER_MOUSE = false;
 
-using namespace std;
+// workaround about the bug in vtkImplicitPlaneWidget class
+// that eats mouse button release event
+// causing clipping plane preview in SMESH sticking up
+#define Fix_Of_vtkImplicitPlaneWidget_bug
 
-SVTK_RenderWindowInteractor* 
-SVTK_RenderWindowInteractor
-::New() 
+/*!
+  Constructor
+*/
+QVTK_RenderWindowInteractor
+::QVTK_RenderWindowInteractor(QWidget* theParent, 
+                              const char* theName):
+  QWidget(theParent),
+  myRenderWindow(vtkRenderWindow::New())
 {
-  vtkObject *ret = vtkObjectFactory::CreateInstance("SVTK_RenderWindowInteractor") ;
-  if( ret ) {
-    return dynamic_cast<SVTK_RenderWindowInteractor *>(ret) ;
-  }
-  return new SVTK_RenderWindowInteractor;
-}
-
-SVTK_RenderWindowInteractor
-::SVTK_RenderWindowInteractor() 
-{
-  this->Enabled = 0 ;
-  this->mTimer = new QTimer( this ) ;
-  myDisplayMode = 0;
-  myGUIWindow = 0;
+  setAttribute( Qt::WA_PaintOnScreen );
+  setAttribute( Qt::WA_NoSystemBackground );
 
-  myBasicPicker = vtkPicker::New();
-  myCellPicker = vtkCellPicker::New();
-  myPointPicker = vtkPointPicker::New();
+  setObjectName(theName);
 
-  myCellActor = SVTK_Actor::New(); 
-  myCellActor->PickableOff();
-  myCellActor->GetProperty()->SetColor(1,1,0);
-  myCellActor->GetProperty()->SetLineWidth(5);
-  myCellActor->GetProperty()->SetRepresentationToSurface();
+  setMouseTracking(true);
 
-  myEdgeActor = SVTK_Actor::New(); 
-  myEdgeActor->PickableOff();
-  myEdgeActor->GetProperty()->SetColor(1,0,0);
-  myEdgeActor->GetProperty()->SetLineWidth(5);
-  myEdgeActor->GetProperty()->SetRepresentationToWireframe();
+  myRenderWindow->Delete();
+  myRenderWindow->DoubleBufferOn();
 
-  myPointActor = SVTK_Actor::New(); 
-  myPointActor->PickableOff();
-  myPointActor->GetProperty()->SetColor(1,1,0);
-  myPointActor->GetProperty()->SetPointSize(5);
-  myPointActor->GetProperty()->SetRepresentationToPoints();
-
-  connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
+#if !defined WIN32 && !defined __APPLE__
+  myRenderWindow->SetDisplayId((void*)QX11Info::display());
+#endif
+  myRenderWindow->SetWindowId((void*)winId());
 }
 
-
-SVTK_RenderWindowInteractor
-::~SVTK_RenderWindowInteractor() 
+/*!
+  To initialize by vtkGenericRenderWindowInteractor instance
+*/
+void 
+QVTK_RenderWindowInteractor
+::Initialize(vtkGenericRenderWindowInteractor* theDevice)
 {
-  delete mTimer ;
-
-  myViewWindow->RemoveActor(myCellActor);
-  myViewWindow->RemoveActor(myEdgeActor);
-  myViewWindow->RemoveActor(myPointActor);
+  if ( GetDevice() )
+    myDevice->SetRenderWindow( NULL );
 
-  myCellActor->Delete();
-  myEdgeActor->Delete();
-  myPointActor->Delete();
+  myDevice = theDevice;
 
-  myBasicPicker->Delete();
-  myCellPicker->Delete();
-  myPointPicker->Delete();
+  if ( theDevice )
+    theDevice->SetRenderWindow( getRenderWindow() );
 }
 
-//
-// We never allow the SVTK_RenderWindowInteractor to control 
-// the event loop. The application always has the control. 
-//
-void
-SVTK_RenderWindowInteractor
-::Initialize() 
-{
-  //
-  // We cannot do much unless there is a render window 
-  // associated with this interactor. 
-  //
-  if( ! RenderWindow ) {
-    vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ;
-    return ;
-  }
-
-  //
-  // We cannot hand a render window which is not a VTKViewer_RenderWindow. 
-  // One way to force this is to use dynamic_cast and hope that 
-  // it works. If the dynamic_cast does not work, we flag an error
-  // and get the hell out.
-  //
-  vtkRenderWindow *aRenderWindow = dynamic_cast<vtkRenderWindow *>(RenderWindow) ;
-  if( !aRenderWindow ) {
-    vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ;
-    return ;
-  }
-
-  //
-  // If the render window has zero size, then set it to a default 
-  // value of 300x300.
-  // 
-  int* aSize = aRenderWindow->GetSize();
-  this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300);
-  this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300);
-
-  this->SetPicker(myBasicPicker);
-
-  SetSelectionTolerance();
+/*!
+  Destructor
+*/
+QVTK_RenderWindowInteractor
+::~QVTK_RenderWindowInteractor() 
+{
+#if !defined WIN32 && !defined __APPLE__
+  SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
+  if ( aSpaceMouse && aSpaceMouse->isSpaceMouseOn() )
+    aSpaceMouse->close( QX11Info::connection() );
+#endif
+}
 
-  //
-  // Enable the interactor. 
-  //
-  this->Enable() ;
 
-  //
-  // Start the rendering of the window. 
-  //
-  aRenderWindow->Start() ;
+/*!
+  \return corresponding render window interactor
+*/
+vtkGenericRenderWindowInteractor* 
+QVTK_RenderWindowInteractor
+::GetDevice()
+{
+  return myDevice.GetPointer();
+}
 
-  //
-  // The interactor has been initialized.
-  //
-  this->Initialized = 1 ;
+/*!
+  \return corresponding render window
+*/
+vtkRenderWindow*
+QVTK_RenderWindowInteractor
+::getRenderWindow()
+{
+  return myRenderWindow.GetPointer();
+}
 
-  return ;
+/*!
+  Just to simplify usage of its device (vtkGenericRenderWindowInteractor)
+*/
+void
+QVTK_RenderWindowInteractor
+::InvokeEvent(unsigned long theEvent, void* theCallData)
+{
+  GetDevice()->InvokeEvent(theEvent,theCallData);
 }
 
+/*!
+  Get paint engine for the scene
+*/
+QPaintEngine* QVTK_RenderWindowInteractor::paintEngine() const
+{
+  return 0;
+}
 
-//----------------------------------------------------------------------------
+/*!
+  Need for initial contents display on Win32
+*/
 void
-SVTK_RenderWindowInteractor
-::setGUIWindow(QWidget* theWindow)
+QVTK_RenderWindowInteractor
+::show()
 {
-  myGUIWindow = theWindow;
+  QWidget::show();
+  update(); // needed for initial contents display on Win32
 }
 
-//----------------------------------------------------------------------------
+/*!
+  To implement final initialization, just before the widget is displayed
+*/
 void
-SVTK_RenderWindowInteractor
-::setViewWindow(SVTK_ViewWindow* theViewWindow)
+QVTK_RenderWindowInteractor
+::polish()
 {
-  myViewWindow = theViewWindow;
-
-  myViewWindow->InsertActor(myCellActor);
-  myViewWindow->InsertActor(myEdgeActor);
-  myViewWindow->InsertActor(myPointActor);
+  // Final initialization just before the widget is displayed
+  GetDevice()->SetSize(width(),height());
+  if(!GetDevice()->GetInitialized() && GetDevice()->GetRenderWindow()){
+    GetDevice()->Initialize();
+    GetDevice()->ConfigureEvent();
+  }
 }
 
-//----------------------------------------------------------------------------
+/*!
+  To adjust widget and vtkRenderWindow size
+*/
 void
-SVTK_RenderWindowInteractor
-::MoveInternalActors()
+QVTK_RenderWindowInteractor
+::resize(int w, int h) 
 {
-  myViewWindow->MoveActor(myCellActor);
-  myViewWindow->MoveActor(myEdgeActor);
-  myViewWindow->MoveActor(myPointActor);
+  GetDevice()->UpdateSize(w,h);
 }
 
-//----------------------------------------------------------------------------
+/*!
+  Custom paint event handler
+*/
 void
-SVTK_RenderWindowInteractor
-::SetInteractorStyle(vtkInteractorObserver *theInteractor)
+QVTK_RenderWindowInteractor
+::paintEvent( QPaintEvent* /*theEvent*/ ) 
 {
-  myInteractorStyle = dynamic_cast<SVTK_InteractorStyle*>(theInteractor);
-  vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
+  GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
 }
 
 
+/*!
+  Custom resize event handler
+*/
 void
-SVTK_RenderWindowInteractor
-::SetSelectionMode(Selection_Mode theMode)
+QVTK_RenderWindowInteractor
+::resizeEvent( QResizeEvent* /*theEvent*/ )
 {
-  myCellActor->SetVisibility(false);
-  myEdgeActor->SetVisibility(false);
-  myPointActor->SetVisibility(false);
+  int* aSize = getRenderWindow()->GetSize();
+  int aWidth = aSize[0];
+  int aHeight = aSize[1];
 
-  switch(theMode){
-  case ActorSelection:
-    this->SetPicker(myBasicPicker);
-    break;
-  case NodeSelection:
-    this->SetPicker(myPointPicker);
-    break;
-  case CellSelection:
-  case EdgeSelection:
-  case FaceSelection:
-  case VolumeSelection:
-  case EdgeOfCellSelection:
-    this->SetPicker(myCellPicker);
-    break;
+  GetDevice()->UpdateSize(width(),height());
+
+  if(isVisible() && aWidth && aHeight){
+    if( aWidth != width() || aHeight != height() ) {
+      vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers();
+      aRenderers->InitTraversal();
+      double aCoeff = 1.0;
+      if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) {
+        vtkCamera *aCamera = aRenderer->GetActiveCamera();
+        double aScale = aCamera->GetParallelScale();
+        if((aWidth - width())*(aHeight - height()) > 0)
+          aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
+        else
+          aCoeff = double(aWidth)/double(width());
+        aCamera->SetParallelScale(aScale*aCoeff);
+      }
+    }
   }
 
-  myInteractorStyle->OnSelectionModeChanged();
+  update(); 
 }
 
+
+
+/*!
+  Custom context menu event handler
+*/
 void
-SVTK_RenderWindowInteractor
-::SetSelectionProp(const double& theRed, 
-                  const double& theGreen, 
-                  const double& theBlue, 
-                  const int& theWidth) 
-{
-  myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
-  myCellActor->GetProperty()->SetLineWidth(theWidth);
+QVTK_RenderWindowInteractor
+::contextMenuEvent( QContextMenuEvent* /*event*/ )
+{}
 
-  myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
-  myPointActor->GetProperty()->SetPointSize(theWidth);
+/*!
+  Custom mouse move event handler
+*/
+void
+QVTK_RenderWindowInteractor
+::mouseMoveEvent( QMouseEvent* event ) 
+{
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                        event->y(),
+                                        event->modifiers() & Qt::ControlModifier,
+                                        event->modifiers() & Qt::ShiftModifier);
+  GetDevice()->MouseMoveEvent();
+}
+
+
+/*!
+  Custom mouse press event handler
+*/
+void
+QVTK_RenderWindowInteractor
+::mousePressEvent( QMouseEvent* event ) 
+{
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                        event->y(),
+                                        event->modifiers() & Qt::ControlModifier,
+                                        event->modifiers() & Qt::ShiftModifier);
+  if( event->button() & Qt::LeftButton )
+    GetDevice()->LeftButtonPressEvent();
+  else if( event->button() & Qt::MidButton )
+    GetDevice()->MiddleButtonPressEvent();
+  else if( event->button() & Qt::RightButton )
+    GetDevice()->RightButtonPressEvent();
+}
+
+
+/*!
+  Custom mouse release event handler
+*/
+void
+QVTK_RenderWindowInteractor
+::mouseReleaseEvent( QMouseEvent *event )
+{
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                        event->y(),
+                                        event->modifiers() & Qt::ControlModifier,
+                                        event->modifiers() & Qt::ShiftModifier);
+
+  if( event->button() & Qt::LeftButton )
+    GetDevice()->LeftButtonReleaseEvent();
+  else if( event->button() & Qt::MidButton )
+    GetDevice()->MiddleButtonReleaseEvent();
+  else if( event->button() & Qt::RightButton ) {
+#if defined(Fix_Of_vtkImplicitPlaneWidget_bug)
+    GetDevice()->SetEventInformationFlipY( -99999, -99999,
+                                           event->modifiers() & Qt::ControlModifier,
+                                           event->modifiers() & Qt::ShiftModifier);
+    bool blocked = blockSignals( true );
+    GetDevice()->LeftButtonPressEvent();
+    GetDevice()->LeftButtonReleaseEvent();
+    blockSignals( blocked );
+    GetDevice()->SetEventInformationFlipY(event->x(),
+                                          event->y(),
+                                          event->modifiers() & Qt::ControlModifier,
+                                          event->modifiers() & Qt::ShiftModifier);
+#endif
+    GetDevice()->RightButtonReleaseEvent();
+  }
 }
 
-void
-SVTK_RenderWindowInteractor
-::SetSelectionTolerance(const double& theTolNodes, 
-                       const double& theTolItems)
-{
-  myTolNodes = theTolNodes;
-  myTolItems = theTolItems;
 
-  myBasicPicker->SetTolerance(myTolItems);
-  myCellPicker->SetTolerance(myTolItems);
-  myPointPicker->SetTolerance(myTolNodes);
+/*!
+  Custom mouse double click event handler
+*/
+void
+QVTK_RenderWindowInteractor
+::mouseDoubleClickEvent( QMouseEvent* /*event*/ )
+{}
 
-}
 
-// ================================== 
+/*!
+  Custom mouse wheel event handler
+*/
 void
-SVTK_RenderWindowInteractor
-::Start() 
+QVTK_RenderWindowInteractor
+::wheelEvent( QWheelEvent* event )
 {
-  //
-  // We do not allow this interactor to control the 
-  // event loop. Only the QtApplication objects are
-  // allowed to do that. 
-  //
-  vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ;
-  return ;
+  activateWindow();
+  setFocus();
+  GetDevice()->SetEventInformationFlipY(event->x(), 
+                                        event->y(),
+                                        event->modifiers() & Qt::ControlModifier,
+                                        event->modifiers() & Qt::ShiftModifier);
+  if ( event->delta()>0)
+    GetDevice()->MouseWheelForwardEvent();
+  else
+    GetDevice()->MouseWheelBackwardEvent();
 }
 
+
+/*!
+  Custom key press event handler
+*/
 void
-SVTK_RenderWindowInteractor
-::UpdateSize(int w, int h
+QVTK_RenderWindowInteractor
+::keyPressEvent( QKeyEvent* event 
 {
-  // if the size changed send this on to the RenderWindow
-  if ((w != this->Size[0])||(h != this->Size[1])) {
-    this->Size[0] = w;
-    this->Size[1] = h;
-    this->RenderWindow->SetSize(w,h);
-  }
+  GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier,
+                                      event->modifiers() & Qt::ShiftModifier,
+                                      event->key());
+  GetDevice()->KeyPressEvent();
+  GetDevice()->CharEvent();
 }
 
-int
-SVTK_RenderWindowInteractor
-::CreateTimer(int vtkNotUsed(timertype)) 
+/*!
+  Custom key release event handler
+*/
+void
+QVTK_RenderWindowInteractor
+::keyReleaseEvent( QKeyEvent * event ) 
 {
-  //
-  // Start a one-shot timer for 10ms. 
-  //
-  mTimer->start(10, TRUE) ;
-  return 1 ;
+  GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier,
+                                      event->modifiers() & Qt::ShiftModifier,
+                                      event->key());
+  GetDevice()->KeyReleaseEvent();
 }
 
-int
-SVTK_RenderWindowInteractor
-::DestroyTimer(void) 
-{
-  //
-  // :TRICKY: Tue May  2 00:17:32 2000 Pagey
-  //
-  // QTimer will automatically expire after 10ms. So 
-  // we do not need to do anything here. In fact, we 
-  // should not even Stop() the QTimer here because doing 
-  // this will skip some of the processing that the TimerFunc()
-  // does and will result in undesirable effects. For 
-  // example, this will result in vtkLODActor to leave
-  // the models in low-res mode after the mouse stops
-  // moving. 
-  //
-  return 1 ;
-}
 
-void
-SVTK_RenderWindowInteractor
-::TimerFunc() 
+/*!
+  Custom enter event handler
+*/
+void  
+QVTK_RenderWindowInteractor
+::enterEvent( QEvent* /*event*/ )
 {
-  if( ! this->Enabled ) {
-    return ;
+  if(FOCUS_UNDER_MOUSE){
+    activateWindow();
+    setFocus();
   }
-
-  myInteractorStyle->OnTimer();
-
-  emit RenderWindowModified();
+  GetDevice()->EnterEvent();
 }
 
-void
-SVTK_RenderWindowInteractor
-::MouseMove(const QMouseEvent *event) 
+/*!
+  Custom leave event handler
+*/
+void  
+QVTK_RenderWindowInteractor
+::leaveEvent( QEvent * )
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ;
-  if (myInteractorStyle->needsRedrawing() )
-    emit RenderWindowModified() ; 
+  GetDevice()->LeaveEvent();
 }
 
-void
-SVTK_RenderWindowInteractor
-::LeftButtonPressed(const QMouseEvent *event) 
+/*!
+  Reimplemented from QWidget in order to set window - receiver
+  of space mouse events. 
+*/
+void  
+QVTK_RenderWindowInteractor
+::focusInEvent( QFocusEvent* event )
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), 
-                                     (event->state() & ShiftButton), 
-                                     event->x(), event->y());
-}
+  QWidget::focusInEvent( event );
 
-void
-SVTK_RenderWindowInteractor
-::LeftButtonReleased(const QMouseEvent *event) {
-  if( ! this->Enabled ) {
-    return ;
+#if !defined WIN32 && !defined __APPLE__
+  // register set space mouse events receiver
+  SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
+  if ( aSpaceMouse )
+  {
+    if ( !aSpaceMouse->isSpaceMouseOn() )
+      // initialize 3D space mouse driver
+      aSpaceMouse->initialize( QX11Info::connection(), winId() );
+    else
+      aSpaceMouse->setWindow( QX11Info::connection(), winId() );
   }
-  myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), 
-                                    (event->state() & ShiftButton), 
-                                    event->x(), event->y() ) ;
+#endif
 }
 
-void 
-SVTK_RenderWindowInteractor
-::MiddleButtonPressed(const QMouseEvent *event) 
+/*!
+  Reimplemented from QWidget in order to set window - receiver
+  of space mouse events. 
+*/
+void  
+QVTK_RenderWindowInteractor
+::focusOutEvent ( QFocusEvent* event )
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
-}
+  QWidget::focusOutEvent( event );
 
-void
-SVTK_RenderWindowInteractor
-::MiddleButtonReleased(const QMouseEvent *event) 
-{
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), 
-                                      (event->state() & ShiftButton), 
-                                      event->x(), event->y() ) ;
+#if !defined WIN32 && !defined __APPLE__
+  SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance();
+  if ( aSpaceMouse && aSpaceMouse->isSpaceMouseOn() )
+    aSpaceMouse->setWindow( QX11Info::connection(), 0 );
+#endif
 }
 
-void
-SVTK_RenderWindowInteractor
-::RightButtonPressed(const QMouseEvent *event) 
+bool QVTK_RenderWindowInteractor
+::nativeEvent(const QByteArray& eventType, void* message, long* result)
 {
-  if( ! this->Enabled ) {
-    return ;
+#if defined(WIN32)
+  // TODO: WIN32-related implementation
+#elif !defined(__APPLE__)
+  if ( eventType == "xcb_generic_event_t" )
+  {
+    xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message);
+    if ( SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance() )
+    {
+      if ( aSpaceMouse->isSpaceMouseOn() && ev->response_type == XCB_CLIENT_MESSAGE )
+      {
+        SVTK_SpaceMouse::MoveEvent anEvent;
+        int type = aSpaceMouse->translateEvent( QX11Info::connection(), (xcb_client_message_event_t*)ev, &anEvent, 1.0, 1.0 );
+        switch ( type )
+        {
+        case SVTK_SpaceMouse::SpaceMouseMove:
+                GetDevice()->InvokeEvent( SVTK::SpaceMouseMoveEvent, anEvent.data );
+                break;
+        case SVTK_SpaceMouse::SpaceButtonPress:
+                GetDevice()->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button );
+                break;
+        case SVTK_SpaceMouse::SpaceButtonRelease:
+                break;
+        }
+        return true; // stop handling the event
+      }
+    }
   }
-  myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
+#endif
+ return QWidget::nativeEvent( eventType, message, result );
 }
 
-void
+/*!
+  Constructor
+*/
 SVTK_RenderWindowInteractor
-::RightButtonReleased(const QMouseEvent *event) 
+::SVTK_RenderWindowInteractor(QWidget* theParent, 
+                               const char* theName):
+  QVTK_RenderWindowInteractor(theParent,theName),
+  myEventCallbackCommand(vtkCallbackCommand::New())
 {
-  if( ! this->Enabled ) {
-    return ;
-  }
-  myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), 
-                                     (event->state() & ShiftButton), 
-                                     event->x(), event->y() ) ;
+  myEventCallbackCommand->Delete();
 
-  if(myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && !( event->state() & KeyButtonMask )){
-    QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
-                              event->pos(), event->globalPos(),
-                              event->state() );
-    emit contextMenuRequested( &aEvent );
-  }
+  myEventCallbackCommand->SetClientData(this); 
+  myPriority = 0.0;
+
+  myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents);
 }
 
+/*!
+  To initialize properly the class
+*/
 void
 SVTK_RenderWindowInteractor
-::ButtonPressed(const QMouseEvent *event) 
+::Initialize(vtkGenericRenderWindowInteractor* theDevice,
+             SVTK_Renderer* theRenderer,
+             SVTK_Selector* theSelector)
 {
-  return ;
+  QVTK_RenderWindowInteractor::Initialize(theDevice);
+  SetRenderer(theRenderer);
+  SetSelector(theSelector);
 }
 
-void
+/*!
+  Destructor
+*/
 SVTK_RenderWindowInteractor
-::ButtonReleased(const QMouseEvent *event
+::~SVTK_RenderWindowInteractor(
 {
-  return ;
+  // Sequence of the destruction call are fixed and should be changed.
+  // vtkRenderWindow instance should be destroyed after all vtkRenderer's
+  GetDevice()->SetInteractorStyle(NULL); 
+  while(!myInteractorStyles.empty()){
+    const PInteractorStyle& aStyle = myInteractorStyles.top();
+    aStyle->SetInteractor(NULL);
+    myInteractorStyles.pop();
+  }
 }
 
-
-int
+/*!
+  To get corresponding SVTK_Renderer instance
+*/
+SVTK_Renderer* 
 SVTK_RenderWindowInteractor
-::GetDisplayMode() 
+::GetRenderer()
 {
-  return myDisplayMode;
+  return myRenderer.GetPointer();
 }
 
-void
+/*!
+  To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer)
+*/
+vtkRenderer* 
 SVTK_RenderWindowInteractor
-::SetDisplayMode(int theMode)
+::getRenderer()
 {
-  if(theMode == 0) 
-    ChangeRepresentationToWireframe();
-  else 
-    ChangeRepresentationToSurface();
-  myDisplayMode = theMode;
+  return GetRenderer()->GetDevice();
 }
 
-
+/*!
+  Changes renderer
+  \param theRenderer - new renderer
+*/
 void
 SVTK_RenderWindowInteractor
-::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, 
-                int theMode)
+::SetRenderer(SVTK_Renderer* theRenderer)
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,int>
-                         (&SALOME_Actor::setDisplayMode,theMode));
-}
+  if(theRenderer == myRenderer.GetPointer())
+    return;
 
+  if(GetRenderer())
+    myRenderWindow->RemoveRenderer(getRenderer());
 
-void
-SVTK_RenderWindowInteractor
-::ChangeRepresentationToWireframe()
-{
-  ChangeRepresentationToWireframe(GetRenderer()->GetActors());
+  myRenderer = theRenderer;
+
+  if(GetRenderer())
+    myRenderWindow->AddRenderer(getRenderer());
 }
 
+
+/*!
+  Changes interactor style
+  \param theStyle - new interactor style
+*/
 void
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToSurface()
+::InitInteractorStyle(vtkInteractorStyle* theStyle)
 {
-  ChangeRepresentationToSurface(GetRenderer()->GetActors());
+  GetDevice()->SetInteractorStyle(theStyle); 
 }
 
-
+/*!
+  To change current interactor style by pushing the new one into the container
+*/
 void
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToWireframe(vtkActorCollection* theCollection)
+::PushInteractorStyle(vtkInteractorStyle* theStyle)
 {
-  using namespace VTK;
-  ForEach<SALOME_Actor>(theCollection,
-                       TSetFunction<SALOME_Actor,int>
-                       (&SALOME_Actor::setDisplayMode,0));
-  emit RenderWindowModified();
+  myInteractorStyles.push(PInteractorStyle(theStyle));
+  InitInteractorStyle(theStyle);
 }
 
+/*!
+  To restore previous interactor style
+*/
 void
 SVTK_RenderWindowInteractor
-::ChangeRepresentationToSurface(vtkActorCollection* theCollection)
+::PopInteractorStyle()
 {
-  using namespace VTK;
-  ForEach<SALOME_Actor>(theCollection,
-                       TSetFunction<SALOME_Actor,int>
-                       (&SALOME_Actor::setDisplayMode,1));
-  emit RenderWindowModified();
+  if(GetInteractorStyle())
+    myInteractorStyles.pop();
+  
+  if(GetInteractorStyle()) 
+    InitInteractorStyle(GetInteractorStyle());
 }
 
-
-vtkRenderer* 
+/*!
+  To get current interactor style
+*/
+vtkInteractorStyle* 
 SVTK_RenderWindowInteractor
-::GetRenderer()
+::GetInteractorStyle()
 {
-  vtkRendererCollection * theRenderers =  this->RenderWindow->GetRenderers();
-  theRenderers->InitTraversal();
-  return theRenderers->GetNextItem();
+  return myInteractorStyles.empty() ? 0 : myInteractorStyles.top().GetPointer();
 }
 
 
-struct TErase{
-  VTK::TSetFunction<vtkActor,int> mySetFunction;
-  TErase():
-    mySetFunction(&vtkActor::SetVisibility,false)
-  {}
-  void operator()(SALOME_Actor* theActor){
-    theActor->SetVisibility(false);
-    // Erase dependent actors
-    vtkActorCollection* aCollection = vtkActorCollection::New(); 
-    theActor->GetChildActors(aCollection);
-    VTK::ForEach<vtkActor>(aCollection,mySetFunction);
-    aCollection->Delete();
-  }
-};
-
-void
+/*!
+  To get current selector
+*/
+SVTK_Selector* 
 SVTK_RenderWindowInteractor
-::EraseAll()
-{   
-  using namespace VTK;
-  ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
-                       TErase());
-
-  emit RenderWindowModified() ;
-}
-
-void
-SVTK_RenderWindowInteractor
-::DisplayAll()
+::GetSelector() 
 { 
-  vtkActorCollection* aCollection = GetRenderer()->GetActors();
-  using namespace VTK;
-  ForEach<SALOME_Actor>(aCollection,TSetVisibility<SALOME_Actor>(true));
-
-  emit RenderWindowModified() ;
+  return mySelector.GetPointer(); 
 }
 
 
+/*!
+  Changes selector
+  \param theSelector - new selector
+*/
 void
 SVTK_RenderWindowInteractor
-::Erase(SALOME_Actor* theActor, bool update)
-{
-  TErase()(theActor);
-
-  if(update)
-    emit RenderWindowModified();
-}
+::SetSelector(SVTK_Selector* theSelector)
+{ 
+  if(mySelector.GetPointer())
+    mySelector->RemoveObserver(myEventCallbackCommand.GetPointer());
 
+  mySelector = theSelector; 
 
-void
-SVTK_RenderWindowInteractor
-::Erase(const Handle(SALOME_InteractiveObject)& theIObject, 
-       bool update)
-{
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TErase());
-
-  if(update)
-    emit RenderWindowModified();
+  if(mySelector.GetPointer())
+    mySelector->AddObserver(vtkCommand::EndPickEvent, 
+                            myEventCallbackCommand.GetPointer(), 
+                            myPriority);
 }
 
-
-struct TRemoveAction{
-  vtkRenderer* myRen;
-  TRemoveAction(vtkRenderer* theRen): myRen(theRen){}
-  void operator()(SALOME_Actor* theActor){
-    myRen->RemoveActor(theActor);
-  }
-};
-
-void
+/*!
+  Main process VTK event method
+*/
+void 
 SVTK_RenderWindowInteractor
-::Remove(const Handle(SALOME_InteractiveObject)& theIObject, 
-        bool update)
+::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
+                unsigned long theEvent,
+                void* theClientData, 
+                void* vtkNotUsed(theCallData))
 {
-  vtkRenderer* aRen = GetRenderer();
+  SVTK_RenderWindowInteractor* self = reinterpret_cast<SVTK_RenderWindowInteractor*>(theClientData);
 
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(aRen->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TRemoveAction(aRen));
-}
-
-void
-SVTK_RenderWindowInteractor
-::Remove( SALOME_Actor* SActor, bool updateViewer )
-{
-  if ( SActor != 0 )
-  {
-    GetRenderer()->RemoveProp( SActor );
-    if ( updateViewer )
-      emit RenderWindowModified();
+  switch(theEvent){
+  case vtkCommand::EndPickEvent:
+    self->onEmitSelectionChanged();
+    break;
   }
 }
 
+/*!
+  To change selection mode (just to simplify collobaration with SVTK_Selector)
+*/
 void
 SVTK_RenderWindowInteractor
-::RemoveAll( const bool updateViewer )
+::SetSelectionMode(Selection_Mode theMode)
 {
-  vtkRenderer* aRenderer = GetRenderer();
-  vtkActorCollection* anActors = aRenderer->GetActors();
-  if ( anActors )
-  {
-    anActors->InitTraversal();
-    while ( vtkActor *anAct = anActors->GetNextActor() )
-    {
-      if ( anAct->IsA( "SALOME_Actor" ) )
-      {
-        SALOME_Actor* aSAct = (SALOME_Actor*)anAct;
-        if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() )
-          aRenderer->RemoveActor( anAct );
-      }
-    }
-
-    if ( updateViewer )
-      emit RenderWindowModified();
-  }
+  mySelector->SetSelectionMode(theMode);
 }
 
-
-float
+/*!
+  To get current selection mode (just to simplify collobaration with SVTK_Selector)
+*/
+Selection_Mode
 SVTK_RenderWindowInteractor
-::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) 
+::SelectionMode() const
 {
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  if(anActor)
-    return 1.0 - anActor->GetOpacity();
-  return -1.0;
+  return mySelector->SelectionMode();
 }
 
 
+/*!
+  Emits signal selectionChanged()
+*/
 void
 SVTK_RenderWindowInteractor
-::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, 
-                 float theTrans)
+::onEmitSelectionChanged()
 {
-  float anOpacity = 1.0 - theTrans;
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,float>
-                         (&SALOME_Actor::SetOpacity,anOpacity));
+  return emit selectionChanged();
 }
 
 
+/*!
+  Custom mouse move event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::Display(SALOME_Actor* theActor, bool update)
+::mouseMoveEvent( QMouseEvent* event ) 
 {
-  GetRenderer()->AddActor(theActor);
-  theActor->SetVisibility(true);
+  QVTK_RenderWindowInteractor::mouseMoveEvent(event);
 
-  if(update)
-    emit RenderWindowModified();
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseMove( event );
 }
 
 
+/*!
+  Custom mouse press event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
+::mousePressEvent( QMouseEvent* event ) 
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetVisibility<SALOME_Actor>(true));
+  QVTK_RenderWindowInteractor::mousePressEvent(event);
 
-  if(update)
-    emit RenderWindowModified() ;
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseButtonPressed( event );
 }
 
 
+/*!
+  Custom mouse release event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::KeyPressed(QKeyEvent *event)
-{}
-
-
-struct THighlightAction{
-  bool myIsHighlight;
-  SVTK_InteractorStyle* myInteractorStyle;
-  THighlightAction(SVTK_InteractorStyle* theInteractorStyle,
-                  bool theIsHighlight): 
-    myInteractorStyle(theInteractorStyle),
-    myIsHighlight(theIsHighlight)
-  {}
-  void operator()(SALOME_Actor* theActor){
-    if(theActor->GetMapper()){
-      if(theActor->hasHighlight())
-       theActor->highlight(myIsHighlight);
-      else{
-       if(theActor->GetVisibility() && myIsHighlight)
-         myInteractorStyle->HighlightProp(theActor);
-       else if(!myIsHighlight)
-         myInteractorStyle->HighlightProp(NULL);
-      }
-    }
-  }
-};
-
-bool
-SVTK_RenderWindowInteractor
-::highlight( const Handle(SALOME_InteractiveObject)& theIObject, 
-            bool hilight, 
-            bool update)
+::mouseReleaseEvent( QMouseEvent *event )
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         THighlightAction(myInteractorStyle,hilight));
-
-  if(update)
-    emit RenderWindowModified();
-
-  return false;
-}
-
-
-struct TUpdateAction{
-  void operator()(vtkActor* theActor){
-    theActor->ApplyProperties();
+  SVTK_InteractorStyle* style = 0;
+  bool aRightBtn = event->button() == Qt::RightButton;
+  bool isOperation = false;
+  bool isPolygonalSelection = false;
+  if( aRightBtn && GetInteractorStyle()) {
+    style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
+    if ( style )
+      isOperation = style->CurrentState() != VTK_INTERACTOR_STYLE_CAMERA_NONE;
   }
-};
-
-void
-SVTK_RenderWindowInteractor
-::Update() 
-{
-  vtkRenderer* aRen = GetRenderer();
 
-  using namespace VTK;
-  ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
+  QVTK_RenderWindowInteractor::mouseReleaseEvent(event);
 
-  aRen->ResetCamera();
-
-  emit RenderWindowModified();  
-}
-
-
-void
-SVTK_RenderWindowInteractor
-::unHighlightSubSelection()
-{
-  myPointActor->SetVisibility(false);
-  myEdgeActor->SetVisibility(false);
-  myCellActor->SetVisibility(false);
-}
-
-
-bool
-SVTK_RenderWindowInteractor
-::unHighlightAll()
-{
-  unHighlightSubSelection();
-
-  using namespace VTK;
-  ForEach<SALOME_Actor>(GetRenderer()->GetActors(),
-                       THighlightAction(myInteractorStyle,false));
-
-  emit RenderWindowModified() ;
+  if ( style ) {
+    isPolygonalSelection = style->GetPolygonState() == Finished;
+    style->SetPolygonState( Disable );
+  }
 
-  return false;
+  if ( aRightBtn && !isOperation && !isPolygonalSelection &&
+       !( event->modifiers() & Qt::ControlModifier ) &&
+       !( event->modifiers() & Qt::ShiftModifier ) ) {
+    QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
+                              event->pos(), event->globalPos() );
+    emit contextMenuRequested( &aEvent );
+  }
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseButtonReleased( event );
 }
 
-//-----------------
-// Color methods
-//-----------------
 
+/*!
+  Custom mouse double click event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor) 
+::mouseDoubleClickEvent( QMouseEvent* event )
 {
-  float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.};
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,const float*>
-                         (&SALOME_Actor::SetColor,aColor));
-}
-
-
-QColor
-SVTK_RenderWindowInteractor
-::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) 
-{
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  if(anActor){
-    float r,g,b;
-    anActor->GetColor(r,g,b);
-    return QColor(int(r*255),int(g*255),int(b*255));
+  if( GetInteractorStyle() && event->button() == Qt::LeftButton ) {
+    SVTK_InteractorStyle* style = dynamic_cast<SVTK_InteractorStyle*>( GetInteractorStyle() );
+    if ( style )
+      style->OnMouseButtonDoubleClick();
   }
-  return QColor(0,0,0);
-}
 
+  QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event);
 
-bool
-SVTK_RenderWindowInteractor
-::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject)
-{
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  return anActor != NULL;
-}
-
-
-bool
-SVTK_RenderWindowInteractor
-::isVisible(const Handle(SALOME_InteractiveObject)& theIObject)
-{
-  using namespace VTK;
-  SALOME_Actor* anActor = 
-    Find<SALOME_Actor>(GetRenderer()->GetActors(),
-                      TIsSameIObject<SALOME_Actor>(theIObject));
-  return anActor != NULL && anActor->GetVisibility();
+  if(GENERATE_SUIT_EVENTS)
+    emit MouseDoubleClicked( event );
 }
 
 
+/*!
+  Custom mouse wheel event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName)
+::wheelEvent( QWheelEvent* event )
 {
-  using namespace VTK;
-  ForEachIf<SALOME_Actor>(GetRenderer()->GetActors(),
-                         TIsSameIObject<SALOME_Actor>(theIObject),
-                         TSetFunction<SALOME_Actor,const char*,QString>
-                         (&SALOME_Actor::setName,theName.latin1()));
-}
-
-
-//----------------------------------------------------------------------------
-bool
-SVTK_RenderWindowInteractor
-::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
-           SALOME_Actor* theMapActor, 
-           SVTK_Actor* theActor,
-           TUpdateActor theFun, 
-           bool hilight, 
-           bool update)
-{
-  if(theMapIndex.Extent() == 0) return false;
-  
-  if (hilight) {
-    setActorData(theMapIndex,theMapActor,theActor,theFun);
-    theActor->SetVisibility(true);
-  }
-  else {
-    theActor->SetVisibility(false);
-  }
+  QVTK_RenderWindowInteractor::wheelEvent(event);
 
-  if(update){
-    this->RenderWindow->Render();  
-    emit RenderWindowModified() ;
-  }
+  if(event->delta() > 0)
+    GetDevice()->InvokeEvent(SVTK::ZoomInEvent,NULL);
+  else
+    GetDevice()->InvokeEvent(SVTK::ZoomOutEvent,NULL);
 
-  return false;
+  if(GENERATE_SUIT_EVENTS)
+    emit WheelMoved( event );
 }
-  
+
+/*!
+  Custom key press event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
-              SALOME_Actor* theMapActor,
-              SVTK_Actor *theActor,
-              TUpdateActor theFun)
+::keyPressEvent( QKeyEvent* event ) 
 {
-  (*theFun)(theMapIndex,theMapActor,theActor);
-  float aPos[3];
-  theMapActor->GetPosition(aPos);
-  theActor->SetPosition(aPos);
-}
+  QVTK_RenderWindowInteractor::keyPressEvent(event);
 
-
-//----------------------------------------------------------------------------
-static void CellsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                            SALOME_Actor* theMapActor, 
-                            SVTK_Actor* theActor)
-{
-  theActor->MapCells(theMapActor,theMapIndex);
-}
-  
-bool
-SVTK_RenderWindowInteractor
-::highlightCell(const TColStd_IndexedMapOfInteger& theMapIndex,
-               SALOME_Actor* theMapActor, 
-               bool hilight, 
-               bool update)
-{
-  return highlight(theMapIndex,theMapActor,myCellActor,&CellsUpdateActor,hilight,update);
-}
-  
-void 
-SVTK_RenderWindowInteractor
-::setCellData(const int& theIndex, 
-             SALOME_Actor* theMapActor,
-             SVTK_Actor* theActor)
-{
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theIndex);
-  theActor->MapCells(theMapActor,MapIndex);
+  if(GENERATE_SUIT_EVENTS)
+    emit KeyPressed( event );
 }
 
-
-//----------------------------------------------------------------------------
-static void PointsUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                             SALOME_Actor* theMapActor, 
-                             SVTK_Actor* theActor)
-{
-  theActor->MapPoints(theMapActor,theMapIndex);
-}
-  
-bool
-SVTK_RenderWindowInteractor
-::highlightPoint(const TColStd_IndexedMapOfInteger& theMapIndex,
-                SALOME_Actor* theMapActor, 
-                bool hilight, 
-                bool update)
-{
-  return highlight(theMapIndex,theMapActor,myPointActor,&PointsUpdateActor,hilight,update);
-}
-  
+/*!
+  Custom key release event handler
+*/
 void
 SVTK_RenderWindowInteractor
-::setPointData(const int& theIndex, 
-              SALOME_Actor* theMapActor,
-              SVTK_Actor* theActor)
+::keyReleaseEvent( QKeyEvent * event ) 
 {
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theIndex);
-  theActor->MapPoints(theMapActor,MapIndex);
-}
+  QVTK_RenderWindowInteractor::keyReleaseEvent(event);
 
-  
-//----------------------------------------------------------------------------
-static void EdgesUpdateActor(const TColStd_IndexedMapOfInteger& theMapIndex,
-                            SALOME_Actor* theMapActor, 
-                            SVTK_Actor* theActor)
-{
-  theActor->MapEdge(theMapActor,theMapIndex);
-}
-  
-bool
-SVTK_RenderWindowInteractor
-::highlightEdge(const TColStd_IndexedMapOfInteger& theMapIndex,
-               SALOME_Actor* theMapActor, 
-               bool hilight, 
-               bool update)
-{
-  return highlight(theMapIndex,theMapActor,myEdgeActor,&EdgesUpdateActor,hilight,update);
-}
-  
-void 
-SVTK_RenderWindowInteractor
-::setEdgeData(const int& theCellIndex, 
-             SALOME_Actor* theMapActor,
-             const int& theEdgeIndex, 
-             SVTK_Actor* theActor )
-{
-  TColStd_IndexedMapOfInteger MapIndex; 
-  MapIndex.Add(theCellIndex); 
-  MapIndex.Add(theEdgeIndex);
-  theActor->MapEdge(theMapActor,MapIndex);
+  if(GENERATE_SUIT_EVENTS)
+    emit KeyReleased( event );
 }
+