1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VVTK_PickingDlg.cxx
8 // Author : Oleg Uvarov
11 #include "VVTK_PickingDlg.h"
13 #include "VISU_GaussPtsAct.h"
14 #include "VISU_GaussPtsSettings.h"
16 #include "SUIT_MessageBox.h"
17 #include "SUIT_ResourceMgr.h"
18 #include "SUIT_Session.h"
20 #include "SVTK_MainWindow.h"
21 #include "SVTK_RenderWindowInteractor.h"
23 #include <vtkActorCollection.h>
24 #include <vtkCallbackCommand.h>
25 #include <vtkObjectFactory.h>
26 #include <vtkRenderer.h>
27 #include <vtkGenericRenderWindowInteractor.h>
28 #include <vtkSmartPointer.h>
30 #include "utilities.h"
32 #include <qcheckbox.h>
33 #include <qcolordialog.h>
34 #include <qcombobox.h>
35 #include <qgroupbox.h>
38 #include <qpushbutton.h>
41 #include "QtxAction.h"
42 #include "QtxDblSpinBox.h"
43 #include "QtxIntSpinBox.h"
45 #include "LightApp_Application.h"
49 VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction,
50 SVTK_MainWindow* theParent,
52 SVTK_DialogBase(theAction,
55 myEventCallbackCommand( vtkCallbackCommand::New() ),
56 myPickingSettings( VISU_PickingSettings::New() )
59 myEventCallbackCommand->Delete();
60 myEventCallbackCommand->SetClientData(this);
61 myEventCallbackCommand->SetCallback(VVTK_PickingDlg::ProcessEvents);
63 setCaption( tr( "PICKING_DLG_TITLE" ) );
64 setSizeGripEnabled(TRUE);
66 QVBoxLayout* TopLayout = new QVBoxLayout( this );
67 TopLayout->setSpacing(6);
68 TopLayout->setMargin(11);
70 QVBox* aBox = new QVBox( this );
75 QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), aBox, "CursorGroup" );
76 CursorGroup->setColumnLayout(0, Qt::Vertical );
77 CursorGroup->layout()->setSpacing( 0 );
78 CursorGroup->layout()->setMargin( 0 );
80 QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup->layout());
81 CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
82 CursorGroupLayout->setSpacing(6);
83 CursorGroupLayout->setMargin(11);
85 QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup );
86 myCursorSizeSpinBox = new QtxDblSpinBox( 0, 1, 0.1, CursorGroup );
87 myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89 QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup );
90 double aHeightMin=1.e-7;
91 double aHeightMax=10.;
92 double aHeightStep=0.1;
93 myPyramidHeightSpinBox = new QtxDblSpinBox(aHeightMin, aHeightMax, aHeightStep, CursorGroup );
94 myPyramidHeightSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96 QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup );
97 mySelectionColorButton = new QPushButton( CursorGroup );
98 mySelectionColorButton->setPaletteBackgroundColor( Qt::blue );
99 mySelectionColorButton->setPaletteForegroundColor( Qt::blue );
100 connect( mySelectionColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
102 CursorGroupLayout->addWidget( CursorSizeLabel, 0, 0 );
103 CursorGroupLayout->addWidget( myCursorSizeSpinBox, 0, 1 );
104 CursorGroupLayout->addWidget( PyramidHeightLabel, 1, 0 );
105 CursorGroupLayout->addWidget( myPyramidHeightSpinBox, 1, 1 );
106 CursorGroupLayout->addWidget( SelectionColorLabel, 2, 0 );
107 CursorGroupLayout->addWidget( mySelectionColorButton, 2, 1 );
110 QGroupBox* ToleranceGroup = new QGroupBox( tr( "TOLERANCE_TITLE" ), aBox, "ToleranceGroup" );
111 ToleranceGroup->setColumnLayout(0, Qt::Vertical );
112 ToleranceGroup->layout()->setSpacing( 0 );
113 ToleranceGroup->layout()->setMargin( 0 );
115 QGridLayout* ToleranceGroupLayout = new QGridLayout (ToleranceGroup->layout());
116 ToleranceGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
117 ToleranceGroupLayout->setSpacing(6);
118 ToleranceGroupLayout->setMargin(11);
120 QLabel* PointToleranceLabel = new QLabel( tr( "POINT_TOLERANCE" ), ToleranceGroup );
121 myPointToleranceSpinBox = new QtxDblSpinBox( 0.001, 10.0, 0.01, ToleranceGroup );
122 myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
124 ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
125 ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
127 // Information window
128 QGroupBox* InfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), aBox, "InfoWindowGroup" );
129 InfoWindowGroup->setColumnLayout(0, Qt::Vertical );
130 InfoWindowGroup->layout()->setSpacing( 0 );
131 InfoWindowGroup->layout()->setMargin( 0 );
133 QGridLayout* InfoWindowGroupLayout = new QGridLayout (InfoWindowGroup->layout());
134 InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
135 InfoWindowGroupLayout->setSpacing(6);
136 InfoWindowGroupLayout->setMargin(11);
138 QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), InfoWindowGroup );
139 myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, InfoWindowGroup );
140 myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
143 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
145 QLabel* PositionLabel = new QLabel( tr( "POSITION" ), InfoWindowGroup );
146 myPositionComboBox = new QComboBox( InfoWindowGroup );
147 myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
149 myPositionComboBox->insertItem( tr( "BELOW_POINT" ) );
150 myPositionComboBox->insertItem( tr( "TOP_LEFT_CORNER" ) );
152 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
153 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
154 InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
155 InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
157 // Movement of the camera
158 QGroupBox* CameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), aBox, "CameraGroup" );
159 CameraGroup->setColumnLayout(0, Qt::Vertical );
160 CameraGroup->layout()->setSpacing( 0 );
161 CameraGroup->layout()->setMargin( 0 );
163 QGridLayout* CameraGroupLayout = new QGridLayout (CameraGroup->layout());
164 CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
165 CameraGroupLayout->setSpacing(6);
166 CameraGroupLayout->setMargin(11);
168 QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), CameraGroup );
169 myZoomFactorSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1, CameraGroup );
170 myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
172 QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), CameraGroup );
173 myStepNumberSpinBox = new QtxIntSpinBox( 1, 100, 1, CameraGroup );
174 myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
176 CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
177 CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
178 CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
179 CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
181 // Display parent mesh element
182 QGroupBox* ParentMeshGroup = new QGroupBox( tr( "PARENT_MESH_TITLE" ), aBox, "ParentMeshGroup" );
183 ParentMeshGroup->setColumnLayout(0, Qt::Vertical );
184 ParentMeshGroup->layout()->setSpacing( 0 );
185 ParentMeshGroup->layout()->setMargin( 0 );
187 QGridLayout* ParentMeshGroupLayout = new QGridLayout (ParentMeshGroup->layout());
188 ParentMeshGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
189 ParentMeshGroupLayout->setSpacing(6);
190 ParentMeshGroupLayout->setMargin(11);
192 myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), ParentMeshGroup );
193 ParentMeshGroupLayout->addWidget( myDisplayParentMeshCheckBox, 0, 0 );
195 // Common buttons ===========================================================
196 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
197 GroupButtons->setColumnLayout(0, Qt::Vertical );
198 GroupButtons->layout()->setSpacing( 0 );
199 GroupButtons->layout()->setMargin( 0 );
200 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
201 GroupButtonsLayout->setAlignment( Qt::AlignTop );
202 GroupButtonsLayout->setSpacing( 6 );
203 GroupButtonsLayout->setMargin( 11 );
205 QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
206 buttonApply->setAutoDefault( TRUE );
207 buttonApply->setDefault( TRUE );
208 GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
209 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
211 QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
212 buttonClose->setAutoDefault( TRUE );
213 GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
215 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
216 buttonHelp->setAutoDefault( TRUE );
217 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
219 TopLayout->addWidget( aBox );
220 TopLayout->addWidget( GroupButtons );
222 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
223 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
224 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
227 VVTK_PickingDlg::~VVTK_PickingDlg()
231 void VVTK_PickingDlg::AddActor( VISU_GaussPtsAct* theActor )
233 theActor->SetPickingSettings( myPickingSettings.GetPointer() );
236 void VVTK_PickingDlg::RemoveActor( VISU_GaussPtsAct* theActor )
238 theActor->SetPickingSettings( NULL );
241 void VVTK_PickingDlg::Update()
243 float aCursorSize = 0.5;
244 float aPyramidHeight = 10.0;
245 float aPointTolerance = 0.1;
246 QColor aColor = Qt::yellow;
247 int anInfoWindowTransparency = 50;
248 int anInfoWindowPosition = VISU_PickingSettings::BelowPoint;
249 float aZoomFactor = 1.5;
250 int aStepNumber = 10;
251 bool aDisplayParentMesh = false;
253 if( !myPickingSettings->GetInitial() )
255 myCursorSizeSpinBox->setValue( myPickingSettings->GetCursorSize() );
256 myPyramidHeightSpinBox->setValue( myPickingSettings->GetPyramidHeight() );
257 myPointToleranceSpinBox->setValue( myPickingSettings->GetPointTolerance() );
258 myTransparencySpinBox->setValue( int(myPickingSettings->GetInfoWindowTransparency() * 100.0) );
259 myPositionComboBox->setCurrentItem( myPickingSettings->GetInfoWindowPosition() );
260 myZoomFactorSpinBox->setValue( myPickingSettings->GetZoomFactor() );
261 myStepNumberSpinBox->setValue( myPickingSettings->GetStepNumber() );
262 myDisplayParentMeshCheckBox->setChecked( myPickingSettings->GetDisplayParentMesh() );
264 vtkFloatingPointType* aColor = myPickingSettings->GetColor();
265 mySelectionColorButton->setPaletteBackgroundColor( QColor( ( int )( aColor[0] * 255.0 ),
266 ( int )( aColor[1] * 255.0 ),
267 ( int )( aColor[2] * 255.0 ) ) );
272 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
274 aCursorSize = aResourceMgr->doubleValue( "VISU", "picking_cursor_size", aCursorSize );
275 myCursorSizeSpinBox->setValue( aCursorSize );
277 aPyramidHeight = aResourceMgr->doubleValue( "VISU", "picking_pyramid_height", aPyramidHeight );
278 myPyramidHeightSpinBox->setValue( aPyramidHeight );
280 aPointTolerance = aResourceMgr->doubleValue( "VISU", "picking_point_tolerance", aPointTolerance );
281 myPointToleranceSpinBox->setValue( aPointTolerance );
283 aColor = aResourceMgr->colorValue( "VISU", "picking_selection_color", aColor );
284 mySelectionColorButton->setPaletteBackgroundColor( aColor );
286 anInfoWindowTransparency = aResourceMgr->integerValue( "VISU", "picking_transparency", anInfoWindowTransparency );
287 myTransparencySpinBox->setValue( anInfoWindowTransparency );
289 anInfoWindowPosition = aResourceMgr->integerValue( "VISU", "picking_position", anInfoWindowPosition );
290 myPositionComboBox->setCurrentItem( anInfoWindowPosition );
292 aZoomFactor = aResourceMgr->doubleValue( "VISU", "picking_zoom_factor", aZoomFactor );
293 myZoomFactorSpinBox->setValue( aZoomFactor );
295 aStepNumber = aResourceMgr->integerValue( "VISU", "picking_step_number", aStepNumber );
296 myStepNumberSpinBox->setValue( aStepNumber );
298 aDisplayParentMesh = aResourceMgr->booleanValue( "VISU", "picking_display_parent_mesh", aDisplayParentMesh );
299 myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
305 VISU_PickingSettings*
307 ::GetPickingSettings()
309 return myPickingSettings.GetPointer();
312 void VVTK_PickingDlg::SetInteractor( SVTK_RenderWindowInteractor* theInteractor )
314 myInteractor = theInteractor;
316 theInteractor->GetDevice()->AddObserver(vtkCommand::KeyPressEvent,
317 myEventCallbackCommand.GetPointer(),
322 void VVTK_PickingDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
323 unsigned long theEvent,
325 void* vtkNotUsed(theCallData))
327 VVTK_PickingDlg* self = reinterpret_cast<VVTK_PickingDlg*>(theClientData);
330 case vtkCommand::KeyPressEvent:
336 void VVTK_PickingDlg::KeyPressed()
338 if( myInteractor->GetDevice()->GetKeyCode() == 'P' )
340 bool aDisplayParentMesh = !myPickingSettings->GetDisplayParentMesh();
341 myPickingSettings->SetDisplayParentMesh( aDisplayParentMesh );
343 myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
345 myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL);
349 void VVTK_PickingDlg::onClickApply()
351 myPickingSettings->SetInitial( false );
353 myPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
354 myPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
355 myPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
356 myPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 );
357 myPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentItem() );
358 myPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() );
359 myPickingSettings->SetStepNumber( myStepNumberSpinBox->value() );
360 myPickingSettings->SetDisplayParentMesh( myDisplayParentMeshCheckBox->isChecked() );
362 QColor aButtonColor = mySelectionColorButton->paletteBackgroundColor();
363 vtkFloatingPointType aColor[3];
364 aColor[0] = aButtonColor.red() / 255.0;
365 aColor[1] = aButtonColor.green() / 255.0;
366 aColor[2] = aButtonColor.blue() / 255.0;
367 myPickingSettings->SetColor( aColor );
369 myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL);
372 void VVTK_PickingDlg::onClickClose()
377 void VVTK_PickingDlg::onClickHelp()
379 QString aHelpFileName = "picking.htm";
380 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
382 app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
384 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
385 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
386 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
387 QObject::tr("BUT_OK"));
391 void VVTK_PickingDlg::onColorButtonPressed()
393 QColor aColor = QColorDialog::getColor( mySelectionColorButton->paletteBackgroundColor(), this );
394 if( aColor.isValid() )
395 mySelectionColorButton->setPaletteBackgroundColor( aColor );