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 // File : VisuGUI_SelectionPrefDlg.cxx
23 // Author : Oleg UVAROV
26 #include "VisuGUI_SelectionPrefDlg.h"
29 #include "VISU_PickingSettings.h"
31 #include <SUIT_Session.h>
32 #include <SUIT_Application.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Tools.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <LightApp_Application.h>
40 #include <QtxColorButton.h>
41 #include <QtxDoubleSpinBox.h>
42 #include <QtxIntSpinBox.h>
50 #include <QPushButton>
57 VisuGUI_SelectionPrefDlg::VisuGUI_SelectionPrefDlg( QWidget* parent )
58 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
59 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
61 setWindowTitle( tr("TLT_SELECTION_PREFERENCES") );
62 setSizeGripEnabled( TRUE );
65 QVBoxLayout* topLayout = new QVBoxLayout( this );
66 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
68 // Cursor (gauss points)
69 QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), this );
70 QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup);
71 CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
72 CursorGroupLayout->setSpacing(6);
73 CursorGroupLayout->setMargin(11);
75 QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup );
76 myCursorSizeSpinBox = new QtxDoubleSpinBox( 0, 1, 0.1, CursorGroup );
77 myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
79 QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup );
80 double aHeightMin=1.e-7;
81 double aHeightMax=10.;
82 double aHeightStep=0.1;
83 myPyramidHeightSpinBox = new QtxDoubleSpinBox(aHeightMin, aHeightMax, aHeightStep, CursorGroup );
84 myPyramidHeightSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup );
87 mySelectionColorButton = new QtxColorButton( CursorGroup );
88 mySelectionColorButton->setColor( Qt::blue );
90 CursorGroupLayout->addWidget( CursorSizeLabel, 0, 0 );
91 CursorGroupLayout->addWidget( myCursorSizeSpinBox, 0, 1 );
92 CursorGroupLayout->addWidget( PyramidHeightLabel, 1, 0 );
93 CursorGroupLayout->addWidget( myPyramidHeightSpinBox, 1, 1 );
94 CursorGroupLayout->addWidget( SelectionColorLabel, 2, 0 );
95 CursorGroupLayout->addWidget( mySelectionColorButton, 2, 1 );
97 topLayout->addWidget( CursorGroup );
99 // Tolerance (gauss points)
100 QGroupBox* ToleranceGroup = new QGroupBox( tr( "TOLERANCE_TITLE" ), this );
101 QGridLayout* ToleranceGroupLayout = new QGridLayout (ToleranceGroup);
102 ToleranceGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
103 ToleranceGroupLayout->setSpacing(6);
104 ToleranceGroupLayout->setMargin(11);
106 QLabel* PointToleranceLabel = new QLabel( tr( "POINT_TOLERANCE" ), ToleranceGroup );
107 myPointToleranceSpinBox = new QtxDoubleSpinBox( 0.001, 10.0, 0.01, ToleranceGroup );
108 myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
110 ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
111 ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
113 topLayout->addWidget( ToleranceGroup );
115 // Information window
116 myInfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), this );
117 myInfoWindowGroup->setCheckable( true );
119 QGridLayout* InfoWindowGroupLayout = new QGridLayout (myInfoWindowGroup);
120 InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
122 QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), myInfoWindowGroup );
123 myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, myInfoWindowGroup );
124 myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
126 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
127 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
129 QLabel* PositionLabel = new QLabel( tr( "POSITION" ), myInfoWindowGroup );
130 myPositionComboBox = new QComboBox( myInfoWindowGroup );
131 myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
133 myPositionComboBox->addItem( tr( "BELOW_POINT" ) );
134 myPositionComboBox->addItem( tr( "TOP_LEFT_CORNER" ) );
136 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
137 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
138 InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
139 InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
141 topLayout->addWidget( myInfoWindowGroup );
143 // Movement of the camera
144 myCameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), this );
145 myCameraGroup->setCheckable( true );
147 QGridLayout* CameraGroupLayout = new QGridLayout (myCameraGroup);
148 CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
150 QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), myCameraGroup );
151 myZoomFactorSpinBox = new QtxDoubleSpinBox( 0.1, 10.0, 0.1, myCameraGroup );
152 myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
154 QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), myCameraGroup );
155 StepNumberLabel->setToolTip( tr( "STEP_NUMBER_TIP" ) );
156 myStepNumberSpinBox = new QtxIntSpinBox( 1, 100, 1, myCameraGroup );
157 myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
159 CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
160 CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
161 CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
162 CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
164 topLayout->addWidget( myCameraGroup );
167 QGroupBox* GroupButtons = new QGroupBox( this );
168 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
169 GroupButtonsLayout->setAlignment( Qt::AlignTop );
170 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
172 myButtonOk = new QPushButton( GroupButtons );
173 myButtonOk->setText( tr( "BUT_OK" ) );
174 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
175 GroupButtonsLayout->addWidget( myButtonOk );
177 myButtonApply = new QPushButton( GroupButtons );
178 myButtonApply->setText( tr( "BUT_APPLY" ) );
179 myButtonApply->setAutoDefault( TRUE );
180 GroupButtonsLayout->addWidget( myButtonApply );
182 GroupButtonsLayout->addStretch();
184 myButtonCancel = new QPushButton( GroupButtons );
185 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
186 myButtonCancel->setAutoDefault( TRUE );
187 GroupButtonsLayout->addWidget( myButtonCancel );
189 myButtonHelp = new QPushButton( GroupButtons );
190 myButtonHelp->setText( tr( "BUT_HELP" ) );
191 myButtonHelp->setAutoDefault( TRUE );
192 GroupButtonsLayout->addWidget( myButtonHelp );
193 /***************************************************************/
195 //topLayout->addWidget( GroupC1 );
196 topLayout->addWidget( GroupButtons );
198 // signals and slots connections
199 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
200 connect( myButtonApply, SIGNAL( clicked() ), this, SLOT( onApply() ) );
201 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
202 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
204 /* Move widget on the botton right corner of main widget */
205 SUIT_Tools::centerWidget( this, parent );
211 VisuGUI_SelectionPrefDlg::~VisuGUI_SelectionPrefDlg()
215 void VisuGUI_SelectionPrefDlg::update()
217 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
219 myCursorSizeSpinBox->setValue( aPickingSettings->GetCursorSize() );
220 myPyramidHeightSpinBox->setValue( aPickingSettings->GetPyramidHeight() );
221 myPointToleranceSpinBox->setValue( aPickingSettings->GetPointTolerance() );
223 vtkFloatingPointType* aColor = aPickingSettings->GetColor();
224 mySelectionColorButton->setColor( QColor( ( int )( aColor[0] * 255.0 ),
225 ( int )( aColor[1] * 255.0 ),
226 ( int )( aColor[2] * 255.0 ) ) );
228 myInfoWindowGroup->setChecked( aPickingSettings->GetInfoWindowEnabled() );
229 myTransparencySpinBox->setValue( int(aPickingSettings->GetInfoWindowTransparency() * 100.0) );
230 myPositionComboBox->setCurrentIndex( aPickingSettings->GetInfoWindowPosition() );
231 myCameraGroup->setChecked( aPickingSettings->GetCameraMovementEnabled() );
232 myZoomFactorSpinBox->setValue( aPickingSettings->GetZoomFactor() );
233 myStepNumberSpinBox->setValue( aPickingSettings->GetStepNumber() );
236 void VisuGUI_SelectionPrefDlg::accept()
243 void VisuGUI_SelectionPrefDlg::onApply()
245 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
247 aPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
248 aPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
249 aPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
251 QColor aButtonColor = mySelectionColorButton->color();
252 vtkFloatingPointType aColor[3];
253 aColor[0] = aButtonColor.red() / 255.0;
254 aColor[1] = aButtonColor.green() / 255.0;
255 aColor[2] = aButtonColor.blue() / 255.0;
256 aPickingSettings->SetColor( aColor );
258 aPickingSettings->SetInfoWindowEnabled( myInfoWindowGroup->isChecked() );
259 aPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 );
260 aPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentIndex() );
261 aPickingSettings->SetCameraMovementEnabled( myCameraGroup->isChecked() );
262 aPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() );
263 aPickingSettings->SetStepNumber( myStepNumberSpinBox->value() );
265 aPickingSettings->InvokeEvent( VISU::UpdatePickingSettingsEvent,NULL );
268 void VisuGUI_SelectionPrefDlg::onHelp()
270 QString aHelpFileName = "selection_preferences_page.html";
271 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
273 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
274 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
279 platform = "winapplication";
281 platform = "application";
283 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
284 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
285 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
289 void VisuGUI_SelectionPrefDlg::keyPressEvent( QKeyEvent* e )
291 QDialog::keyPressEvent( e );
292 if ( e->isAccepted() )
295 if ( e->key() == Qt::Key_F1 )