From 6f8a150643e0d83b190425a643270ea36f6bf02f Mon Sep 17 00:00:00 2001 From: apo Date: Tue, 6 Sep 2005 06:40:18 +0000 Subject: [PATCH] To avoid run-time OpenGL inititalization errors --- src/SVTK/SVTK_RenderWindowInteractor.cxx | 49 ++++++++++++++++-------- src/SVTK/SVTK_RenderWindowInteractor.h | 16 ++------ src/SVTK/SVTK_View.cxx | 12 +----- src/SVTK/SVTK_View.h | 3 -- src/SVTK/SVTK_ViewWindow.cxx | 2 - 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 2f3ec2916..d90c71479 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -132,6 +132,8 @@ QVTK_RenderWindowInteractor myInteractor(QtRenderWindowInteractor::New()) { myInteractor->Delete(); + + setMouseTracking(true); } @@ -157,15 +159,7 @@ QVTK_RenderWindowInteractor ::SetRenderWindow(vtkRenderWindow *theRenderWindow) { myInteractor->SetRenderWindow(theRenderWindow); -#ifndef WNT - theRenderWindow->SetDisplayId((void*)x11Display()); -#endif - theRenderWindow->SetWindowId((void*)winId()); theRenderWindow->DoubleBufferOn(); - setMouseTracking(true); - - // To avoid UnbindContext: Assertion `vb.context == ctx' failed - // Initialize(); } vtkRenderWindow* @@ -178,23 +172,39 @@ QVTK_RenderWindowInteractor //---------------------------------------------------------------------------- void QVTK_RenderWindowInteractor -::Initialize() +::InvokeEvent(unsigned long theEvent, void* theCallData) { - myInteractor->Initialize(); + myInteractor->InvokeEvent(theEvent,theCallData); } //---------------------------------------------------------------------------- void QVTK_RenderWindowInteractor -::InvokeEvent(unsigned long theEvent, void* theCallData) +::show() { - myInteractor->InvokeEvent(theEvent,theCallData); + QWidget::show(); + update(); // needed for initial contents display on Win32 } //---------------------------------------------------------------------------- void QVTK_RenderWindowInteractor -::UpdateSize(int w, int h) +::polish() +{ + // Final initialization just before the widget is displayed. + myInteractor->SetSize(width(),height()); +#ifndef WNT + GetRenderWindow()->SetDisplayId((void*)x11Display()); +#endif + GetRenderWindow()->SetWindowId((void*)winId()); + myInteractor->Enable(); + myInteractor->ConfigureEvent(); +} + +//---------------------------------------------------------------------------- +void +QVTK_RenderWindowInteractor +::resize(int w, int h) { myInteractor->UpdateSize(w,h); } @@ -204,7 +214,12 @@ void QVTK_RenderWindowInteractor ::paintEvent( QPaintEvent* theEvent ) { - myInteractor->Render(); + if(myInteractor->GetEnabled()){ + if(!myInteractor->GetInitialized()) + myInteractor->Initialize(); + else + myInteractor->Render(); + } } @@ -217,7 +232,9 @@ QVTK_RenderWindowInteractor int aWidth = aSize[0]; int aHeight = aSize[1]; - UpdateSize( width(), height() ); + //myInteractor->SetSize(width(),height()); + myInteractor->UpdateSize(width(),height()); + myInteractor->ConfigureEvent(); if( aWidth != width() || aHeight != height() ) { @@ -235,6 +252,8 @@ QVTK_RenderWindowInteractor aCamera->SetParallelScale(aScale*aCoeff); } } + + update(); } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 0a07e4332..cd5ddbfee 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -108,22 +108,14 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget vtkRenderWindow* GetRenderWindow(); - // Description: - // Initializes the event handlers without an XtAppContext. This is - // good for when you don`t have a user interface, but you still - // want to have mouse interaction. - void - Initialize(); - virtual void InvokeEvent(unsigned long theEvent, void* theCallData); - // Description: - // Event loop notification member for Window size change - virtual - void - UpdateSize(int x,int y); + public slots: + virtual void show(); + virtual void polish(); + virtual void resize(int w, int h); protected: virtual void paintEvent( QPaintEvent* ); diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 4cef4ea32..c3665f6f0 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -563,8 +563,6 @@ SVTK_InteractorHolder myInteractor = theInteractor; if(myInteractor){ - myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); - connect(myInteractor,SIGNAL(KeyPressed(QKeyEvent*)), this,SIGNAL(KeyPressed(QKeyEvent*)) ); connect(myInteractor,SIGNAL(KeyReleased(QKeyEvent*)), @@ -589,6 +587,8 @@ SVTK_InteractorHolder myInteractor->setFocusPolicy(StrongFocus); myInteractor->setFocus(); setFocusProxy(myInteractor); + + myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); } } @@ -635,14 +635,6 @@ SVTK_InteractorHolder myInteractor->InvokeEvent(theEvent,theCallData); } -//---------------------------------------------------------------------------- -void -SVTK_InteractorHolder -::Initialize() -{ - myInteractor->Initialize(); -} - //---------------------------------------------------------------------------- void SVTK_InteractorHolder diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index da0c89e14..87525dab7 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -173,9 +173,6 @@ public: void InvokeEvent(unsigned long theEvent, void* theCallData); - void - Initialize(); - void SetRenderWindow(vtkRenderWindow *theRenderWindow); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 948d80f09..037340fab 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -64,8 +64,6 @@ SVTK_ViewWindow ::Initialize(SVTK_View* theView, SVTK_ViewModelBase* theModel) { - theView->Initialize(); - onResetView(); connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), -- 2.39.2