1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_RenderWindow.cxx
25 // Author : Nicolas REJNERI
29 #include "VTKViewer_RenderWindow.h"
30 #include "utilities.h"
31 #include "QAD_Settings.h"
32 #include "QAD_Config.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Study.h"
35 #include "QAD_Tools.h"
36 #include "SALOME_Selection.h"
38 #include <qcolordialog.h>
44 #include <vtkRenderWindowInteractor.h>
45 #include <vtkRendererCollection.h>
46 #include <vtkXOpenGLRenderWindow.h>
47 #include <vtkCamera.h>
58 VTKViewer_RenderWindow::VTKViewer_RenderWindow(QWidget *parent, const char *name) :
60 Qt::WStyle_NoBorder | Qt::WDestructiveClose |
61 Qt::WResizeNoErase | Qt::WRepaintNoErase)
63 myRW = vtkRenderWindow::New();
64 MESSAGE(QString("RenderWindow is ") + QString(myRW->GetClassName()));
65 myRW->SetDisplayId((void*)x11Display());
66 myRW->SetWindowId((void*)winId());
67 myRW->DoubleBufferOn();
68 setMouseTracking(true);
71 VTKViewer_RenderWindow::~VTKViewer_RenderWindow() {
72 myRW->Delete(); //BUG SAL2954, Commented by SRN, to avoid problems when using rlogin
73 // Uncommented because of bug SAL3913
76 void VTKViewer_RenderWindow::paintEvent(QPaintEvent* theEvent) {
80 void VTKViewer_RenderWindow::resizeEvent(QResizeEvent* theEvent) {
81 int aWidth = myRW->GetSize()[0], aHeight = myRW->GetSize()[1];
82 if(vtkRenderWindowInteractor* aRWI = myRW->GetInteractor())
83 aRWI->UpdateSize(width(), height());
84 if(aWidth != width() || aHeight != height()){
85 vtkRendererCollection * aRenderers = myRW->GetRenderers();
86 aRenderers->InitTraversal();
88 if(vtkRenderer *aRenderer = aRenderers->GetNextItem()){
89 vtkCamera *aCamera = aRenderer->GetActiveCamera();
90 double aScale = aCamera->GetParallelScale();
91 if((aWidth - width())*(aHeight - height()) > 0)
92 aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
94 aCoeff = double(aWidth)/double(width());
95 aCamera->SetParallelScale(aScale*aCoeff);
101 void VTKViewer_RenderWindow::mouseMoveEvent( QMouseEvent *event ) {
102 emit MouseMove(event) ;
105 void VTKViewer_RenderWindow::mousePressEvent( QMouseEvent *event ) {
106 emit ButtonPressed(event) ;
107 switch(event->button()) {
109 emit LeftButtonPressed(event) ;
112 emit MiddleButtonPressed(event) ;
115 if ( event->state() == Qt::ControlButton ) {
116 emit RightButtonPressed(event) ;
118 QPopupMenu* popup = createPopup();
120 QAD_Tools::checkPopup( popup );
121 if ( popup->count()>0 ) {
122 popup->exec( QCursor::pos() );
134 void VTKViewer_RenderWindow::mouseReleaseEvent( QMouseEvent *event ) {
135 emit ButtonReleased(event) ;
136 switch(event->button()) {
138 emit LeftButtonReleased(event) ;
141 emit MiddleButtonReleased(event) ;
144 emit RightButtonReleased(event) ;
151 void VTKViewer_RenderWindow::keyPressEvent (QKeyEvent * event) {
152 emit KeyPressed(event) ;
158 void VTKViewer_RenderWindow::onCreatePopup()
161 QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
162 QAD_Study* myActiveStudy = Desktop->getActiveStudy();
163 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
166 QString theParent("Viewer");
169 Desktop->definePopup( theContext, theParent, theObject );
170 Desktop->createPopup( myPopup, theContext, theParent, theObject);
171 Desktop->customPopup( myPopup, theContext, theParent, theObject );
173 // if (Sel->IObjectCount() == 0 && myPopup->count()<1) {
174 if ( myPopup->count() > 0 )
175 myIDs.append ( myPopup->insertSeparator() );
177 myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
178 QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
184 void VTKViewer_RenderWindow::onChangeBackgroundColor()
186 float red, green, blue;
189 vtkRendererCollection * theRenderers = myRW->GetRenderers();
190 theRenderers->InitTraversal();
191 vtkRenderer * theRenderer = theRenderers->GetNextItem();
192 theRenderer->GetBackground(backint);
194 QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
195 if ( selColor.isValid() ) {
196 theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. );
197 /* VSR : PAL5420 ---------------------------------------------------
198 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", selColor.red() );
199 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", selColor.green() );
200 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", selColor.blue() );
201 VSR : PAL5420 --------------------------------------------------- */