From f1ba234ab48cce4f8826ee5adce7fe3335019880 Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 18 Aug 2005 12:05:10 +0000 Subject: [PATCH] To implement right way of TimerEvent invocation --- src/SVTK/SVTK_InteractorStyle.cxx | 16 ++- src/SVTK/SVTK_InteractorStyle.h | 4 +- src/SVTK/SVTK_RenderWindowInteractor.cxx | 146 ++++++++++------------- src/SVTK/SVTK_RenderWindowInteractor.h | 68 ++++++----- 4 files changed, 113 insertions(+), 121 deletions(-) diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 720aace60..4624e1da0 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -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 diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 9627e93d3..aae56d379 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -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(); diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 4ef7a4cbd..aee2c14cb 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -50,8 +50,8 @@ #include // QT Includes +#include #include -#include #include #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 ); } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 03d9f39b2..d969e22af 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -35,11 +35,10 @@ #include "SALOME_InteractiveObject.hxx" -// QT Includes -#include - // VTK Includes -#include +#include + +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 ); - }; -- 2.39.2