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 "GEOM_AISShape.hxx"
33 #include "SALOME_ListIO.hxx"
34 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include <SVTK_ViewModel.h>
37 #include <SVTK_ViewWindow.h>
38 #include <SVTK_View.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewWindow.h>
43 #include <SUIT_ViewManager.h>
44 #include <SUIT_Application.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
55 #include <qpushbutton.h>
60 #include <qwhatsthis.h>
61 #include <qapplication.h>
62 #include <qgroupbox.h>
64 #include <AIS_InteractiveContext.hxx>
67 //=================================================================================
68 // class : GEOMBase_TransparencyDlg()
69 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
70 // name 'name' and widget flags set to 'f'.
72 // : WARNING : this dialog is modal !
74 //=================================================================================
75 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
76 :QDialog( parent, "GEOMBase_TransparencyDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
79 setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
80 setSizeGripEnabled(TRUE);
81 QGridLayout* lay = new QGridLayout(this);
85 /*************************************************************************/
86 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
87 GroupButtons->setColumnLayout(0, Qt::Vertical );
88 GroupButtons->layout()->setSpacing( 0 );
89 GroupButtons->layout()->setMargin( 0 );
90 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
91 GroupButtonsLayout->setAlignment( Qt::AlignTop );
92 GroupButtonsLayout->setSpacing( 6 );
93 GroupButtonsLayout->setMargin( 11 );
95 QPushButton* buttonOk = new QPushButton( GroupButtons, "buttonOk" );
96 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
97 buttonOk->setAutoDefault( TRUE );
98 buttonOk->setDefault( TRUE );
99 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0 );
100 GroupButtonsLayout->addWidget( buttonOk, 0, 1 );
101 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2 );
103 /*************************************************************************/
104 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
105 GroupC1->setColumnLayout(0, Qt::Vertical );
106 GroupC1->layout()->setSpacing( 0 );
107 GroupC1->layout()->setMargin( 0 );
108 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
109 GroupC1Layout->setAlignment( Qt::AlignTop );
110 GroupC1Layout->setSpacing( 6 );
111 GroupC1Layout->setMargin( 11 );
113 QLabel* TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
114 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
115 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
116 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
117 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
119 QLabel* TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
120 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
121 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
122 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
124 mySlider = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "mySlider" );
125 mySlider->setMinimumSize( 300, 0 );
126 mySlider->setTickmarks( QSlider::Left );
127 GroupC1Layout->addMultiCellWidget( mySlider, 1, 1, 0, 2 );
128 /*************************************************************************/
130 lay->addWidget(GroupC1, 0, 0);
131 lay->addWidget(GroupButtons, 1, 0);
133 /* First call valueChanged() method for initialisation */
134 /* The default value of transparency will change with the selection */
136 // mySlider->setMaxValue( 10 );
137 // mySlider->setValue( 5 ) ;
138 ValueHasChanged(mySlider->value());
140 // signals and slots connections : after ValueHasChanged()
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
146 //=================================================================================
147 // function : ~GEOMBase_TransparencyDlg()
149 //=================================================================================
150 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
152 // no need to delete child widgets, Qt does it all for us
156 //=======================================================================
157 // function : ClickOnOk()
159 //=======================================================================
160 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
167 //=======================================================================
168 // function : ClickOnClose()
170 //=======================================================================
171 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
178 //=================================================================================
179 // function : ValueHasChanged()
180 // purpose : Called when value of slider change
181 // : or the first time as initilisation
182 //=================================================================================
183 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
185 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
188 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
191 SALOME_ListIO selected;
192 aSelMgr->selectedObjects( selected );
193 if ( selected.IsEmpty() )
196 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
197 if ( FirstIOS.IsNull() )
200 SUIT_ViewWindow* window = app->desktop()->activeWindow();
201 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
202 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
205 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
208 SVTK_View* aView = vtkVW->getView();
211 float transp = (aView->GetTransparency(FirstIOS))*10.0;
212 mySlider->setValue(int(transp));
216 SUIT_OverrideCursor();
217 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
218 aView->SetTransparency( It.Value(), newValue/10.0 );
224 GEOMBase* gb = new GEOMBase();
225 Standard_Boolean found;
226 Handle(GEOM_AISShape) aisShape;
229 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
232 float transp = (int(aisShape->Transparency() * 10.0 + 0.001));
233 mySlider->setValue(int(transp));
237 SUIT_OverrideCursor();
238 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
241 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
242 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
243 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
245 ic->SetTransparency( aisShape, newValue / 10.0, false );
246 ic->Redisplay( aisShape, Standard_False, Standard_True );
249 ic->UpdateCurrentViewer();