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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMToolsGUI_TransparencyDlg.cxx
23 // Author : Lucien PIGNOLONI
26 #include "GEOMToolsGUI_TransparencyDlg.h"
28 #include <GEOM_AISShape.hxx>
29 #include <GeometryGUI.h>
31 #include <SALOME_ListIO.hxx>
32 #include <SALOME_ListIteratorOfListIO.hxx>
34 #include <SVTK_ViewModel.h>
35 #include <SVTK_ViewWindow.h>
36 #include <SVTK_View.h>
38 #include <OCCViewer_ViewModel.h>
40 #include <SUIT_ViewManager.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <SalomeApp_Application.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
52 #include <QPushButton>
54 #include <QGridLayout>
58 #include <AIS_InteractiveContext.hxx>
62 //=================================================================================
63 // class : GEOMBase_TransparencyDlg()
64 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
65 // name 'name' and widget flags set to 'f'.
67 // : WARNING : this dialog is modal !
69 //=================================================================================
70 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
71 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
73 setObjectName( "GEOMBase_TransparencyDlg" );
77 setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
78 setSizeGripEnabled(TRUE);
79 QGridLayout* lay = new QGridLayout(this);
83 /*************************************************************************/
84 QGroupBox* GroupButtons = new QGroupBox( this );
85 GroupButtons->setObjectName( "GroupButtons" );
86 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
87 GroupButtonsLayout->setAlignment( Qt::AlignTop );
88 GroupButtonsLayout->setSpacing( 6 );
89 GroupButtonsLayout->setMargin( 11 );
91 QPushButton* buttonOk = new QPushButton( GroupButtons );
92 buttonOk->setObjectName( "buttonOk" );
93 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
94 buttonOk->setAutoDefault( TRUE );
95 buttonOk->setDefault( TRUE );
97 QPushButton* buttonHelp = new QPushButton( GroupButtons );
98 buttonHelp->setObjectName( "buttonHelp" );
99 buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
100 buttonHelp->setAutoDefault( TRUE );
101 buttonHelp->setDefault( TRUE );
103 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
104 GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
105 GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
107 /*************************************************************************/
108 QGroupBox* GroupC1 = new QGroupBox( this );
109 GroupC1->setObjectName( "GroupC1" );
110 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
111 GroupC1Layout->setAlignment( Qt::AlignTop );
112 GroupC1Layout->setSpacing( 6 );
113 GroupC1Layout->setMargin( 11 );
115 QLabel* TextLabelOpaque = new QLabel( GroupC1 );
116 TextLabelOpaque->setObjectName( "TextLabelOpaque" );
117 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
118 TextLabelOpaque->setAlignment( Qt::AlignLeft );
119 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
120 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
122 QLabel* TextLabelTransparent = new QLabel( GroupC1 );
123 TextLabelTransparent->setObjectName( "TextLabelTransparent" );
124 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
125 TextLabelTransparent->setAlignment( Qt::AlignRight );
126 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
128 mySlider = new QSlider( Qt::Horizontal, GroupC1 );
129 mySlider->setObjectName( "mySlider" );
130 mySlider->setMinimum( 0 );
131 mySlider->setMaximum( 10 );
132 mySlider->setPageStep( 1 );
133 mySlider->setValue( 5 );
134 mySlider->setMinimumSize( 300, 0 );
135 mySlider->setTickPosition( QSlider::TicksLeft );
136 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
137 /*************************************************************************/
139 lay->addWidget(GroupC1, 0, 0);
140 lay->addWidget(GroupButtons, 1, 0);
142 /* First call valueChanged() method for initialisation */
143 /* The default value of transparency will change with the selection */
145 // mySlider->setMaxValue( 10 );
146 // mySlider->setValue( 5 ) ;
147 ValueHasChanged(mySlider->value());
149 myHelpFileName = "transparency_page.html";
151 // signals and slots connections : after ValueHasChanged()
152 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
154 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
158 //=================================================================================
159 // function : ~GEOMBase_TransparencyDlg()
161 //=================================================================================
162 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
164 // no need to delete child widgets, Qt does it all for us
168 //=======================================================================
169 // function : ClickOnOk()
171 //=======================================================================
172 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
179 //=======================================================================
180 // function : ClickOnClose()
182 //=======================================================================
183 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
189 //=================================================================================
190 // function : ClickOnHelp()
192 //=================================================================================
193 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
195 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
197 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
198 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
203 platform = "winapplication";
205 platform = "application";
207 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
208 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
209 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
210 QObject::tr("BUT_OK"));
214 //=================================================================================
215 // function : ValueHasChanged()
216 // purpose : Called when value of slider change
217 // : or the first time as initilisation
218 //=================================================================================
219 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
221 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
224 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
227 SALOME_ListIO selected;
228 aSelMgr->selectedObjects( selected );
229 if ( selected.IsEmpty() )
232 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
233 if ( FirstIOS.IsNull() )
236 SUIT_ViewWindow* window = app->desktop()->activeWindow();
237 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
238 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
241 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
244 SVTK_View* aView = vtkVW->getView();
247 float transp = (aView->GetTransparency(FirstIOS))*10.0;
248 mySlider->setValue(int(transp));
252 SUIT_OverrideCursor();
253 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
254 aView->SetTransparency( It.Value(), newValue/10.0 );
260 GEOMBase* gb = new GEOMBase();
261 Standard_Boolean found;
262 Handle(GEOM_AISShape) aisShape;
265 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
268 float transp = (int(aisShape->Transparency() * 10.0 + 0.001));
269 mySlider->setValue(int(transp));
273 SUIT_OverrideCursor();
274 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
277 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
278 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
279 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
281 ic->SetTransparency( aisShape, newValue / 10.0, false );
282 ic->Redisplay( aisShape, Standard_False, Standard_True );
285 ic->UpdateCurrentViewer();
289 //=================================================================================
290 // function : keyPressEvent()
292 //=================================================================================
293 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
295 QDialog::keyPressEvent( e );
296 if ( e->isAccepted() )
299 if ( e->key() == Qt::Key_F1 )