Salome HOME
Add support for tetra, pyramid and prism
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_TransparencyDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_TransparencyDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_TransparencyDlg.h"
31 #include "SMESHGUI.h"
32
33 // QT Includes
34 #include <qframe.h>
35 #include <qlabel.h>
36 #include <qpushbutton.h>
37 #include <qslider.h>
38 #include <qlayout.h>
39 #include <qvariant.h>
40 #include <qtooltip.h>
41 #include <qwhatsthis.h>
42 #include <qapplication.h>
43 #include <qgroupbox.h>
44
45 #include "VTKViewer_ViewFrame.h"
46 #include "VTKViewer_RenderWindowInteractor.h"
47 #include "QAD_RightFrame.h"
48 #include "SALOME_ListIteratorOfListIO.hxx"
49
50 //=================================================================================
51 // class    : SMESHGUI_TransparencyDlg()
52 // purpose  : 
53 //
54 //=================================================================================
55 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent,
56                                                     const char* name,
57                                                     SALOME_Selection* Sel,
58                                                     bool modal,
59                                                     WFlags fl )
60   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
61 {
62   if ( !name )
63     setName( "SMESHGUI_TransparencyDlg" );
64   resize( 152, 107 ); 
65   setCaption( tr( "SMESH_TRANSPARENCY_TITLE"  ) );
66   setSizeGripEnabled( TRUE );
67   SMESHGUI_TransparencyDlgLayout = new QGridLayout( this ); 
68   SMESHGUI_TransparencyDlgLayout->setSpacing( 6 );
69   SMESHGUI_TransparencyDlgLayout->setMargin( 11 );
70
71   /*************************************************************************/
72   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
73   GroupButtons->setColumnLayout(0, Qt::Vertical );
74   GroupButtons->layout()->setSpacing( 0 );
75   GroupButtons->layout()->setMargin( 0 );
76   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
77   GroupButtonsLayout->setAlignment( Qt::AlignTop );
78   GroupButtonsLayout->setSpacing( 6 );
79   GroupButtonsLayout->setMargin( 11 );
80
81   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
82   buttonOk->setText( tr( "GEOM_BUT_OK" ) );
83   buttonOk->setAutoDefault( TRUE );
84   buttonOk->setDefault( TRUE );
85   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
86   GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
87   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
88
89   /*************************************************************************/
90   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
91   GroupC1->setColumnLayout(0, Qt::Vertical );
92   GroupC1->layout()->setSpacing( 0 );
93   GroupC1->layout()->setMargin( 0 );
94   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
95   GroupC1Layout->setAlignment( Qt::AlignTop );
96   GroupC1Layout->setSpacing( 6 );
97   GroupC1Layout->setMargin( 11 );
98   
99   TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
100   TextLabelOpaque->setText( tr( "SMESH_TRANSPARENCY_OPAQUE"  ) );
101   TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
102   GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
103   GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
104   
105   TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
106   TextLabelTransparent->setText( tr( "SMESH_TRANSPARENCY_TRANSPARENT"  ) );
107   TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
108   GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
109   
110   Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
111   Slider1->setMinimumSize( 300, 0 );
112   Slider1->setTickmarks( QSlider::Left );
113   GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
114
115   SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1,      0, 0 );
116   SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
117   
118   /* Initialisations */
119   this->mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
120   this->mySel = Sel ;
121   
122   /* First call valueChanged() method for initialisation               */
123   /* The default value of transparency will change with the selection  */
124   this->myFirstInit = true ;
125 //  Slider1->setMaxValue( 10 );
126 //  Slider1->setValue( 5 ) ;
127
128
129   this->ValueHasChanged( Slider1->value() ) ;
130   
131   // signals and slots connections : after ValueHasChanged()
132   connect( buttonOk, SIGNAL( clicked() ),         this, SLOT( ClickOnOk() ) );
133   connect( Slider1,  SIGNAL( valueChanged(int) ), this, SLOT( ValueHasChanged(int) ) );
134   
135   /* Move widget on the botton right corner of main widget */
136   int x, y ;
137   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
138   this->move( x, y ) ;
139   this->show() ; /* Displays this Dialog */
140 }
141
142
143
144
145 //=================================================================================
146 // function : ~SMESHGUI_TransparencyDlg()
147 // purpose  :
148 //=================================================================================
149 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
150 {
151     // no need to delete child widgets, Qt does it all for us
152 }
153
154
155 //=======================================================================
156 // function : ClickOnOk()
157 // purpose  :
158 //=======================================================================
159 void SMESHGUI_TransparencyDlg::ClickOnOk()
160 {
161   accept() ;
162   return ;
163 }
164
165
166 //=======================================================================
167 // function : ClickOnClose()
168 // purpose  :
169 //=======================================================================
170 void SMESHGUI_TransparencyDlg::ClickOnClose()
171 {
172   accept() ;
173   return ;
174 }
175
176
177 //=================================================================================
178 // function : ValueHasChanged()
179 // purpose  : Called when value of slider change
180 //          : or the first time as initilisation
181 //=================================================================================
182 void SMESHGUI_TransparencyDlg::ValueHasChanged( int newValue )
183 {
184
185   if ( mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
186     VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
187     SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
188     Handle(SALOME_InteractiveObject) FirstIOS =  mySel->firstIObject();
189     if( !FirstIOS.IsNull() ) {
190       /* The first time as initialisation */
191       if( this->myFirstInit ) { 
192         this->myFirstInit = false ;
193         float transp = ( myRenderInter->GetTransparency(FirstIOS))*10.0 ;
194         this->Slider1->setValue( int(transp) ) ;
195         return;
196       }
197     }
198     
199     QApplication::setOverrideCursor( Qt::waitCursor );
200     for( ;It.More(); It.Next() ) {
201       Handle(SALOME_InteractiveObject) IOS = It.Value();
202       myRenderInter->SetTransparency( IOS, newValue/10.0 );
203     }
204     QApplication::restoreOverrideCursor();
205   }
206   QApplication::restoreOverrideCursor();
207   return ;
208 }