1 // SMESH SMESHGUI : GUI for SMESH 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 : SMESHGUI_TransparencyDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_VTKUtils.h"
36 #include <qpushbutton.h>
39 #include <qgroupbox.h>
41 #include "VTKViewer_ViewFrame.h"
42 #include "QAD_RightFrame.h"
43 #include "QAD_WaitCursor.h"
44 #include "SALOME_ListIteratorOfListIO.hxx"
45 #include "SMESH_Actor.h"
46 #include "SALOME_Selection.h"
47 #include "SALOME_InteractiveObject.hxx"
51 //=================================================================================
52 // class : SMESHGUI_TransparencyDlg()
55 //=================================================================================
56 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent,
60 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
63 setName( "SMESHGUI_TransparencyDlg" );
64 setCaption( tr( "SMESH_TRANSPARENCY_TITLE" ) );
65 setSizeGripEnabled( TRUE );
66 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout( this );
67 SMESHGUI_TransparencyDlgLayout->setSpacing( 6 );
68 SMESHGUI_TransparencyDlgLayout->setMargin( 11 );
70 /*************************************************************************/
71 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
72 GroupC1->setColumnLayout(0, Qt::Vertical );
73 GroupC1->layout()->setSpacing( 0 );
74 GroupC1->layout()->setMargin( 0 );
75 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
76 GroupC1Layout->setAlignment( Qt::AlignTop );
77 GroupC1Layout->setSpacing( 6 );
78 GroupC1Layout->setMargin( 11 );
80 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
81 TextLabelTransparent->setText( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ) );
82 TextLabelTransparent->setAlignment( AlignLeft );
83 GroupC1Layout->addWidget( TextLabelTransparent, 0, 0 );
85 ValueLab = new QLabel( GroupC1, "ValueLab" );
86 ValueLab->setAlignment( AlignCenter );
87 ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
88 QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
89 GroupC1Layout->addWidget( ValueLab, 0, 1 );
91 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
92 TextLabelOpaque->setText( tr( "SMESH_TRANSPARENCY_OPAQUE" ) );
93 TextLabelOpaque->setAlignment( AlignRight );
94 GroupC1Layout->addWidget( TextLabelOpaque, 0, 2 );
96 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
97 Slider1->setFocusPolicy( QWidget::NoFocus );
98 Slider1->setMinimumSize( 300, 0 );
99 Slider1->setTickmarks( QSlider::Above );
100 Slider1->setTickInterval( 10 );
101 Slider1->setTracking( true );
102 Slider1->setMinValue( 0 ) ;
103 Slider1->setMaxValue( 100 );
104 Slider1->setLineStep( 1 );
105 Slider1->setPageStep( 10 );
106 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
108 /*************************************************************************/
109 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
110 GroupButtons->setColumnLayout(0, Qt::Vertical );
111 GroupButtons->layout()->setSpacing( 0 );
112 GroupButtons->layout()->setMargin( 0 );
113 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
114 GroupButtonsLayout->setAlignment( Qt::AlignTop );
115 GroupButtonsLayout->setSpacing( 6 );
116 GroupButtonsLayout->setMargin( 11 );
118 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
119 buttonOk->setText( tr( "SMESH_BUT_CLOSE" ) );
120 buttonOk->setAutoDefault( TRUE );
121 buttonOk->setDefault( TRUE );
122 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
124 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
126 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 );
127 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
129 mySelection = SALOME_Selection::Selection( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getSelection());
132 this->onSelectionChanged() ;
134 // signals and slots connections : after ValueHasChanged()
135 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136 connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( SetTransparency() ) );
137 connect( Slider1, SIGNAL( sliderMoved(int) ), this, SLOT( ValueHasChanged() ) );
138 connect( SMESHGUI::GetSMESHGUI(), SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnOk() ) ) ;
139 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
141 /* Move widget on the botton right corner of main widget */
143 SMESHGUI::GetSMESHGUI()->DefineDlgPosition( this, x, y ) ;
149 //=================================================================================
150 // function : ~SMESHGUI_TransparencyDlg()
152 //=================================================================================
153 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
155 // no need to delete child widgets, Qt does it all for us
159 //=======================================================================
160 // function : ClickOnOk()
162 //=======================================================================
163 void SMESHGUI_TransparencyDlg::ClickOnOk()
169 //=================================================================================
170 // function : SetTransparency()
171 // purpose : Called when value of slider change
172 // : or the first time as initilisation
173 //=================================================================================
174 void SMESHGUI_TransparencyDlg::SetTransparency()
176 if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
178 float opacity = this->Slider1->value() / 100. ;
179 SALOME_ListIteratorOfListIO It( mySelection->StoredIObjects() );
180 for( ;It.More(); It.Next() ) {
181 Handle(SALOME_InteractiveObject) IOS = It.Value();
182 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
184 anActor->SetOpacity( opacity );
186 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
191 //=================================================================================
192 // function : ValueHasChanged()
193 // purpose : Called when user moves a slider
194 //=================================================================================
195 void SMESHGUI_TransparencyDlg::ValueHasChanged()
197 ValueLab->setText( QString::number( this->Slider1->value() ) + "%" );
200 //=================================================================================
201 // function : onSelectionChanged()
202 // purpose : Called when selection is changed
203 //=================================================================================
204 void SMESHGUI_TransparencyDlg::onSelectionChanged()
206 if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
208 if ( mySelection->IObjectCount() == 1 ) {
209 Handle(SALOME_InteractiveObject) FirstIOS = mySelection->firstIObject();
210 if( !FirstIOS.IsNull() ) {
211 SMESH_Actor* anActor = SMESH::FindActorByEntry( FirstIOS->getEntry() );
213 opacity = int( anActor->GetOpacity() * 100. + 0.5 );
216 else if ( mySelection->IObjectCount() > 1 ) {
217 SALOME_ListIteratorOfListIO It( mySelection->StoredIObjects() );
219 for ( ; It.More(); It.Next() ) {
220 Handle(SALOME_InteractiveObject) IO = It.Value();
222 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
224 int op = int( anActor->GetOpacity() * 100. + 0.5 );
227 else if ( setOp != op ) {
237 Slider1->setValue( opacity ) ;