2 // File : GeometryGUI_TransparencyDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
11 #include "GeometryGUI_TransparencyDlg.h"
12 #include "GeometryGUI.h"
14 #include "VTKViewer_ViewFrame.h"
15 #include "VTKViewer_RenderWindowInteractor.h"
17 //#include "QAD_ViewVTKFrame.h"
18 #include "QAD_RightFrame.h"
19 #include "SALOME_ListIteratorOfListIO.hxx"
23 #include <qpushbutton.h>
28 #include <qwhatsthis.h>
29 #include <qapplication.h>
30 #include <qgroupbox.h>
33 //=================================================================================
34 // class : GeometryGUI_TransparencyDlg()
35 // purpose : Constructs a GeometryGUI_SUBSHAPE which is a child of 'parent', with the
36 // name 'name' and widget flags set to 'f'.
38 // : WARNING : this dialog is modal !
40 //=================================================================================
41 GeometryGUI_TransparencyDlg::GeometryGUI_TransparencyDlg( QWidget* parent,
43 SALOME_Selection* Sel,
44 const Handle(AIS_InteractiveContext)& ic,
47 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
50 setName( "GeometryGUI_TransparencyDlg" );
52 setCaption( tr( "GEOM_TRANSPARENCY_TITLE" ) );
53 setSizeGripEnabled( TRUE );
54 GeometryGUI_TransparencyDlgLayout = new QGridLayout( this );
55 GeometryGUI_TransparencyDlgLayout->setSpacing( 6 );
56 GeometryGUI_TransparencyDlgLayout->setMargin( 11 );
58 /*************************************************************************/
59 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
60 GroupButtons->setColumnLayout(0, Qt::Vertical );
61 GroupButtons->layout()->setSpacing( 0 );
62 GroupButtons->layout()->setMargin( 0 );
63 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
64 GroupButtonsLayout->setAlignment( Qt::AlignTop );
65 GroupButtonsLayout->setSpacing( 6 );
66 GroupButtonsLayout->setMargin( 11 );
68 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
69 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
70 buttonOk->setAutoDefault( TRUE );
71 buttonOk->setDefault( TRUE );
72 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
73 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
74 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
76 /*************************************************************************/
77 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
78 GroupC1->setColumnLayout(0, Qt::Vertical );
79 GroupC1->layout()->setSpacing( 0 );
80 GroupC1->layout()->setMargin( 0 );
81 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
82 GroupC1Layout->setAlignment( Qt::AlignTop );
83 GroupC1Layout->setSpacing( 6 );
84 GroupC1Layout->setMargin( 11 );
86 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
87 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
88 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
89 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
90 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
92 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
93 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
94 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
95 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
97 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
98 Slider1->setMinimumSize( 300, 0 );
99 Slider1->setTickmarks( QSlider::Left );
100 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
101 /*************************************************************************/
103 GeometryGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 );
104 GeometryGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
106 /* Initialisations */
107 this->myGeomGUI = GeometryGUI::GetGeometryGUI() ;
111 /* First call valueChanged() method for initialisation */
112 /* The default value of transparency will change with the selection */
113 this->myFirstInit = true ;
114 // Slider1->setMaxValue( 10 );
115 // Slider1->setValue( 5 ) ;
116 this->ValueHasChanged( Slider1->value() ) ;
118 // signals and slots connections : after ValueHasChanged()
119 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
120 connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( ValueHasChanged(int) ) );
122 /* Move widget on the botton right corner of main widget */
124 myGeomGUI->DefineDlgPosition( this, x, y ) ;
126 this->show() ; /* Displays this Dialog */
132 //=================================================================================
133 // function : ~GeometryGUI_TransparencyDlg()
135 //=================================================================================
136 GeometryGUI_TransparencyDlg::~GeometryGUI_TransparencyDlg()
138 // no need to delete child widgets, Qt does it all for us
142 //=======================================================================
143 // function : ClickOnOk()
145 //=======================================================================
146 void GeometryGUI_TransparencyDlg::ClickOnOk()
153 //=======================================================================
154 // function : ClickOnClose()
156 //=======================================================================
157 void GeometryGUI_TransparencyDlg::ClickOnClose()
164 //=================================================================================
165 // function : ValueHasChanged()
166 // purpose : Called when value of slider change
167 // : or the first time as initilisation
168 //=================================================================================
169 void GeometryGUI_TransparencyDlg::ValueHasChanged( int newValue )
172 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
174 // vtkQGLRenderWindowInteractor* myRenderInter= myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
175 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
176 SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
178 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject();
179 if( !FirstIOS.IsNull() ) {
181 /* The first time as initialisation */
182 if( this->myFirstInit ) {
183 this->myFirstInit = false ;
184 float transp = ( myRenderInter->GetTransparency(FirstIOS))*10.0 ;
185 this->Slider1->setValue( int(transp) ) ;
189 QApplication::setOverrideCursor( Qt::waitCursor );
190 for( ;It.More(); It.Next() ) {
191 Handle(SALOME_InteractiveObject) IOS = It.Value();
192 myRenderInter->SetTransparency( IOS, newValue/10.0 );
194 QApplication::restoreOverrideCursor();
197 else if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
199 SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
200 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject() ;
201 if( !FirstIOS.IsNull() ) {
203 /* The first time as initialisation */
204 if( this->myFirstInit ) {
205 this->myFirstInit = false ;
206 Standard_Boolean found;
207 Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(FirstIOS, found);
211 float transp = ( int( Shape->Transparency() * 10.0 + 0.001) );
212 this->Slider1->setValue(int(transp) ) ;
217 QApplication::setOverrideCursor( Qt::waitCursor );
218 for( ;It.More(); It.Next() ) {
219 Handle(SALOME_InteractiveObject) IObject = It.Value();
220 Standard_Boolean found;
221 Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found);
223 QApplication::restoreOverrideCursor();
226 this->myIc->SetTransparency( Shape, newValue / 10.0, false );
227 myIc->Redisplay( Shape, Standard_False, Standard_True );
229 myIc->UpdateCurrentViewer();
231 QApplication::restoreOverrideCursor();