From: apo Date: Thu, 8 Sep 2005 07:32:59 +0000 (+0000) Subject: To customize vtkRenderWindow X-Git-Tag: BR-D5-38-2003_D2005-12-09~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3a8f12ca9519c8957bde0680312554ff43da1b17;p=modules%2Fgui.git To customize vtkRenderWindow --- diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index ea2fcc976..6fa4c4516 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -42,8 +42,6 @@ #include "SVTK_ViewManager.h" #include "SVTK_ViewWindow.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_RenderWindowInteractor.h" using namespace std; diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index f56bd406b..1bfc3eefe 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -46,7 +46,7 @@ LIB_SRC= SVTK_Prs.cxx \ SVTK_ViewModel.cxx \ SVTK_Renderer.cxx \ SVTK_ViewWindow.cxx \ - SVTK_RenderWindow.cxx \ + SVTK_RenderWindow.cxx\ SVTK_InteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ SVTK_SpaceMouse.cxx \ @@ -54,7 +54,6 @@ LIB_SRC= SVTK_Prs.cxx \ LIB_MOC = SVTK_RenderWindowInteractor.h \ SVTK_InteractorStyle.h \ - SVTK_RenderWindow.h \ SVTK_View.h \ SVTK_ViewWindow.h \ SVTK_ViewModel.h \ diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 7f642941e..8b4cd9a75 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -32,8 +32,6 @@ #include "VTKViewer_Utilities.h" #include "VTKViewer_RectPicker.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_ViewWindow.h" #include "SVTK_Selection.h" #include "SVTK_Event.h" #include "SVTK_Selector.h" @@ -59,6 +57,7 @@ #include #include +#include //VRV: porting on Qt 3.0.5 #if QT_VERSION >= 0x030005 #include @@ -640,7 +639,9 @@ SVTK_InteractorStyle ::eventFilter(QObject* object, QEvent* event) { if (!myRenderWidget) return false; - if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myRenderWidget) + if ( (event->type() == QEvent::MouseButtonPress || + event->type() == QEvent::KeyPress) && + object != myRenderWidget) { qApp->removeEventFilter(this); startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); @@ -1408,3 +1409,5 @@ 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 index b90b3a30b..435265ea3 100644 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ b/src/SVTK/SVTK_RenderWindow.cxx @@ -1,57 +1,99 @@ -#include "SVTK_RenderWindow.h" -#include "SVTK_Trihedron.h" -#include "SVTK_CubeAxesActor2D.h" -#include "SALOME_Actor.h" +// 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 "VTKViewer_Transform.h" -#include "VTKViewer_Utilities.h" +#include "SVTK_RenderWindow.h" #include "SVTK_Renderer.h" +#include "SVTK_Selector.h" -#include "QtxAction.h" +#include -#include "SUIT_Session.h" -#include "SUIT_ToolButton.h" -#include "SUIT_MessageBox.h" +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_RenderWindow); -#include "SUIT_Tools.h" -#include "SUIT_ResourceMgr.h" -#include +//---------------------------------------------------------------------------- +SVTK_RenderWindow +::SVTK_RenderWindow(): + myRenderWidget(NULL) +{ +} + +SVTK_RenderWindow +::~SVTK_RenderWindow() +{} -#if QT_VERSION > 300 -#include -#endif //---------------------------------------------------------------------------- +SVTK_Renderer* SVTK_RenderWindow -::SVTK_RenderWindow(QWidget* parent, const char* name) : - QMainWindow(parent, name, - Qt::WStyle_NoBorder | - Qt::WDestructiveClose | - Qt::WResizeNoErase | - Qt::WRepaintNoErase), - myRenderWindow(vtkRenderWindow::New()) +::GetRenderer() { - myRenderWindow->Delete(); + return myRenderer.GetPointer(); +} -#ifndef WNT - myRenderWindow->SetDisplayId((void*)x11Display()); -#endif - myRenderWindow->SetWindowId((void*)winId()); - myRenderWindow->DoubleBufferOn(); - setMouseTracking(true); +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 -::~SVTK_RenderWindow() -{} +::SetSelector(SVTK_Selector* theSelector) +{ + mySelector = theSelector; +} -vtkRenderWindow* +//---------------------------------------------------------------------------- +SVTK_RenderWindow::TRenderWidget* SVTK_RenderWindow -::getRenderWindow() -{ - return myRenderWindow.GetPointer(); +::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 index 712f1fb6d..2b990ea51 100644 --- a/src/SVTK/SVTK_RenderWindow.h +++ b/src/SVTK/SVTK_RenderWindow.h @@ -29,31 +29,46 @@ #ifndef SVTK_RenderWindow_h #define SVTK_RenderWindow_h -#include +#include "SVTK.h" -#include -#include +#include -#include "SVTK.h" +#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(); -class vtkRenderer; -class vtkRenderWindow; + SVTK_RenderWindow(); + virtual ~SVTK_RenderWindow(); -class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow -{ - Q_OBJECT; + SVTK_Renderer* GetRenderer(); + void SetRenderer(SVTK_Renderer* theRenderer); - public: - SVTK_RenderWindow( QWidget*, const char* ); - virtual ~SVTK_RenderWindow() ; + SVTK_Selector* GetSelector(); + void SetSelector(SVTK_Selector* theSelector); - vtkRenderWindow* getRenderWindow(); + typedef QWidget TRenderWidget; + TRenderWidget* GetRenderWidget(); + void GetRenderWidget(TRenderWidget* theWidget); protected: - vtkSmartPointer myRenderWindow; + vtkSmartPointer mySelector; + vtkSmartPointer myRenderer; + TRenderWidget* myRenderWidget; }; + #endif diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 98ce10b3e..05abcc196 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -232,24 +232,22 @@ QVTK_RenderWindowInteractor int aWidth = aSize[0]; int aHeight = aSize[1]; - //myInteractor->SetSize(width(),height()); myInteractor->UpdateSize(width(),height()); - myInteractor->ConfigureEvent(); - - if( aWidth != width() || aHeight != height() ) - { - vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers(); - aRenderers->InitTraversal(); - double aCoeff = 1.0; - if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) - { - vtkCamera *aCamera = aRenderer->GetActiveCamera(); - double aScale = aCamera->GetParallelScale(); - if((aWidth - width())*(aHeight - height()) > 0) - aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); - else - aCoeff = double(aWidth)/double(width()); - aCamera->SetParallelScale(aScale*aCoeff); + + if(true || aWidth && aHeight){ + if( aWidth != width() || aHeight != height() ) { + vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers(); + aRenderers->InitTraversal(); + double aCoeff = 1.0; + if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) { + vtkCamera *aCamera = aRenderer->GetActiveCamera(); + double aScale = aCamera->GetParallelScale(); + if((aWidth - width())*(aHeight - height()) > 0) + aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); + else + aCoeff = double(aWidth)/double(width()); + aCamera->SetParallelScale(aScale*aCoeff); + } } } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index cd5ddbfee..9d9df812b 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -31,7 +31,6 @@ #include "SVTK.h" #include "SVTK_Selection.h" -#include "SVTK_RenderWindow.h" #include "SALOME_InteractiveObject.hxx" @@ -39,6 +38,7 @@ #include #include +#include class QTimer; diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx index e342545c3..ae067194f 100644 --- a/src/SVTK/SVTK_Renderer.cxx +++ b/src/SVTK/SVTK_Renderer.cxx @@ -1,3 +1,31 @@ +// 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_Renderer.h" #include "SVTK_Trihedron.h" diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h index 25ad29939..6f78b4383 100644 --- a/src/SVTK/SVTK_Renderer.h +++ b/src/SVTK/SVTK_Renderer.h @@ -35,10 +35,10 @@ #ifndef VTK_IMPLEMENT_MESA_CXX #include -#define RENDERER_SUPERCLASS vtkOpenGLRenderer +#define SVTK_RENDERER_SUPERCLASS vtkOpenGLRenderer #else #include -#define RENDERER_SUPERCLASS vtkMesaRenderer +#define SVTK_RENDERER_SUPERCLASS vtkMesaRenderer #endif class vtkCallbackCommand; @@ -48,7 +48,7 @@ class VTKViewer_Transform; class SVTK_CubeAxesActor2D; class VTKViewer_Actor; -class SVTK_EXPORT SVTK_Renderer : public RENDERER_SUPERCLASS +class SVTK_EXPORT SVTK_Renderer : public SVTK_RENDERER_SUPERCLASS { protected: SVTK_Renderer(); @@ -73,7 +73,7 @@ class SVTK_EXPORT SVTK_Renderer : public RENDERER_SUPERCLASS void* calldata); public: - vtkTypeMacro(SVTK_Renderer,RENDERER_SUPERCLASS); + vtkTypeMacro(SVTK_Renderer,SVTK_RENDERER_SUPERCLASS); static SVTK_Renderer* New(); VTKViewer_Trihedron* GetTrihedron(); diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index c3665f6f0..6c162f8a0 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -28,6 +28,7 @@ #include "SVTK_Event.h" #include "SVTK_Renderer.h" #include "SVTK_ViewModel.h" +#include "SVTK_RenderWindow.h" #include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindowInteractor.h" @@ -537,7 +538,7 @@ SVTK_InteractorHolder const char* theName, SUIT_ResourceMgr* theResourceMgr) : SVTK_ActionHolder(theParent,theName,theResourceMgr), - myRenderWindow(vtkRenderWindow::New()) + myRenderWindow(SVTK_RenderWindow::New()) { myRenderWindow->Delete(); diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 87525dab7..f5ef4d6c3 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -215,7 +215,7 @@ public: protected: SVTK_RenderWindowInteractor* myInteractor; - vtkSmartPointer myRenderWindow; + vtkSmartPointer myRenderWindow; };