From f758bf480f8860f2448b0d9b0b2aecf1200591b4 Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 9 Sep 2005 05:42:47 +0000 Subject: [PATCH] To use native vtkRenderWindow --- src/SVTK/Makefile.in | 2 - src/SVTK/SVTK_InteractorStyle.cxx | 2 - src/SVTK/SVTK_RenderWindow.cxx | 99 --------------------- src/SVTK/SVTK_RenderWindow.h | 74 ---------------- src/SVTK/SVTK_RenderWindowInteractor.cxx | 107 ++++++++++++++++------- src/SVTK/SVTK_RenderWindowInteractor.h | 45 ++++++++-- src/SVTK/SVTK_View.cxx | 76 ++++++++-------- src/SVTK/SVTK_View.h | 17 ++-- src/SVTK/SVTK_ViewWindow.cxx | 7 +- 9 files changed, 156 insertions(+), 273 deletions(-) delete mode 100644 src/SVTK/SVTK_RenderWindow.cxx delete mode 100644 src/SVTK/SVTK_RenderWindow.h diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index 1bfc3eefe..d81a1e22a 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -23,7 +23,6 @@ EXPORT_HEADERS= SVTK.h \ SVTK_ViewModel.h \ SVTK_ViewWindow.h \ SVTK_Renderer.h \ - SVTK_RenderWindow.h \ SVTK_InteractorStyle.h \ SVTK_RenderWindowInteractor.h \ SVTK_Selector.h \ @@ -46,7 +45,6 @@ LIB_SRC= SVTK_Prs.cxx \ SVTK_ViewModel.cxx \ SVTK_Renderer.cxx \ SVTK_ViewWindow.cxx \ - SVTK_RenderWindow.cxx\ SVTK_InteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ SVTK_SpaceMouse.cxx \ diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index ce5a1a840..4fe4eb51e 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -1407,5 +1407,3 @@ SVTK_InteractorStyle } vtkInteractorStyle::ProcessEvents( object, event, clientData, callData ); } - -#include "SVTK_RenderWindow.h" diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx deleted file mode 100644 index 435265ea3..000000000 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ /dev/null @@ -1,99 +0,0 @@ -// SALOME VTKViewer : build VTK viewer into Salome desktop -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : -// Author : -// Module : -// $Header$ - -#include "SVTK_RenderWindow.h" - -#include "SVTK_Renderer.h" -#include "SVTK_Selector.h" - -#include - -//---------------------------------------------------------------------------- -vtkStandardNewMacro(SVTK_RenderWindow); - - -//---------------------------------------------------------------------------- -SVTK_RenderWindow -::SVTK_RenderWindow(): - myRenderWidget(NULL) -{ -} - -SVTK_RenderWindow -::~SVTK_RenderWindow() -{} - - -//---------------------------------------------------------------------------- -SVTK_Renderer* -SVTK_RenderWindow -::GetRenderer() -{ - return myRenderer.GetPointer(); -} - -void -SVTK_RenderWindow -::SetRenderer(SVTK_Renderer* theRenderer) -{ - this->RemoveRenderer(GetRenderer()); - myRenderer = theRenderer; - this->AddRenderer(GetRenderer()); -} - - -//---------------------------------------------------------------------------- -SVTK_Selector* -SVTK_RenderWindow -::GetSelector() -{ - return mySelector.GetPointer(); -} - -void -SVTK_RenderWindow -::SetSelector(SVTK_Selector* theSelector) -{ - mySelector = theSelector; -} - - -//---------------------------------------------------------------------------- -SVTK_RenderWindow::TRenderWidget* -SVTK_RenderWindow -::GetRenderWidget() -{ - return myRenderWidget; -} - -void -SVTK_RenderWindow -::GetRenderWidget(TRenderWidget* theWidget) -{ - myRenderWidget = theWidget; -} diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h deleted file mode 100644 index 2b990ea51..000000000 --- a/src/SVTK/SVTK_RenderWindow.h +++ /dev/null @@ -1,74 +0,0 @@ -// SALOME VTKViewer : build VTK viewer into Salome desktop -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : VTKViewer_RenderWindow.h -// Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - -#ifndef SVTK_RenderWindow_h -#define SVTK_RenderWindow_h - -#include "SVTK.h" - -#include - -#ifndef VTK_IMPLEMENT_MESA_CXX -#include -#define SVTK_RENDER_WINDOW_SUPERCLASS vtkXOpenGLRenderWindow -#else -#include -#define SVTK_RENDER_WINDOW_SUPERCLASS vtkXMesaRenderWindow -#endif - -class QWidget; -class SVTK_Renderer; -class SVTK_Selector; - -class SVTK_EXPORT SVTK_RenderWindow: public SVTK_RENDER_WINDOW_SUPERCLASS -{ - public: - vtkTypeMacro(SVTK_RenderWindow,SVTK_RENDER_WINDOW_SUPERCLASS); - static SVTK_RenderWindow* New(); - - SVTK_RenderWindow(); - virtual ~SVTK_RenderWindow(); - - SVTK_Renderer* GetRenderer(); - void SetRenderer(SVTK_Renderer* theRenderer); - - SVTK_Selector* GetSelector(); - void SetSelector(SVTK_Selector* theSelector); - - typedef QWidget TRenderWidget; - TRenderWidget* GetRenderWidget(); - void GetRenderWidget(TRenderWidget* theWidget); - - protected: - vtkSmartPointer mySelector; - vtkSmartPointer myRenderer; - TRenderWidget* myRenderWidget; -}; - - -#endif diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index fc97faef0..1c6df4d46 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -29,12 +29,15 @@ #include "SVTK_RenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" -#include "VTKViewer_Algorithm.h" +#include "SVTK_Renderer.h" #include "SVTK_Functor.h" #include "SALOME_Actor.h" + #include "SVTK_SpaceMouse.h" #include "SVTK_Event.h" +#include "VTKViewer_Algorithm.h" + #include #include #include @@ -416,7 +419,8 @@ SVTK_RenderWindowInteractor ::SVTK_RenderWindowInteractor(QWidget* theParent, const char* theName): QVTK_RenderWindowInteractor(theParent,theName), - myEventCallbackCommand(vtkCallbackCommand::New()) + myEventCallbackCommand(vtkCallbackCommand::New()), + myRenderWindow(vtkRenderWindow::New()) { myEventCallbackCommand->Delete(); @@ -425,55 +429,47 @@ SVTK_RenderWindowInteractor myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); + myRenderWindow->Delete(); + GetDevice()->SetRenderWindow(getRenderWindow()); + SetSelector(SVTK_Selector::New()); - GetSelector()->Delete(); + mySelector->Delete(); } SVTK_RenderWindowInteractor ::~SVTK_RenderWindowInteractor() {} - -//---------------------------------------------------------------------------- -SVTK_Selector* +vtkRenderWindow* SVTK_RenderWindowInteractor -::GetSelector() -{ - return mySelector.GetPointer(); +::getRenderWindow() +{ + return myRenderWindow.GetPointer(); } -void +//---------------------------------------------------------------------------- +SVTK_Renderer* SVTK_RenderWindowInteractor -::SetSelector(SVTK_Selector* theSelector) -{ - if(mySelector.GetPointer()) - mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); - - mySelector = theSelector; - - if(mySelector.GetPointer()) - mySelector->AddObserver(vtkCommand::EndPickEvent, - myEventCallbackCommand.GetPointer(), - myPriority); +::GetRenderer() +{ + return myRenderer.GetPointer(); } - -//---------------------------------------------------------------------------- -void +vtkRenderer* SVTK_RenderWindowInteractor -::ProcessEvents(vtkObject* vtkNotUsed(theObject), - unsigned long theEvent, - void* theClientData, - void* vtkNotUsed(theCallData)) +::getRenderer() { - SVTK_RenderWindowInteractor* self = reinterpret_cast(theClientData); + return GetRenderer(); +} - switch(theEvent){ - case vtkCommand::EndPickEvent: - self->onEmitSelectionChanged(); - break; - } +void +SVTK_RenderWindowInteractor +::SetRenderer(SVTK_Renderer* theRenderer) +{ + myRenderWindow->RemoveRenderer(GetRenderer()); + myRenderer = theRenderer; + myRenderWindow->AddRenderer(GetRenderer()); } @@ -521,6 +517,49 @@ SVTK_RenderWindowInteractor } +//---------------------------------------------------------------------------- +SVTK_Selector* +SVTK_RenderWindowInteractor +::GetSelector() +{ + return mySelector.GetPointer(); +} + + +void +SVTK_RenderWindowInteractor +::SetSelector(SVTK_Selector* theSelector) +{ + if(mySelector.GetPointer()) + mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); + + mySelector = theSelector; + + if(mySelector.GetPointer()) + mySelector->AddObserver(vtkCommand::EndPickEvent, + myEventCallbackCommand.GetPointer(), + myPriority); +} + + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SVTK_RenderWindowInteractor* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::EndPickEvent: + self->onEmitSelectionChanged(); + break; + } +} + + //---------------------------------------------------------------- void SVTK_RenderWindowInteractor diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 0e544b93e..6ac251674 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -48,6 +48,7 @@ class vtkGenericRenderWindowInteractor; class SALOME_Actor; class SVTK_Selector; +class SVTK_Renderer; class SVTK_InteractorStyle; // ------------------------------------------------------------ @@ -152,15 +153,41 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto ~SVTK_RenderWindowInteractor(); - SVTK_Selector* GetSelector(); - void SetSelector(SVTK_Selector* theSelector); + vtkRenderWindow* + getRenderWindow(); + + //---------------------------------------------------------------------------- + void + SetRenderer(SVTK_Renderer *theRenderer); + + SVTK_Renderer* + GetRenderer(); - SVTK_InteractorStyle* GetInteractorStyle(); - void PushInteractorStyle(SVTK_InteractorStyle* theStyle); - void PopInteractorStyle(); + vtkRenderer* + getRenderer(); - Selection_Mode SelectionMode() const; - void SetSelectionMode(Selection_Mode theMode); + //---------------------------------------------------------------------------- + SVTK_InteractorStyle* + GetInteractorStyle(); + + void + PushInteractorStyle(SVTK_InteractorStyle* theStyle); + + void + PopInteractorStyle(); + + //---------------------------------------------------------------------------- + SVTK_Selector* + GetSelector(); + + void + SetSelector(SVTK_Selector* theSelector); + + Selection_Mode + SelectionMode() const; + + void + SetSelectionMode(Selection_Mode theMode); public: void @@ -210,8 +237,12 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteracto vtkSmartPointer mySelector; + vtkSmartPointer myRenderer; + vtkSmartPointer myRenderWindow; + typedef vtkSmartPointer PInteractorStyle; QValueStack myInteractorStyles; }; + #endif diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 1e2ddf707..1cf6e52b8 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -28,7 +28,6 @@ #include "SVTK_Event.h" #include "SVTK_Renderer.h" #include "SVTK_ViewModel.h" -#include "SVTK_RenderWindow.h" #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindowInteractor.h" @@ -55,6 +54,22 @@ SVTK_MainWindow createToolBar(); } +void +SVTK_MainWindow +::Initialize() +{ + SetInteractor(new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor")); + + SVTK_Renderer* aRenderer = SVTK_Renderer::New(); + GetInteractor()->SetRenderer(aRenderer); + aRenderer->Delete(); + + SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New(); + GetInteractor()->PushInteractorStyle(aStyle); + aStyle->Delete(); +} + + //---------------------------------------------------------------------------- SVTK_MainWindow ::~SVTK_MainWindow() @@ -90,6 +105,13 @@ SVTK_MainWindow return GetInteractor()->GetDevice(); } +vtkRenderWindow* +SVTK_MainWindow +::getRenderWindow() +{ + return GetInteractor()->getRenderWindow(); +} + //---------------------------------------------------------------------------- void SVTK_MainWindow @@ -114,7 +136,7 @@ void SVTK_MainWindow ::InvokeEvent(unsigned long theEvent, void* theCallData) { - myInteractor->InvokeEvent(theEvent,theCallData); + GetInteractor()->InvokeEvent(theEvent,theCallData); } //---------------------------------------------------------------------------- @@ -122,21 +144,21 @@ SVTK_InteractorStyle* SVTK_MainWindow ::GetInteractorStyle() { - return myInteractor->GetInteractorStyle(); + return GetInteractor()->GetInteractorStyle(); } void SVTK_MainWindow ::PushInteractorStyle(SVTK_InteractorStyle* theStyle) { - myInteractor->PushInteractorStyle(theStyle); + GetInteractor()->PushInteractorStyle(theStyle); } void SVTK_MainWindow ::PopInteractorStyle() { - myInteractor->PopInteractorStyle(); + GetInteractor()->PopInteractorStyle(); } //---------------------------------------------------------------------------- @@ -144,14 +166,14 @@ SVTK_Selector* SVTK_MainWindow ::GetSelector() { - return myInteractor->GetSelector(); + return GetInteractor()->GetSelector(); } void SVTK_MainWindow ::SetSelector(SVTK_Selector* theSelector) { - myInteractor->SetSelector(theSelector); + GetInteractor()->SetSelector(theSelector); } Selection_Mode @@ -172,39 +194,23 @@ SVTK_MainWindow //---------------------------------------------------------------------------- void SVTK_MainWindow -::SetRenderWindow(SVTK_RenderWindow *theRenderWindow) -{ - myRenderWindow = theRenderWindow; -} - -SVTK_RenderWindow* -SVTK_MainWindow -::GetRenderWindow() +::SetRenderer(SVTK_Renderer* theRenderer) { - return myRenderWindow.GetPointer(); + GetInteractor()->SetRenderer(theRenderer); } -vtkRenderWindow* -SVTK_MainWindow -::getRenderWindow() -{ - return myRenderWindow.GetPointer(); -} - - -//---------------------------------------------------------------------------- SVTK_Renderer* SVTK_MainWindow ::GetRenderer() { - return GetRenderWindow()->GetRenderer(); + return GetInteractor()->GetRenderer(); } vtkRenderer* SVTK_MainWindow ::getRenderer() { - return GetRenderWindow()->GetRenderer(); + return GetInteractor()->getRenderer(); } //---------------------------------------------------------------------------- @@ -654,7 +660,7 @@ QImage SVTK_MainWindow ::dumpView() { - QPixmap px = QPixmap::grabWindow( winId() ); + QPixmap px = QPixmap::grabWindow( GetInteractor()->winId() ); return px.convertToImage(); } @@ -665,19 +671,7 @@ SVTK_SignalHandler QObject(theMainWindow), myMainWindow(theMainWindow) { - SVTK_RenderWindow* aRenderWindow = SVTK_RenderWindow::New(); - theMainWindow->SetRenderWindow(aRenderWindow); - aRenderWindow->Delete(); - - aRenderWindow->SetRenderer(SVTK_Renderer::New()); - - SVTK_RenderWindowInteractor* anInteractor = - new SVTK_RenderWindowInteractor(theMainWindow,"SVTK_RenderWindowInteractor"); - anInteractor->SetRenderWindow(aRenderWindow); - - theMainWindow->SetInteractor(anInteractor); - - anInteractor->PushInteractorStyle(SVTK_InteractorStyle::New()); + SVTK_RenderWindowInteractor* anInteractor = theMainWindow->GetInteractor(); connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)), this,SIGNAL(KeyPressed(QKeyEvent*)) ); diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index c00d97160..1514b8d38 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -51,6 +51,10 @@ public: const char* theName, SUIT_ResourceMgr* theResourceMgr); + virtual + void + Initialize(); + virtual ~SVTK_MainWindow(); @@ -64,6 +68,9 @@ public: vtkRenderWindowInteractor* getInteractor(); + vtkRenderWindow* + getRenderWindow(); + void Repaint(); @@ -98,15 +105,8 @@ public: //---------------------------------------------------------------------------- void - SetRenderWindow(SVTK_RenderWindow *theRenderWindow); + SetRenderer(SVTK_Renderer* theRenderer); - SVTK_RenderWindow* - GetRenderWindow(); - - vtkRenderWindow* - getRenderWindow(); - - //---------------------------------------------------------------------------- SVTK_Renderer* GetRenderer(); @@ -203,7 +203,6 @@ public: QToolBar* myToolBar; SVTK_RenderWindowInteractor* myInteractor; - vtkSmartPointer myRenderWindow; }; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 38ea4162c..96da68fea 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -44,13 +44,14 @@ SVTK_ViewWindow SUIT_ViewWindow(theDesktop) {} -//---------------------------------------------------------------------------- void SVTK_ViewWindow ::Initialize(SVTK_ViewModelBase* theModel) { if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr); + myMainWindow->Initialize(); + setCentralWidget(myMainWindow); myView = new SVTK_View(myMainWindow); @@ -58,7 +59,6 @@ SVTK_ViewWindow } } - void SVTK_ViewWindow ::Initialize(SVTK_View* theView, @@ -82,14 +82,11 @@ SVTK_ViewWindow theModel,SLOT(onSelectionChanged())); } -//---------------------------------------------------------------------------- SVTK_ViewWindow ::~SVTK_ViewWindow() {} -//---------------------------------------------------------------------------- -//---------------------------------------------------------------------------- //---------------------------------------------------------------------------- SVTK_View* SVTK_ViewWindow -- 2.39.2