1 // GEOM GEOMGUI : GUI for Geometry component
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 : GeometryGUI_TransparencyDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GeometryGUI_TransparencyDlg.h"
30 #include "GeometryGUI.h"
32 #include "QAD_RightFrame.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include <qpushbutton.h>
42 #include <qwhatsthis.h>
43 #include <qapplication.h>
44 #include <qgroupbox.h>
46 #include "VTKViewer_ViewFrame.h"
47 #include "VTKViewer_RenderWindowInteractor.h"
49 //=================================================================================
50 // class : GeometryGUI_TransparencyDlg()
51 // purpose : Constructs a GeometryGUI_SUBSHAPE which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
54 // : WARNING : this dialog is modal !
56 //=================================================================================
57 GeometryGUI_TransparencyDlg::GeometryGUI_TransparencyDlg( QWidget* parent,
59 SALOME_Selection* Sel,
60 const Handle(AIS_InteractiveContext)& ic,
63 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 setName( "GeometryGUI_TransparencyDlg" );
68 setCaption( tr( "GEOM_TRANSPARENCY_TITLE" ) );
69 setSizeGripEnabled( TRUE );
70 GeometryGUI_TransparencyDlgLayout = new QGridLayout( this );
71 GeometryGUI_TransparencyDlgLayout->setSpacing( 6 );
72 GeometryGUI_TransparencyDlgLayout->setMargin( 11 );
74 /*************************************************************************/
75 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
76 GroupButtons->setColumnLayout(0, Qt::Vertical );
77 GroupButtons->layout()->setSpacing( 0 );
78 GroupButtons->layout()->setMargin( 0 );
79 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
80 GroupButtonsLayout->setAlignment( Qt::AlignTop );
81 GroupButtonsLayout->setSpacing( 6 );
82 GroupButtonsLayout->setMargin( 11 );
84 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
85 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
86 buttonOk->setAutoDefault( TRUE );
87 buttonOk->setDefault( TRUE );
88 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
89 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
90 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
92 /*************************************************************************/
93 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
94 GroupC1->setColumnLayout(0, Qt::Vertical );
95 GroupC1->layout()->setSpacing( 0 );
96 GroupC1->layout()->setMargin( 0 );
97 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
98 GroupC1Layout->setAlignment( Qt::AlignTop );
99 GroupC1Layout->setSpacing( 6 );
100 GroupC1Layout->setMargin( 11 );
102 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
103 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
104 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
105 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
106 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
108 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
109 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
110 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
111 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
113 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
114 Slider1->setMinimumSize( 300, 0 );
115 Slider1->setTickmarks( QSlider::Left );
116 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
117 /*************************************************************************/
119 GeometryGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 );
120 GeometryGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
122 /* Initialisations */
123 this->myGeomGUI = GeometryGUI::GetGeometryGUI() ;
127 /* First call valueChanged() method for initialisation */
128 /* The default value of transparency will change with the selection */
129 this->myFirstInit = true ;
130 // Slider1->setMaxValue( 10 );
131 // Slider1->setValue( 5 ) ;
132 this->ValueHasChanged( Slider1->value() ) ;
134 // signals and slots connections : after ValueHasChanged()
135 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136 connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( ValueHasChanged(int) ) );
138 /* Move widget on the botton right corner of main widget */
140 myGeomGUI->DefineDlgPosition( this, x, y ) ;
142 this->show() ; /* Displays this Dialog */
148 //=================================================================================
149 // function : ~GeometryGUI_TransparencyDlg()
151 //=================================================================================
152 GeometryGUI_TransparencyDlg::~GeometryGUI_TransparencyDlg()
154 // no need to delete child widgets, Qt does it all for us
158 //=======================================================================
159 // function : ClickOnOk()
161 //=======================================================================
162 void GeometryGUI_TransparencyDlg::ClickOnOk()
169 //=======================================================================
170 // function : ClickOnClose()
172 //=======================================================================
173 void GeometryGUI_TransparencyDlg::ClickOnClose()
180 //=================================================================================
181 // function : ValueHasChanged()
182 // purpose : Called when value of slider change
183 // : or the first time as initilisation
184 //=================================================================================
185 void GeometryGUI_TransparencyDlg::ValueHasChanged( int newValue )
188 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
190 // vtkQGLRenderWindowInteractor* myRenderInter= myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
191 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
192 SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
194 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject();
195 if( !FirstIOS.IsNull() ) {
197 /* The first time as initialisation */
198 if( this->myFirstInit ) {
199 this->myFirstInit = false ;
200 float transp = ( myRenderInter->GetTransparency(FirstIOS))*10.0 ;
201 this->Slider1->setValue( int(transp) ) ;
205 QApplication::setOverrideCursor( Qt::waitCursor );
206 for( ;It.More(); It.Next() ) {
207 Handle(SALOME_InteractiveObject) IOS = It.Value();
208 myRenderInter->SetTransparency( IOS, newValue/10.0 );
210 QApplication::restoreOverrideCursor();
213 else if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
215 SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
216 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject() ;
217 if( !FirstIOS.IsNull() ) {
219 /* The first time as initialisation */
220 if( this->myFirstInit ) {
221 this->myFirstInit = false ;
222 Standard_Boolean found;
223 Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(FirstIOS, found);
227 float transp = ( int( Shape->Transparency() * 10.0 + 0.001) );
228 this->Slider1->setValue(int(transp) ) ;
233 QApplication::setOverrideCursor( Qt::waitCursor );
234 for( ;It.More(); It.Next() ) {
235 Handle(SALOME_InteractiveObject) IObject = It.Value();
236 Standard_Boolean found;
237 Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found);
239 QApplication::restoreOverrideCursor();
242 this->myIc->SetTransparency( Shape, newValue / 10.0, false );
243 myIc->Redisplay( Shape, Standard_False, Standard_True );
245 myIc->UpdateCurrentViewer();
247 QApplication::restoreOverrideCursor();