1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_TransparencyDlg.cxx
24 // 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>
40 #include <OCCViewer_ViewWindow.h>
42 #include <SUIT_ViewManager.h>
43 #include <SUIT_Application.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
55 #include <qpushbutton.h>
60 #include <qwhatsthis.h>
61 #include <qapplication.h>
62 #include <qgroupbox.h>
64 #include <AIS_InteractiveContext.hxx>
67 //=================================================================================
68 // class : GEOMBase_TransparencyDlg()
69 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
70 // name 'name' and widget flags set to 'f'.
72 // : WARNING : this dialog is modal !
74 //=================================================================================
75 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
76 :QDialog( parent, "GEOMBase_TransparencyDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
79 setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
80 setSizeGripEnabled(TRUE);
81 QGridLayout* lay = new QGridLayout(this);
85 /*************************************************************************/
86 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
87 GroupButtons->setColumnLayout(0, Qt::Vertical );
88 GroupButtons->layout()->setSpacing( 0 );
89 GroupButtons->layout()->setMargin( 0 );
90 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
91 GroupButtonsLayout->setAlignment( Qt::AlignTop );
92 GroupButtonsLayout->setSpacing( 6 );
93 GroupButtonsLayout->setMargin( 11 );
95 QPushButton* buttonOk = new QPushButton( GroupButtons, "buttonOk" );
96 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
97 buttonOk->setAutoDefault( TRUE );
98 buttonOk->setDefault( TRUE );
100 QPushButton* buttonHelp = new QPushButton( GroupButtons, "buttonHelp" );
101 buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
102 buttonHelp->setAutoDefault( TRUE );
103 buttonHelp->setDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
106 GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
107 GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
109 /*************************************************************************/
110 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
111 GroupC1->setColumnLayout(0, Qt::Vertical );
112 GroupC1->layout()->setSpacing( 0 );
113 GroupC1->layout()->setMargin( 0 );
114 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
115 GroupC1Layout->setAlignment( Qt::AlignTop );
116 GroupC1Layout->setSpacing( 6 );
117 GroupC1Layout->setMargin( 11 );
119 QLabel* TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
120 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
121 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
122 GroupC1Layout->addWidget( TextLabelTransparent, 0, 0 );
124 myValueLab = new QLabel(GroupC1, "myValueLab");
125 myValueLab->setAlignment(AlignCenter);
126 myValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
127 QFont fnt = myValueLab->font(); fnt.setBold(true); myValueLab->setFont(fnt);
128 GroupC1Layout->addWidget(myValueLab, 0, 1);
130 QLabel* TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
131 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
132 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
133 GroupC1Layout->addWidget( TextLabelOpaque, 0, 2 );
135 // GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
137 mySlider = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "mySlider" );
138 mySlider->setFocusPolicy(QWidget::NoFocus);
139 mySlider->setMinimumSize( 300, 0 );
140 mySlider->setTickmarks( QSlider::Above );
141 mySlider->setTickInterval( 10 );
142 mySlider->setMinValue( 0 );
143 mySlider->setMaxValue( 100 );
144 mySlider->setLineStep( 1 );
145 mySlider->setPageStep( 10 );
146 GroupC1Layout->addMultiCellWidget( mySlider, 1, 1, 0, 2 );
147 /*************************************************************************/
149 lay->addWidget(GroupC1, 0, 0);
150 lay->addWidget(GroupButtons, 1, 0);
152 /* First call valueChanged() method for initialisation */
153 /* The default value of transparency will change with the selection */
155 // mySlider->setMaxValue( 10 );
156 // mySlider->setValue( 5 ) ;
159 myHelpFileName = "transparency_page.html";
161 // signals and slots connections : after ValueHasChanged()
162 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
163 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
164 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
165 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
169 //=================================================================================
170 // function : ~GEOMBase_TransparencyDlg()
172 //=================================================================================
173 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
175 // no need to delete child widgets, Qt does it all for us
179 //=======================================================================
180 // function : ClickOnOk()
182 //=======================================================================
183 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
190 //=======================================================================
191 // function : ClickOnClose()
193 //=======================================================================
194 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
200 //=================================================================================
201 // function : ClickOnHelp()
203 //=================================================================================
204 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
206 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
208 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
209 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
214 platform = "winapplication";
216 platform = "application";
218 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
219 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
220 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
221 QObject::tr("BUT_OK"));
225 //=================================================================================
226 // function : ValueHasChanged()
227 // purpose : Called when value of slider change
228 //=================================================================================
229 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
231 myValueLab->setText(QString::number(this->mySlider->value()) + "%");
234 //=================================================================================
235 // function : SetTransparency()
236 // purpose : Called when value of slider change
237 // : or the first time as initilisation
238 //=================================================================================
239 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
241 float newValue = ( 100 - mySlider->value() ) / 100.;
243 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
246 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
249 SALOME_ListIO selected;
250 aSelMgr->selectedObjects( selected );
251 if ( selected.IsEmpty() )
254 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
255 if ( FirstIOS.IsNull() )
258 SUIT_ViewWindow* window = app->desktop()->activeWindow();
259 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
260 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
263 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
266 SVTK_View* aView = vtkVW->getView();
269 int transp = int (100 - ((aView->GetTransparency(FirstIOS))*100.0) + 0.5);
270 mySlider->setValue(transp);
275 SUIT_OverrideCursor();
276 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
277 aView->SetTransparency( It.Value(), newValue );
283 GEOMBase* gb = new GEOMBase();
284 Standard_Boolean found;
285 Handle(GEOM_AISShape) aisShape;
288 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
291 int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
292 mySlider->setValue(transp);
297 SUIT_OverrideCursor();
298 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
301 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
302 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
303 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
305 ic->SetTransparency( aisShape, newValue, false );
306 ic->Redisplay( aisShape, Standard_False, Standard_True );
309 ic->UpdateCurrentViewer();
315 //=================================================================================
316 // function : keyPressEvent()
318 //=================================================================================
319 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
321 QDialog::keyPressEvent( e );
322 if ( e->isAccepted() )
325 if ( e->key() == Key_F1 )