1 // GEOM GEOMGUI : GUI for Geometry 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 : GEOMBase_TransparencyDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "QAD_RightFrame.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
33 #include <AIS_InteractiveContext.hxx>
37 #include <qpushbutton.h>
42 #include <qwhatsthis.h>
43 #include <qapplication.h>
44 #include <qgroupbox.h>
46 #include "VTKViewer_ViewFrame.h"
47 #include "VTKViewer_RenderWindowInteractor.h"
49 //=================================================================================
50 // class : GEOMBase_TransparencyDlg()
51 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
54 // : WARNING : this dialog is modal !
56 //=================================================================================
57 GEOMBase_TransparencyDlg::GEOMBase_TransparencyDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, const Handle(AIS_InteractiveContext)& ic, bool modal, WFlags fl)
58 :QDialog(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 setName("GEOMBase_TransparencyDlg");
63 setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
64 setSizeGripEnabled(TRUE);
65 GEOMBase_TransparencyDlgLayout = new QGridLayout(this);
66 GEOMBase_TransparencyDlgLayout->setSpacing(6);
67 GEOMBase_TransparencyDlgLayout->setMargin(11);
69 /*************************************************************************/
70 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
71 GroupButtons->setColumnLayout(0, Qt::Vertical );
72 GroupButtons->layout()->setSpacing( 0 );
73 GroupButtons->layout()->setMargin( 0 );
74 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
75 GroupButtonsLayout->setAlignment( Qt::AlignTop );
76 GroupButtonsLayout->setSpacing( 6 );
77 GroupButtonsLayout->setMargin( 11 );
79 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
80 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
81 buttonOk->setAutoDefault( TRUE );
82 buttonOk->setDefault( TRUE );
83 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
84 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
85 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
87 /*************************************************************************/
88 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
89 GroupC1->setColumnLayout(0, Qt::Vertical );
90 GroupC1->layout()->setSpacing( 0 );
91 GroupC1->layout()->setMargin( 0 );
92 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
93 GroupC1Layout->setAlignment( Qt::AlignTop );
94 GroupC1Layout->setSpacing( 6 );
95 GroupC1Layout->setMargin( 11 );
97 TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
98 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
99 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
100 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
101 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
103 TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
104 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
105 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
106 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
108 Slider1 = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "Slider1" );
109 Slider1->setMinimumSize( 300, 0 );
110 Slider1->setTickmarks( QSlider::Left );
111 GroupC1Layout->addMultiCellWidget( Slider1, 1, 1, 0, 2 );
112 /*************************************************************************/
114 GEOMBase_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
115 GEOMBase_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
117 /* Initialisations */
118 this->myGeomGUI = GEOMContext::GetGeomGUI();
119 this->myGeomBase = new GEOMBase();
123 /* First call valueChanged() method for initialisation */
124 /* The default value of transparency will change with the selection */
125 this->myFirstInit = true;
126 // Slider1->setMaxValue( 10 );
127 // Slider1->setValue( 5 ) ;
128 this->ValueHasChanged(Slider1->value());
130 // signals and slots connections : after ValueHasChanged()
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
134 /* Move widget on the botton right corner of main widget */
136 myGeomBase->DefineDlgPosition(this, x, y);
138 this->show() ; /* Displays this Dialog */
142 //=================================================================================
143 // function : ~GEOMBase_TransparencyDlg()
145 //=================================================================================
146 GEOMBase_TransparencyDlg::~GEOMBase_TransparencyDlg()
148 // no need to delete child widgets, Qt does it all for us
152 //=======================================================================
153 // function : ClickOnOk()
155 //=======================================================================
156 void GEOMBase_TransparencyDlg::ClickOnOk()
163 //=======================================================================
164 // function : ClickOnClose()
166 //=======================================================================
167 void GEOMBase_TransparencyDlg::ClickOnClose()
174 //=================================================================================
175 // function : ValueHasChanged()
176 // purpose : Called when value of slider change
177 // : or the first time as initilisation
178 //=================================================================================
179 void GEOMBase_TransparencyDlg::ValueHasChanged(int newValue)
181 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
183 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
184 SALOME_ListIteratorOfListIO It(this->mySel->StoredIObjects());
186 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject();
187 if(!FirstIOS.IsNull()) {
188 /* The first time as initialisation */
189 if(this->myFirstInit) {
190 this->myFirstInit = false;
191 float transp = (myRenderInter->GetTransparency(FirstIOS))*10.0;
192 this->Slider1->setValue(int(transp));
196 QApplication::setOverrideCursor(Qt::waitCursor);
197 for(;It.More(); It.Next()) {
198 Handle(SALOME_InteractiveObject) IOS = It.Value();
199 myRenderInter->SetTransparency(IOS, newValue/10.0);
201 QApplication::restoreOverrideCursor();
204 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
206 SALOME_ListIteratorOfListIO It(this->mySel->StoredIObjects());
207 Handle(SALOME_InteractiveObject) FirstIOS = mySel->firstIObject();
208 if(!FirstIOS.IsNull()) {
210 /* The first time as initialisation */
211 if(this->myFirstInit) {
212 this->myFirstInit = false;
213 Standard_Boolean found;
214 Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(FirstIOS, found);
217 float transp = (int(Shape->Transparency() * 10.0 + 0.001));
218 this->Slider1->setValue(int(transp));
223 QApplication::setOverrideCursor(Qt::waitCursor);
224 for(;It.More(); It.Next()) {
225 Handle(SALOME_InteractiveObject) IObject = It.Value();
226 Standard_Boolean found;
227 Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found);
229 QApplication::restoreOverrideCursor();
232 this->myIc->SetTransparency(Shape, newValue / 10.0, false);
233 myIc->Redisplay(Shape, Standard_False, Standard_True);
235 myIc->UpdateCurrentViewer();
237 QApplication::restoreOverrideCursor();