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
24 // File : GEOMBase_TransparencyDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOM_AISShape.hxx"
32 #include "GeometryGUI.h"
34 #include "SALOME_ListIO.hxx"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include <SVTK_ViewModel.h>
38 #include <SVTK_ViewWindow.h>
39 #include <SVTK_View.h>
41 #include <OCCViewer_ViewModel.h>
43 #include <SUIT_ViewManager.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
55 #include <QPushButton>
57 #include <QGridLayout>
61 #include <AIS_InteractiveContext.hxx>
64 //=================================================================================
65 // class : GEOMBase_TransparencyDlg()
66 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
67 // name 'name' and widget flags set to 'f'.
69 // : WARNING : this dialog is modal !
71 //=================================================================================
72 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
73 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
75 setObjectName( "GEOMBase_TransparencyDlg" );
79 setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
80 setSizeGripEnabled(TRUE);
81 QGridLayout* lay = new QGridLayout(this);
85 /*************************************************************************/
86 QGroupBox* GroupButtons = new QGroupBox( this );
87 GroupButtons->setObjectName( "GroupButtons" );
88 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
89 GroupButtonsLayout->setAlignment( Qt::AlignTop );
90 GroupButtonsLayout->setSpacing( 6 );
91 GroupButtonsLayout->setMargin( 11 );
93 QPushButton* buttonOk = new QPushButton( GroupButtons );
94 buttonOk->setObjectName( "buttonOk" );
95 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
96 buttonOk->setAutoDefault( TRUE );
97 buttonOk->setDefault( TRUE );
99 QPushButton* buttonHelp = new QPushButton( GroupButtons );
100 buttonHelp->setObjectName( "buttonHelp" );
101 buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
102 buttonHelp->setAutoDefault( TRUE );
103 buttonHelp->setDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
106 GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
107 GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
109 /*************************************************************************/
110 QGroupBox* GroupC1 = new QGroupBox( this );
111 GroupC1->setObjectName( "GroupC1" );
112 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
113 GroupC1Layout->setAlignment( Qt::AlignTop );
114 GroupC1Layout->setSpacing( 6 );
115 GroupC1Layout->setMargin( 11 );
117 QLabel* TextLabelOpaque = new QLabel( GroupC1 );
118 TextLabelOpaque->setObjectName( "TextLabelOpaque" );
119 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
120 TextLabelOpaque->setAlignment( Qt::AlignLeft );
121 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
122 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
124 QLabel* TextLabelTransparent = new QLabel( GroupC1 );
125 TextLabelTransparent->setObjectName( "TextLabelTransparent" );
126 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
127 TextLabelTransparent->setAlignment( Qt::AlignRight );
128 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
130 mySlider = new QSlider( Qt::Horizontal, GroupC1 );
131 mySlider->setObjectName( "mySlider" );
132 mySlider->setMinimum( 0 );
133 mySlider->setMaximum( 10 );
134 mySlider->setPageStep( 1 );
135 mySlider->setValue( 5 );
136 mySlider->setMinimumSize( 300, 0 );
137 mySlider->setTickPosition( QSlider::TicksLeft );
138 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
139 /*************************************************************************/
141 lay->addWidget(GroupC1, 0, 0);
142 lay->addWidget(GroupButtons, 1, 0);
144 /* First call valueChanged() method for initialisation */
145 /* The default value of transparency will change with the selection */
147 // mySlider->setMaxValue( 10 );
148 // mySlider->setValue( 5 ) ;
149 ValueHasChanged(mySlider->value());
151 myHelpFileName = "transparency.htm";
153 // signals and slots connections : after ValueHasChanged()
154 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
156 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
160 //=================================================================================
161 // function : ~GEOMBase_TransparencyDlg()
163 //=================================================================================
164 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
166 // no need to delete child widgets, Qt does it all for us
170 //=======================================================================
171 // function : ClickOnOk()
173 //=======================================================================
174 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
181 //=======================================================================
182 // function : ClickOnClose()
184 //=======================================================================
185 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
191 //=================================================================================
192 // function : ClickOnHelp()
194 //=================================================================================
195 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
197 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
199 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
200 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
205 platform = "winapplication";
207 platform = "application";
209 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
210 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
211 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
212 QObject::tr("BUT_OK"));
216 //=================================================================================
217 // function : ValueHasChanged()
218 // purpose : Called when value of slider change
219 // : or the first time as initilisation
220 //=================================================================================
221 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
223 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
226 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
229 SALOME_ListIO selected;
230 aSelMgr->selectedObjects( selected );
231 if ( selected.IsEmpty() )
234 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
235 if ( FirstIOS.IsNull() )
238 SUIT_ViewWindow* window = app->desktop()->activeWindow();
239 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
240 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
243 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
246 SVTK_View* aView = vtkVW->getView();
249 float transp = (aView->GetTransparency(FirstIOS))*10.0;
250 mySlider->setValue(int(transp));
254 SUIT_OverrideCursor();
255 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
256 aView->SetTransparency( It.Value(), newValue/10.0 );
262 GEOMBase* gb = new GEOMBase();
263 Standard_Boolean found;
264 Handle(GEOM_AISShape) aisShape;
267 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
270 float transp = (int(aisShape->Transparency() * 10.0 + 0.001));
271 mySlider->setValue(int(transp));
275 SUIT_OverrideCursor();
276 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
279 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
280 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
281 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
283 ic->SetTransparency( aisShape, newValue / 10.0, false );
284 ic->Redisplay( aisShape, Standard_False, Standard_True );
287 ic->UpdateCurrentViewer();
291 //=================================================================================
292 // function : keyPressEvent()
294 //=================================================================================
295 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
297 QDialog::keyPressEvent( e );
298 if ( e->isAccepted() )
301 if ( e->key() == Qt::Key_F1 )