From: ouv Date: Wed, 14 Dec 2005 14:20:40 +0000 (+0000) Subject: Fixed bug GVIEW10706 : transparency (or opacity) dialog not right X-Git-Tag: TG-D5-38-2003_D2005-20-12~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ad62a08184865ece63e36239f38dc8ccd7bdee2;p=modules%2Fvisu.git Fixed bug GVIEW10706 : transparency (or opacity) dialog not right --- diff --git a/src/VISUGUI/Makefile.in b/src/VISUGUI/Makefile.in index b568b22d..cb4e7176 100644 --- a/src/VISUGUI/Makefile.in +++ b/src/VISUGUI/Makefile.in @@ -73,6 +73,7 @@ LIB_SRC = VisuGUI.cxx \ VisuGUI_Displayer.cxx \ VisuGUI_SetupPlot2dDlg.cxx \ VisuGUI_BuildProgressDlg.cxx \ + VisuGUI_TransparencyDlg.cxx \ VisuGUI_Timer.cxx LIB_MOC = VisuGUI.h \ @@ -96,7 +97,8 @@ LIB_MOC = VisuGUI.h \ VisuGUI_StreamLinesDlg.h \ VisuGUI_VectorsDlg.h \ VisuGUI_SetupPlot2dDlg.h \ - VisuGUI_BuildProgressDlg.h + VisuGUI_BuildProgressDlg.h \ + VisuGUI_TransparencyDlg.h LIB_CLIENT_IDL = SALOME_Exception.idl \ VISU_Gen.idl \ diff --git a/src/VISUGUI/VISUM_msg_en.po b/src/VISUGUI/VISUM_msg_en.po index 03634395..4d8e95a2 100644 --- a/src/VISUGUI/VISUM_msg_en.po +++ b/src/VISUGUI/VISUM_msg_en.po @@ -361,6 +361,18 @@ msgstr "Start" msgid "VVTK_RecorderDlg::CLOSE" msgstr "Close" +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_TITLE" +msgstr "Change Transparency" + +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_TRANSPARENT" +msgstr "Transparent" + +msgid "VisuGUI_TransparencyDlg::TRANSPARENCY_OPAQUE" +msgstr "Opaque" + +msgid "VisuGUI_TransparencyDlg::BUT_CLOSE" +msgstr "Close" + msgid "VVTK_ViewManager::VTK_VIEW_TITLE" msgstr "VISU scene:%1 - viewer:%2" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 2f4191ef..240853de 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -105,6 +105,7 @@ #include "VisuGUI_OffsetDlg.h" #include "VisuGUI_Displayer.h" #include "VisuGUI_BuildProgressDlg.h" +#include "VisuGUI_TransparencyDlg.h" #include "VISU_ScalarMap_i.hh" #include "VisuGUI_ScalarBarDlg.h" @@ -982,25 +983,8 @@ OnChangeOpacity() VISU_Actor* anActor = GetActor(aPrsObject, vw); if (!anActor) return; - VisuGUI_CursorDlg* CursorDlg = - new VisuGUI_CursorDlg (GetDesktop(this), tr("DLG_OPACITY_TITLE"), TRUE); - - CursorDlg->Comment1->setText(tr("DLG_OPACITY_CMT1")); - CursorDlg->Comment2->setText(tr("DLG_OPACITY_CMT2")); - CursorDlg->SpinBox1->setMinValue(0); - CursorDlg->SpinBox1->setMaxValue(100); - - float oldopac = anActor->GetOpacity(); - int intopac = int(oldopac*100. + 0.5); - CursorDlg->SpinBox1->setValue(intopac); - - int ret = CursorDlg->exec(); - if (ret == 1) { - intopac = CursorDlg->SpinBox1->value(); - float newopac = intopac/100.; - anActor->SetOpacity(newopac); - } - delete CursorDlg; + VisuGUI_TransparencyDlg* aTransparencyDlg = new VisuGUI_TransparencyDlg( this ); + aTransparencyDlg->show(); } void diff --git a/src/VISUGUI/VisuGUI_TransparencyDlg.cxx b/src/VISUGUI/VisuGUI_TransparencyDlg.cxx new file mode 100644 index 00000000..bf893f50 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TransparencyDlg.cxx @@ -0,0 +1,245 @@ +// VISU VISUGUI : GUI of VISU 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 : VisuGUI_TransparencyDlg.cxx +// Author : Nicolas REJNERI +// Module : VISU +// $Header$ + +#include "VisuGUI_TransparencyDlg.h" + +#include "VisuGUI.h" +#include "VisuGUI_ViewTools.h" +#include "VisuGUI_Tools.h" +#include "VISU_Actor.h" + +#include "SUIT_Desktop.h" +#include "SUIT_OverrideCursor.h" + +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOME_InteractiveObject.hxx" + +#include "LightApp_Study.h" +#include "LightApp_SelectionMgr.h" + +#include "SVTK_ViewWindow.h" + +// QT Includes +#include +#include +#include +#include +#include + +using namespace std; + +//================================================================================= +// class : VisuGUI_TransparencyDlg() +// purpose : +// +//================================================================================= +VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule, + const char* name, + bool modal, + WFlags fl) + : QDialog( VISU::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu | WDestructiveClose ), + mySelectionMgr( VISU::GetSelectionMgr( theModule ) ), + myViewWindow( VISU::GetViewWindow( theModule ) ) +{ + if (!name) + setName("VisuGUI_TransparencyDlg"); + setCaption(tr("TRANSPARENCY_TITLE" )); + setSizeGripEnabled(TRUE); + QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this); + VisuGUI_TransparencyDlgLayout->setSpacing(6); + VisuGUI_TransparencyDlgLayout->setMargin(11); + + /*************************************************************************/ + 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("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("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* 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("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); + + VisuGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0); + VisuGUI_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(SetTransparency())); + connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged())); + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged())); +} + +//================================================================================= +// function : ~VisuGUI_TransparencyDlg() +// purpose : +//================================================================================= +VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +//======================================================================= +// function : ClickOnOk() +// purpose : +//======================================================================= +void VisuGUI_TransparencyDlg::ClickOnOk() +{ + close(); +} + +//================================================================================= +// function : SetTransparency() +// purpose : Called when value of slider change +// : or the first time as initilisation +//================================================================================= +void VisuGUI_TransparencyDlg::SetTransparency() +{ + 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(); + VISU_Actor* anActor = VISU::FindActor(myViewWindow, IOS->getEntry()); + if (anActor) + anActor->SetOpacity(opacity); + } + myViewWindow->Repaint(); + } + ValueHasChanged(); +} + +//================================================================================= +// function : ValueHasChanged() +// purpose : Called when user moves a slider +//================================================================================= +void VisuGUI_TransparencyDlg::ValueHasChanged() +{ + ValueLab->setText(QString::number(this->Slider1->value()) + "%"); +} + +//================================================================================= +// function : onSelectionChanged() +// purpose : Called when selection is changed +//================================================================================= +void VisuGUI_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()) { + VISU_Actor* anActor = VISU::FindActor(myViewWindow, 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()) { + VISU_Actor* anActor = VISU::FindActor(myViewWindow, 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 { + } + Slider1->setValue(opacity); + } + ValueHasChanged(); +} diff --git a/src/VISUGUI/VisuGUI_TransparencyDlg.h b/src/VISUGUI/VisuGUI_TransparencyDlg.h new file mode 100644 index 00000000..6dbc9437 --- /dev/null +++ b/src/VISUGUI/VisuGUI_TransparencyDlg.h @@ -0,0 +1,76 @@ +// VISU VisuGUI : GUI for VISU 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 : VisuGUI_TransparencyDlg.h +// Author : Nicolas REJNERI +// Module : VISU +// $Header$ + +#ifndef VISUGUI_TRANSPARENCYDLG_H +#define VISUGUI_TRANSPARENCYDLG_H + +// QT Includes +#include + +class QLabel; +class QPushButton; +class QSlider; +class LightApp_SelectionMgr; +class SVTK_Selector; +class SVTK_ViewWindow; +class VisuGUI; + +//================================================================================= +// class : VisuGUI_TransparencyDlg +// purpose : +//================================================================================= +class VisuGUI_TransparencyDlg : public QDialog +{ + Q_OBJECT + +public: + VisuGUI_TransparencyDlg( VisuGUI* = 0, + const char* name = 0, + bool modal = false, + WFlags fl = 0 ); + + ~VisuGUI_TransparencyDlg(); + +private : + LightApp_SelectionMgr* mySelectionMgr; + SVTK_ViewWindow* myViewWindow; + + QPushButton* buttonOk; + QLabel* TextLabelOpaque; + QLabel* ValueLab; + QLabel* TextLabelTransparent; + QSlider* Slider1; + +public slots: + void ClickOnOk(); + void ValueHasChanged(); + void SetTransparency(); + void onSelectionChanged(); +}; + +#endif