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>
57 #include <qpushbutton.h>
62 #include <qwhatsthis.h>
63 #include <qapplication.h>
64 #include <qgroupbox.h>
66 #include <AIS_InteractiveContext.hxx>
69 //=================================================================================
70 // class : GEOMBase_TransparencyDlg()
71 // purpose : Constructs a GEOMBase_SUBSHAPE which is a child of 'parent', with the
72 // name 'name' and widget flags set to 'f'.
74 // : WARNING : this dialog is modal !
76 //=================================================================================
77 GEOMToolsGUI_TransparencyDlg::GEOMToolsGUI_TransparencyDlg( QWidget* parent )
78 :QDialog( parent, "GEOMBase_TransparencyDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
81 setCaption(tr("GEOM_TRANSPARENCY_TITLE"));
82 setSizeGripEnabled(TRUE);
83 QGridLayout* lay = new QGridLayout(this);
87 /*************************************************************************/
88 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
89 GroupButtons->setColumnLayout(0, Qt::Vertical );
90 GroupButtons->layout()->setSpacing( 0 );
91 GroupButtons->layout()->setMargin( 0 );
92 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
93 GroupButtonsLayout->setAlignment( Qt::AlignTop );
94 GroupButtonsLayout->setSpacing( 6 );
95 GroupButtonsLayout->setMargin( 11 );
97 QPushButton* buttonOk = new QPushButton( GroupButtons, "buttonOk" );
98 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
99 buttonOk->setAutoDefault( TRUE );
100 buttonOk->setDefault( TRUE );
102 QPushButton* buttonHelp = new QPushButton( GroupButtons, "buttonHelp" );
103 buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
104 buttonHelp->setAutoDefault( TRUE );
105 buttonHelp->setDefault( TRUE );
107 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
108 GroupButtonsLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
109 GroupButtonsLayout->addWidget( buttonHelp, 0, 2 );
111 /*************************************************************************/
112 QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
113 GroupC1->setColumnLayout(0, Qt::Vertical );
114 GroupC1->layout()->setSpacing( 0 );
115 GroupC1->layout()->setMargin( 0 );
116 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
117 GroupC1Layout->setAlignment( Qt::AlignTop );
118 GroupC1Layout->setSpacing( 6 );
119 GroupC1Layout->setMargin( 11 );
121 QLabel* TextLabelTransparent = new QLabel( GroupC1, "TextLabelTransparent" );
122 TextLabelTransparent->setText( tr( "GEOM_TRANSPARENCY_TRANSPARENT" ) );
123 TextLabelTransparent->setAlignment( int( QLabel::AlignRight ) );
124 GroupC1Layout->addWidget( TextLabelTransparent, 0, 0 );
126 myValueLab = new QLabel(GroupC1, "myValueLab");
127 myValueLab->setAlignment(AlignCenter);
128 myValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
129 QFont fnt = myValueLab->font(); fnt.setBold(true); myValueLab->setFont(fnt);
130 GroupC1Layout->addWidget(myValueLab, 0, 1);
132 QLabel* TextLabelOpaque = new QLabel( GroupC1, "TextLabelOpaque" );
133 TextLabelOpaque->setText( tr( "GEOM_TRANSPARENCY_OPAQUE" ) );
134 TextLabelOpaque->setAlignment( int( QLabel::AlignLeft ) );
135 GroupC1Layout->addWidget( TextLabelOpaque, 0, 2 );
137 // GroupC1Layout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
139 mySlider = new QSlider( 0, 10, 1, 5, Horizontal, GroupC1, "mySlider" );
140 mySlider->setFocusPolicy(QWidget::NoFocus);
141 mySlider->setMinimumSize( 300, 0 );
142 mySlider->setTickmarks( QSlider::Above );
143 mySlider->setTickInterval( 10 );
144 mySlider->setMinValue( 0 );
145 mySlider->setMaxValue( 100 );
146 mySlider->setLineStep( 1 );
147 mySlider->setPageStep( 10 );
148 GroupC1Layout->addMultiCellWidget( mySlider, 1, 1, 0, 2 );
149 /*************************************************************************/
151 lay->addWidget(GroupC1, 0, 0);
152 lay->addWidget(GroupButtons, 1, 0);
154 /* First call valueChanged() method for initialisation */
155 /* The default value of transparency will change with the selection */
157 // mySlider->setMaxValue( 10 );
158 // mySlider->setValue( 5 ) ;
161 myHelpFileName = "transparency_page.html";
163 // signals and slots connections : after ValueHasChanged()
164 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
165 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
166 connect(mySlider, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
167 connect(mySlider, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
171 //=================================================================================
172 // function : ~GEOMBase_TransparencyDlg()
174 //=================================================================================
175 GEOMToolsGUI_TransparencyDlg::~GEOMToolsGUI_TransparencyDlg()
177 // no need to delete child widgets, Qt does it all for us
181 //=======================================================================
182 // function : ClickOnOk()
184 //=======================================================================
185 void GEOMToolsGUI_TransparencyDlg::ClickOnOk()
192 //=======================================================================
193 // function : ClickOnClose()
195 //=======================================================================
196 void GEOMToolsGUI_TransparencyDlg::ClickOnClose()
202 //=================================================================================
203 // function : ClickOnHelp()
205 //=================================================================================
206 void GEOMToolsGUI_TransparencyDlg::ClickOnHelp()
208 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
210 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
211 app->onHelpContextModule(aGeomGUI ? app->moduleName(aGeomGUI->moduleName()) : QString(""), myHelpFileName);
216 platform = "winapplication";
218 platform = "application";
220 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
221 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
222 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
223 QObject::tr("BUT_OK"));
227 //=================================================================================
228 // function : ValueHasChanged()
229 // purpose : Called when value of slider change
230 //=================================================================================
231 void GEOMToolsGUI_TransparencyDlg::ValueHasChanged()
233 myValueLab->setText(QString::number(this->mySlider->value()) + "%");
236 //=================================================================================
237 // function : SetTransparency()
238 // purpose : Called when value of slider change
239 // : or the first time as initilisation
240 //=================================================================================
241 void GEOMToolsGUI_TransparencyDlg::SetTransparency()
243 float newValue = ( 100 - mySlider->value() ) / 100.;
245 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
248 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
251 SALOME_ListIO selected;
252 aSelMgr->selectedObjects( selected );
253 if ( selected.IsEmpty() )
256 Handle(SALOME_InteractiveObject) FirstIOS = selected.First();
257 if ( FirstIOS.IsNull() )
260 SUIT_ViewWindow* window = app->desktop()->activeWindow();
261 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
262 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
265 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
268 SVTK_View* aView = vtkVW->getView();
271 int transp = int (100 - ((aView->GetTransparency(FirstIOS))*100.0) + 0.5);
272 mySlider->setValue(transp);
277 SUIT_OverrideCursor();
278 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
279 aView->SetTransparency( It.Value(), newValue );
285 GEOMBase* gb = new GEOMBase();
286 Standard_Boolean found;
287 Handle(GEOM_AISShape) aisShape;
290 aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
293 int transp = int( 100 - ( aisShape->Transparency() * 100.0 ) + 0.5);
294 mySlider->setValue(transp);
299 SUIT_OverrideCursor();
300 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
303 Handle(AIS_InteractiveContext) ic = vm->getAISContext();
304 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
305 aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
307 ic->SetTransparency( aisShape, newValue, false );
308 ic->Redisplay( aisShape, Standard_False, Standard_True );
311 ic->UpdateCurrentViewer();
317 //=================================================================================
318 // function : keyPressEvent()
320 //=================================================================================
321 void GEOMToolsGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
323 QDialog::keyPressEvent( e );
324 if ( e->isAccepted() )
327 if ( e->key() == Key_F1 )