1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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>
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
47 #include <SVTK_ViewWindow.h>
51 #include <QPushButton>
53 #include <QVBoxLayout>
54 #include <QHBoxLayout>
55 #include <QGridLayout>
62 //=================================================================================
63 // class : SMESHGUI_TransparencyDlg()
66 //=================================================================================
67 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule )
68 : QDialog( SMESH::GetDesktop( theModule ) ),
69 mySMESHGUI( theModule ),
70 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
71 myViewWindow( SMESH::GetViewWindow( theModule ) )
74 setAttribute( Qt::WA_DeleteOnClose, true );
75 setWindowTitle( tr( "SMESH_TRANSPARENCY_TITLE" ) );
76 setSizeGripEnabled( true );
78 QVBoxLayout* SMESHGUI_TransparencyDlgLayout = new QVBoxLayout( this );
79 SMESHGUI_TransparencyDlgLayout->setSpacing( SPACING );
80 SMESHGUI_TransparencyDlgLayout->setMargin( MARGIN );
82 /*************************************************************************/
83 QGroupBox* GroupC1 = new QGroupBox( this );
84 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
85 GroupC1Layout->setSpacing( SPACING );
86 GroupC1Layout->setMargin( MARGIN );
88 TextLabelTransparent = new QLabel( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
89 TextLabelTransparent->setAlignment( Qt::AlignRight );
91 ValueLab = new QLabel( GroupC1 );
92 ValueLab->setAlignment( Qt::AlignCenter );
93 ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
96 TextLabelOpaque = new QLabel( tr( "SMESH_TRANSPARENCY_OPAQUE" ), GroupC1 );
97 TextLabelOpaque->setAlignment( Qt::AlignLeft );
99 Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
100 Slider1->setRange( 0, 100 );
101 Slider1->setSingleStep( 1 );
102 Slider1->setPageStep( 10 );
103 Slider1->setTickPosition( QSlider::TicksAbove );
104 Slider1->setTickInterval( 10 );
105 Slider1->setTracking( true );
106 Slider1->setFocusPolicy( Qt::NoFocus );
107 Slider1->setMinimumWidth( 300 );
109 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
110 GroupC1Layout->addWidget( ValueLab, 0, 1 );
111 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
112 GroupC1Layout->addWidget( Slider1, 1, 0, 1, 3 );
114 /*************************************************************************/
115 QGroupBox* GroupButtons = new QGroupBox( this );
116 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
117 GroupButtonsLayout->setSpacing( SPACING );
118 GroupButtonsLayout->setMargin( MARGIN );
120 buttonOk = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
121 buttonOk->setAutoDefault( true );
122 buttonOk->setDefault( true );
123 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
124 buttonHelp->setAutoDefault( true );
126 GroupButtonsLayout->addWidget( buttonOk );
127 GroupButtonsLayout->addSpacing( 10 );
128 GroupButtonsLayout->addStretch();
129 GroupButtonsLayout->addWidget( buttonHelp );
131 /*************************************************************************/
132 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1 );
133 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons );
136 onSelectionChanged();
138 // signals and slots connections : after ValueHasChanged()
139 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
140 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
141 connect( Slider1, SIGNAL( valueChanged( int ) ), this, SLOT( SetTransparency() ) );
142 connect( Slider1, SIGNAL( sliderMoved( int ) ), this, SLOT( ValueHasChanged() ) );
143 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnOk() ) );
144 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
146 myHelpFileName = "transparency.html";
149 //=================================================================================
150 // function : ~SMESHGUI_TransparencyDlg()
152 //=================================================================================
153 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
157 //=======================================================================
158 // function : ClickOnOk()
160 //=======================================================================
161 void SMESHGUI_TransparencyDlg::ClickOnOk()
166 //=================================================================================
167 // function : ClickOnHelp()
169 //=================================================================================
170 void SMESHGUI_TransparencyDlg::ClickOnHelp()
172 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
174 app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) :
175 QString( "" ), myHelpFileName );
179 platform = "winapplication";
181 platform = "application";
183 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
184 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
185 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
187 arg( myHelpFileName ) );
191 //=================================================================================
192 // function : SetTransparency()
193 // purpose : Called when value of slider change
194 // : or the first time as initialisation
195 //=================================================================================
196 void SMESHGUI_TransparencyDlg::SetTransparency()
198 if ( myViewWindow ) {
199 SUIT_OverrideCursor wc;
200 //float opacity = ( 100.f - Slider1->value() ) / 100.;
201 float opacity = float( 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 ) {