]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
To implement right way of TimerEvent invocation
authorapo <apo@opencascade.com>
Thu, 18 Aug 2005 12:05:10 +0000 (12:05 +0000)
committerapo <apo@opencascade.com>
Thu, 18 Aug 2005 12:05:10 +0000 (12:05 +0000)
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_RenderWindowInteractor.cxx
src/SVTK/SVTK_RenderWindowInteractor.h

index 720aace60d4d9165d95661e66de1606b122f4653..4624e1da03ccd815a59c432d532932278c6beb49 100644 (file)
@@ -1120,8 +1120,10 @@ SVTK_InteractorStyle
   
   Interactor->EndPickCallback();
 
-  if(anIsChanged)
-    Interactor->Render();
+  if(anIsChanged){
+    Interactor->CreateTimer(VTKI_TIMER_FIRST);
+    //Interactor->Render();
+  }
   
   this->LastPos[0] = x;
   this->LastPos[1] = y;
@@ -1278,6 +1280,16 @@ SVTK_InteractorStyle
   interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority );
 }
 
+
+//----------------------------------------------------------------------------
+void
+SVTK_InteractorStyle
+::OnTimer() 
+{
+  //vtkInteractorStyle::OnTimer();
+  this->Interactor->Render();
+}
+
 //----------------------------------------------------------------------------
 void
 SVTK_InteractorStyle
index 9627e93d30f2d61000c1bd017bdc5d01361af921..aae56d379b23be8d0af4c2b0b1f7df0a8347a671 100644 (file)
@@ -87,7 +87,6 @@ class SVTK_EXPORT SVTK_InteractorStyle :
 
   SVTK_SelectionEvent GetSelectionEvent();
 
