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
30 #include "VTKViewer_RenderWindow.h"
31 #include "utilities.h"
32 #include "QAD_Settings.h"
33 #include "QAD_Config.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Study.h"
36 #include "QAD_Tools.h"
37 #include "SALOME_Selection.h"
39 #include <qcolordialog.h>
45 #include <vtkRenderWindowInteractor.h>
46 #include <vtkRendererCollection.h>
47 #include <vtkXOpenGLRenderWindow.h>
57 VTKViewer_RenderWindow::VTKViewer_RenderWindow(QWidget *parent, const char *name) :
59 Qt::WStyle_NoBorder | Qt::WDestructiveClose |
60 Qt::WResizeNoErase | Qt::WRepaintNoErase)
62 myRW = vtkRenderWindow::New();
63 MESSAGE(QString("RenderWindow is ") + QString(myRW->GetClassName()));
64 myRW->SetDisplayId((void*)x11Display());
65 myRW->SetWindowId((void*)winId());
66 myRW->DoubleBufferOn();
69 VTKViewer_RenderWindow::~VTKViewer_RenderWindow() {
70 //myRW->Delete(); //BUG SAL2954, Commented by SRN, to avoid problems when using rlogin
73 void VTKViewer_RenderWindow::paintEvent(QPaintEvent* theEvent) {
77 void VTKViewer_RenderWindow::resizeEvent(QResizeEvent* theEvent) {
78 vtkRenderWindowInteractor* aRWI = myRW->GetInteractor();
80 aRWI->SetSize(width(), height());
81 myRW->SetSize(width(), height());
85 void VTKViewer_RenderWindow::mouseMoveEvent( QMouseEvent *event ) {
86 emit MouseMove(event) ;
89 void VTKViewer_RenderWindow::mousePressEvent( QMouseEvent *event ) {
90 emit ButtonPressed(event) ;
91 switch(event->button()) {
93 emit LeftButtonPressed(event) ;
96 emit MiddleButtonPressed(event) ;
99 if ( event->state() == Qt::ControlButton ) {
100 emit RightButtonPressed(event) ;
102 QPopupMenu* popup = createPopup();
104 QAD_Tools::checkPopup( popup );
105 if ( popup->count()>0 ) {
106 popup->exec( QCursor::pos() );
118 void VTKViewer_RenderWindow::mouseReleaseEvent( QMouseEvent *event ) {
119 emit ButtonReleased(event) ;
120 switch(event->button()) {
122 emit LeftButtonReleased(event) ;
125 emit MiddleButtonReleased(event) ;
128 emit RightButtonReleased(event) ;
135 void VTKViewer_RenderWindow::keyPressEvent (QKeyEvent * event) {
136 emit KeyPressed(event) ;
142 void VTKViewer_RenderWindow::onCreatePopup()
145 QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
146 QAD_Study* myActiveStudy = Desktop->getActiveStudy();
147 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
150 QString theParent("Viewer");
153 Desktop->definePopup( theContext, theParent, theObject );
154 Desktop->createPopup( myPopup, theContext, theParent, theObject);
155 Desktop->customPopup( myPopup, theContext, theParent, theObject );
157 // if (Sel->IObjectCount() == 0 && myPopup->count()<1) {
158 if ( myPopup->count() > 0 )
159 myIDs.append ( myPopup->insertSeparator() );
161 myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
162 QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
168 void VTKViewer_RenderWindow::onChangeBackgroundColor()
170 float red, green, blue;
173 vtkRendererCollection * theRenderers = myRW->GetRenderers();
174 theRenderers->InitTraversal();
175 vtkRenderer * theRenderer = theRenderers->GetNextItem();
176 theRenderer->GetBackground(backint);
178 QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
179 if ( selColor.isValid() ) {
180 theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. );
181 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", selColor.red() );
182 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", selColor.green() );
183 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", selColor.blue() );