1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VVTK_PickingDlg.cxx
21 // Author : Oleg Uvarov
24 #include "VVTK_PickingDlg.h"
26 #include "VISU_GaussPtsAct.h"
27 #include "VISU_GaussPtsSettings.h"
29 #include "SUIT_MessageBox.h"
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Session.h"
33 #include "SVTK_MainWindow.h"
34 #include "SVTK_RenderWindowInteractor.h"
36 #include <vtkActorCollection.h>
37 #include <vtkCallbackCommand.h>
38 #include <vtkObjectFactory.h>
39 #include <vtkRenderer.h>
40 #include <vtkGenericRenderWindowInteractor.h>
41 #include <vtkSmartPointer.h>
43 #include "utilities.h"
45 #include <qcheckbox.h>
46 #include <qcolordialog.h>
47 #include <qcombobox.h>
48 #include <qgroupbox.h>
51 #include <qpushbutton.h>
54 #include "QtxAction.h"
55 #include "QtxDblSpinBox.h"
56 #include "QtxIntSpinBox.h"
58 #include "LightApp_Application.h"
62 VVTK_PickingDlg::VVTK_PickingDlg(QtxAction* theAction,
63 SVTK_MainWindow* theParent,
65 SVTK_DialogBase(theAction,
68 myEventCallbackCommand( vtkCallbackCommand::New() ),
69 myPickingSettings( VISU_PickingSettings::New() )
72 myEventCallbackCommand->Delete();
73 myEventCallbackCommand->SetClientData(this);
74 myEventCallbackCommand->SetCallback(VVTK_PickingDlg::ProcessEvents);
76 setCaption( tr( "PICKING_DLG_TITLE" ) );
77 setSizeGripEnabled(TRUE);
79 QVBoxLayout* TopLayout = new QVBoxLayout( this );
80 TopLayout->setSpacing(6);
81 TopLayout->setMargin(11);
83 QVBox* aBox = new QVBox( this );
88 QGroupBox* CursorGroup = new QGroupBox( tr( "CURSOR_TITLE" ), aBox, "CursorGroup" );
89 CursorGroup->setColumnLayout(0, Qt::Vertical );
90 CursorGroup->layout()->setSpacing( 0 );
91 CursorGroup->layout()->setMargin( 0 );
93 QGridLayout* CursorGroupLayout = new QGridLayout (CursorGroup->layout());
94 CursorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
95 CursorGroupLayout->setSpacing(6);
96 CursorGroupLayout->setMargin(11);
98 QLabel* CursorSizeLabel = new QLabel( tr( "CURSOR_SIZE" ), CursorGroup );
99 myCursorSizeSpinBox = new QtxDblSpinBox( 0, 1, 0.1, CursorGroup );
100 myCursorSizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
102 QLabel* PyramidHeightLabel = new QLabel( tr( "PYRAMID_HEIGHT" ), CursorGroup );
103 double aHeightMin=1.e-7;
104 double aHeightMax=10.;
105 double aHeightStep=0.1;
106 myPyramidHeightSpinBox = new QtxDblSpinBox(aHeightMin, aHeightMax, aHeightStep, CursorGroup );
107 myPyramidHeightSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
109 QLabel* SelectionColorLabel = new QLabel( tr( "SELECTION_COLOR" ), CursorGroup );
110 mySelectionColorButton = new QPushButton( CursorGroup );
111 mySelectionColorButton->setPaletteBackgroundColor( Qt::blue );
112 mySelectionColorButton->setPaletteForegroundColor( Qt::blue );
113 connect( mySelectionColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
115 CursorGroupLayout->addWidget( CursorSizeLabel, 0, 0 );
116 CursorGroupLayout->addWidget( myCursorSizeSpinBox, 0, 1 );
117 CursorGroupLayout->addWidget( PyramidHeightLabel, 1, 0 );
118 CursorGroupLayout->addWidget( myPyramidHeightSpinBox, 1, 1 );
119 CursorGroupLayout->addWidget( SelectionColorLabel, 2, 0 );
120 CursorGroupLayout->addWidget( mySelectionColorButton, 2, 1 );
123 QGroupBox* ToleranceGroup = new QGroupBox( tr( "TOLERANCE_TITLE" ), aBox, "ToleranceGroup" );
124 ToleranceGroup->setColumnLayout(0, Qt::Vertical );
125 ToleranceGroup->layout()->setSpacing( 0 );
126 ToleranceGroup->layout()->setMargin( 0 );
128 QGridLayout* ToleranceGroupLayout = new QGridLayout (ToleranceGroup->layout());
129 ToleranceGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
130 ToleranceGroupLayout->setSpacing(6);
131 ToleranceGroupLayout->setMargin(11);
133 QLabel* PointToleranceLabel = new QLabel( tr( "POINT_TOLERANCE" ), ToleranceGroup );
134 myPointToleranceSpinBox = new QtxDblSpinBox( 0.001, 10.0, 0.01, ToleranceGroup );
135 myPointToleranceSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 ToleranceGroupLayout->addWidget( PointToleranceLabel, 0, 0 );
138 ToleranceGroupLayout->addWidget( myPointToleranceSpinBox, 0, 1 );
140 // Information window
141 QGroupBox* InfoWindowGroup = new QGroupBox( tr( "INFO_WINDOW_TITLE" ), aBox, "InfoWindowGroup" );
142 InfoWindowGroup->setColumnLayout(0, Qt::Vertical );
143 InfoWindowGroup->layout()->setSpacing( 0 );
144 InfoWindowGroup->layout()->setMargin( 0 );
146 QGridLayout* InfoWindowGroupLayout = new QGridLayout (InfoWindowGroup->layout());
147 InfoWindowGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
148 InfoWindowGroupLayout->setSpacing(6);
149 InfoWindowGroupLayout->setMargin(11);
151 QLabel* TransparencyLabel = new QLabel( tr( "TRANSPARENCY" ), InfoWindowGroup );
152 myTransparencySpinBox = new QtxIntSpinBox( 0, 100, 10, InfoWindowGroup );
153 myTransparencySpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
155 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
156 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
158 QLabel* PositionLabel = new QLabel( tr( "POSITION" ), InfoWindowGroup );
159 myPositionComboBox = new QComboBox( InfoWindowGroup );
160 myPositionComboBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
162 myPositionComboBox->insertItem( tr( "BELOW_POINT" ) );
163 myPositionComboBox->insertItem( tr( "TOP_LEFT_CORNER" ) );
165 InfoWindowGroupLayout->addWidget( TransparencyLabel, 0, 0 );
166 InfoWindowGroupLayout->addWidget( myTransparencySpinBox, 0, 1 );
167 InfoWindowGroupLayout->addWidget( PositionLabel, 1, 0 );
168 InfoWindowGroupLayout->addWidget( myPositionComboBox, 1, 1 );
170 // Movement of the camera
171 QGroupBox* CameraGroup = new QGroupBox( tr( "CAMERA_TITLE" ), aBox, "CameraGroup" );
172 CameraGroup->setColumnLayout(0, Qt::Vertical );
173 CameraGroup->layout()->setSpacing( 0 );
174 CameraGroup->layout()->setMargin( 0 );
176 QGridLayout* CameraGroupLayout = new QGridLayout (CameraGroup->layout());
177 CameraGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
178 CameraGroupLayout->setSpacing(6);
179 CameraGroupLayout->setMargin(11);
181 QLabel* ZoomFactorLabel = new QLabel( tr( "ZOOM_FACTOR" ), CameraGroup );
182 myZoomFactorSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1, CameraGroup );
183 myZoomFactorSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
185 QLabel* StepNumberLabel = new QLabel( tr( "STEP_NUMBER" ), CameraGroup );
186 myStepNumberSpinBox = new QtxIntSpinBox( 1, 100, 1, CameraGroup );
187 myStepNumberSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
189 CameraGroupLayout->addWidget( ZoomFactorLabel, 0, 0 );
190 CameraGroupLayout->addWidget( myZoomFactorSpinBox, 0, 1 );
191 CameraGroupLayout->addWidget( StepNumberLabel, 1, 0 );
192 CameraGroupLayout->addWidget( myStepNumberSpinBox, 1, 1 );
194 // Display parent mesh element
195 QGroupBox* ParentMeshGroup = new QGroupBox( tr( "PARENT_MESH_TITLE" ), aBox, "ParentMeshGroup" );
196 ParentMeshGroup->setColumnLayout(0, Qt::Vertical );
197 ParentMeshGroup->layout()->setSpacing( 0 );
198 ParentMeshGroup->layout()->setMargin( 0 );
200 QGridLayout* ParentMeshGroupLayout = new QGridLayout (ParentMeshGroup->layout());
201 ParentMeshGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
202 ParentMeshGroupLayout->setSpacing(6);
203 ParentMeshGroupLayout->setMargin(11);
205 myDisplayParentMeshCheckBox = new QCheckBox( tr( "DISPLAY_PARENT_MESH" ), ParentMeshGroup );
206 ParentMeshGroupLayout->addWidget( myDisplayParentMeshCheckBox, 0, 0 );
208 // Common buttons ===========================================================
209 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
210 GroupButtons->setColumnLayout(0, Qt::Vertical );
211 GroupButtons->layout()->setSpacing( 0 );
212 GroupButtons->layout()->setMargin( 0 );
213 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
214 GroupButtonsLayout->setAlignment( Qt::AlignTop );
215 GroupButtonsLayout->setSpacing( 6 );
216 GroupButtonsLayout->setMargin( 11 );
218 QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
219 buttonApply->setAutoDefault( TRUE );
220 buttonApply->setDefault( TRUE );
221 GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
222 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
224 QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
225 buttonClose->setAutoDefault( TRUE );
226 GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
228 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
229 buttonHelp->setAutoDefault( TRUE );
230 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
232 TopLayout->addWidget( aBox );
233 TopLayout->addWidget( GroupButtons );
235 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
236 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
237 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
240 VVTK_PickingDlg::~VVTK_PickingDlg()
244 void VVTK_PickingDlg::AddActor( VISU_GaussPtsAct* theActor )
246 theActor->SetPickingSettings( myPickingSettings.GetPointer() );
249 void VVTK_PickingDlg::RemoveActor( VISU_GaussPtsAct* theActor )
251 theActor->SetPickingSettings( NULL );
254 void VVTK_PickingDlg::Update()
256 float aCursorSize = 0.5;
257 float aPyramidHeight = 10.0;
258 float aPointTolerance = 0.1;
259 QColor aColor = Qt::yellow;
260 int anInfoWindowTransparency = 50;
261 int anInfoWindowPosition = VISU_PickingSettings::BelowPoint;
262 float aZoomFactor = 1.5;
263 int aStepNumber = 10;
264 bool aDisplayParentMesh = false;
266 if( !myPickingSettings->GetInitial() )
268 myCursorSizeSpinBox->setValue( myPickingSettings->GetCursorSize() );
269 myPyramidHeightSpinBox->setValue( myPickingSettings->GetPyramidHeight() );
270 myPointToleranceSpinBox->setValue( myPickingSettings->GetPointTolerance() );
271 myTransparencySpinBox->setValue( int(myPickingSettings->GetInfoWindowTransparency() * 100.0) );
272 myPositionComboBox->setCurrentItem( myPickingSettings->GetInfoWindowPosition() );
273 myZoomFactorSpinBox->setValue( myPickingSettings->GetZoomFactor() );
274 myStepNumberSpinBox->setValue( myPickingSettings->GetStepNumber() );
275 myDisplayParentMeshCheckBox->setChecked( myPickingSettings->GetDisplayParentMesh() );
277 vtkFloatingPointType* aColor = myPickingSettings->GetColor();
278 mySelectionColorButton->setPaletteBackgroundColor( QColor( ( int )( aColor[0] * 255.0 ),
279 ( int )( aColor[1] * 255.0 ),
280 ( int )( aColor[2] * 255.0 ) ) );
285 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
287 aCursorSize = aResourceMgr->doubleValue( "VISU", "picking_cursor_size", aCursorSize );
288 myCursorSizeSpinBox->setValue( aCursorSize );
290 aPyramidHeight = aResourceMgr->doubleValue( "VISU", "picking_pyramid_height", aPyramidHeight );
291 myPyramidHeightSpinBox->setValue( aPyramidHeight );
293 aPointTolerance = aResourceMgr->doubleValue( "VISU", "picking_point_tolerance", aPointTolerance );
294 myPointToleranceSpinBox->setValue( aPointTolerance );
296 aColor = aResourceMgr->colorValue( "VISU", "picking_selection_color", aColor );
297 mySelectionColorButton->setPaletteBackgroundColor( aColor );
299 anInfoWindowTransparency = aResourceMgr->integerValue( "VISU", "picking_transparency", anInfoWindowTransparency );
300 myTransparencySpinBox->setValue( anInfoWindowTransparency );
302 anInfoWindowPosition = aResourceMgr->integerValue( "VISU", "picking_position", anInfoWindowPosition );
303 myPositionComboBox->setCurrentItem( anInfoWindowPosition );
305 aZoomFactor = aResourceMgr->doubleValue( "VISU", "picking_zoom_factor", aZoomFactor );
306 myZoomFactorSpinBox->setValue( aZoomFactor );
308 aStepNumber = aResourceMgr->integerValue( "VISU", "picking_step_number", aStepNumber );
309 myStepNumberSpinBox->setValue( aStepNumber );
311 aDisplayParentMesh = aResourceMgr->booleanValue( "VISU", "picking_display_parent_mesh", aDisplayParentMesh );
312 myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
318 VISU_PickingSettings*
320 ::GetPickingSettings()
322 return myPickingSettings.GetPointer();
325 void VVTK_PickingDlg::SetInteractor( SVTK_RenderWindowInteractor* theInteractor )
327 myInteractor = theInteractor;
329 theInteractor->GetDevice()->AddObserver(vtkCommand::KeyPressEvent,
330 myEventCallbackCommand.GetPointer(),
335 void VVTK_PickingDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
336 unsigned long theEvent,
338 void* vtkNotUsed(theCallData))
340 VVTK_PickingDlg* self = reinterpret_cast<VVTK_PickingDlg*>(theClientData);
343 case vtkCommand::KeyPressEvent:
349 void VVTK_PickingDlg::KeyPressed()
351 if( myInteractor->GetDevice()->GetKeyCode() == 'P' )
353 bool aDisplayParentMesh = !myPickingSettings->GetDisplayParentMesh();
354 myPickingSettings->SetDisplayParentMesh( aDisplayParentMesh );
356 myDisplayParentMeshCheckBox->setChecked( aDisplayParentMesh );
358 myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL);
362 void VVTK_PickingDlg::onClickApply()
364 myPickingSettings->SetInitial( false );
366 myPickingSettings->SetCursorSize( myCursorSizeSpinBox->value() );
367 myPickingSettings->SetPyramidHeight( myPyramidHeightSpinBox->value() );
368 myPickingSettings->SetPointTolerance( myPointToleranceSpinBox->value() );
369 myPickingSettings->SetInfoWindowTransparency( myTransparencySpinBox->value() / 100.0 );
370 myPickingSettings->SetInfoWindowPosition( myPositionComboBox->currentItem() );
371 myPickingSettings->SetZoomFactor( myZoomFactorSpinBox->value() );
372 myPickingSettings->SetStepNumber( myStepNumberSpinBox->value() );
373 myPickingSettings->SetDisplayParentMesh( myDisplayParentMeshCheckBox->isChecked() );
375 QColor aButtonColor = mySelectionColorButton->paletteBackgroundColor();
376 vtkFloatingPointType aColor[3];
377 aColor[0] = aButtonColor.red() / 255.0;
378 aColor[1] = aButtonColor.green() / 255.0;
379 aColor[2] = aButtonColor.blue() / 255.0;
380 myPickingSettings->SetColor( aColor );
382 myPickingSettings->InvokeEvent(VISU::UpdatePickingSettingsEvent,NULL);
385 void VVTK_PickingDlg::onClickClose()
390 void VVTK_PickingDlg::onClickHelp()
392 QString aHelpFileName = "picking.htm";
393 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
395 app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
397 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
398 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
399 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
400 QObject::tr("BUT_OK"));
404 void VVTK_PickingDlg::onColorButtonPressed()
406 QColor aColor = QColorDialog::getColor( mySelectionColorButton->paletteBackgroundColor(), this );
407 if( aColor.isValid() )
408 mySelectionColorButton->setPaletteBackgroundColor( aColor );