1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMToolsGUI_TransparencyDlg.cxx
25 // Author : Lucien PIGNOLONI
27 #include "GEOMToolsGUI_TransparencyDlg.h"
29 #include <GEOM_AISShape.hxx>
30 #include <GeometryGUI.h>
32 #include <SALOME_ListIO.hxx>
33 #include <SALOME_ListIteratorOfListIO.hxx>
35 #include <SVTK_ViewModel.h>
36 #include <SVTK_ViewWindow.h>
37 #include <SVTK_View.h>
39 #include <OCCViewer_ViewModel.h>
41 #include <SUIT_ViewManager.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <SalomeApp_Application.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
53 #include <QPushButton>
55 #include <QGridLayout>
56 #include <QVBoxLayout>
57 #include <QHBoxLayout>
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 )
78 setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
79 setSizeGripEnabled(true);
80 QVBoxLayout* lay = new QVBoxLayout(this);
84 /*************************************************************************/
85 QGroupBox* GroupButtons = new QGroupBox( this );
86 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
87 GroupButtonsLayout->setAlignment( Qt::AlignTop );
88 GroupButtonsLayout->setSpacing( 6 );
89 GroupButtonsLayout->setMargin( 11 );
91 /*************************************************************************/
92 QGroupBox* GroupC1 = new QGroupBox( this );
93 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
94 GroupC1Layout->setAlignment( Qt::AlignTop );
95 GroupC1Layout->setSpacing( 6 );
96 GroupC1Layout->setMargin( 11 );
98 QLabel* TextLabelTransparent = new QLabel( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
99 TextLabelTransparent->setAlignment( Qt::AlignRight );
100 GroupC1Layout->addWidget( TextLabelTransparent, 0, 0 );
102 myValueLab = new QLabel( GroupC1 );
103 myValueLab->setAlignment( Qt::AlignCenter );
104 myValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
105 QFont fnt = myValueLab->font(); fnt.setBold( true ); myValueLab->setFont( fnt );
106 GroupC1Layout->addWidget( myValueLab, 0, 1 );
108 QLabel* TextLabelOpaque = new QLabel( tr( "GEOM_TRANSPARENCY_OPAQUE" ), GroupC1 );
109 TextLabelOpaque->setAlignment( Qt::AlignLeft );
110 GroupC1Layout->addWidget( TextLabelOpaque, 0, 2 );
111 //GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
113 mySlider = new QSlider( Qt::Horizontal, GroupC1 );
114 mySlider->setFocusPolicy( Qt::NoFocus );
115 mySlider->setMinimumSize( 300, 0 );
116 mySlider->setTickPosition( QSlider::TicksAbove );
117 mySlider->setTickInterval( 10 );
118 mySlider->setMinimum( 0 );
119 mySlider->setMaximum( 100 );
120 mySlider->setSingleStep( 1 );
121 mySlider->setPageStep( 10 );
122 //mySlider->setValue( 5 );
124 mySlider->setTickPosition( QSlider::TicksLeft );
125 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
127 /*************************************************************************/
128 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ), GroupButtons );
129 buttonOk->setAutoDefault( true );
130 buttonOk->setDefault( true );
132 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ), GroupButtons );
133 buttonHelp->setAutoDefault( true );
134 buttonHelp->setDefault( true );
136 GroupButtonsLayout->addWidget( buttonOk );
137 GroupButtonsLayout->addSpacing( 10 );
138 GroupButtonsLayout->addStretch();
139 GroupButtonsLayout->addWidget( buttonHelp );
141 /*************************************************************************/
142 lay->addWidget(GroupC1);
143 lay->addWidget(GroupButtons);
145 /* First call valueChanged() method for initialisation */
146 /* The default value of transparency will change with the selection */
148 // mySlider->setMaxValue( 10 );
149 // mySlider->setValue( 5 ) ;
152 myHelpFileName = "transparency_page.html";
154 // signals and slots connections : after ValueHasChanged()
155 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
156 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
157 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
158 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
162 //=================================================================================
163 // function : ~GEOMBase_TransparencyDlg()
165 //=================================================================================
166 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
168 // no need to delete child widgets, Qt does it all for us
172 //=======================================================================
173 // function : ClickOnOk()
175 //=======================================================================
176 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
183 //=======================================================================
184 // function : ClickOnClose()
186 //=======================================================================
187 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
193 //=================================================================================
194 // function : ClickOnHelp()
196 //=================================================================================
197 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
199 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
201 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
202 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
207 platform = "winapplication";
209 platform = "application";
211 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
212 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
213 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
214 QObject::tr("BUT_OK"));
218 //=================================================================================
219 // function : ValueHasChanged()
220 // purpose : Called when value of slider change
221 //=================================================================================
222 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
224 myValueLab->setText( QString("%1%").arg( mySlider->value() ) );
227 //=================================================================================
228 // function : SetTransparency()
229 // purpose : Called when value of slider change
230 // : or the first time as initilisation
231 //=================================================================================
232 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
234 float newValue = ( 100 - mySlider->value() ) / 100.;
236 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
239 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
242 SALOME_ListIO selected;
243 aSelMgr->selectedObjects( selected );
244 if ( selected.IsEmpty() )
247 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
248 if ( FirstIOS.IsNull() )
251 SUIT_ViewWindow* window = app->desktop()->activeWindow();
252 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
253 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
256 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
259 SVTK_View* aView = vtkVW->getView();
262 int transp = int (100 - ((aView->GetTransparency(FirstIOS))*100.0) + 0.5);
263 mySlider->setValue(transp);
268 SUIT_OverrideCursor();
269 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
270 aView->SetTransparency( It.Value(), newValue );
272 GeometryGUI::Modified();
277 GEOMBase* gb = new GEOMBase();
278 Standard_Boolean found;
279 Handle(GEOM_AISShape) aisShape;
282 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
285 int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
286 mySlider->setValue(transp);
291 SUIT_OverrideCursor();
292 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
295 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
296 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
297 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
299 ic->SetTransparency( aisShape, newValue, false );
300 ic->Redisplay( aisShape, Standard_False, Standard_True );
303 ic->UpdateCurrentViewer();
304 GeometryGUI::Modified();
310 //=================================================================================
311 // function : keyPressEvent()
313 //=================================================================================
314 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
316 QDialog::keyPressEvent( e );
317 if ( e->isAccepted() )
320 if ( e->key() == Qt::Key_F1 )