1 // Copyright (C) 2007-2012 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>
31 #include <GEOM_Constants.h>
33 #include <SALOME_ListIO.hxx>
34 #include <SALOME_ListIteratorOfListIO.hxx>
36 #include <SVTK_ViewModel.h>
37 #include <SVTK_ViewWindow.h>
38 #include <SVTK_View.h>
40 #include <OCCViewer_ViewModel.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <SalomeApp_Application.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <SalomeApp_Study.h>
55 #include <QPushButton>
57 #include <QGridLayout>
58 #include <QVBoxLayout>
59 #include <QHBoxLayout>
63 #include <AIS_InteractiveContext.hxx>
66 //=================================================================================
67 // class : GEOMBase_TransparencyDlg()
68 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
69 // name 'name' and widget flags set to 'f'.
71 // : WARNING : this dialog is modal !
73 //=================================================================================
74 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
75 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
80 setWindowTitle(tr("GEOM_TRANSPARENCY_TITLE"));
81 setSizeGripEnabled(true);
82 QVBoxLayout* lay = new QVBoxLayout(this);
86 /*************************************************************************/
87 QGroupBox* GroupButtons = new QGroupBox( this );
88 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
89 GroupButtonsLayout->setAlignment( Qt::AlignTop );
90 GroupButtonsLayout->setSpacing( 6 );
91 GroupButtonsLayout->setMargin( 11 );
93 /*************************************************************************/
94 QGroupBox* GroupC1 = new QGroupBox( this );
95 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1 );
96 GroupC1Layout->setAlignment( Qt::AlignTop );
97 GroupC1Layout->setSpacing( 6 );
98 GroupC1Layout->setMargin( 11 );
100 QLabel* TextLabelTransparent = new QLabel( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ), GroupC1 );
101 TextLabelTransparent->setAlignment( Qt::AlignLeft );
102 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
104 myValueLab = new QLabel( GroupC1 );
105 myValueLab->setAlignment( Qt::AlignCenter );
106 myValueLab->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
107 QFont fnt = myValueLab->font(); fnt.setBold( true ); myValueLab->setFont( fnt );
108 GroupC1Layout->addWidget( myValueLab, 0, 1 );
110 QLabel* TextLabelOpaque = new QLabel( tr( "GEOM_TRANSPARENCY_OPAQUE" ), GroupC1 );
111 TextLabelOpaque->setAlignment( Qt::AlignRight );
112 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
113 //GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
115 mySlider = new QSlider( Qt::Horizontal, GroupC1 );
116 mySlider->setFocusPolicy( Qt::NoFocus );
117 mySlider->setMinimumSize( 300, 0 );
118 mySlider->setTickPosition( QSlider::TicksAbove );
119 mySlider->setTickInterval( 10 );
120 mySlider->setMinimum( 0 );
121 mySlider->setMaximum( 100 );
122 mySlider->setSingleStep( 1 );
123 mySlider->setPageStep( 10 );
124 //mySlider->setValue( 5 );
125 mySlider->setTracking(false);
127 mySlider->setTickPosition( QSlider::TicksAbove );
128 GroupC1Layout->addWidget( mySlider, 1, 0, 1, 3 );
130 /*************************************************************************/
131 QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ), GroupButtons );
132 buttonOk->setAutoDefault( true );
133 buttonOk->setDefault( true );
135 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ), GroupButtons );
136 buttonHelp->setAutoDefault( true );
137 buttonHelp->setDefault( true );
139 GroupButtonsLayout->addWidget( buttonOk );
140 GroupButtonsLayout->addSpacing( 10 );
141 GroupButtonsLayout->addStretch();
142 GroupButtonsLayout->addWidget( buttonHelp );
144 /*************************************************************************/
145 lay->addWidget(GroupC1);
146 lay->addWidget(GroupButtons);
148 /* First call valueChanged() method for initialisation */
149 /* The default value of transparency will change with the selection */
151 // mySlider->setMaxValue( 10 );
152 // mySlider->setValue( 5 ) ;
155 myHelpFileName = "transparency_page.html";
157 // signals and slots connections : after ValueHasChanged()
158 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
159 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
160 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
161 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(SliderHasMoved(int)));
165 //=================================================================================
166 // function : ~GEOMBase_TransparencyDlg()
168 //=================================================================================
169 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
171 // no need to delete child widgets, Qt does it all for us
175 //=======================================================================
176 // function : ClickOnOk()
178 //=======================================================================
179 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
186 //=======================================================================
187 // function : ClickOnClose()
189 //=======================================================================
190 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
196 //=================================================================================
197 // function : ClickOnHelp()
199 //=================================================================================
200 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
202 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
204 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
205 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
210 platform = "winapplication";
212 platform = "application";
214 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
215 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
216 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
217 QObject::tr("BUT_OK"));
221 //=================================================================================
222 // function : ValueHasChanged()
223 // purpose : Called when value of slider change
224 //=================================================================================
225 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
227 myValueLab->setText( QString("%1%").arg( mySlider->value() ) );
230 //=================================================================================
231 // function : SliderHasMoved()
232 // purpose : Called when value of slider change
233 //=================================================================================
234 void GEOMToolsGUI_TransparencyDlg::SliderHasMoved(int value)
236 myValueLab->setText( QString("%1%").arg( value ) );
239 //=================================================================================
240 // function : SetTransparency()
241 // purpose : Called when value of slider change
242 // : or the first time as initilisation
243 //=================================================================================
244 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
246 float newValue = mySlider->value() / 100.;
248 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
251 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
255 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
260 SALOME_ListIO selected;
261 aSelMgr->selectedObjects( selected );
262 if ( selected.IsEmpty() )
265 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
266 if ( FirstIOS.IsNull() )
269 SUIT_ViewWindow* window = app->desktop()->activeWindow();
270 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
271 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
272 int aMgrId = window->getViewManager()->getGlobalId();
274 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
277 SVTK_View* aView = vtkVW->getView();
280 int transp = int ((aView->GetTransparency(FirstIOS))*100.0 + 0.5);
281 mySlider->setValue(transp);
286 SUIT_OverrideCursor();
287 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
288 aView->SetTransparency( It.Value(), newValue );
289 aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue );
291 GeometryGUI::Modified();
296 GEOMBase* gb = new GEOMBase();
297 Handle(GEOM_AISShape) aisShape;
299 mySlider->setValue(mySlider->maximum());
301 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
302 if( aisShape.IsNull() )
304 int transp = int( aisShape->Transparency() * 100.0 + 0.5);
305 mySlider->setValue(transp);
310 SUIT_OverrideCursor();
311 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
314 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
315 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
316 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
317 if ( !aisShape.IsNull() ) {
318 ic->SetTransparency( aisShape, newValue, false );
319 ic->Redisplay( aisShape, Standard_False, Standard_True );
320 aStudy->setObjectProperty( aMgrId , It.Value()->getEntry(), TRANSPARENCY_PROP , newValue );
323 ic->UpdateCurrentViewer();
324 GeometryGUI::Modified();
330 //=================================================================================
331 // function : keyPressEvent()
333 //=================================================================================
334 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
336 QDialog::keyPressEvent( e );
337 if ( e->isAccepted() )
340 if ( e->key() == Qt::Key_F1 )