From: apo Date: Wed, 21 Sep 2005 11:47:51 +0000 (+0000) Subject: To improve Initialize functionality in order to X-Git-Tag: BR-D5-38-2003_D2005-12-10~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f182c47e6c5b78c1a5f99b111a50681e67a5ac25;p=modules%2Fgui.git To improve Initialize functionality in order to provide explicit way of SVTK initialization --- diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index e004c782a..d627fd761 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -76,13 +76,31 @@ static int MYDEBUG = 0; QVTK_RenderWindowInteractor ::QVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): - QWidget(theParent,theName) + QWidget(theParent,theName), + myRenderWindow(vtkRenderWindow::New()) { if(MYDEBUG) INFOS("QVTK_RenderWindowInteractor() - "<Delete(); + myRenderWindow->DoubleBufferOn(); } +void +QVTK_RenderWindowInteractor +::Initialize(vtkGenericRenderWindowInteractor* theDevice) +{ + if(GetDevice()) + myDevice->SetRenderWindow(NULL); + + myDevice = theDevice; + + if(theDevice) + theDevice->SetRenderWindow(getRenderWindow()); +} + +//---------------------------------------------------------------------------- QVTK_RenderWindowInteractor ::~QVTK_RenderWindowInteractor() { @@ -93,6 +111,7 @@ QVTK_RenderWindowInteractor aSpaceMouse->close(x11Display()); } + //---------------------------------------------------------------------------- vtkGenericRenderWindowInteractor* QVTK_RenderWindowInteractor @@ -101,27 +120,12 @@ QVTK_RenderWindowInteractor return myDevice.GetPointer(); } -void -QVTK_RenderWindowInteractor -::SetDevice(vtkGenericRenderWindowInteractor* theDevice) -{ - myDevice = theDevice; -} - //---------------------------------------------------------------------------- -void -QVTK_RenderWindowInteractor -::SetRenderWindow(vtkRenderWindow *theRenderWindow) -{ - GetDevice()->SetRenderWindow(theRenderWindow); - theRenderWindow->DoubleBufferOn(); -} - vtkRenderWindow* QVTK_RenderWindowInteractor -::GetRenderWindow() +::getRenderWindow() { - return GetDevice()->GetRenderWindow(); + return myRenderWindow.GetPointer(); } //---------------------------------------------------------------------------- @@ -149,9 +153,9 @@ QVTK_RenderWindowInteractor // Final initialization just before the widget is displayed GetDevice()->SetSize(width(),height()); #ifndef WNT - GetRenderWindow()->SetDisplayId((void*)x11Display()); + getRenderWindow()->SetDisplayId((void*)x11Display()); #endif - GetRenderWindow()->SetWindowId((void*)winId()); + getRenderWindow()->SetWindowId((void*)winId()); GetDevice()->Enable(); } @@ -183,7 +187,7 @@ void QVTK_RenderWindowInteractor ::resizeEvent( QResizeEvent* theEvent ) { - int* aSize = GetRenderWindow()->GetSize(); + int* aSize = getRenderWindow()->GetSize(); int aWidth = aSize[0]; int aHeight = aSize[1]; @@ -191,7 +195,7 @@ QVTK_RenderWindowInteractor if(isVisible() && aWidth && aHeight){ if( aWidth != width() || aHeight != height() ) { - vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers(); + vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers(); aRenderers->InitTraversal(); double aCoeff = 1.0; if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) { @@ -374,8 +378,7 @@ SVTK_RenderWindowInteractor ::SVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): QVTK_RenderWindowInteractor(theParent,theName), - myEventCallbackCommand(vtkCallbackCommand::New()), - myRenderWindow(vtkRenderWindow::New()) + myEventCallbackCommand(vtkCallbackCommand::New()) { if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor() - "<SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); +} - SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New(); - SetDevice(aDevice); - aDevice->Delete(); - - aDevice->SetRenderWidget(this); - - SetSelector(SVTK_Selector::New()); - mySelector->Delete(); - - aDevice->SetSelector(GetSelector()); - - GetDevice()->SetRenderWindow(getRenderWindow()); - myRenderWindow->Delete(); +void +SVTK_RenderWindowInteractor +::Initialize(vtkGenericRenderWindowInteractor* theDevice, + SVTK_Renderer* theRenderer, + SVTK_Selector* theSelector) +{ + QVTK_RenderWindowInteractor::Initialize(theDevice); + SetRenderer(theRenderer); + SetSelector(theSelector); } +//---------------------------------------------------------------------------- SVTK_RenderWindowInteractor ::~SVTK_RenderWindowInteractor() { @@ -420,14 +421,6 @@ SVTK_RenderWindowInteractor GetDevice()->SetRenderWindow(NULL); } -vtkRenderWindow* -SVTK_RenderWindowInteractor -::getRenderWindow() -{ - return myRenderWindow.GetPointer(); -} - - //---------------------------------------------------------------------------- SVTK_Renderer* SVTK_RenderWindowInteractor diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index e36bfd23d..4655bdadd 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -57,17 +57,15 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget ~QVTK_RenderWindowInteractor(); - vtkGenericRenderWindowInteractor* - GetDevice(); - + virtual void - SetDevice(vtkGenericRenderWindowInteractor* theDevice); + Initialize(vtkGenericRenderWindowInteractor* theDevice); - void - SetRenderWindow(vtkRenderWindow *theRenderWindow); + vtkGenericRenderWindowInteractor* + GetDevice(); vtkRenderWindow* - GetRenderWindow(); + getRenderWindow(); virtual void @@ -98,6 +96,7 @@ class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget virtual bool x11Event( XEvent *e ); + vtkSmartPointer myRenderWindow; vtkSmartPointer myDevice; }; @@ -113,13 +112,13 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto ~SVTK_RenderWindowInteractor(); - vtkRenderWindow* - getRenderWindow(); - - //---------------------------------------------------------------------------- + virtual void - SetRenderer(SVTK_Renderer *theRenderer); + Initialize(vtkGenericRenderWindowInteractor* theDevice, + SVTK_Renderer* theRenderer, + SVTK_Selector* theSelector); + //---------------------------------------------------------------------------- SVTK_Renderer* GetRenderer(); @@ -140,9 +139,6 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto SVTK_Selector* GetSelector(); - void - SetSelector(SVTK_Selector* theSelector); - Selection_Mode SelectionMode() const; @@ -178,6 +174,12 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto virtual void keyReleaseEvent( QKeyEvent* ); virtual void contextMenuEvent( QContextMenuEvent * e ); + void + SetRenderer(SVTK_Renderer *theRenderer); + + void + SetSelector(SVTK_Selector* theSelector); + void InitInteractorStyle(vtkInteractorStyle* theStyle); @@ -198,7 +200,6 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto vtkSmartPointer mySelector; vtkSmartPointer myRenderer; - vtkSmartPointer myRenderWindow; typedef vtkSmartPointer PInteractorStyle; typedef std::stack TInteractorStyles; diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index b1f648c3d..3507b138c 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -95,24 +95,16 @@ SVTK_MainWindow void SVTK_MainWindow -::Initialize(SVTK_Renderer *theRenderer) +::Initialize(SVTK_RenderWindowInteractor* theInteractor) { - SetInteractor(new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor")); - - SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); - GetInteractor()->PushInteractorStyle(aStyle); - aStyle->Delete(); + myInteractor = theInteractor; + SetEventDispatcher(myInteractor->GetDevice()); - GetInteractor()->SetRenderer(theRenderer); -} + setCentralWidget(myInteractor); -void -SVTK_MainWindow -::Initialize() -{ - SVTK_Renderer* aRenderer = SVTK_Renderer::New(); - Initialize(aRenderer); - aRenderer->Delete(); + myInteractor->setFocusPolicy(StrongFocus); + myInteractor->setFocus(); + setFocusProxy(myInteractor); } @@ -125,20 +117,6 @@ SVTK_MainWindow //---------------------------------------------------------------------------- -void -SVTK_MainWindow -::SetInteractor(SVTK_RenderWindowInteractor* theInteractor) -{ - myInteractor = theInteractor; - SetEventDispatcher(myInteractor->GetDevice()); - - setCentralWidget(myInteractor); - - myInteractor->setFocusPolicy(StrongFocus); - myInteractor->setFocus(); - setFocusProxy(myInteractor); -} - SVTK_RenderWindowInteractor* SVTK_MainWindow ::GetInteractor() @@ -217,13 +195,6 @@ SVTK_MainWindow return GetInteractor()->GetSelector(); } -void -SVTK_MainWindow -::SetSelector(SVTK_Selector* theSelector) -{ - GetInteractor()->SetSelector(theSelector); -} - Selection_Mode SVTK_MainWindow ::SelectionMode() @@ -240,13 +211,6 @@ SVTK_MainWindow //---------------------------------------------------------------------------- -void -SVTK_MainWindow -::SetRenderer(SVTK_Renderer* theRenderer) -{ - GetInteractor()->SetRenderer(theRenderer); -} - SVTK_Renderer* SVTK_MainWindow ::GetRenderer() diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index caa7fae7b..0365e2a07 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -53,11 +53,7 @@ public: virtual void - Initialize(SVTK_Renderer *theRenderer); - - virtual - void - Initialize(); + Initialize(SVTK_RenderWindowInteractor* theInteractor); virtual ~SVTK_MainWindow(); @@ -98,9 +94,6 @@ public: SVTK_Selector* GetSelector(); - void - SetSelector(SVTK_Selector* theSelector); - Selection_Mode SelectionMode(); @@ -108,9 +101,6 @@ public: SetSelectionMode(Selection_Mode theMode); //---------------------------------------------------------------------------- - void - SetRenderer(SVTK_Renderer* theRenderer); - SVTK_Renderer* GetRenderer(); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index d75358b6c..d37277477 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -27,8 +27,12 @@ #include "VTKViewer_CellRectPicker.h" #include "SVTK_Event.h" +#include "SVTK_Renderer.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModelBase.h" +#include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" +#include "SVTK_GenericRenderWindowInteractor.h" #include "SALOME_ListIteratorOfListIO.hxx" @@ -52,7 +56,30 @@ SVTK_ViewWindow { if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr); - myMainWindow->Initialize(); + + SVTK_RenderWindowInteractor* anIteractor = + new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor"); + + SVTK_Renderer* aRenderer = SVTK_Renderer::New(); + + SVTK_Selector* aSelector = SVTK_Selector::New(); + + SVTK_GenericRenderWindowInteractor* aDevice = + SVTK_GenericRenderWindowInteractor::New(); + aDevice->SetRenderWidget(anIteractor); + aDevice->SetSelector(aSelector); + + anIteractor->Initialize(aDevice,aRenderer,aSelector); + + aDevice->Delete(); + aRenderer->Delete(); + aSelector->Delete(); + + myMainWindow->Initialize(anIteractor); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + anIteractor->PushInteractorStyle(aStyle); + aStyle->Delete(); setCentralWidget(myMainWindow);