1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_NodesDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_NodesDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_ActorUtils.h>
37 #include <SMESH_ObjectDef.h>
39 #include <SMDS_Mesh.hxx>
40 #include <SMDS_MeshNode.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Session.h>
44 #include <SUIT_OverrideCursor.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_ResourceMgr.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewWindow.h>
53 #include <VTKViewer_CellLocationsArray.h>
55 // SALOME KERNEL includes
56 #include <SALOMEDS_Study.hxx>
57 #include <SALOMEDS_SObject.hxx>
59 #include <utilities.h>
62 #include <vtkIdList.h>
63 #include <vtkCellArray.h>
64 #include <vtkUnsignedCharArray.h>
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkDataSetMapper.h>
67 #include <vtkRenderer.h>
68 #include <vtkProperty.h>
69 #include <vtkPoints.h>
74 #include <QPushButton>
75 #include <QRadioButton>
76 #include <QHBoxLayout>
77 #include <QVBoxLayout>
79 #include <QButtonGroup>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
90 void AddNode( SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z )
92 SUIT_OverrideCursor wc;
94 _PTR(SObject) aSobj = SMESH::FindSObject( theMesh );
95 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
96 aMeshEditor->AddNode( x, y, z );
97 _PTR(Study) aStudy = GetActiveStudyDocument();
98 CORBA::Long anId = aStudy->StudyId();
99 if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj( anId, aSobj->GetID().c_str() ) ) {
100 aVisualObj->Update( true );
103 catch ( SALOME::SALOME_Exception& exc ) {
104 INFOS( "Follow exception was cought:\n\t" << exc.details.text );
106 catch ( const std::exception& exc ) {
107 INFOS( "Follow exception was cought:\n\t" << exc.what() );
110 INFOS( "Unknown exception was cought !!!" );
114 class TNodeSimulation
116 SVTK_ViewWindow* myViewWindow;
118 SALOME_Actor* myPreviewActor;
119 vtkDataSetMapper* myMapper;
123 TNodeSimulation( SVTK_ViewWindow* theViewWindow ):
124 myViewWindow( theViewWindow )
126 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
129 myPoints = vtkPoints::New();
130 myPoints->SetNumberOfPoints( 1 );
131 myPoints->SetPoint( 0, 0.0, 0.0, 0.0 );
134 vtkIdList *anIdList = vtkIdList::New();
135 anIdList->SetNumberOfIds( 1 );
137 vtkCellArray *aCells = vtkCellArray::New();
138 aCells->Allocate( 2, 0 );
140 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
141 aCellTypesArray->SetNumberOfComponents( 1 );
142 aCellTypesArray->Allocate( 1 );
144 anIdList->SetId( 0, 0 );
145 aCells->InsertNextCell( anIdList );
146 aCellTypesArray->InsertNextValue( VTK_VERTEX );
148 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
149 aCellLocationsArray->SetNumberOfComponents( 1 );
150 aCellLocationsArray->SetNumberOfTuples( 1 );
152 aCells->InitTraversal();
154 aCellLocationsArray->SetValue( 0, aCells->GetTraversalLocation( npts ) );
156 aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
158 aGrid->SetPoints( myPoints );
159 aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
160 aCellLocationsArray->Delete();
161 aCellTypesArray->Delete();
165 // Create and display actor
166 myMapper = vtkDataSetMapper::New();
167 myMapper->SetInput( aGrid );
170 myPreviewActor = SALOME_Actor::New();
171 myPreviewActor->SetInfinitive( true );
172 myPreviewActor->VisibilityOff();
173 myPreviewActor->PickableOff();
174 myPreviewActor->SetMapper( myMapper );
176 vtkProperty* aProp = vtkProperty::New();
177 aProp->SetRepresentationToPoints();
179 vtkFloatingPointType anRGB[3];
180 GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
181 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
183 vtkFloatingPointType aPointSize = GetFloat( "SMESH:node_size", 3 );
184 aProp->SetPointSize( aPointSize );
186 myPreviewActor->SetProperty( aProp );
189 myViewWindow->AddActor( myPreviewActor );
192 void SetPosition( float x, float y, float z )
194 myPoints->SetPoint( 0, x, y, z );
195 myPoints->Modified();
196 SetVisibility( true );
199 void SetVisibility( bool theVisibility )
201 myPreviewActor->SetVisibility( theVisibility );
202 RepaintCurrentView();
207 myViewWindow->RemoveActor( myPreviewActor );
208 myPreviewActor->Delete();
210 myMapper->RemoveAllInputs();
218 //=================================================================================
219 // class : SMESHGUI_NodesDlg()
221 //=================================================================================
222 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( SMESHGUI* theModule ):
223 QDialog( SMESH::GetDesktop( theModule ) ),
224 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
225 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
226 mySMESHGUI( theModule )
229 setAttribute( Qt::WA_DeleteOnClose, true );
230 setWindowTitle( tr("MESH_NODE_TITLE") );
231 setSizeGripEnabled( true );
233 mySimulation = new SMESH::TNodeSimulation( SMESH::GetViewWindow( mySMESHGUI ) );
235 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",
236 tr( "ICON_DLG_NODE" ) ) );
238 QVBoxLayout* SMESHGUI_NodesDlgLayout = new QVBoxLayout( this );
239 SMESHGUI_NodesDlgLayout->setSpacing( SPACING );
240 SMESHGUI_NodesDlgLayout->setMargin( MARGIN );
242 /***************************************************************/
243 GroupConstructors = new QGroupBox( tr( "MESH_NODE" ), this );
244 QButtonGroup* ButtonGroup = new QButtonGroup(this);
245 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout( GroupConstructors );
246 GroupConstructorsLayout->setSpacing( SPACING );
247 GroupConstructorsLayout->setMargin( MARGIN );
249 Constructor1 = new QRadioButton( GroupConstructors );
250 Constructor1->setIcon( image0 );
251 Constructor1->setChecked( true );
253 GroupConstructorsLayout->addWidget( Constructor1 );
254 ButtonGroup->addButton( Constructor1, 0 );
256 /***************************************************************/
257 GroupCoordinates = new QGroupBox( tr( "SMESH_COORDINATES" ), this );
258 QHBoxLayout* GroupCoordinatesLayout = new QHBoxLayout(GroupCoordinates);
259 GroupCoordinatesLayout->setSpacing(SPACING);
260 GroupCoordinatesLayout->setMargin(MARGIN);
262 TextLabel_X = new QLabel( tr( "SMESH_X" ), GroupCoordinates );
263 SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates );
265 TextLabel_Y = new QLabel( tr( "SMESH_Y" ), GroupCoordinates );
266 SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates );
268 TextLabel_Z = new QLabel( tr( "SMESH_Z" ), GroupCoordinates );
269 SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates );
271 GroupCoordinatesLayout->addWidget( TextLabel_X );
272 GroupCoordinatesLayout->addWidget( SpinBox_X );
273 GroupCoordinatesLayout->addWidget( TextLabel_Y);
274 GroupCoordinatesLayout->addWidget( SpinBox_Y );
275 GroupCoordinatesLayout->addWidget( TextLabel_Z );
276 GroupCoordinatesLayout->addWidget( SpinBox_Z );
278 /***************************************************************/
279 GroupButtons = new QGroupBox( this );
280 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
281 GroupButtonsLayout->setSpacing( SPACING );
282 GroupButtonsLayout->setMargin( MARGIN );
283 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
284 buttonOk->setAutoDefault( true );
285 buttonOk->setDefault( true );
286 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
287 buttonApply->setAutoDefault( true );
288 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
289 buttonCancel->setAutoDefault( true );
290 buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
291 buttonHelp->setAutoDefault( true );
293 GroupButtonsLayout->addWidget( buttonOk );
294 GroupButtonsLayout->addSpacing( 10 );
295 GroupButtonsLayout->addWidget( buttonApply );
296 GroupButtonsLayout->addSpacing( 10 );
297 GroupButtonsLayout->addStretch();
298 GroupButtonsLayout->addWidget( buttonCancel );
299 GroupButtonsLayout->addWidget( buttonHelp );
301 /***************************************************************/
302 SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors );
303 SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates );
304 SMESHGUI_NodesDlgLayout->addWidget( GroupButtons );
306 myHelpFileName = "adding_nodes_and_elements_page.html#adding_nodes_anchor";
308 /* Initialisation and display */
312 //=======================================================================
313 // function : ~SMESHGUI_NodesDlg()
314 // purpose : Destructor
315 //=======================================================================
316 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
321 //=================================================================================
324 //=================================================================================
325 void SMESHGUI_NodesDlg::Init()
327 /* Get setting of step value from file configuration */
330 /* min, max, step and decimals for spin boxes */
331 SpinBox_X->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
332 SpinBox_Y->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
333 SpinBox_Z->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
334 SpinBox_X->SetValue( 0.0 );
335 SpinBox_Y->SetValue( 0.0 );
336 SpinBox_Z->SetValue( 0.0 );
338 mySMESHGUI->SetActiveDialogBox( this );
340 /* signals and slots connections */
341 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
342 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
343 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
344 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
346 connect( SpinBox_X, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
347 connect( SpinBox_Y, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
348 connect( SpinBox_Z, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
350 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), SLOT( SelectionIntoArgument() ) );
351 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog() ) );
352 /* to close dialog if study frame change */
353 connect( mySMESHGUI, SIGNAL( SignalStudyFrameChanged() ), SLOT( ClickOnCancel() ) );
355 // set selection mode
356 SMESH::SetPointRepresentation( true );
357 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
358 aViewWindow->SetSelectionMode( NodeSelection );
360 SelectionIntoArgument();
363 //=================================================================================
364 // function : ValueChangedInSpinBox()
366 //=================================================================================
367 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
369 if ( !myMesh->_is_nil() ) {
370 double vx = SpinBox_X->GetValue();
371 double vy = SpinBox_Y->GetValue();
372 double vz = SpinBox_Z->GetValue();
374 mySimulation->SetPosition( vx, vy, vz );
378 //=================================================================================
379 // function : ClickOnOk()
381 //=================================================================================
382 void SMESHGUI_NodesDlg::ClickOnOk()
384 if ( ClickOnApply() )
388 //=================================================================================
389 // function : ClickOnApply()
391 //=================================================================================
392 bool SMESHGUI_NodesDlg::ClickOnApply()
394 if ( mySMESHGUI->isActiveStudyLocked() )
397 if ( myMesh->_is_nil() ) {
398 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ),
399 tr( "MESH_IS_NOT_SELECTED" ) );
403 /* Recup args and call method */
404 double x = SpinBox_X->GetValue();
405 double y = SpinBox_Y->GetValue();
406 double z = SpinBox_Z->GetValue();
407 mySimulation->SetVisibility( false );
408 SMESH::AddNode( myMesh, x, y, z );
409 SMESH::SetPointRepresentation( true );
413 mySelectionMgr->selectedObjects( aList );
414 if ( aList.Extent() != 1 ) {
415 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() ) {
416 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
417 aCollection->InitTraversal();
418 while ( vtkActor *anAct = aCollection->GetNextActor() ) {
419 if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) ) {
420 if ( anActor->hasIO() ) {
421 if ( SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>( anActor->GetObject().get() ) ) {
422 if ( myMesh->_is_equivalent( aMeshObj->GetMeshServer() ) ) {
424 aList.Append( anActor->getIO() );
425 mySelectionMgr->setSelectedObjects( aList, false );
437 //=================================================================================
438 // function : ClickOnCancel()
440 //=================================================================================
441 void SMESHGUI_NodesDlg::ClickOnCancel()
443 disconnect( mySelectionMgr, 0, this, 0 );
444 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
445 aViewWindow->SetSelectionMode( ActorSelection );
447 mySimulation->SetVisibility( false );
448 SMESH::SetPointRepresentation( false );
449 mySMESHGUI->ResetState();
454 //=================================================================================
455 // function : ClickOnHelp()
457 //=================================================================================
458 void SMESHGUI_NodesDlg::ClickOnHelp()
460 LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
462 app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) :
463 QString( "" ), myHelpFileName );
467 platform = "winapplication";
469 platform = "application";
471 SUIT_MessageBox::warning( this, tr("WRN_WARNING"),
472 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
473 arg( app->resourceMgr()->stringValue( "ExternalBrowser",
475 arg( myHelpFileName ) );
479 //=================================================================================
480 // function : SelectionIntoArgument()
481 // purpose : Called when selection as changed or other case
482 //=================================================================================
483 void SMESHGUI_NodesDlg::SelectionIntoArgument()
485 if ( !GroupConstructors->isEnabled() )
488 mySimulation->SetVisibility( false );
489 SMESH::SetPointRepresentation( true );
491 const SALOME_ListIO& aList = mySelector->StoredIObjects();
492 if ( aList.Extent() == 1 ) {
493 Handle(SALOME_InteractiveObject) anIO = aList.First();
494 if ( anIO->hasEntry() ) {
495 myMesh = SMESH::GetMeshByIO( anIO );
496 if ( myMesh->_is_nil() ) return;
498 if ( SMESH::GetNameOfSelectedNodes( mySelector, anIO, aText ) == 1 ) {
499 if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh.in() ) ) {
500 if ( SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh() ) {
501 if ( const SMDS_MeshNode* aNode = aMesh->FindNode( aText.toInt() ) ) {
502 SpinBox_X->SetValue( aNode->X() );
503 SpinBox_Y->SetValue( aNode->Y() );
504 SpinBox_Z->SetValue( aNode->Z() );
509 mySimulation->SetPosition( SpinBox_X->GetValue(),
510 SpinBox_Y->GetValue(),
511 SpinBox_Z->GetValue() );
516 //=================================================================================
517 // function : closeEvent()
519 //=================================================================================
520 void SMESHGUI_NodesDlg::closeEvent( QCloseEvent* )
522 this->ClickOnCancel(); /* same than click on cancel button */
525 //=================================================================================
526 // function : hideEvent()
527 // purpose : caused by ESC key
528 //=================================================================================
529 void SMESHGUI_NodesDlg::hideEvent( QHideEvent* )
531 if ( !isMinimized() )
535 //=================================================================================
536 // function : enterEvent()
537 // purpose : to reactivate this dialog box when mouse enter onto the window
538 //=================================================================================
539 void SMESHGUI_NodesDlg::enterEvent( QEvent* )
541 if ( !GroupConstructors->isEnabled() )
542 ActivateThisDialog();
545 //=================================================================================
546 // function : DeactivateActiveDialog()
547 // purpose : public slot to deactivate if active
548 //=================================================================================
549 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
551 if ( GroupConstructors->isEnabled() ) {
552 GroupConstructors->setEnabled( false );
553 GroupCoordinates->setEnabled( false );
554 GroupButtons->setEnabled( false );
555 mySimulation->SetVisibility( false );
556 mySMESHGUI->ResetState();
557 mySMESHGUI->SetActiveDialogBox( 0 );
561 //=================================================================================
562 // function : ActivateThisDialog()
564 //=================================================================================
565 void SMESHGUI_NodesDlg::ActivateThisDialog()
567 mySMESHGUI->EmitSignalDeactivateDialog();
568 GroupConstructors->setEnabled( true );
569 GroupCoordinates->setEnabled( true );
570 GroupButtons->setEnabled( true );
572 SMESH::SetPointRepresentation( true );
573 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
574 aViewWindow->SetSelectionMode( NodeSelection );
576 SelectionIntoArgument();
579 //=================================================================================
580 // function : keyPressEvent()
582 //=================================================================================
583 void SMESHGUI_NodesDlg::keyPressEvent( QKeyEvent* e )
585 QDialog::keyPressEvent( e );
586 if ( e->isAccepted() )
589 if ( e->key() == Qt::Key_F1 ) {