From b0db2de9de53309569f2ee724a87689145ce02ba Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 19 Aug 2020 13:23:24 +0300 Subject: [PATCH] '[CEA 19033] With VirtualGL, VTK viewer is void' : first attempt --- src/SVTK/SVTK_InteractorStyle.cxx | 1 + src/SVTK/SVTK_RenderWindowInteractor.cxx | 100 +++++++++++------------ src/SVTK/SVTK_ViewModel.cxx | 14 +++- src/SVTK/SVTK_ViewModel.h | 2 + src/SVTK/SVTK_ViewWindow.cxx | 8 +- 5 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 88d61b8c3..ba2963891 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -1551,6 +1551,7 @@ void SVTK_InteractorStyle::OnTimer() // check if bounding box was changed if ( GetCurrentRenderer() ) { + GetCurrentRenderer()->Render(); double aCurrBBCenter[3]; if ( ComputeBBCenter(GetCurrentRenderer(),aCurrBBCenter) ) { diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 592333012..216c9f8ae 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -21,8 +21,8 @@ // // SALOME VTKViewer : build VTK viewer into Salome desktop -// File : -// Author : +// File : +// Author : #include "SVTK_RenderWindowInteractor.h" @@ -40,8 +40,8 @@ #endif #include -#include "SVTK_SpaceMouse.h" -#include "SVTK_Event.h" +#include "SVTK_SpaceMouse.h" +#include "SVTK_Event.h" #include "VTKViewer_Algorithm.h" @@ -67,7 +67,7 @@ static bool FOCUS_UNDER_MOUSE = false; Constructor */ QVTK_RenderWindowInteractor -::QVTK_RenderWindowInteractor(QWidget* theParent, +::QVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): QWidget(theParent), myRenderWindow(vtkRenderWindow::New()) @@ -91,7 +91,7 @@ QVTK_RenderWindowInteractor /*! To initialize by vtkGenericRenderWindowInteractor instance */ -void +void QVTK_RenderWindowInteractor ::Initialize(vtkGenericRenderWindowInteractor* theDevice) { @@ -108,7 +108,7 @@ QVTK_RenderWindowInteractor Destructor */ QVTK_RenderWindowInteractor -::~QVTK_RenderWindowInteractor() +::~QVTK_RenderWindowInteractor() { #if !defined WIN32 && !defined __APPLE__ SVTK_SpaceMouseXCB* aSpaceMouse = SVTK_SpaceMouseXCB::getInstance(); @@ -121,7 +121,7 @@ QVTK_RenderWindowInteractor /*! \return corresponding render window interactor */ -vtkGenericRenderWindowInteractor* +vtkGenericRenderWindowInteractor* QVTK_RenderWindowInteractor ::GetDevice() { @@ -187,7 +187,7 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::resize(int w, int h) +::resize(int w, int h) { GetDevice()->UpdateSize(w,h); } @@ -197,7 +197,7 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::paintEvent( QPaintEvent* theEvent ) +::paintEvent( QPaintEvent* theEvent ) { GetDevice()->CreateTimer(VTKI_TIMER_FIRST); } @@ -233,7 +233,7 @@ QVTK_RenderWindowInteractor } } - update(); + update(); } @@ -251,9 +251,9 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::mouseMoveEvent( QMouseEvent* event ) +::mouseMoveEvent( QMouseEvent* event ) { - GetDevice()->SetEventInformationFlipY(event->x(), + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier); @@ -266,9 +266,9 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::mousePressEvent( QMouseEvent* event ) +::mousePressEvent( QMouseEvent* event ) { - GetDevice()->SetEventInformationFlipY(event->x(), + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier); @@ -288,7 +288,7 @@ void QVTK_RenderWindowInteractor ::mouseReleaseEvent( QMouseEvent *event ) { - GetDevice()->SetEventInformationFlipY(event->x(), + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier); @@ -334,7 +334,7 @@ QVTK_RenderWindowInteractor { activateWindow(); setFocus(); - GetDevice()->SetEventInformationFlipY(event->x(), + GetDevice()->SetEventInformationFlipY(event->x(), event->y(), event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier); @@ -350,7 +350,7 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::keyPressEvent( QKeyEvent* event ) +::keyPressEvent( QKeyEvent* event ) { GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier, @@ -364,7 +364,7 @@ QVTK_RenderWindowInteractor */ void QVTK_RenderWindowInteractor -::keyReleaseEvent( QKeyEvent * event ) +::keyReleaseEvent( QKeyEvent * event ) { GetDevice()->SetKeyEventInformation(event->modifiers() & Qt::ControlModifier, event->modifiers() & Qt::ShiftModifier, @@ -376,7 +376,7 @@ QVTK_RenderWindowInteractor /*! Custom enter event handler */ -void +void QVTK_RenderWindowInteractor ::enterEvent( QEvent* event ) { @@ -390,7 +390,7 @@ QVTK_RenderWindowInteractor /*! Custom leave event handler */ -void +void QVTK_RenderWindowInteractor ::leaveEvent( QEvent * ) { @@ -399,9 +399,9 @@ QVTK_RenderWindowInteractor /*! Reimplemented from QWidget in order to set window - receiver - of space mouse events. + of space mouse events. */ -void +void QVTK_RenderWindowInteractor ::focusInEvent( QFocusEvent* event ) { @@ -423,9 +423,9 @@ QVTK_RenderWindowInteractor /*! Reimplemented from QWidget in order to set window - receiver - of space mouse events. + of space mouse events. */ -void +void QVTK_RenderWindowInteractor ::focusOutEvent ( QFocusEvent* event ) { @@ -476,14 +476,14 @@ bool QVTK_RenderWindowInteractor Constructor */ SVTK_RenderWindowInteractor -::SVTK_RenderWindowInteractor(QWidget* theParent, +::SVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): QVTK_RenderWindowInteractor(theParent,theName), myEventCallbackCommand(vtkCallbackCommand::New()) { myEventCallbackCommand->Delete(); - myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetClientData(this); myPriority = 0.0; myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); @@ -507,11 +507,11 @@ SVTK_RenderWindowInteractor Destructor */ SVTK_RenderWindowInteractor -::~SVTK_RenderWindowInteractor() +::~SVTK_RenderWindowInteractor() { // Sequence of the destruction call are fixed and should be changed. // vtkRenderWindow instance should be destroyed after all vtkRenderer's - GetDevice()->SetInteractorStyle(NULL); + GetDevice()->SetInteractorStyle(NULL); while(!myInteractorStyles.empty()){ const PInteractorStyle& aStyle = myInteractorStyles.top(); aStyle->SetInteractor(NULL); @@ -522,7 +522,7 @@ SVTK_RenderWindowInteractor /*! To get corresponding SVTK_Renderer instance */ -SVTK_Renderer* +SVTK_Renderer* SVTK_RenderWindowInteractor ::GetRenderer() { @@ -532,7 +532,7 @@ SVTK_RenderWindowInteractor /*! To get corresponding SVTK_Renderer device (just to simplify collobaration with SVTK_Renderer) */ -vtkRenderer* +vtkRenderer* SVTK_RenderWindowInteractor ::getRenderer() { @@ -568,7 +568,7 @@ void SVTK_RenderWindowInteractor ::InitInteractorStyle(vtkInteractorStyle* theStyle) { - GetDevice()->SetInteractorStyle(theStyle); + GetDevice()->SetInteractorStyle(theStyle); } /*! @@ -591,15 +591,15 @@ SVTK_RenderWindowInteractor { if(GetInteractorStyle()) myInteractorStyles.pop(); - - if(GetInteractorStyle()) + + if(GetInteractorStyle()) InitInteractorStyle(GetInteractorStyle()); } /*! To get current interactor style */ -vtkInteractorStyle* +vtkInteractorStyle* SVTK_RenderWindowInteractor ::GetInteractorStyle() { @@ -610,11 +610,11 @@ SVTK_RenderWindowInteractor /*! To get current selector */ -SVTK_Selector* +SVTK_Selector* SVTK_RenderWindowInteractor -::GetSelector() -{ - return mySelector.GetPointer(); +::GetSelector() +{ + return mySelector.GetPointer(); } @@ -625,26 +625,26 @@ SVTK_RenderWindowInteractor void SVTK_RenderWindowInteractor ::SetSelector(SVTK_Selector* theSelector) -{ +{ if(mySelector.GetPointer()) mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); - mySelector = theSelector; + mySelector = theSelector; if(mySelector.GetPointer()) - mySelector->AddObserver(vtkCommand::EndPickEvent, - myEventCallbackCommand.GetPointer(), + mySelector->AddObserver(vtkCommand::EndPickEvent, + myEventCallbackCommand.GetPointer(), myPriority); } /*! Main process VTK event method */ -void +void SVTK_RenderWindowInteractor -::ProcessEvents(vtkObject* vtkNotUsed(theObject), +::ProcessEvents(vtkObject* vtkNotUsed(theObject), unsigned long theEvent, - void* theClientData, + void* theClientData, void* vtkNotUsed(theCallData)) { SVTK_RenderWindowInteractor* self = reinterpret_cast(theClientData); @@ -693,7 +693,7 @@ SVTK_RenderWindowInteractor */ void SVTK_RenderWindowInteractor -::mouseMoveEvent( QMouseEvent* event ) +::mouseMoveEvent( QMouseEvent* event ) { QVTK_RenderWindowInteractor::mouseMoveEvent(event); @@ -707,7 +707,7 @@ SVTK_RenderWindowInteractor */ void SVTK_RenderWindowInteractor -::mousePressEvent( QMouseEvent* event ) +::mousePressEvent( QMouseEvent* event ) { QVTK_RenderWindowInteractor::mousePressEvent(event); @@ -795,7 +795,7 @@ SVTK_RenderWindowInteractor */ void SVTK_RenderWindowInteractor -::keyPressEvent( QKeyEvent* event ) +::keyPressEvent( QKeyEvent* event ) { QVTK_RenderWindowInteractor::keyPressEvent(event); @@ -808,7 +808,7 @@ SVTK_RenderWindowInteractor */ void SVTK_RenderWindowInteractor -::keyReleaseEvent( QKeyEvent * event ) +::keyReleaseEvent( QKeyEvent * event ) { QVTK_RenderWindowInteractor::keyReleaseEvent(event); diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index cf8f11a7b..8d800745f 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -186,7 +187,7 @@ SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) this, SLOT(onActorAdded(VTKViewer_Actor*))); connect(aViewWindow, SIGNAL( actorRemoved(VTKViewer_Actor*) ), this, SLOT(onActorRemoved(VTKViewer_Actor*))); - + return aViewWindow; } @@ -528,6 +529,8 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), + this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) ); } /*! @@ -865,3 +868,12 @@ void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor) { emit actorRemoved((SVTK_ViewWindow*)sender(), theActor); } + +void SVTK_Viewer::onViewCreated( SUIT_ViewWindow* view) { + if ( SVTK_ViewWindow* svw = dynamic_cast( view ) ){ + QTimer *timer = new QTimer(this); + timer->setSingleShot(true); + connect(timer, &QTimer::timeout, [svw] () { svw->Repaint(); } ); + timer->start(250); + } +} diff --git a/src/SVTK/SVTK_ViewModel.h b/src/SVTK/SVTK_ViewModel.h index e341fb736..c47219786 100644 --- a/src/SVTK/SVTK_ViewModel.h +++ b/src/SVTK/SVTK_ViewModel.h @@ -220,6 +220,8 @@ protected slots: void onActorAdded(VTKViewer_Actor*); void onActorRemoved(VTKViewer_Actor*); + void onViewCreated( SUIT_ViewWindow* ); + private: void updateToolBars(); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 7e8a5aaf6..187fe1809 100644 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -789,8 +789,14 @@ void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron) GetInteractor()->update(); SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle(); - if ( aStyle ) + if ( aStyle ) { + if ( aStyle->GetCurrentRenderer() == nullptr ) { + if( GetRenderer() ) { + aStyle->SetCurrentRenderer(GetRenderer()->GetDevice()); + } + } aStyle->OnTimer(); + } } /*! -- 2.39.2