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 );
123 mySlider->setTracking(false);
125 mySlider->setTickPosition( QSlider::TicksLeft );
126 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
128 /*************************************************************************/
129 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ), GroupButtons );
130 buttonOk->setAutoDefault( true );
131 buttonOk->setDefault( true );
133 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ), GroupButtons );
134 buttonHelp->setAutoDefault( true );
135 buttonHelp->setDefault( true );
137 GroupButtonsLayout->addWidget( buttonOk );
138 GroupButtonsLayout->addSpacing( 10 );
139 GroupButtonsLayout->addStretch();
140 GroupButtonsLayout->addWidget( buttonHelp );
142 /*************************************************************************/
143 lay->addWidget(GroupC1);
144 lay->addWidget(GroupButtons);
146 /* First call valueChanged() method for initialisation */
147 /* The default value of transparency will change with the selection */
149 // mySlider->setMaxValue( 10 );
150 // mySlider->setValue( 5 ) ;
153 myHelpFileName = "transparency_page.html";
155 // signals and slots connections : after ValueHasChanged()
156 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
157 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
158 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
159 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(SliderHasMoved(int)));
163 //=================================================================================
164 // function : ~GEOMBase_TransparencyDlg()
166 //=================================================================================
167 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
169 // no need to delete child widgets, Qt does it all for us
173 //=======================================================================
174 // function : ClickOnOk()
176 //=======================================================================
177 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
184 //=======================================================================
185 // function : ClickOnClose()
187 //=======================================================================
188 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
194 //=================================================================================
195 // function : ClickOnHelp()
197 //=================================================================================
198 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
200 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
202 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
203 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
208 platform = "winapplication";
210 platform = "application";
212 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
213 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
214 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
215 QObject::tr("BUT_OK"));
219 //=================================================================================
220 // function : ValueHasChanged()
221 // purpose : Called when value of slider change
222 //=================================================================================
223 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
225 myValueLab->setText( QString("%1%").arg( mySlider->value() ) );
228 //=================================================================================
229 // function : SliderHasMoved()
230 // purpose : Called when value of slider change
231 //=================================================================================
232 void GEOMToolsGUI_TransparencyDlg::SliderHasMoved(int value)
234 myValueLab->setText( QString("%1%").arg( value ) );
237 //=================================================================================
238 // function : SetTransparency()
239 // purpose : Called when value of slider change
240 // : or the first time as initilisation
241 //=================================================================================
242 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
244 float newValue = ( 100 - mySlider->value() ) / 100.;
246 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
249 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
252 SALOME_ListIO selected;
253 aSelMgr->selectedObjects( selected );
254 if ( selected.IsEmpty() )
257 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
258 if ( FirstIOS.IsNull() )
261 SUIT_ViewWindow* window = app->desktop()->activeWindow();
262 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
263 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
266 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
269 SVTK_View* aView = vtkVW->getView();
272 int transp = int (100 - ((aView->GetTransparency(FirstIOS))*100.0) + 0.5);
273 mySlider->setValue(transp);
278 SUIT_OverrideCursor();
279 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
280 aView->SetTransparency( It.Value(), newValue );
282 GeometryGUI::Modified();
287 GEOMBase* gb = new GEOMBase();
288 Standard_Boolean found;
289 Handle(GEOM_AISShape) aisShape;
292 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
295 int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
296 mySlider->setValue(transp);
301 SUIT_OverrideCursor();
302 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
305 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
306 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
307 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
309 ic->SetTransparency( aisShape, newValue, false );
310 ic->Redisplay( aisShape, Standard_False, Standard_True );
313 ic->UpdateCurrentViewer();
314 GeometryGUI::Modified();
320 //=================================================================================
321 // function : keyPressEvent()
323 //=================================================================================
324 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
326 QDialog::keyPressEvent( e );
327 if ( e->isAccepted() )
330 if ( e->key() == Qt::Key_F1 )