1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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>
31 #include <GEOM_Constants.h>
33 #include <SALOME_ListIO.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>
51 #include <SalomeApp_Study.h>
54 #include <QPushButton>
56 #include <QGridLayout>
57 #include <QVBoxLayout>
58 #include <QHBoxLayout>
62 #include <AIS_InteractiveContext.hxx>
65 //=================================================================================
66 // class : GEOMBase_TransparencyDlg()
67 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
68 // name 'name' and widget flags set to 'f'.
70 // : WARNING : this dialog is modal !
72 //=================================================================================
73 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
74 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
79 setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
80 setSizeGripEnabled(true);
81 QVBoxLayout* lay = new QVBoxLayout(this);
85 /*************************************************************************/
86 QGroupBox* GroupButtons = new QGroupBox( this );
87 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
88 GroupButtonsLayout->setAlignment( Qt::AlignTop );
89 GroupButtonsLayout->setSpacing( 6 );
90 GroupButtonsLayout->setMargin( 11 );
92 /*************************************************************************/
93 QGroupBox* GroupC1 = new QGroupBox( this );
94 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
95 GroupC1Layout->setAlignment( Qt::AlignTop );
96 GroupC1Layout->setSpacing( 6 );
97 GroupC1Layout->setMargin( 11 );
99 QLabel* TextLabelTransparent = new QLabel( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
100 TextLabelTransparent->setAlignment( Qt::AlignLeft );
101 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
103 myValueLab = new QLabel( GroupC1 );
104 myValueLab->setAlignment( Qt::AlignCenter );
105 myValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 QFont fnt = myValueLab->font(); fnt.setBold( true ); myValueLab->setFont( fnt );
107 GroupC1Layout->addWidget( myValueLab, 0, 1 );
109 QLabel* TextLabelOpaque = new QLabel( tr( "GEOM_TRANSPARENCY_OPAQUE" ), GroupC1 );
110 TextLabelOpaque->setAlignment( Qt::AlignRight );
111 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
112 //GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
114 mySlider = new QSlider( Qt::Horizontal, GroupC1 );
115 mySlider->setFocusPolicy( Qt::NoFocus );
116 mySlider->setMinimumSize( 300, 0 );
117 mySlider->setTickPosition( QSlider::TicksAbove );
118 mySlider->setTickInterval( 10 );
119 mySlider->setMinimum( 0 );
120 mySlider->setMaximum( 100 );
121 mySlider->setSingleStep( 1 );
122 mySlider->setPageStep( 10 );
123 //mySlider->setValue( 5 );
124 mySlider->setTracking(false);
126 mySlider->setTickPosition( QSlider::TicksAbove );
127 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
129 /*************************************************************************/
130 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ), GroupButtons );
131 buttonOk->setAutoDefault( true );
132 buttonOk->setDefault( true );
134 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ), GroupButtons );
135 buttonHelp->setAutoDefault( true );
136 buttonHelp->setDefault( true );
138 GroupButtonsLayout->addWidget( buttonOk );
139 GroupButtonsLayout->addSpacing( 10 );
140 GroupButtonsLayout->addStretch();
141 GroupButtonsLayout->addWidget( buttonHelp );
143 /*************************************************************************/
144 lay->addWidget(GroupC1);
145 lay->addWidget(GroupButtons);
147 /* First call valueChanged() method for initialisation */
148 /* The default value of transparency will change with the selection */
150 // mySlider->setMaxValue( 10 );
151 // mySlider->setValue( 5 ) ;
154 myHelpFileName = "transparency_page.html";
156 // signals and slots connections : after ValueHasChanged()
157 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
158 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
159 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
160 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(SliderHasMoved(int)));
164 //=================================================================================
165 // function : ~GEOMBase_TransparencyDlg()
167 //=================================================================================
168 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
170 // no need to delete child widgets, Qt does it all for us
174 //=======================================================================
175 // function : ClickOnOk()
177 //=======================================================================
178 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
185 //=======================================================================
186 // function : ClickOnClose()
188 //=======================================================================
189 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
195 //=================================================================================
196 // function : ClickOnHelp()
198 //=================================================================================
199 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
201 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
203 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
204 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
209 platform = "winapplication";
211 platform = "application";
213 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
214 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
215 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
216 QObject::tr("BUT_OK"));
220 //=================================================================================
221 // function : ValueHasChanged()
222 // purpose : Called when value of slider change
223 //=================================================================================
224 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
226 myValueLab->setText( QString("%1%").arg( mySlider->value() ) );
229 //=================================================================================
230 // function : SliderHasMoved()
231 // purpose : Called when value of slider change
232 //=================================================================================
233 void GEOMToolsGUI_TransparencyDlg::SliderHasMoved(int value)
235 myValueLab->setText( QString("%1%").arg( value ) );
238 //=================================================================================
239 // function : SetTransparency()
240 // purpose : Called when value of slider change
241 // : or the first time as initilisation
242 //=================================================================================
243 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
245 float newValue = mySlider->value() / 100.;
247 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
250 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
254 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
259 SALOME_ListIO selected;
260 aSelMgr->selectedObjects( selected );
261 if ( selected.IsEmpty() )
264 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
265 if ( FirstIOS.IsNull() )
268 SUIT_ViewWindow* window = app->desktop()->activeWindow();
269 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
270 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
271 int aMgrId = window->getViewManager()->getGlobalId();
273 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
276 SVTK_View* aView = vtkVW->getView();
279 int transp = int ((aView->GetTransparency(FirstIOS))*100.0 + 0.5);
280 mySlider->setValue(transp);
285 SUIT_OverrideCursor wc;
286 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
287 aView->SetTransparency( It.Value(), newValue );
288 aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), GEOM::propertyName( GEOM::Transparency ) , newValue );
290 GeometryGUI::Modified();
295 GEOMBase* gb = new GEOMBase();
296 Handle(GEOM_AISShape) aisShape;
298 mySlider->setValue(mySlider->maximum());
300 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
301 if( aisShape.IsNull() )
303 int transp = int( aisShape->Transparency() * 100.0 + 0.5);
304 mySlider->setValue(transp);
309 SUIT_OverrideCursor wc;
310 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
313 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
314 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
315 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
316 if ( !aisShape.IsNull() ) {
317 ic->SetTransparency( aisShape, newValue, false );
318 ic->Redisplay( aisShape, Standard_False, Standard_True );
319 aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), GEOM::propertyName( GEOM::Transparency ) , newValue );
322 ic->UpdateCurrentViewer();
323 GeometryGUI::Modified();
329 //=================================================================================
330 // function : keyPressEvent()
332 //=================================================================================
333 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
335 QDialog::keyPressEvent( e );
336 if ( e->isAccepted() )
339 if ( e->key() == Qt::Key_F1 )