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
30 #include "SMESHGUI_TransparencyDlg.h"
35 #include <qpushbutton.h>
38 #include <qgroupbox.h>
40 #include "VTKViewer_ViewFrame.h"
41 #include "VTKViewer_RenderWindowInteractor.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"
49 static SMESH_Actor* FindActorByEntry(const char* theEntry)
51 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
52 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
53 VTKViewer_ViewFrame* aViewFrame = dynamic_cast<VTKViewer_ViewFrame*>( aStudyFrame->getRightFrame()->getViewFrame() );
56 vtkRenderer *aRenderer = aViewFrame->getRenderer();
57 vtkActorCollection *aCollection = aRenderer->GetActors();
58 aCollection->InitTraversal();
59 while(vtkActor *anAct = aCollection->GetNextActor()){
60 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
62 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
63 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
73 //=================================================================================
74 // class : SMESHGUI_TransparencyDlg()
77 //=================================================================================
78 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent,
82 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
85 setName( "SMESHGUI_TransparencyDlg" );
86 setCaption( tr( "SMESH_TRANSPARENCY_TITLE" ) );
87 setSizeGripEnabled( TRUE );
88 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout( this );
89 SMESHGUI_TransparencyDlgLayout->setSpacing( 6 );
90 SMESHGUI_TransparencyDlgLayout->setMargin( 11 );
92 /*************************************************************************/
93 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
94 GroupC1->setColumnLayout(0, Qt::Vertical );
95 GroupC1->layout()->setSpacing( 0 );
96 GroupC1->layout()->setMargin( 0 );
97 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
98 GroupC1Layout->setAlignment( Qt::AlignTop );
99 GroupC1Layout->setSpacing( 6 );
100 GroupC1Layout->setMargin( 11 );
102 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
103 TextLabelTransparent->setText( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ) );
104 TextLabelTransparent->setAlignment( AlignLeft );
105 GroupC1Layout->addWidget( TextLabelTransparent, 0, 0 );
107 ValueLab = new QLabel( GroupC1, "ValueLab" );
108 ValueLab->setAlignment( AlignCenter );
109 ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
110 QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
111 GroupC1Layout->addWidget( ValueLab, 0, 1 );
113 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
114 TextLabelOpaque->setText( tr( "SMESH_TRANSPARENCY_OPAQUE" ) );
115 TextLabelOpaque->setAlignment( AlignRight );
116 GroupC1Layout->addWidget( TextLabelOpaque, 0, 2 );
118 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
119 Slider1->setFocusPolicy( QWidget::NoFocus );
120 Slider1->setMinimumSize( 300, 0 );
121 Slider1->setTickmarks( QSlider::Above );
122 Slider1->setTickInterval( 10 );
123 Slider1->setTracking( true );
124 Slider1->setMinValue( 0 ) ;
125 Slider1->setMaxValue( 100 );
126 Slider1->setLineStep( 1 );
127 Slider1->setPageStep( 10 );
128 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
130 /*************************************************************************/
131 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
132 GroupButtons->setColumnLayout(0, Qt::Vertical );
133 GroupButtons->layout()->setSpacing( 0 );
134 GroupButtons->layout()->setMargin( 0 );
135 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
136 GroupButtonsLayout->setAlignment( Qt::AlignTop );
137 GroupButtonsLayout->setSpacing( 6 );
138 GroupButtonsLayout->setMargin( 11 );
140 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
141 buttonOk->setText( tr( "SMESH_BUT_CLOSE" ) );
142 buttonOk->setAutoDefault( TRUE );
143 buttonOk->setDefault( TRUE );
144 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
145 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
146 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
148 SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 );
149 SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 );
151 mySelection = SALOME_Selection::Selection( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getSelection());
154 this->onSelectionChanged() ;
156 // signals and slots connections : after ValueHasChanged()
157 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
158 connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( SetTransparency() ) );
159 connect( Slider1, SIGNAL( sliderMoved(int) ), this, SLOT( ValueHasChanged() ) );
160 connect( SMESHGUI::GetSMESHGUI(), SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnOk() ) ) ;
161 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
163 /* Move widget on the botton right corner of main widget */
165 SMESHGUI::GetSMESHGUI()->DefineDlgPosition( this, x, y ) ;
171 //=================================================================================
172 // function : ~SMESHGUI_TransparencyDlg()
174 //=================================================================================
175 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
177 // no need to delete child widgets, Qt does it all for us
181 //=======================================================================
182 // function : ClickOnOk()
184 //=======================================================================
185 void SMESHGUI_TransparencyDlg::ClickOnOk()
191 //=================================================================================
192 // function : SetTransparency()
193 // purpose : Called when value of slider change
194 // : or the first time as initilisation
195 //=================================================================================
196 void SMESHGUI_TransparencyDlg::SetTransparency()
198 if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
200 float opacity = this->Slider1->value() / 100. ;
201 SALOME_ListIteratorOfListIO It( mySelection->StoredIObjects() );
202 for( ;It.More(); It.Next() ) {
203 Handle(SALOME_InteractiveObject) IOS = It.Value();
204 SMESH_Actor* anActor = FindActorByEntry(IOS->getEntry());
206 anActor->SetOpacity( opacity );
208 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
213 //=================================================================================
214 // function : ValueHasChanged()
215 // purpose : Called when user moves a slider
216 //=================================================================================
217 void SMESHGUI_TransparencyDlg::ValueHasChanged()
219 ValueLab->setText( QString::number( this->Slider1->value() ) + "%" );
222 //=================================================================================
223 // function : onSelectionChanged()
224 // purpose : Called when selection is changed
225 //=================================================================================
226 void SMESHGUI_TransparencyDlg::onSelectionChanged()
228 if ( SMESHGUI::GetSMESHGUI()->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
230 if ( mySelection->IObjectCount() == 1 ) {
231 Handle(SALOME_InteractiveObject) FirstIOS = mySelection->firstIObject();
232 if( !FirstIOS.IsNull() ) {
233 SMESH_Actor* anActor = FindActorByEntry( FirstIOS->getEntry() );
235 opacity = int( anActor->GetOpacity() * 100. + 0.5 );
238 else if ( mySelection->IObjectCount() > 1 ) {
239 SALOME_ListIteratorOfListIO It( mySelection->StoredIObjects() );
241 for ( ; It.More(); It.Next() ) {
242 Handle(SALOME_InteractiveObject) IO = It.Value();
244 SMESH_Actor* anActor = FindActorByEntry( IO->getEntry() );
246 int op = int( anActor->GetOpacity() * 100. + 0.5 );
249 else if ( setOp != op ) {
259 Slider1->setValue( opacity ) ;