Back to index

salome-smesh  6.5.0
SMESHGUI_TransparencyDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_TransparencyDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_TransparencyDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 #include "SMESHGUI_Utils.h"
00033 #include "SMESH_Actor.h"
00034 
00035 // SALOME GUI includes
00036 #include <SUIT_Desktop.h>
00037 #include <SUIT_OverrideCursor.h>
00038 #include <SUIT_Session.h>
00039 #include <SUIT_MessageBox.h>
00040 #include <SUIT_ResourceMgr.h>
00041 
00042 #include <SALOME_ListIO.hxx>
00043 #include <SALOME_ListIteratorOfListIO.hxx>
00044 
00045 #include <LightApp_Application.h>
00046 #include <LightApp_SelectionMgr.h>
00047 
00048 #include <SVTK_ViewWindow.h>
00049 
00050 // Qt includes
00051 #include <QLabel>
00052 #include <QPushButton>
00053 #include <QSlider>
00054 #include <QVBoxLayout>
00055 #include <QHBoxLayout>
00056 #include <QGridLayout>
00057 #include <QGroupBox>
00058 #include <QKeyEvent>
00059 
00060 #define SPACING 6
00061 #define MARGIN  11
00062 
00063 //=================================================================================
00064 // class    : SMESHGUI_TransparencyDlg()
00065 // purpose  :
00066 //
00067 //=================================================================================
00068 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule )
00069   : QDialog( SMESH::GetDesktop( theModule ) ),
00070     mySMESHGUI( theModule ),
00071     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00072     myViewWindow( SMESH::GetViewWindow( theModule ) )
00073 {
00074   setModal( false );
00075   setAttribute( Qt::WA_DeleteOnClose, true );
00076   setWindowTitle( tr( "SMESH_TRANSPARENCY_TITLE" ) );
00077   setSizeGripEnabled( true );
00078 
00079   QVBoxLayout* SMESHGUI_TransparencyDlgLayout = new QVBoxLayout( this );
00080   SMESHGUI_TransparencyDlgLayout->setSpacing( SPACING );
00081   SMESHGUI_TransparencyDlgLayout->setMargin( MARGIN );
00082 
00083   /*************************************************************************/
00084   QGroupBox* GroupC1 = new QGroupBox( this );
00085   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
00086   GroupC1Layout->setSpacing( SPACING );
00087   GroupC1Layout->setMargin( MARGIN );
00088 
00089   TextLabelTransparent = new QLabel( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
00090   TextLabelTransparent->setAlignment( Qt::AlignRight );
00091 
00092   ValueLab = new QLabel( GroupC1 );
00093   ValueLab->setAlignment( Qt::AlignCenter );
00094   ValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00095   QFont fnt = ValueLab->font(); fnt.setBold( true ); ValueLab->setFont( fnt );
00096 
00097   TextLabelOpaque = new QLabel( tr( "SMESH_TRANSPARENCY_OPAQUE" ), GroupC1 );
00098   TextLabelOpaque->setAlignment( Qt::AlignLeft );
00099 
00100   Slider1 = new QSlider( Qt::Horizontal, GroupC1 );
00101   Slider1->setRange( 0, 100 );
00102   Slider1->setSingleStep( 1 );
00103   Slider1->setPageStep( 10 );
00104   Slider1->setTickPosition( QSlider::TicksAbove );
00105   Slider1->setTickInterval( 10 );
00106   Slider1->setTracking( true );
00107   Slider1->setFocusPolicy( Qt::NoFocus );
00108   Slider1->setMinimumWidth( 300 );
00109 
00110   GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
00111   GroupC1Layout->addWidget( ValueLab, 0, 1 );
00112   GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
00113   GroupC1Layout->addWidget( Slider1, 1, 0, 1, 3 );
00114 
00115   /*************************************************************************/
00116   QGroupBox* GroupButtons = new QGroupBox( this );
00117   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00118   GroupButtonsLayout->setSpacing( SPACING );
00119   GroupButtonsLayout->setMargin( MARGIN );
00120 
00121   buttonOk = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
00122   buttonOk->setAutoDefault( true );
00123   buttonOk->setDefault( true );
00124   buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
00125   buttonHelp->setAutoDefault( true );
00126 
00127   GroupButtonsLayout->addWidget( buttonOk );
00128   GroupButtonsLayout->addSpacing( 10 );
00129   GroupButtonsLayout->addStretch();
00130   GroupButtonsLayout->addWidget( buttonHelp );  
00131 
00132   /*************************************************************************/
00133   SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1 );
00134   SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons );
00135 
00136   // Initial state
00137   onSelectionChanged();
00138 
00139   // signals and slots connections : after ValueHasChanged()
00140   connect( buttonOk,       SIGNAL( clicked() ),                 this, SLOT( ClickOnOk() ) );
00141   connect( buttonHelp,     SIGNAL( clicked() ),                 this, SLOT( ClickOnHelp() ) );
00142   connect( Slider1,        SIGNAL( valueChanged( int ) ),       this, SLOT( SetTransparency() ) );
00143   connect( Slider1,        SIGNAL( sliderMoved( int ) ),        this, SLOT( ValueHasChanged() ) );
00144   connect( mySMESHGUI,     SIGNAL( SignalCloseAllDialogs() ),   this, SLOT( ClickOnOk() ) );
00145   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
00146 
00147   myHelpFileName = "transparency_page.html";
00148 }
00149 
00150 //=================================================================================
00151 // function : ~SMESHGUI_TransparencyDlg()
00152 // purpose  :
00153 //=================================================================================
00154 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
00155 {
00156 }
00157 
00158 //=======================================================================
00159 // function : ClickOnOk()
00160 // purpose  :
00161 //=======================================================================
00162 void SMESHGUI_TransparencyDlg::ClickOnOk()
00163 {
00164   close();
00165 }
00166 
00167 //=================================================================================
00168 // function : ClickOnHelp()
00169 // purpose  :
00170 //=================================================================================
00171 void SMESHGUI_TransparencyDlg::ClickOnHelp()
00172 {
00173   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00174   if ( app )
00175     app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : 
00176                               QString( "" ), myHelpFileName );
00177   else {
00178     QString platform;
00179 #ifdef WIN32
00180     platform = "winapplication";
00181 #else
00182     platform = "application";
00183 #endif
00184     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
00185                               tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
00186                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
00187                                                                     platform ) ).
00188                               arg( myHelpFileName ) );
00189   }
00190 }
00191 
00192 //=================================================================================
00193 // function : SetTransparency()
00194 // purpose  : Called when value of slider change
00195 //          : or the first time as initilisation
00196 //=================================================================================
00197 void SMESHGUI_TransparencyDlg::SetTransparency()
00198 {
00199   if ( myViewWindow ) {
00200     SUIT_OverrideCursor wc;
00201     float opacity = ( 100 - Slider1->value() ) / 100.;
00202 
00203     SALOME_ListIO aList;
00204     mySelectionMgr->selectedObjects( aList );
00205 
00206     SALOME_ListIteratorOfListIO It( aList );
00207     for ( ; It.More(); It.Next() ) {
00208       Handle(SALOME_InteractiveObject) IOS = It.Value();
00209       SMESH_Actor* anActor = SMESH::FindActorByEntry( IOS->getEntry() );
00210       if ( anActor )
00211         anActor->SetOpacity( opacity );
00212     }
00213     myViewWindow->Repaint();
00214   }
00215   ValueHasChanged();
00216 }
00217 
00218 //=================================================================================
00219 // function : ValueHasChanged()
00220 // purpose  : Called when user moves a slider
00221 //=================================================================================
00222 void SMESHGUI_TransparencyDlg::ValueHasChanged()
00223 {
00224   ValueLab->setText( QString::number( Slider1->value() ) + "%") ;
00225 }
00226 
00227 //=================================================================================
00228 // function : onSelectionChanged()
00229 // purpose  : Called when selection is changed
00230 //=================================================================================
00231 void SMESHGUI_TransparencyDlg::onSelectionChanged()
00232 {
00233   if ( myViewWindow ) {
00234     int opacity = 100;
00235 
00236     SALOME_ListIO aList;
00237     mySelectionMgr->selectedObjects( aList );
00238 
00239     if ( aList.Extent() == 1 ) {
00240       Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
00241       if ( !FirstIOS.IsNull() ) {
00242         SMESH_Actor* anActor = SMESH::FindActorByEntry( FirstIOS->getEntry() );
00243         if ( anActor )
00244           opacity = int( anActor->GetOpacity() * 100. + 0.5 );
00245       }
00246     } 
00247     else if ( aList.Extent() > 1 ) {
00248       SALOME_ListIteratorOfListIO It( aList );
00249       int setOp = -1;
00250       for ( ; It.More(); It.Next() ) {
00251         Handle(SALOME_InteractiveObject) IO = It.Value();
00252         if ( !IO.IsNull() ) {
00253           SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
00254           if ( anActor ) {
00255             int op = int( anActor->GetOpacity() * 100. + 0.5 );
00256             if ( setOp < 0 )
00257               setOp = op;
00258             else if ( setOp != op ) {
00259               setOp = 100;
00260               break;
00261             }
00262           }
00263         }
00264       }
00265       if ( setOp >= 0 )
00266         opacity = setOp;
00267     } 
00268     else {
00269     }
00270     Slider1->setValue( 100 - opacity );
00271   }
00272   ValueHasChanged();
00273 }
00274 
00275 //=================================================================================
00276 // function : keyPressEvent()
00277 // purpose  :
00278 //=================================================================================
00279 void SMESHGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
00280 {
00281   QDialog::keyPressEvent( e );
00282   if ( e->isAccepted() )
00283     return;
00284 
00285   if ( e->key() == Qt::Key_F1 ) {
00286     e->accept();
00287     ClickOnHelp();
00288   }
00289 }