]> SALOME platform Git repositories - modules/visu.git/blob - src/VVTK/VVTK_PickingDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VVTK / VVTK_PickingDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VVTK_PickingDlg.cxx
21 //  Author : Oleg Uvarov
22 //  Module : VISU
23
24 #include "VVTK_PickingDlg.h"
25
26 #include "VISU_GaussPtsAct.h"
27 #include "VISU_GaussPtsSettings.h"
28 #include "VISU_GaussPointsPL.hxx"
29
30 #include "SUIT_MessageBox.h"
31 #include "SUIT_ResourceMgr.h"
32 #include "SUIT_Session.h"
33
34 #include "SVTK_Selector.h"
35 #include "SVTK_MainWindow.h"
36 #include "SVTK_RenderWindowInteractor.h"
37
38 #include "VTKViewer_Algorithm.h"
39 #include "SVTK_Functor.h"
40
41 #include <vtkActorCollection.h>
42 #include <vtkCallbackCommand.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkRenderer.h>
45 #include <vtkGenericRenderWindowInteractor.h>
46 #include <vtkSmartPointer.h>
47
48 #include "utilities.h"
49
50 #include <qcheckbox.h>
51 #include <qcolordialog.h>
52 #include <qcombobox.h>
53 #include <qgroupbox.h>
54 #include <qlabel.h>
55 #include <qlayout.h>
56 #include <qpushbutton.h>
57 #include <qvbox.h>
58 #include <qvalidator.h>
59
60 #include "QtxAction.h"
61 #include "QtxDblSpinBox.h"
62 #include "QtxIntSpinBox.h"
63
64 #include "LightApp_Application.h"
65
66 namespace
67 {
68   struct SelectorHelper
69   {
70   public:
71     SelectorHelper( SVTK_RenderWindowInteractor* theInteractor ):
72       myInteractor( theInteractor )
73     {}
74
75     bool
76     get()
77     {
78       bool aResult = false;
79       myMapIndex.Clear();
80       mySelector = NULL;
81       myPipeLine = NULL;
82       myActor = NULL;
83
84       if ( !myInteractor )
85         return aResult;
86       
87       mySelector = myInteractor->GetSelector();
88       if ( !mySelector )
89         return aResult;
90       
91       const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
92       if ( aListIO.Extent() != 1 ) 
93         return aResult;
94       
95       myIO = aListIO.First();
96       if ( mySelector->HasIndex( myIO ) )
97         mySelector->GetIndex(myIO, myMapIndex);
98         
99       myActor = SVTK::Find<VISU_GaussPtsAct>(myInteractor->getRenderer()->GetActors(),
100                                              SVTK::TIsSameIObject<VISU_GaussPtsAct>( myIO ));
101       if ( !myActor )
102         return aResult;
103       
104       myPipeLine = myActor->GetGaussPointsPL();
105
106       return true;
107     }
108
109     SVTK_RenderWindowInteractor* myInteractor;
110     TColStd_IndexedMapOfInteger myMapIndex;
111     Handle(SALOME_InteractiveObject) myIO;
112     SVTK_Selector* mySelector;
113
114     VISU_GaussPointsPL* myPipeLine;
115     VISU_GaussPtsAct* myActor;
116   };
117
118
119   
120   class GaussPtsIDValidator: public QIntValidator
121   {
122   public:
123     GaussPtsIDValidator( SVTK_RenderWindowInteractor* theInteractor,
124                          QObject * theParent ):
125       QIntValidator( 0, VTK_LARGE_ID, theParent ),
126       myHelper(theInteractor)
127     {}
128
129     virtual 
130     State
131     validate ( QString & theInput, int & thePos ) const
132     {
133       if ( QIntValidator::validate( theInput, thePos ) == QValidator::Invalid)
134         return QValidator::Invalid;
135       
136       if ( !myHelper.get() )
137         return QValidator::Invalid;
138
139       return QValidator::Acceptable;
140     }
141
142   protected:
143     mutable SelectorHelper myHelper;
144   };
145
146
147   class GaussCellIDValidator: public GaussPtsIDValidator
148   {
149   public:
150     GaussCellIDValidator( QLineEdit* theLocalPointLabel,
151                           SVTK_RenderWindowInteractor* theInteractor,
152                           QObject * theParent ):
153       GaussPtsIDValidator( theInteractor, theParent ),
154       myLocalPointLineEdit( theLocalPointLabel )
155     {}
156
157     virtual 
158     State
159     validate ( QString & theInput, int & thePos ) const
160     {
161       if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid)
162         return QValidator::Invalid;
163
164       VISU::TCellID aCellID = theInput.toInt();
165       VISU::TLocalPntID aLocalPntID = myLocalPointLineEdit->text().toInt();
166       VISU::PGaussPtsIDMapper anIDMapper = myHelper.myPipeLine->GetGaussPtsIDMapper();
167       if ( anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) ) < 0 )
168         return QValidator::Intermediate;
169
170       return QValidator::Acceptable;
171     }
172
173   private:
174     QLineEdit* myLocalPointLineEdit;
175   };
176
177
178   class GaussLocalPointIDValidator: public GaussPtsIDValidator
179   {
180   public:
181     GaussLocalPointIDValidator( QLineEdit* theParentElementLineEdit,
182                                 SVTK_RenderWindowInteractor* theInteractor,
183                                 QObject * theParent ):
184       GaussPtsIDValidator( theInteractor, theParent ),
185       myParentElementLineEdit( theParentElementLineEdit )
186     {}
187
188     virtual 
189     State
190     validate ( QString & theInput, int & thePos ) const
191     {
192       if ( GaussPtsIDValidator::validate( theInput, thePos ) == QValidator::Invalid)
193         return QValidator::Invalid;
194
195       VISU::TLocalPntID aLocalPntID = theInput.toInt();
196       VISU::TCellID aCellID = myParentElementLineEdit->text().toInt();
197       VISU::PGaussPtsIDMapper anIDMapper = myHelper.myPipeLine->GetGaussPtsIDMapper();
198       if ( anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) ) < 0 )
199         return QValidator::Intermediate;
200
201       return QValidator::Acceptable;
202     }
203
204   private:
205     QLineEdit* myParentElementLineEdit;
206   };
207 }
208
209
210 VVTK_ValidatedLineEdit::VVTK_ValidatedLineEdit( QWidget * parent, const char * name ):
211   QLineEdit( parent, name )
212 {
213   connect( this, SIGNAL( textChanged( const QString& ) ), this, SLOT( MarkValidated( const QString& ) ) );
214 }
215
216 void VVTK_ValidatedLineEdit::MarkValidated( const QString& theText )
217 {
218   if ( !validator() )
219     return;
220   
221   int aPos;
222   QString aText( theText );
223   switch ( validator()->validate( aText, aPos ) ) {
224   case QValidator::Invalid:
225   case QValidator::Intermediate:
226     setPaletteForegroundColor( QColor( 255, 0, 0 ) );
227     break;
228   case QValidator::Acceptable:
229     setPaletteForegroundColor( QColor( 0, 0, 0 ) );
230     break;
231   }
232 }
233
234 //---------------------------------------------------------------------------------
235
236 VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction,
237                                  SVTK_MainWindow* theParent,
238                                  const char* theName):
239   SVTK_DialogBase(theAction,
240                   theParent, 
241                   theName),
242   myEventCallbackCommand( vtkCallbackCommand::New() ),
243   myPickingSettings( VISU_PickingSettings::New() )
244 {
245   myPriority = 0.0;
246   myEventCallbackCommand->Delete();
247   myEventCallbackCommand->SetClientData(this); 
248   myEventCallbackCommand->SetCallback(VVTK_PickingDlg::ProcessEvents);
249
250   setCaption( tr( "PICKING_DLG_TITLE" ) );
251   setSizeGripEnabled(TRUE);
252
253   QVBoxLayout* TopLayout = new QVBoxLayout( this );
254   TopLayout->setSpacing(6);
255   TopLayout->setMargin(11);
256
257   QVBox* aBox = new QVBox( this );
258   aBox->setMargin(0);
259   aBox->setSpacing(6);
260
261   // Cursor
262   QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), aBox, "CursorGroup" );
263   CursorGroup->setColumnLayout(0, Qt::Vertical );
264   CursorGroup->layout()->setSpacing( 0 );
265   CursorGroup->layout()->setMargin( 0 );
266
267   QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup->layout());
268   CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
269   CursorGroupLayout->setSpacing(6);
270   CursorGroupLayout->setMargin(11);
271
272   QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup );
273   myCursorSizeSpinBox = new QtxDblSpinBox( 0, 1, 0.1, CursorGroup );
274   myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
275
276   QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup );
277   double aHeightMin=1.e-7;
278   double aHeightMax=10.;
279   double aHeightStep=0.1;
280   myPyramidHeightSpinBox = new QtxDblSpinBox(aHeightMin, aHeightMax, aHeightStep, CursorGroup );
281   myPyramidHeightSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
282   
283   QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup );
284   mySelectionColorButton = new QPushButton( CursorGroup );
285   mySelectionColorButton->setPaletteBackgroundColor( Qt::blue );
286   mySelectionColorButton->setPaletteForegroundColor( Qt::blue );
287   connect( mySelectionColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
288
289   CursorGroupLayout->addWidget( CursorSizeLabel, 0, 0 );
290   CursorGroupLayout->addWidget( myCursorSizeSpinBox, 0, 1 );
291   CursorGroupLayout->addWidget( PyramidHeightLabel, 1, 0 );
292   CursorGroupLayout->addWidget( myPyramidHeightSpinBox, 1, 1 );
293   CursorGroupLayout->addWidget( SelectionColorLabel, 2, 0 );
294   CursorGroupLayout->addWidget( mySelectionColorButton, 2, 1 );
295
296   // Tolerance
297   QGroupBox* ToleranceGroup = new QGroupBox( tr( "TOLERANCE_TITLE" ), aBox, "ToleranceGroup" );
298   ToleranceGroup->setColumnLayout(0, Qt::Vertical );
299   ToleranceGroup->layout()->setSpacing( 0 );
300   ToleranceGroup->layout()->setMargin( 0 );
301
302   QGridLayout* ToleranceGroupLayout = new QGridLayout (ToleranceGroup->layout());
303   ToleranceGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
304   ToleranceGroupLayout->setSpacing(6);
305   ToleranceGroupLayout->setMargin(11);
306
307   QLabel* PointToleranceLabel = new QLabel( tr( "POINT_TOLERANCE" ), ToleranceGroup );
308   myPointToleranceSpinBox = new QtxDblSpinBox( 0.001, 10.0, 0.01, ToleranceGroup );
309   myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
310
311   ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
312   ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
313
314   // Information window
315   QGroupBox* InfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), aBox, "InfoWindowGroup" );
316   InfoWindowGroup->setColumnLayout(0, Qt::Vertical );
317   InfoWindowGroup->layout()->setSpacing( 0 );
318   InfoWindowGroup->layout()->setMargin( 0 );
319
320   QGridLayout* InfoWindowGroupLayout = new QGridLayout (InfoWindowGroup->layout());
321   InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
322   InfoWindowGroupLayout->setSpacing(6);
323   InfoWindowGroupLayout->setMargin(11);
324
325   QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), InfoWindowGroup );
326   myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, InfoWindowGroup );
327   myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
328
329   InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
330   InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
331
332   QLabel* PositionLabel = new QLabel( tr( "POSITION" ), InfoWindowGroup );
333   myPositionComboBox = new QComboBox( InfoWindowGroup );
334   myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
335
336   myPositionComboBox->insertItem( tr( "BELOW_POINT" ) );
337   myPositionComboBox->insertItem( tr( "TOP_LEFT_CORNER" ) );
338
339   InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
340   InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
341   InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
342   InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
343
344   // Movement of the camera
345   QGroupBox* CameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), aBox, "CameraGroup" );
346   CameraGroup->setColumnLayout(0, Qt::Vertical );
347   CameraGroup->layout()->setSpacing( 0 );
348   CameraGroup->layout()->setMargin( 0 );
349
350   QGridLayout* CameraGroupLayout = new QGridLayout (CameraGroup->layout());
351   CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
352   CameraGroupLayout->setSpacing(6);
353   CameraGroupLayout->setMargin(11);
354
355   QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), CameraGroup );
356   myZoomFactorSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1, CameraGroup );
357   myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
358
359   QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), CameraGroup );
360   myStepNumberSpinBox = new QtxIntSpinBox( 1, 100, 1, CameraGroup );
361   myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
362
363   CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
364   CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
365   CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
366   CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
367
368   // Display parent mesh element
369   QGroupBox* PositionGroup = new QGroupBox( tr( "DATA_POSITION" ), aBox, "Position" );
370   PositionGroup->setColumnLayout(0, Qt::Vertical );
371   PositionGroup->layout()->setSpacing( 0 );
372   PositionGroup->layout()->setMargin( 0 );
373
374   QGridLayout* PositionGroupLayout = new QGridLayout (PositionGroup->layout());
375   PositionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
376   PositionGroupLayout->setSpacing(6);
377   PositionGroupLayout->setMargin(11);
378
379   QLabel* ParentElementLabel = new QLabel( tr( "PARENT_ELEMENT" ), PositionGroup );
380   PositionGroupLayout->addMultiCellWidget( ParentElementLabel, 0, 0, 0, 2 );
381
382   myParentElementLineEdit = new VVTK_ValidatedLineEdit( PositionGroup );
383   PositionGroupLayout->addMultiCellWidget( myParentElementLineEdit, 0, 0, 3, 3 );
384
385   QLabel* LocalPointLabel = new QLabel( tr( "LOCAL_POINT" ), PositionGroup );
386   PositionGroupLayout->addMultiCellWidget( LocalPointLabel, 1, 1, 0, 2 );
387
388   myLocalPointLineEdit = new VVTK_ValidatedLineEdit( PositionGroup );
389   PositionGroupLayout->addMultiCellWidget( myLocalPointLineEdit, 1, 1, 3, 3 );
390
391   myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), PositionGroup );
392   PositionGroupLayout->addMultiCellWidget( myDisplayParentMeshCheckBox, 2, 2, 0, 3 );
393
394   // Common buttons ===========================================================
395   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
396   GroupButtons->setColumnLayout(0, Qt::Vertical );
397   GroupButtons->layout()->setSpacing( 0 );
398   GroupButtons->layout()->setMargin( 0 );
399   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
400   GroupButtonsLayout->setAlignment( Qt::AlignTop );
401   GroupButtonsLayout->setSpacing( 6 );
402   GroupButtonsLayout->setMargin( 11 );
403
404   QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
405   buttonApply->setAutoDefault( TRUE );
406   buttonApply->setDefault( TRUE );
407   GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
408   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
409
410   QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
411   buttonClose->setAutoDefault( TRUE );
412   GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
413
414   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
415   buttonHelp->setAutoDefault( TRUE );
416   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
417
418   TopLayout->addWidget( aBox );
419   TopLayout->addWidget( GroupButtons );
420
421   connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
422   connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
423   connect( buttonHelp,  SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
424
425   connect( myParentElementLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onSelectionValidate() ) );
426   connect( myLocalPointLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onSelectionValidate() ) );
427
428 }
429
430 VVTK_PickingDlg::~VVTK_PickingDlg()
431 {
432 }
433
434 void VVTK_PickingDlg::AddActor( VISU_GaussPtsAct* theActor )
435 {
436   theActor->SetPickingSettings( myPickingSettings.GetPointer() );
437 }
438
439 void VVTK_PickingDlg::RemoveActor( VISU_GaussPtsAct* theActor )
440 {
441   theActor->SetPickingSettings( NULL );
442 }
443
444 void VVTK_PickingDlg::Update()
445 {
446   float aCursorSize = 0.5;
447   float aPyramidHeight = 10.0;
448   float aPointTolerance = 0.1;
449   QColor aColor = Qt::yellow;
450   int anInfoWindowTransparency = 50;
451   int anInfoWindowPosition = VISU_PickingSettings::BelowPoint;
452   float aZoomFactor = 1.5;
453   int aStepNumber = 10;
454   bool aDisplayParentMesh = false;
455
456   if( !myPickingSettings->GetInitial() )
457   {
458     myCursorSizeSpinBox->setValue( myPickingSettings->GetCursorSize() );
459     myPyramidHeightSpinBox->setValue( myPickingSettings->GetPyramidHeight() );
460     myPointToleranceSpinBox->setValue( myPickingSettings->GetPointTolerance() );
461     myTransparencySpinBox->setValue( int(myPickingSettings->GetInfoWindowTransparency() * 100.0) );
462     myPositionComboBox->setCurrentItem( myPickingSettings->GetInfoWindowPosition() );
463     myZoomFactorSpinBox->setValue( myPickingSettings->GetZoomFactor() );
464     myStepNumberSpinBox->setValue( myPickingSettings->GetStepNumber() );
465     myDisplayParentMeshCheckBox->setChecked( myPickingSettings->GetDisplayParentMesh() );
466
467     vtkFloatingPointType* aColor = myPickingSettings->GetColor();
468     mySelectionColorButton->setPaletteBackgroundColor( QColor( ( int )( aColor[0] * 255.0 ),
469                                                                ( int )( aColor[1] * 255.0 ),
470                                                                ( int )( aColor[2] * 255.0 ) ) );
471
472     return;
473   }
474
475   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
476
477   aCursorSize = aResourceMgr->doubleValue( "VISU", "picking_cursor_size", aCursorSize );
478   myCursorSizeSpinBox->setValue( aCursorSize );
479
480   aPyramidHeight = aResourceMgr->doubleValue( "VISU", "picking_pyramid_height", aPyramidHeight );
481   myPyramidHeightSpinBox->setValue( aPyramidHeight );
482
483   aPointTolerance = aResourceMgr->doubleValue( "VISU", "picking_point_tolerance", aPointTolerance );
484   myPointToleranceSpinBox->setValue( aPointTolerance );
485
486   aColor = aResourceMgr->colorValue( "VISU", "picking_selection_color", aColor );
487   mySelectionColorButton->setPaletteBackgroundColor( aColor );
488
489   anInfoWindowTransparency = aResourceMgr->integerValue( "VISU", "picking_transparency", anInfoWindowTransparency );
490   myTransparencySpinBox->setValue( anInfoWindowTransparency );
491
492   anInfoWindowPosition = aResourceMgr->integerValue( "VISU", "picking_position", anInfoWindowPosition );
493   myPositionComboBox->setCurrentItem( anInfoWindowPosition );
494
495   aZoomFactor = aResourceMgr->doubleValue( "VISU", "picking_zoom_factor", aZoomFactor );
496   myZoomFactorSpinBox->setValue( aZoomFactor );
497
498   aStepNumber = aResourceMgr->integerValue( "VISU", "picking_step_number", aStepNumber );
499   myStepNumberSpinBox->setValue( aStepNumber );
500
501   aDisplayParentMesh = aResourceMgr->booleanValue( "VISU", "picking_display_parent_mesh", aDisplayParentMesh );
502   myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
503
504   onClickApply();
505 }
506
507 void VVTK_PickingDlg::onSelectionValidate() 
508 {
509   myParentElementLineEdit->MarkValidated( myParentElementLineEdit->text() );
510   myLocalPointLineEdit->MarkValidated( myLocalPointLineEdit->text() );
511 }
512
513 void VVTK_PickingDlg::onSelectionEvent() 
514 {
515   SelectorHelper aHelper( myInteractor );
516   if ( !aHelper.get() )
517     return;
518
519   const TColStd_IndexedMapOfInteger& aMapIndex = aHelper.myMapIndex;
520   if ( aMapIndex.Extent() != 1 )
521     return;
522
523   int anObjId = aHelper.myMapIndex(1);
524
525   VISU::TGaussPointID aGaussPointID = aHelper.myPipeLine->GetObjID( anObjId );
526
527   VISU::TCellID aCellID = aGaussPointID.first;
528   myParentElementLineEdit->setText( QString::number( aCellID ) );
529
530   VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
531   myLocalPointLineEdit->setText( QString::number( aLocalPntID ) );
532 }
533
534 VISU_PickingSettings* 
535 VVTK_PickingDlg
536 ::GetPickingSettings()
537 {
538   return myPickingSettings.GetPointer();
539 }
540
541 void VVTK_PickingDlg::SetInteractor( SVTK_RenderWindowInteractor* theInteractor )
542 {
543   myInteractor = theInteractor;
544
545   theInteractor->GetDevice()->AddObserver(vtkCommand::KeyPressEvent, 
546                                           myEventCallbackCommand.GetPointer(), 
547                                           myPriority);
548   theInteractor->GetDevice()->AddObserver(vtkCommand::EndPickEvent, 
549                                           myEventCallbackCommand.GetPointer(), 
550                                           myPriority);
551   {
552     QValidator* aValidator = new GaussCellIDValidator( myLocalPointLineEdit, theInteractor, myParentElementLineEdit );
553     myParentElementLineEdit->setValidator( aValidator );
554   }
555   {
556     QValidator* aValidator = new GaussLocalPointIDValidator( myParentElementLineEdit, theInteractor, myLocalPointLineEdit );
557     myLocalPointLineEdit->setValidator( aValidator );
558   }
559 }
560
561 void VVTK_PickingDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
562                                     unsigned long theEvent,
563                                     void* theClientData, 
564                                     void* vtkNotUsed(theCallData))
565 {
566   VVTK_PickingDlg* self = reinterpret_cast<VVTK_PickingDlg*>(theClientData);
567
568   switch(theEvent){
569   case vtkCommand::KeyPressEvent:
570     self->KeyPressed();
571     break;
572   case vtkCommand::EndPickEvent:
573     self->onSelectionEvent();
574     break;
575   }
576 }
577
578 void VVTK_PickingDlg::KeyPressed()
579 {
580   if( myInteractor->GetDevice()->GetKeyCode() == 'P' )
581   {
582     bool aDisplayParentMesh = !myPickingSettings->GetDisplayParentMesh();
583     myPickingSettings->SetDisplayParentMesh( aDisplayParentMesh );
584
585     myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
586
587     myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL);
588   }
589 }
590
591 void VVTK_PickingDlg::onClickApply()
592 {
593   myPickingSettings->SetInitial( false );
594
595   myPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
596   myPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
597   myPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
598   myPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 );
599   myPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentItem() );
600   myPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() );
601   myPickingSettings->SetStepNumber( myStepNumberSpinBox->value() );
602   myPickingSettings->SetDisplayParentMesh( myDisplayParentMeshCheckBox->isChecked() );
603
604   QColor aButtonColor = mySelectionColorButton->paletteBackgroundColor();
605   vtkFloatingPointType aColor[3];
606   aColor[0] = aButtonColor.red() / 255.0;
607   aColor[1] = aButtonColor.green() / 255.0;
608   aColor[2] = aButtonColor.blue() / 255.0;
609   myPickingSettings->SetColor( aColor );
610
611   myPickingSettings->InvokeEvent( VISU::UpdatePickingSettingsEvent,NULL );
612
613   SelectorHelper aHelper( myInteractor );
614   if ( !aHelper.get() )
615     return;
616
617   VISU::TCellID aCellID = myParentElementLineEdit->text().toInt();
618   VISU::TLocalPntID aLocalPntID = myLocalPointLineEdit->text().toInt();
619   VISU::PGaussPtsIDMapper anIDMapper = aHelper.myPipeLine->GetGaussPtsIDMapper();
620   vtkIdType anObjId = anIDMapper->GetVTKID( VISU::TGaussPointID( aCellID, aLocalPntID ) );
621   if ( anObjId < 0 )
622     return;
623
624   aHelper.myMapIndex.Clear();
625   aHelper.myMapIndex.Add( anObjId );
626   aHelper.mySelector->AddOrRemoveIndex( aHelper.myIO, aHelper.myMapIndex, false );
627   aHelper.myActor->Highlight( aHelper.myIO );
628   myInteractor->GetDevice()->CreateTimer( VTKI_TIMER_FIRST );
629 }
630
631 void VVTK_PickingDlg::onClickClose()
632 {
633   reject();
634 }
635
636 void VVTK_PickingDlg::onClickHelp()
637 {
638   QString aHelpFileName = "picking.htm";
639   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
640   if (app)
641     app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
642   else {
643                 QString platform;
644 #ifdef WIN32
645                 platform = "winapplication";
646 #else
647                 platform = "application";
648 #endif
649     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
650                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
651                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
652                            QObject::tr("BUT_OK"));
653   }
654 }
655
656 void VVTK_PickingDlg::onColorButtonPressed()
657 {
658   QColor aColor = QColorDialog::getColor( mySelectionColorButton->paletteBackgroundColor(), this );
659   if( aColor.isValid() )
660     mySelectionColorButton->setPaletteBackgroundColor( aColor );
661 }
662
663 void VVTK_PickingDlg::keyPressEvent( QKeyEvent* e )
664 {
665   QDialog::keyPressEvent( e );
666   if ( e->isAccepted() )
667     return;
668
669   if ( e->key() == Key_F1 )
670     {
671       e->accept();
672       onClickHelp();
673     }
674 }