1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VisuGUI_SelectionPrefDlg.cxx
21 // Author : Oleg UVAROV
24 #include "VisuGUI_SelectionPrefDlg.h"
26 #include "VisuGUI_Tools.h"
28 #include "VISU_PickingSettings.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_Application.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Tools.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <LightApp_Application.h>
39 #include <SalomeApp_IntSpinBox.h>
40 #include <SalomeApp_DoubleSpinBox.h>
42 #include <QtxColorButton.h>
50 #include <QPushButton>
55 VisuGUI_SelectionPrefDlg::VisuGUI_SelectionPrefDlg( QWidget* parent )
56 : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(),
57 Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
59 setWindowTitle( tr("TLT_SELECTION_PREFERENCES") );
60 setSizeGripEnabled( TRUE );
63 QVBoxLayout* topLayout = new QVBoxLayout( this );
64 topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
66 // Cursor (gauss points)
67 QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), this );
68 QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup);
69 CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
70 CursorGroupLayout->setSpacing(6);
71 CursorGroupLayout->setMargin(11);
73 QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup );
74 myCursorSizeSpinBox = new SalomeApp_DoubleSpinBox( CursorGroup );
75 VISU::initSpinBox( myCursorSizeSpinBox, 0, 1, 0.1, "parametric_precision" );
76 myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
78 QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup );
79 double aHeightMin=1.e-7;
80 double aHeightMax=10.;
81 double aHeightStep=0.1;
82 myPyramidHeightSpinBox = new SalomeApp_DoubleSpinBox(CursorGroup );
83 VISU::initSpinBox( myPyramidHeightSpinBox, aHeightMin, aHeightMax, aHeightStep, "length_precision" );
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 SalomeApp_DoubleSpinBox(ToleranceGroup );
108 VISU::initSpinBox( myPointToleranceSpinBox, 0.001, 10.0, 0.01, "len_tol_precision" );
109 myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
111 ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
112 ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
114 topLayout->addWidget( ToleranceGroup );
116 // Information window
117 myInfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), this );
118 myInfoWindowGroup->setCheckable( true );
120 QGridLayout* InfoWindowGroupLayout = new QGridLayout (myInfoWindowGroup);
121 InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
123 QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), myInfoWindowGroup );
124 myTransparencySpinBox = new SalomeApp_IntSpinBox( 0, 100, 10, myInfoWindowGroup );
125 myTransparencySpinBox->setAcceptNames( false );
126 myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
128 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
129 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
131 QLabel* PositionLabel = new QLabel( tr( "POSITION" ), myInfoWindowGroup );
132 myPositionComboBox = new QComboBox( myInfoWindowGroup );
133 myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
135 myPositionComboBox->addItem( tr( "BELOW_POINT" ) );
136 myPositionComboBox->addItem( tr( "TOP_LEFT_CORNER" ) );
138 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
139 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
140 InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
141 InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
143 topLayout->addWidget( myInfoWindowGroup );
145 // Movement of the camera
146 myCameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), this );
147 myCameraGroup->setCheckable( true );
149 QGridLayout* CameraGroupLayout = new QGridLayout (myCameraGroup);
150 CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
152 QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), myCameraGroup );
153 myZoomFactorSpinBox = new SalomeApp_DoubleSpinBox( myCameraGroup );
154 VISU::initSpinBox( myZoomFactorSpinBox, 0.1, 10.0, 0.1, "parametric_precision" );
155 myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
157 QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), myCameraGroup );
158 StepNumberLabel->setToolTip( tr( "STEP_NUMBER_TIP" ) );
159 myStepNumberSpinBox = new SalomeApp_IntSpinBox( 1, 100, 1, myCameraGroup );
160 myStepNumberSpinBox->setAcceptNames( false );
161 myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
163 CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
164 CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
165 CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
166 CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
168 topLayout->addWidget( myCameraGroup );
171 QGroupBox* GroupButtons = new QGroupBox( this );
172 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
173 GroupButtonsLayout->setAlignment( Qt::AlignTop );
174 GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
176 myButtonOk = new QPushButton( GroupButtons );
177 myButtonOk->setText( tr( "BUT_OK" ) );
178 myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
179 GroupButtonsLayout->addWidget( myButtonOk );
181 myButtonApply = new QPushButton( GroupButtons );
182 myButtonApply->setText( tr( "BUT_APPLY" ) );
183 myButtonApply->setAutoDefault( TRUE );
184 GroupButtonsLayout->addWidget( myButtonApply );
186 GroupButtonsLayout->addStretch();
188 myButtonCancel = new QPushButton( GroupButtons );
189 myButtonCancel->setText( tr( "BUT_CANCEL" ) );
190 myButtonCancel->setAutoDefault( TRUE );
191 GroupButtonsLayout->addWidget( myButtonCancel );
193 myButtonHelp = new QPushButton( GroupButtons );
194 myButtonHelp->setText( tr( "BUT_HELP" ) );
195 myButtonHelp->setAutoDefault( TRUE );
196 GroupButtonsLayout->addWidget( myButtonHelp );
197 /***************************************************************/
199 //topLayout->addWidget( GroupC1 );
200 topLayout->addWidget( GroupButtons );
202 // signals and slots connections
203 connect( myButtonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
204 connect( myButtonApply, SIGNAL( clicked() ), this, SLOT( onApply() ) );
205 connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
206 connect( myButtonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
208 /* Move widget on the botton right corner of main widget */
209 SUIT_Tools::centerWidget( this, parent );
215 VisuGUI_SelectionPrefDlg::~VisuGUI_SelectionPrefDlg()
219 void VisuGUI_SelectionPrefDlg::update()
221 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
223 myCursorSizeSpinBox->setValue( aPickingSettings->GetCursorSize() );
224 myPyramidHeightSpinBox->setValue( aPickingSettings->GetPyramidHeight() );
225 myPointToleranceSpinBox->setValue( aPickingSettings->GetPointTolerance() );
227 vtkFloatingPointType* aColor = aPickingSettings->GetColor();
228 mySelectionColorButton->setColor( QColor( ( int )( aColor[0] * 255.0 ),
229 ( int )( aColor[1] * 255.0 ),
230 ( int )( aColor[2] * 255.0 ) ) );
232 myInfoWindowGroup->setChecked( aPickingSettings->GetInfoWindowEnabled() );
233 myTransparencySpinBox->setValue( int(aPickingSettings->GetInfoWindowTransparency() * 100.0) );
234 myPositionComboBox->setCurrentIndex( aPickingSettings->GetInfoWindowPosition() );
235 myCameraGroup->setChecked( aPickingSettings->GetCameraMovementEnabled() );
236 myZoomFactorSpinBox->setValue( aPickingSettings->GetZoomFactor() );
237 myStepNumberSpinBox->setValue( aPickingSettings->GetStepNumber() );
240 void VisuGUI_SelectionPrefDlg::accept()
247 void VisuGUI_SelectionPrefDlg::onApply()
249 VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
251 aPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
252 aPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
253 aPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
255 QColor aButtonColor = mySelectionColorButton->color();
256 vtkFloatingPointType aColor[3];
257 aColor[0] = aButtonColor.red() / 255.0;
258 aColor[1] = aButtonColor.green() / 255.0;
259 aColor[2] = aButtonColor.blue() / 255.0;
260 aPickingSettings->SetColor( aColor );
262 aPickingSettings->SetInfoWindowEnabled( myInfoWindowGroup->isChecked() );
263 aPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 );
264 aPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentIndex() );
265 aPickingSettings->SetCameraMovementEnabled( myCameraGroup->isChecked() );
266 aPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() );
267 aPickingSettings->SetStepNumber( myStepNumberSpinBox->value() );
269 aPickingSettings->InvokeEvent( VISU::UpdatePickingSettingsEvent,NULL );
272 void VisuGUI_SelectionPrefDlg::onHelp()
274 QString aHelpFileName = "selection_preferences_page.html";
275 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
277 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
278 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
283 platform = "winapplication";
285 platform = "application";
287 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
288 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
289 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
293 void VisuGUI_SelectionPrefDlg::keyPressEvent( QKeyEvent* e )
295 QDialog::keyPressEvent( e );
296 if ( e->isAccepted() )
299 if ( e->key() == Qt::Key_F1 )