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>
42 #include <OCCViewer_ViewWindow.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_Application.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
52 #include <SalomeApp_Application.h>
53 #include <LightApp_Application.h>
54 #include <LightApp_SelectionMgr.h>
58 #include <qpushbutton.h>
63 #include <qwhatsthis.h>
64 #include <qapplication.h>
65 #include <qgroupbox.h>
67 #include <AIS_InteractiveContext.hxx>
70 //=================================================================================
71 // class : GEOMBase_TransparencyDlg()
72 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
73 // name 'name' and widget flags set to 'f'.
75 // : WARNING : this dialog is modal !
77 //=================================================================================
78 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
79 :QDialog( parent, "GEOMBase_TransparencyDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
82 setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
83 setSizeGripEnabled(TRUE);
84 QGridLayout* lay = new QGridLayout(this);
88 /*************************************************************************/
89 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
90 GroupButtons->setColumnLayout(0, Qt::Vertical );
91 GroupButtons->layout()->setSpacing( 0 );
92 GroupButtons->layout()->setMargin( 0 );
93 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
94 GroupButtonsLayout->setAlignment( Qt::AlignTop );
95 GroupButtonsLayout->setSpacing( 6 );
96 GroupButtonsLayout->setMargin( 11 );
98 QPushButton* buttonOk = new QPushButton( GroupButtons, "buttonOk" );
99 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
100 buttonOk->setAutoDefault( TRUE );
101 buttonOk->setDefault( TRUE );
103 QPushButton* buttonHelp = new QPushButton( GroupButtons, "buttonHelp" );
104 buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
105 buttonHelp->setAutoDefault( TRUE );
106 buttonHelp->setDefault( TRUE );
108 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
109 GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
110 GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
112 /*************************************************************************/
113 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
114 GroupC1->setColumnLayout(0, Qt::Vertical );
115 GroupC1->layout()->setSpacing( 0 );
116 GroupC1->layout()->setMargin( 0 );
117 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
118 GroupC1Layout->setAlignment( Qt::AlignTop );
119 GroupC1Layout->setSpacing( 6 );
120 GroupC1Layout->setMargin( 11 );
122 QLabel* TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
123 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
124 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
125 GroupC1Layout->addWidget( TextLabelOpaque, 0, 0 );
126 GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
128 QLabel* TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
129 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
130 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
131 GroupC1Layout->addWidget( TextLabelTransparent, 0, 2 );
133 mySlider = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "mySlider" );
134 mySlider->setMinimumSize( 300, 0 );
135 mySlider->setTickmarks( QSlider::Left );
136 GroupC1Layout->addMultiCellWidget( mySlider, 1, 1, 0, 2 );
137 /*************************************************************************/
139 lay->addWidget(GroupC1, 0, 0);
140 lay->addWidget(GroupButtons, 1, 0);
142 /* First call valueChanged() method for initialisation */
143 /* The default value of transparency will change with the selection */
145 // mySlider->setMaxValue( 10 );
146 // mySlider->setValue( 5 ) ;
147 ValueHasChanged(mySlider->value());
149 myHelpFileName = "transparency.htm";
151 // signals and slots connections : after ValueHasChanged()
152 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
154 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(ValueHasChanged(int)));
158 //=================================================================================
159 // function : ~GEOMBase_TransparencyDlg()
161 //=================================================================================
162 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
164 // no need to delete child widgets, Qt does it all for us
168 //=======================================================================
169 // function : ClickOnOk()
171 //=======================================================================
172 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
179 //=======================================================================
180 // function : ClickOnClose()
182 //=======================================================================
183 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
189 //=================================================================================
190 // function : ClickOnHelp()
192 //=================================================================================
193 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
195 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
197 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
198 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
203 platform = "winapplication";
205 platform = "application";
207 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
208 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
209 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
210 QObject::tr("BUT_OK"));
214 //=================================================================================
215 // function : ValueHasChanged()
216 // purpose : Called when value of slider change
217 // : or the first time as initilisation
218 //=================================================================================
219 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged( int newValue )
221 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
224 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
227 SALOME_ListIO selected;
228 aSelMgr->selectedObjects( selected );
229 if ( selected.IsEmpty() )
232 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
233 if ( FirstIOS.IsNull() )
236 SUIT_ViewWindow* window = app->desktop()->activeWindow();
237 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
238 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
241 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
244 SVTK_View* aView = vtkVW->getView();
247 float transp = (aView->GetTransparency(FirstIOS))*10.0;
248 mySlider->setValue(int(transp));
252 SUIT_OverrideCursor();
253 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
254 aView->SetTransparency( It.Value(), newValue/10.0 );
260 GEOMBase* gb = new GEOMBase();
261 Standard_Boolean found;
262 Handle(GEOM_AISShape) aisShape;
265 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
268 float transp = (int(aisShape->Transparency() * 10.0 + 0.001));
269 mySlider->setValue(int(transp));
273 SUIT_OverrideCursor();
274 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
277 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
278 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
279 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
281 ic->SetTransparency( aisShape, newValue / 10.0, false );
282 ic->Redisplay( aisShape, Standard_False, Standard_True );
285 ic->UpdateCurrentViewer();
289 //=================================================================================
290 // function : keyPressEvent()
292 //=================================================================================
293 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
295 QDialog::keyPressEvent( e );
296 if ( e->isAccepted() )
299 if ( e->key() == Key_F1 )