X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_TransparencyDlg.cxx;h=283306aa4e90479e82792f8ed42ebaaacd63bac8;hp=cb35a3538f69e705ba3d9ec601923d23bee7d8b6;hb=b0105f0f9d05ef09ad770cf0d343901589cba620;hpb=bef9beee88cac57394b8dc3bc914381c1a2fff83 diff --git a/src/SMESHGUI/SMESHGUI_TransparencyDlg.cxx b/src/SMESHGUI/SMESHGUI_TransparencyDlg.cxx index cb35a3538..283306aa4 100644 --- a/src/SMESHGUI/SMESHGUI_TransparencyDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_TransparencyDlg.cxx @@ -1,191 +1,253 @@ -using namespace std; -// File : SMESHGUI_TransparencyDlg.cxx -// Created : Thu Jun 06 16:41:42 2002 -// Author : Nicolas REJNERI - -// Project : SALOME -// Module : SMESH -// Copyright : Open CASCADE 2002 +// SMESH SMESHGUI : GUI for SMESH component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_TransparencyDlg.cxx +// Author : Nicolas REJNERI +// Module : SMESH // $Header$ - #include "SMESHGUI_TransparencyDlg.h" + #include "SMESHGUI.h" +#include "SMESHGUI_VTKUtils.h" +#include "SMESHGUI_Utils.h" +#include "SMESH_Actor.h" -#include "VTKViewer_ViewFrame.h" -#include "VTKViewer_RenderWindowInteractor.h" -#include "QAD_RightFrame.h" +#include "SUIT_Desktop.h" +#include "SUIT_OverrideCursor.h" + +#include "SALOME_ListIO.hxx" #include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOME_InteractiveObject.hxx" + +#include "SalomeApp_Study.h" +#include "SalomeApp_SelectionMgr.h" + +#include "SVTK_ViewWindow.h" // QT Includes -#include #include #include #include #include -#include -#include -#include -#include #include +using namespace std; //================================================================================= // class : SMESHGUI_TransparencyDlg() -// purpose : +// purpose : // //================================================================================= -SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( QWidget* parent, +SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule, const char* name, - SALOME_Selection* Sel, bool modal, - WFlags fl ) - : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) + WFlags fl) + : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu | WDestructiveClose ), + mySMESHGUI( theModule ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + myViewWindow( SMESH::GetViewWindow( theModule ) ) { - if ( !name ) - setName( "SMESHGUI_TransparencyDlg" ); - resize( 152, 107 ); - setCaption( tr( "SMESH_TRANSPARENCY_TITLE" ) ); - setSizeGripEnabled( TRUE ); - SMESHGUI_TransparencyDlgLayout = new QGridLayout( this ); - SMESHGUI_TransparencyDlgLayout->setSpacing( 6 ); - SMESHGUI_TransparencyDlgLayout->setMargin( 11 ); + if (!name) + setName("SMESHGUI_TransparencyDlg"); + setCaption(tr("SMESH_TRANSPARENCY_TITLE" )); + setSizeGripEnabled(TRUE); + QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout(this); + SMESHGUI_TransparencyDlgLayout->setSpacing(6); + SMESHGUI_TransparencyDlgLayout->setMargin(11); /*************************************************************************/ - QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); - GroupButtons->setColumnLayout(0, Qt::Vertical ); - GroupButtons->layout()->setSpacing( 0 ); - GroupButtons->layout()->setMargin( 0 ); - QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); - GroupButtonsLayout->setAlignment( Qt::AlignTop ); - GroupButtonsLayout->setSpacing( 6 ); - GroupButtonsLayout->setMargin( 11 ); - - buttonOk = new QPushButton( GroupButtons, "buttonOk" ); - buttonOk->setText( tr( "GEOM_BUT_OK" ) ); - buttonOk->setAutoDefault( TRUE ); - buttonOk->setDefault( TRUE ); - GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 ); - GroupButtonsLayout->addWidget( buttonOk, 0, 1 ); - GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 ); + QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1"); + GroupC1->setColumnLayout(0, Qt::Vertical); + GroupC1->layout()->setSpacing(0); + GroupC1->layout()->setMargin(0); + QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout()); + GroupC1Layout->setAlignment(Qt::AlignTop); + GroupC1Layout->setSpacing(6); + GroupC1Layout->setMargin(11); + + TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent"); + TextLabelTransparent->setText(tr("SMESH_TRANSPARENCY_TRANSPARENT" )); + TextLabelTransparent->setAlignment(AlignLeft); + GroupC1Layout->addWidget(TextLabelTransparent, 0, 0); + + ValueLab = new QLabel(GroupC1, "ValueLab"); + ValueLab->setAlignment(AlignCenter); + ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt); + GroupC1Layout->addWidget(ValueLab, 0, 1); + + TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque"); + TextLabelOpaque->setText(tr("SMESH_TRANSPARENCY_OPAQUE" )); + TextLabelOpaque->setAlignment(AlignRight); + GroupC1Layout->addWidget(TextLabelOpaque, 0, 2); + + Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1"); + Slider1->setFocusPolicy(QWidget::NoFocus); + Slider1->setMinimumSize(300, 0); + Slider1->setTickmarks(QSlider::Above); + Slider1->setTickInterval(10); + Slider1->setTracking(true); + Slider1->setMinValue(0); + Slider1->setMaxValue(100); + Slider1->setLineStep(1); + Slider1->setPageStep(10); + GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2); /*************************************************************************/ - QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" ); - GroupC1->setColumnLayout(0, Qt::Vertical ); - GroupC1->layout()->setSpacing( 0 ); - GroupC1->layout()->setMargin( 0 ); - QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() ); - GroupC1Layout->setAlignment( Qt::AlignTop ); - GroupC1Layout->setSpacing( 6 ); - GroupC1Layout->setMargin( 11 ); - - TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" ); - TextLabelOpaque->setText( tr( "SMESH_TRANSPARENCY_OPAQUE" ) ); - TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) ); - GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 ); - GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); - - TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" ); - TextLabelTransparent->setText( tr( "SMESH_TRANSPARENCY_TRANSPARENT" ) ); - TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) ); - GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 ); - - Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" ); - Slider1->setMinimumSize( 300, 0 ); - Slider1->setTickmarks( QSlider::Left ); - GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 ); - - SMESHGUI_TransparencyDlgLayout->addWidget( GroupC1, 0, 0 ); - SMESHGUI_TransparencyDlgLayout->addWidget( GroupButtons, 1, 0 ); - - /* Initialisations */ - this->mySMESHGUI = SMESHGUI::GetSMESHGUI() ; - this->mySel = Sel ; - - /* First call valueChanged() method for initialisation */ - /* The default value of transparency will change with the selection */ - this->myFirstInit = true ; -// Slider1->setMaxValue( 10 ); -// Slider1->setValue( 5 ) ; - - - this->ValueHasChanged( Slider1->value() ) ; - + QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); + GroupButtons->setColumnLayout(0, Qt::Vertical); + GroupButtons->layout()->setSpacing(0); + GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); + GroupButtonsLayout->setAlignment(Qt::AlignTop); + GroupButtonsLayout->setSpacing(6); + GroupButtonsLayout->setMargin(11); + + buttonOk = new QPushButton(GroupButtons, "buttonOk"); + buttonOk->setText(tr("SMESH_BUT_CLOSE")); + buttonOk->setAutoDefault(TRUE); + buttonOk->setDefault(TRUE); + GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0); + GroupButtonsLayout->addWidget(buttonOk, 0, 1); + GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2); + + SMESHGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0); + SMESHGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0); + + // Initial state + this->onSelectionChanged(); + // signals and slots connections : after ValueHasChanged() - connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( Slider1, SIGNAL( valueChanged(int) ), this, SLOT( ValueHasChanged(int) ) ); - + connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency())); + connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged())); + connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnOk())); + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged())); + /* Move widget on the botton right corner of main widget */ - int x, y ; - mySMESHGUI->DefineDlgPosition( this, x, y ) ; - this->move( x, y ) ; - this->show() ; /* Displays this Dialog */ + int x, y; + mySMESHGUI->DefineDlgPosition(this, x, y); + this->move(x, y); + this->show(); } - - - //================================================================================= // function : ~SMESHGUI_TransparencyDlg() // purpose : //================================================================================= SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg() { - // no need to delete child widgets, Qt does it all for us + // no need to delete child widgets, Qt does it all for us } - //======================================================================= // function : ClickOnOk() // purpose : //======================================================================= void SMESHGUI_TransparencyDlg::ClickOnOk() { - accept() ; - return ; + close(); } - -//======================================================================= -// function : ClickOnClose() -// purpose : -//======================================================================= -void SMESHGUI_TransparencyDlg::ClickOnClose() +//================================================================================= +// function : SetTransparency() +// purpose : Called when value of slider change +// : or the first time as initilisation +//================================================================================= +void SMESHGUI_TransparencyDlg::SetTransparency() { - accept() ; - return ; -} + if( myViewWindow ) { + SUIT_OverrideCursor wc; + float opacity = this->Slider1->value() / 100.; + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList); + + SALOME_ListIteratorOfListIO It (aList); + for (;It.More(); It.Next()) { + Handle(SALOME_InteractiveObject) IOS = It.Value(); + SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry()); + if (anActor) + anActor->SetOpacity(opacity); + } + myViewWindow->Repaint(); + } + ValueHasChanged(); +} //================================================================================= // function : ValueHasChanged() -// purpose : Called when value of slider change -// : or the first time as initilisation +// purpose : Called when user moves a slider //================================================================================= -void SMESHGUI_TransparencyDlg::ValueHasChanged( int newValue ) +void SMESHGUI_TransparencyDlg::ValueHasChanged() { + ValueLab->setText(QString::number(this->Slider1->value()) + "%"); +} - if ( mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)mySMESHGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - SALOME_ListIteratorOfListIO It( this->mySel->StoredIObjects() ); - Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject(); - if( !FirstIOS.IsNull() ) { - /* The first time as initialisation */ - if( this->myFirstInit ) { - this->myFirstInit = false ; - float transp = ( myRenderInter->GetTransparency(FirstIOS))*10.0 ; - this->Slider1->setValue( int(transp) ) ; - return; +//================================================================================= +// function : onSelectionChanged() +// purpose : Called when selection is changed +//================================================================================= +void SMESHGUI_TransparencyDlg::onSelectionChanged() +{ + if( myViewWindow ) { + int opacity = 100; + + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList); + + if (aList.Extent() == 1) { + Handle(SALOME_InteractiveObject) FirstIOS = aList.First(); + if (!FirstIOS.IsNull()) { + SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry()); + if (anActor) + opacity = int(anActor->GetOpacity() * 100. + 0.5); } + } else if (aList.Extent() > 1) { + SALOME_ListIteratorOfListIO It (aList); + int setOp = -1; + for (; It.More(); It.Next()) { + Handle(SALOME_InteractiveObject) IO = It.Value(); + if (!IO.IsNull()) { + SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry()); + if (anActor) { + int op = int(anActor->GetOpacity() * 100. + 0.5); + if (setOp < 0) + setOp = op; + else if (setOp != op) { + setOp = 100; + break; + } + } + } + } + if (setOp >= 0) + opacity = setOp; + } else { } - - QApplication::setOverrideCursor( Qt::waitCursor ); - for( ;It.More(); It.Next() ) { - Handle(SALOME_InteractiveObject) IOS = It.Value(); - myRenderInter->SetTransparency( IOS, newValue/10.0 ); - } - QApplication::restoreOverrideCursor(); + Slider1->setValue(opacity); } - QApplication::restoreOverrideCursor(); - return ; + ValueHasChanged(); }