Salome HOME
9615a0476b182f0ead050fbb8045b16536598958
[modules/visu.git] / src / VISUGUI / VisuGUI_SelectionPrefDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : VisuGUI_SelectionPrefDlg.cxx
23 //  Author : Oleg UVAROV
24 //  Module : SALOME
25 //
26 #include "VisuGUI_SelectionPrefDlg.h"
27 #include "VisuGUI.h"
28
29 #include "VISU_PickingSettings.h"
30
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>
37
38 #include <LightApp_Application.h>
39
40 #include <QtxColorButton.h>
41 #include <QtxDoubleSpinBox.h>
42 #include <QtxIntSpinBox.h>
43
44 #include <QComboBox>
45 #include <QGroupBox>
46 #include <QKeyEvent>
47 #include <QLabel>
48 #include <QLayout>
49 #include <QLineEdit>
50 #include <QPushButton>
51
52 using namespace std;
53
54 /*!
55   Constructor
56 */
57 VisuGUI_SelectionPrefDlg::VisuGUI_SelectionPrefDlg( QWidget* parent )
58     : QDialog( parent ? parent : SUIT_Session::session()->activeApplication()->desktop(), 
59                Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
60 {
61   setWindowTitle( tr("TLT_SELECTION_PREFERENCES") );
62   setSizeGripEnabled( TRUE );
63   setModal( true );
64
65   QVBoxLayout* topLayout = new QVBoxLayout( this );
66   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
67
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);
74
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 ) );
78
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 ) );
85   
86   QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup );
87   mySelectionColorButton = new QtxColorButton( CursorGroup );
88   mySelectionColorButton->setColor( Qt::blue );
89
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 );
96
97   topLayout->addWidget( CursorGroup );
98
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);
105
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 ) );
109
110   ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
111   ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
112
113   topLayout->addWidget( ToleranceGroup );
114
115   // Information window
116   myInfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), this );
117   myInfoWindowGroup->setCheckable( true );
118
119   QGridLayout* InfoWindowGroupLayout = new QGridLayout (myInfoWindowGroup);
120   InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
121
122   QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), myInfoWindowGroup );
123   myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, myInfoWindowGroup );
124   myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125
126   InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
127   InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
128
129   QLabel* PositionLabel = new QLabel( tr( "POSITION" ), myInfoWindowGroup );
130   myPositionComboBox = new QComboBox( myInfoWindowGroup );
131   myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
132
133   myPositionComboBox->addItem( tr( "BELOW_POINT" ) );
134   myPositionComboBox->addItem( tr( "TOP_LEFT_CORNER" ) );
135
136   InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
137   InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
138   InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
139   InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
140
141   topLayout->addWidget( myInfoWindowGroup );
142
143   // Movement of the camera
144   myCameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), this );
145   myCameraGroup->setCheckable( true );
146
147   QGridLayout* CameraGroupLayout = new QGridLayout (myCameraGroup);
148   CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
149
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 ) );
153
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 ) );
158
159   CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
160   CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
161   CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
162   CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
163
164   topLayout->addWidget( myCameraGroup );
165
166   // Common buttons
167   QGroupBox* GroupButtons = new QGroupBox( this );
168   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
169   GroupButtonsLayout->setAlignment( Qt::AlignTop );
170   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
171   
172   myButtonOk = new QPushButton( GroupButtons );
173   myButtonOk->setText( tr( "BUT_OK"  ) );
174   myButtonOk->setAutoDefault( TRUE ); myButtonOk->setDefault( TRUE );
175   GroupButtonsLayout->addWidget( myButtonOk );
176
177   myButtonApply = new QPushButton( GroupButtons );
178   myButtonApply->setText( tr( "BUT_APPLY"  ) );
179   myButtonApply->setAutoDefault( TRUE );
180   GroupButtonsLayout->addWidget( myButtonApply );
181
182   GroupButtonsLayout->addStretch();
183   
184   myButtonCancel = new QPushButton( GroupButtons );
185   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
186   myButtonCancel->setAutoDefault( TRUE );
187   GroupButtonsLayout->addWidget( myButtonCancel );
188
189   myButtonHelp = new QPushButton( GroupButtons );
190   myButtonHelp->setText( tr( "BUT_HELP"  ) );
191   myButtonHelp->setAutoDefault( TRUE );
192   GroupButtonsLayout->addWidget( myButtonHelp );
193   /***************************************************************/
194   
195   //topLayout->addWidget( GroupC1 );
196   topLayout->addWidget( GroupButtons );
197   
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() ) );
203   
204   /* Move widget on the botton right corner of main widget */
205   SUIT_Tools::centerWidget( this, parent );
206 }
207
208 /*!
209   Destructor
210 */
211 VisuGUI_SelectionPrefDlg::~VisuGUI_SelectionPrefDlg()
212 {
213 }
214
215 void VisuGUI_SelectionPrefDlg::update()
216 {
217   VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
218
219   myCursorSizeSpinBox->setValue( aPickingSettings->GetCursorSize() );
220   myPyramidHeightSpinBox->setValue( aPickingSettings->GetPyramidHeight() );
221   myPointToleranceSpinBox->setValue( aPickingSettings->GetPointTolerance() );
222
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 ) ) );
227
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() );
234 }
235
236 void VisuGUI_SelectionPrefDlg::accept()
237 {
238   onApply();
239
240   QDialog::accept();
241 }
242
243 void VisuGUI_SelectionPrefDlg::onApply()
244 {
245   VISU_PickingSettings* aPickingSettings = VISU_PickingSettings::Get();
246
247   aPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
248   aPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
249   aPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
250
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 );
257
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() );
264
265   aPickingSettings->InvokeEvent( VISU::UpdatePickingSettingsEvent,NULL );
266 }
267
268 void VisuGUI_SelectionPrefDlg::onHelp()
269 {
270   QString aHelpFileName = "selection_preferences_page.html";
271   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
272   if (app) {
273     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
274     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
275   }
276   else {
277     QString platform;
278 #ifdef WIN32
279     platform = "winapplication";
280 #else
281     platform = "application";
282 #endif
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) );
286   }
287 }
288
289 void VisuGUI_SelectionPrefDlg::keyPressEvent( QKeyEvent* e )
290 {
291   QDialog::keyPressEvent( e );
292   if ( e->isAccepted() )
293     return;
294
295   if ( e->key() == Qt::Key_F1 )
296     {
297       e->accept();
298       onHelp();
299     }
300 }