1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_TransparencyDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_TransparencyDlg.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESH_Actor.h"
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SALOME_ListIO.hxx>
43 #include <SALOME_ListIteratorOfListIO.hxx>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
48 #include <SVTK_ViewWindow.h>
52 #include <QPushButton>
54 #include <QVBoxLayout>
55 #include <QHBoxLayout>
56 #include <QGridLayout>
63 //=================================================================================
64 // class : SMESHGUI_TransparencyDlg()
67 //=================================================================================
68 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule )
69 : QDialog( SMESH::GetDesktop( theModule ) ),
70 mySMESHGUI( theModule ),
71 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
72 myViewWindow( SMESH::GetViewWindow( theModule ) )
75 setAttribute( Qt::WA_DeleteOnClose, true );
76 setWindowTitle( tr( "SMESH_TRANSPARENCY_TITLE" ) );
77 setSizeGripEnabled( true );
79 QVBoxLayout* SMESHGUI_TransparencyDlgLayout = new QVBoxLayout( this );
80 SMESHGUI_TransparencyDlgLayout->setSpacing( SPACING );
81 SMESHGUI_TransparencyDlgLayout->setMargin( MARGIN );
83 /*************************************************************************/
84 QGroupBox* GroupC1 = new QGroupBox( this );
85 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
86 GroupC1Layout->setSpacing( SPACING );
87 GroupC1Layout->setMargin( MARGIN );
89 TextLabelTransparent = new QLabel( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
90 TextLabelTransparent->setAlignment( Qt::AlignRight );
92 ValueLab = new QLabel( GroupC1 );
93 ValueLab->setAlignment( Qt::AlignCenter );
94 ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
97 TextLabelOpaque = new QLabel( tr( "SMESH_TRANSPARENCY_OPAQUE" ), GroupC1 );
98 TextLabelOpaque->setAlignment( Qt::AlignLeft );
100 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
101 Slider1->setRange( 0, 100 );
102 Slider1->setSingleStep( 1 );
103 Slider1->setPageStep( 10 );
104 Slider1->setTickPosition( QSlider::TicksAbove );
105 Slider1->setTickInterval( 10 );
106 Slider1->setTracking( true );
107 Slider1->setFocusPolicy( Qt::NoFocus );
108 Slider1->setMinimumWidth( 300 );
110 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
111 GroupC1Layout->addWidget( ValueLab, 0, 1 );
112 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
113 GroupC1Layout->addWidget( Slider1, 1, 0, 1, 3 );
115 /*************************************************************************/
116 QGroupBox* GroupButtons = new QGroupBox( this );
117 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
118 GroupButtonsLayout->setSpacing( SPACING );
119 GroupButtonsLayout->setMargin( MARGIN );
121 buttonOk = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
122 buttonOk->setAutoDefault( true );
123 buttonOk->setDefault( true );
124 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
125 buttonHelp->setAutoDefault( true );
127 GroupButtonsLayout->addWidget( buttonOk );
128 GroupButtonsLayout->addSpacing( 10 );
129 GroupButtonsLayout->addStretch();
130 GroupButtonsLayout->addWidget( buttonHelp );
132 /*************************************************************************/
133 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1 );
134 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons );
137 onSelectionChanged();
139 // signals and slots connections : after ValueHasChanged()
140 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
141 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
142 connect( Slider1, SIGNAL( valueChanged( int ) ), this, SLOT( SetTransparency() ) );
143 connect( Slider1, SIGNAL( sliderMoved( int ) ), this, SLOT( ValueHasChanged() ) );
144 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnOk() ) );
145 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
147 myHelpFileName = "transparency_page.html";
150 //=================================================================================
151 // function : ~SMESHGUI_TransparencyDlg()
153 //=================================================================================
154 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
158 //=======================================================================
159 // function : ClickOnOk()
161 //=======================================================================
162 void SMESHGUI_TransparencyDlg::ClickOnOk()
167 //=================================================================================
168 // function : ClickOnHelp()
170 //=================================================================================
171 void SMESHGUI_TransparencyDlg::ClickOnHelp()
173 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
175 app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) :
176 QString( "" ), myHelpFileName );
180 platform = "winapplication";
182 platform = "application";
184 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
185 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
186 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
188 arg( myHelpFileName ) );
192 //=================================================================================
193 // function : SetTransparency()
194 // purpose : Called when value of slider change
195 // : or the first time as initilisation
196 //=================================================================================
197 void SMESHGUI_TransparencyDlg::SetTransparency()
199 if ( myViewWindow ) {
200 SUIT_OverrideCursor wc;
201 float opacity = ( 100 - Slider1->value() ) / 100.;
204 mySelectionMgr->selectedObjects( aList );
206 SALOME_ListIteratorOfListIO It( aList );
207 for ( ; It.More(); It.Next() ) {
208 Handle(SALOME_InteractiveObject) IOS = It.Value();
209 SMESH_Actor* anActor = SMESH::FindActorByEntry( IOS->getEntry() );
211 anActor->SetOpacity( opacity );
213 myViewWindow->Repaint();
218 //=================================================================================
219 // function : ValueHasChanged()
220 // purpose : Called when user moves a slider
221 //=================================================================================
222 void SMESHGUI_TransparencyDlg::ValueHasChanged()
224 ValueLab->setText( QString::number( Slider1->value() ) + "%") ;
227 //=================================================================================
228 // function : onSelectionChanged()
229 // purpose : Called when selection is changed
230 //=================================================================================
231 void SMESHGUI_TransparencyDlg::onSelectionChanged()
233 if ( myViewWindow ) {
237 mySelectionMgr->selectedObjects( aList );
239 if ( aList.Extent() == 1 ) {
240 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
241 if ( !FirstIOS.IsNull() ) {
242 SMESH_Actor* anActor = SMESH::FindActorByEntry( FirstIOS->getEntry() );
244 opacity = int( anActor->GetOpacity() * 100. + 0.5 );
247 else if ( aList.Extent() > 1 ) {
248 SALOME_ListIteratorOfListIO It( aList );
250 for ( ; It.More(); It.Next() ) {
251 Handle(SALOME_InteractiveObject) IO = It.Value();
252 if ( !IO.IsNull() ) {
253 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
255 int op = int( anActor->GetOpacity() * 100. + 0.5 );
258 else if ( setOp != op ) {
270 Slider1->setValue( 100 - opacity );
275 //=================================================================================
276 // function : keyPressEvent()
278 //=================================================================================
279 void SMESHGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
281 QDialog::keyPressEvent( e );
282 if ( e->isAccepted() )
285 if ( e->key() == Qt::Key_F1 ) {