-  //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron);
   void setPreselectionProp(const double& theRed = 0, 
                           const double& theGreen = 1,
                           const double& theBlue = 1, 
@@ -96,6 +95,9 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   // redefined in order to add an observer (callback) for custorm event (space mouse event)
   virtual void SetInteractor( vtkRenderWindowInteractor* );
 
+  // redefined in order to cach rendering
+  virtual void OnTimer();
+
   // VTK events
   virtual void OnMouseMove();
   virtual void OnLeftButtonDown();
index 4ef7a4cbd4236a137d6e17bcd13beb31aa620491..aee2c14cbe5f0e3c6f3a9bae7f40e50e44df3c79 100644 (file)
@@ -50,8 +50,8 @@
 #include <vtkCamera.h>
 
 // QT Includes
+#include <qtimer.h>
 #include <qcolordialog.h>
-#include <qwidget.h>
 #include <qpaintdevice.h>
 
 #include "utilities.h"
@@ -66,65 +66,45 @@ static int MYDEBUG = 0;
 
 
 //----------------------------------------------------------------------------
-SVTK_RenderWindowInteractor
-::SVTK_RenderWindowInteractor( QWidget* parent, const char* name ) :
-  SVTK_RenderWindow( parent, name )
-{
-  myInteractor = vtkGenericRenderWindowInteractor::New();
-
-  myInteractor->SetRenderWindow( getRenderWindow() );
-  myDisplayMode = 0;
+vtkStandardNewMacro(QtRenderWindowInteractor);
 
-  mTimer = new QTimer( this ) ;
-  connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ;
-}
-
-
-SVTK_RenderWindowInteractor
-::~SVTK_RenderWindowInteractor() 
+QtRenderWindowInteractor
+::QtRenderWindowInteractor()
 {
-  if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor::~SVTK_RenderWindowInteractor()");
-
-  // stop 3d space mouse driver
-  SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance();
-  if ( sm->isSpaceMouseOn() )
-    sm->close( x11Display() );
-
-  delete mTimer ;
-
-  myInteractor->Delete();
+  myTimer = new QTimer( ) ;
+  connect(myTimer, SIGNAL(timeout()), this, SLOT(OnTimeOut())) ;
 }
 
-//----------------------------------------------------------------------------
-void
-SVTK_RenderWindowInteractor
-::Initialize() 
+QtRenderWindowInteractor
+::~QtRenderWindowInteractor()
 {
-  myInteractor->Initialize();
+  delete myTimer;
 }
 
+
 //----------------------------------------------------------------------------
 void
-SVTK_RenderWindowInteractor
-::UpdateSize(int w, int h
+QtRenderWindowInteractor
+::OnTimeOut(
 {
-  myInteractor->UpdateSize(w,h);
+  if( GetEnabled() ) {
+    this->InvokeEvent(vtkCommand::TimerEvent,NULL);
+  }
 }
 
-//----------------------------------------------------------------------------
 int
-SVTK_RenderWindowInteractor
+QtRenderWindowInteractor
 ::CreateTimer(int vtkNotUsed(timertype)) 
 {
   //
   // Start a one-shot timer for 10ms. 
   //
-  mTimer->start(10, TRUE) ;
+  myTimer->start(10, TRUE) ;
   return 1 ;
 }
 
 int
-SVTK_RenderWindowInteractor
+QtRenderWindowInteractor
 ::DestroyTimer(void) 
 {
   //
@@ -142,20 +122,47 @@ SVTK_RenderWindowInteractor
   return 1 ;
 }
 
-void
+
+//----------------------------------------------------------------------------
 SVTK_RenderWindowInteractor
-::TimerFunc() 
+::SVTK_RenderWindowInteractor( QWidget* parent, const char* name ) :
+  SVTK_RenderWindow( parent, name )
 {
-  if( ! myInteractor->GetEnabled() ) {
-    return ;
-  }
+  myInteractor = QtRenderWindowInteractor::New();
+
+  myInteractor->SetRenderWindow( getRenderWindow() );
+  myDisplayMode = 0;
+}
 
-  vtkInteractorStyle* aStyle = vtkInteractorStyle::SafeDownCast( myInteractor->GetInteractorStyle() );
-  aStyle->OnTimer();
 
-  update();
+SVTK_RenderWindowInteractor
+::~SVTK_RenderWindowInteractor() 
+{
+  if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor::~SVTK_RenderWindowInteractor()");
+
+  // stop 3d space mouse driver
+  SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance();
+  if ( sm->isSpaceMouseOn() )
+    sm->close( x11Display() );
+
+  myInteractor->Delete();
 }
 
+//----------------------------------------------------------------------------
+void
+SVTK_RenderWindowInteractor
+::Initialize() 
+{
+  myInteractor->Initialize();
+}
+
+//----------------------------------------------------------------------------
+void
+SVTK_RenderWindowInteractor
+::UpdateSize(int w, int h) 
+{
+  myInteractor->UpdateSize(w,h);
+}
 
 //----------------------------------------------------------------------------
 int
@@ -510,14 +517,10 @@ void
 SVTK_RenderWindowInteractor
 ::mouseMoveEvent( QMouseEvent* event ) 
 {
-  //cout << "SVTK_RenderWindowInteractor::mouseMoveEvent" << endl;
-
   myInteractor->SetEventInformation( event->x(), event->y(),
                                     ( event->state() & ControlButton ),
                                     ( event->state() & ShiftButton ) );
   myInteractor->MouseMoveEvent();
-
-  //emit MouseMove( event ) ;
 }
 
 //----------------------------------------------------------------------------
@@ -525,20 +528,15 @@ void
 SVTK_RenderWindowInteractor
 ::mousePressEvent( QMouseEvent* event ) 
 {
-  //cout << "SVTK_RenderWindowInteractor::mousePressEvent" << endl;
-
   myInteractor->SetEventInformation( event->x(), event->y(),
                                     ( event->state() & ControlButton ),
                                     ( event->state() & ShiftButton ) );
-
   if( event->button() & LeftButton )
     myInteractor->LeftButtonPressEvent();
   else if( event->button() & MidButton )
     myInteractor->MiddleButtonPressEvent();
   else if( event->button() & RightButton )
     myInteractor->RightButtonPressEvent();
-
-  //emit MouseButtonPressed( event );
 }
 
 //----------------------------------------------------------------------------
@@ -546,8 +544,6 @@ void
 SVTK_RenderWindowInteractor
 ::mouseReleaseEvent( QMouseEvent *event )
 {
-  //cout << "SVTK_RenderWindowInteractor::mouseReleaseEvent" << endl;
-
   myInteractor->SetEventInformation( event->x(), event->y(),
                                     ( event->state() & ControlButton ),
                                     ( event->state() & ShiftButton ) );
@@ -558,34 +554,23 @@ SVTK_RenderWindowInteractor
     myInteractor->MiddleButtonReleaseEvent();
   else if( event->button() & RightButton )
     myInteractor->RightButtonReleaseEvent();
-
-  //emit MouseButtonReleased( event );
 }
 
 //----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
 ::mouseDoubleClickEvent( QMouseEvent* event )
-{
-  //cout << "SVTK_RenderWindowInteractor::mouseDoubleClickEvent" << endl;
-
-  //emit MouseDoubleClicked( event );
-}
+{}
 
 //----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
 ::keyPressEvent( QKeyEvent* event ) 
 {
-  //cout << "SVTK_RenderWindowInteractor::keyPressEvent" << endl;
-
   myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ),
                                        ( event->state() & ShiftButton ),
                                        0 );
-
   myInteractor->KeyPressEvent();
-
-  //emit KeyPressed(event) ;
 }
 
 //----------------------------------------------------------------------------
@@ -593,44 +578,33 @@ void
 SVTK_RenderWindowInteractor
 ::keyReleaseEvent( QKeyEvent * event ) 
 {
-  //cout << "SVTK_RenderWindowInteractor::keyReleaseEvent" << endl;
-
   myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ),
                                        ( event->state() & ShiftButton ),
                                        0 );
-
   myInteractor->KeyReleaseEvent();
