]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI_TransparencyDlg.cxx
Salome HOME
9c6a510875db6a875f46af8e6d1428b9999330bc
[modules/geom.git] / src / GEOMGUI / GeometryGUI_TransparencyDlg.cxx
1 using namespace std;
2 //  File      : GeometryGUI_TransparencyDlg.cxx
3 //  Created   :
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Headers
9
10
11 #include "GeometryGUI_TransparencyDlg.h"
12 #include "GeometryGUI.h"
13
14 #include "VTKViewer_ViewFrame.h"
15 #include "VTKViewer_RenderWindowInteractor.h"
16
17 //#include "QAD_ViewVTKFrame.h"
18 #include "QAD_RightFrame.h"
19 #include "SALOME_ListIteratorOfListIO.hxx"
20
21 #include <qframe.h>
22 #include <qlabel.h>
23 #include <qpushbutton.h>
24 #include <qslider.h>
25 #include <qlayout.h>
26 #include <qvariant.h>
27 #include <qtooltip.h>
28 #include <qwhatsthis.h>
29 #include <qapplication.h>
30 #include <qgroupbox.h>
31
32
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'.
37 //
38 //          : WARNING : this dialog is modal !
39 //
40 //=================================================================================
41 GeometryGUI_TransparencyDlg::GeometryGUI_TransparencyDlg( QWidget* parent,
42                                                           const char* name,
43                                                           SALOME_Selection* Sel,
44                                                           const Handle(AIS_InteractiveContext)& ic,
45                                                           bool modal,
46                                                           WFlags fl )
47   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
48 {
49   if ( !name )
50     setName( "GeometryGUI_TransparencyDlg" );
51   resize( 152, 107 ); 
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 );
57
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 );
67   
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 );
75
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 );
85   
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 );
91   
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 );
96   
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   /*************************************************************************/
102   
103   GeometryGUI_TransparencyDlgLayout->addWidget( GroupC1,      0,  0 );
104   GeometryGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
105   
106   /* Initialisations */
107   this->myGeomGUI = GeometryGUI::GetGeometryGUI() ;
108   this->myIc  = ic ;
109   this->mySel = Sel ;
110   
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() ) ;
117   
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) ) );
121   
122   /* Move widget on the botton right corner of main widget */
123   int x, y ;
124   myGeomGUI->DefineDlgPosition( this, x, y ) ;
125   this->move( x, y ) ;
126   this->show() ; /* Displays this Dialog */
127 }
128
129
130
131
132 //=================================================================================
133 // function : ~GeometryGUI_TransparencyDlg()
134 // purpose  :
135 //=================================================================================
136 GeometryGUI_TransparencyDlg::~GeometryGUI_TransparencyDlg()
137 {
138     // no need to delete child widgets, Qt does it all for us
139 }
140
141
142 //=======================================================================
143 // function : ClickOnOk()
144 // purpose  :
145 //=======================================================================
146 void GeometryGUI_TransparencyDlg::ClickOnOk()
147 {
148   accept() ;
149   return ;
150 }
151
152
153 //=======================================================================
154 // function : ClickOnClose()
155 // purpose  :
156 //=======================================================================
157 void GeometryGUI_TransparencyDlg::ClickOnClose()
158 {
159   accept() ;
160   return ;
161 }
162
163
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 )
170 {
171
172   if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
173     // 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() );
177
178     Handle(SALOME_InteractiveObject) FirstIOS =  mySel->firstIObject();
179     if( !FirstIOS.IsNull() ) {
180       
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) ) ;
186       }
187     }
188     
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 );
193     }
194     QApplication::restoreOverrideCursor();
195   }
196
197   else if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
198     // OCC  
199     SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() );
200     Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject() ;
201     if( !FirstIOS.IsNull() ) {
202       
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);
208         if( !found ) {
209           return ;
210         }
211         float transp = ( int( Shape->Transparency() * 10.0 + 0.001) );
212         this->Slider1->setValue(int(transp) ) ;
213         return ;
214       }
215     }
216
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);      
222       if( !found ) {
223         QApplication::restoreOverrideCursor();
224         return ;
225       }
226       this->myIc->SetTransparency( Shape, newValue / 10.0, false );
227       myIc->Redisplay( Shape, Standard_False, Standard_True );
228     }
229     myIc->UpdateCurrentViewer();
230   }
231   QApplication::restoreOverrideCursor();
232   return ;
233 }