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
71 // Uncommented because of bug SAL3913
74 void VTKViewer_RenderWindow::paintEvent(QPaintEvent* theEvent) {
78 void VTKViewer_RenderWindow::resizeEvent(QResizeEvent* theEvent) {
79 vtkRenderWindowInteractor* aRWI = myRW->GetInteractor();
81 aRWI->SetSize(width(), height());
82 myRW->SetSize(width(), height());
86 void VTKViewer_RenderWindow::mouseMoveEvent( QMouseEvent *event ) {
87 emit MouseMove(event) ;
90 void VTKViewer_RenderWindow::mousePressEvent( QMouseEvent *event ) {
91 emit ButtonPressed(event) ;
92 switch(event->button()) {
94 emit LeftButtonPressed(event) ;
97 emit MiddleButtonPressed(event) ;
100 if ( event->state() == Qt::ControlButton ) {
101 emit RightButtonPressed(event) ;
103 QPopupMenu* popup = createPopup();
105 QAD_Tools::checkPopup( popup );
106 if ( popup->count()>0 ) {
107 popup->exec( QCursor::pos() );
119 void VTKViewer_RenderWindow::mouseReleaseEvent( QMouseEvent *event ) {
120 emit ButtonReleased(event) ;
121 switch(event->button()) {
123 emit LeftButtonReleased(event) ;
126 emit MiddleButtonReleased(event) ;
129 emit RightButtonReleased(event) ;
136 void VTKViewer_RenderWindow::keyPressEvent (QKeyEvent * event) {
137 emit KeyPressed(event) ;
143 void VTKViewer_RenderWindow::onCreatePopup()
146 QAD_Desktop* Desktop = (QAD_Desktop*) QAD_Application::getDesktop();
147 QAD_Study* myActiveStudy = Desktop->getActiveStudy();
148 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
151 QString theParent("Viewer");
154 Desktop->definePopup( theContext, theParent, theObject );
155 Desktop->createPopup( myPopup, theContext, theParent, theObject);
156 Desktop->customPopup( myPopup, theContext, theParent, theObject );
158 // if (Sel->IObjectCount() == 0 && myPopup->count()<1) {
159 if ( myPopup->count() > 0 )
160 myIDs.append ( myPopup->insertSeparator() );
162 myIDs.append ( id = myPopup->insertItem (tr ("MEN_VP3D_CHANGEBGR")) );
163 QAD_ASSERT ( myPopup->connectItem ( id, this, SLOT(onChangeBackgroundColor())) );
169 void VTKViewer_RenderWindow::onChangeBackgroundColor()
171 float red, green, blue;
174 vtkRendererCollection * theRenderers = myRW->GetRenderers();
175 theRenderers->InitTraversal();
176 vtkRenderer * theRenderer = theRenderers->GetNextItem();
177 theRenderer->GetBackground(backint);
179 QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
180 if ( selColor.isValid() ) {
181 theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. );
182 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", selColor.red() );
183 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", selColor.green() );
184 QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", selColor.blue() );