-
-  //emit KeyReleased(event) ;
 }
 
 //----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
 ::wheelEvent( QWheelEvent* event )
-{
-  //cout << "SVTK_RenderWindowInteractor::wheelEvent" << endl;
-
-  //emit WheelMoved(event) ;
-}
+{}
 
 //----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::contextMenuEvent( QContextMenuEvent* event )
+::paintEvent( QPaintEvent* theEvent ) 
 {
-  //cout << "SVTK_RenderWindowInteractor::contextMenuEvent" << endl;
-
-  if( !( event->state() & KeyButtonMask ) )
-    emit contextMenuRequested( event );
+  getRenderWindow()->Render();
 }
 
 //----------------------------------------------------------------------------
 void
 SVTK_RenderWindowInteractor
-::paintEvent( QPaintEvent* theEvent ) 
+::contextMenuEvent( QContextMenuEvent* event )
 {
-  getRenderWindow()->Render();
+  if( !( event->state() & KeyButtonMask ) )
+    emit contextMenuRequested( event );
 }
 
 //----------------------------------------------------------------------------
index 03d9f39b233ffd68d407044518379860555a9645..d969e22af743bf613ab67620c3e445da82f05c6d 100644 (file)
 
 #include "SALOME_InteractiveObject.hxx"
 
-// QT Includes
-#include <qtimer.h>
-
 // VTK Includes
-#include <vtkVersion.h>
+#include <vtkGenericRenderWindowInteractor.h>
+
+class QTimer;
 
 class vtkActorCollection;
 class vtkGenericRenderWindowInteractor;
@@ -53,15 +52,43 @@ class SALOME_Actor;
 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
 // matters here. Be careful not to change it by accident. 
 // ------------------------------------------------------------
-class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow//, public vtkRenderWindowInteractor
+class SVTK_EXPORT QtRenderWindowInteractor: 
+ public QObject,
+ public vtkGenericRenderWindowInteractor
 {
-  Q_OBJECT
+  Q_OBJECT;
+
+ protected slots:
+  virtual
+  void
+  OnTimeOut();
+
+ protected:
+  QtRenderWindowInteractor();
+  ~QtRenderWindowInteractor();
+
+  QTimer* myTimer ;
+
+ public:
+  
+  static QtRenderWindowInteractor* New();
+  vtkTypeMacro(QtRenderWindowInteractor,vtkGenericRenderWindowInteractor);
+
+  virtual int CreateTimer( int ) ; 
+  virtual int DestroyTimer() ; 
+};
+
 
-public:
+// ------------------------------------------------------------
+class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow
+{
+  Q_OBJECT;
+
+ public:
   SVTK_RenderWindowInteractor( QWidget*, const char* );
   ~SVTK_RenderWindowInteractor();
 
-  vtkGenericRenderWindowInteractor* getInteractor() { return myInteractor; }
+  vtkRenderWindowInteractor* getInteractor() { return myInteractor; }
 
   // Description:
   // Initializes the event handlers without an XtAppContext.  This is
@@ -73,15 +100,6 @@ public:
   // Event loop notification member for Window size change
   virtual void UpdateSize(int x,int y);
 
-  // Description:
-  // Timer methods must be overridden by platform dependent subclasses.
-  // flag is passed to indicate if this is first timer set or an update
-  // as Win32 uses repeating timers, whereas X uses One shot more timer
-  // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
-  // otherwise Win32 should exit and X should perform AddTimeOut()
-  virtual int CreateTimer(int ) ; 
-  virtual int DestroyTimer() ; 
-  
   /* Selection Management */
   bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
@@ -139,14 +157,7 @@ public:
  protected:
   vtkGenericRenderWindowInteractor* myInteractor;
 
-  // Timer used during various mouse events to figure 
-  // out mouse movements. 
-  QTimer *mTimer ;
-
   int myDisplayMode;
-  
-  // User for switching to stereo mode.
-  int PositionBeforeStereo[2];
 
  protected:
   virtual void mouseMoveEvent( QMouseEvent* );
@@ -156,7 +167,6 @@ public:
   virtual void wheelEvent( QWheelEvent* );
   virtual void keyPressEvent( QKeyEvent* );
   virtual void keyReleaseEvent( QKeyEvent* );
-  virtual void contextMenuEvent( QContextMenuEvent * e );
   virtual bool x11Event( XEvent *e );
 
   virtual void paintEvent( QPaintEvent* );
@@ -168,16 +178,10 @@ public:
   virtual void focusInEvent ( QFocusEvent* );
   virtual void focusOutEvent( QFocusEvent* );
 
- private slots:
-  // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
-  // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
-  // we have to include all of these for the time being. Once,
-  // this bug in MOC is fixed, we can separate these. 
-  void TimerFunc() ;
+  virtual void contextMenuEvent( QContextMenuEvent * e );
 
  signals:
   void contextMenuRequested( QContextMenuEvent *e );
-
 };