Salome HOME
Fix of issue 0020614: EDF 1133 SMESH : Put new added elements and nodes to group
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_NodesDlg.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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_NodesDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_NodesDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_GroupUtils.h"
35
36 #include <SMESH_Actor.h>
37 #include <SMESH_ActorUtils.h>
38 #include <SMESH_ObjectDef.h>
39
40 #include <SMDS_Mesh.hxx>
41 #include <SMDS_MeshNode.hxx>
42
43 // SALOME GUI includes
44 #include <SUIT_Session.h>
45 #include <SUIT_OverrideCursor.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ResourceMgr.h>
49
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52
53 #include <SVTK_ViewWindow.h>
54 #include <VTKViewer_Algorithm.h>
55 #include <VTKViewer_CellLocationsArray.h>
56
57 // SALOME KERNEL includes
58 #include <SALOMEDS_Study.hxx>
59 #include <SALOMEDS_SObject.hxx>
60
61 #include <utilities.h>
62
63 // VTK includes
64 #include <vtkIdList.h>
65 #include <vtkCellArray.h>
66 #include <vtkUnsignedCharArray.h>
67 #include <vtkUnstructuredGrid.h>
68 #include <vtkDataSetMapper.h>
69 #include <vtkRenderer.h>
70 #include <vtkProperty.h>
71 #include <vtkPoints.h>
72
73 // Qt includes
74 #include <QComboBox>
75 #include <QGroupBox>
76 #include <QLabel>
77 #include <QPushButton>
78 #include <QRadioButton>
79 #include <QHBoxLayout>
80 #include <QVBoxLayout>
81 #include <QKeyEvent>
82 #include <QButtonGroup>
83
84 // IDL includes
85 #include <SALOMEconfig.h>
86 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
87
88 #define SPACING 6
89 #define MARGIN  11
90
91 namespace SMESH
92 {
93   long AddNode( SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z, const QStringList& theParameters )
94   {
95     long aNodeId = -1;
96     SUIT_OverrideCursor wc;
97     try {
98       _PTR(SObject) aSobj = SMESH::FindSObject( theMesh );
99       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
100       aNodeId = aMeshEditor->AddNode( x, y, z );
101       theMesh->SetParameters( theParameters.join(":").toLatin1().constData() );
102       _PTR(Study) aStudy = GetActiveStudyDocument();
103       CORBA::Long anId = aStudy->StudyId();
104       if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj( anId, aSobj->GetID().c_str() ) ) {
105         aVisualObj->Update( true );
106       }
107     } 
108     catch ( SALOME::SALOME_Exception& exc ) {
109       INFOS( "Follow exception was cought:\n\t" << exc.details.text );
110     }
111     catch ( const std::exception& exc ) {
112       INFOS( "Follow exception was cought:\n\t" << exc.what() );
113     } 
114     catch ( ... ) {
115       INFOS( "Unknown exception was cought !!!" );
116     }
117     return aNodeId;
118   }
119
120   class TNodeSimulation 
121   {
122     SVTK_ViewWindow*  myViewWindow;
123
124     SALOME_Actor*     myPreviewActor;
125     vtkDataSetMapper* myMapper;
126     vtkPoints*        myPoints;
127
128   public:
129     TNodeSimulation( SVTK_ViewWindow* theViewWindow ):
130       myViewWindow( theViewWindow )
131     {
132       vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
133
134       // Create points
135       myPoints = vtkPoints::New();
136       myPoints->SetNumberOfPoints( 1 );
137       myPoints->SetPoint( 0, 0.0, 0.0, 0.0 );
138
139       // Create cells
140       vtkIdList *anIdList = vtkIdList::New();
141       anIdList->SetNumberOfIds( 1 );
142
143       vtkCellArray *aCells = vtkCellArray::New();
144       aCells->Allocate( 2, 0 );
145
146       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
147       aCellTypesArray->SetNumberOfComponents( 1 );
148       aCellTypesArray->Allocate( 1 );
149
150       anIdList->SetId( 0, 0 );
151       aCells->InsertNextCell( anIdList );
152       aCellTypesArray->InsertNextValue( VTK_VERTEX );
153
154       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
155       aCellLocationsArray->SetNumberOfComponents( 1 );
156       aCellLocationsArray->SetNumberOfTuples( 1 );
157
158       aCells->InitTraversal();
159       vtkIdType npts = 0;
160       aCellLocationsArray->SetValue( 0, aCells->GetTraversalLocation( npts ) );
161
162       aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
163
164       aGrid->SetPoints( myPoints );
165       aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
166       aCellLocationsArray->Delete();
167       aCellTypesArray->Delete();
168       aCells->Delete();
169       anIdList->Delete();
170
171       // Create and display actor
172       myMapper = vtkDataSetMapper::New();
173       myMapper->SetInput( aGrid );
174       aGrid->Delete();
175
176       myPreviewActor = SALOME_Actor::New();
177       myPreviewActor->SetInfinitive( true );
178       myPreviewActor->VisibilityOff();
179       myPreviewActor->PickableOff();
180       myPreviewActor->SetMapper( myMapper );
181
182       vtkProperty* aProp = vtkProperty::New();
183       aProp->SetRepresentationToPoints();
184
185       vtkFloatingPointType anRGB[3];
186       GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
187       aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
188
189       vtkFloatingPointType aPointSize = GetFloat( "SMESH:node_size", 3 );
190       aProp->SetPointSize( aPointSize );
191
192       myPreviewActor->SetProperty( aProp );
193       aProp->Delete();
194
195       myViewWindow->AddActor( myPreviewActor );
196     }
197
198     void SetPosition( float x, float y, float z )
199     {
200       myPoints->SetPoint( 0, x, y, z );
201       myPoints->Modified();
202       SetVisibility( true );
203     }
204
205     void SetVisibility( bool theVisibility )
206     {
207       myPreviewActor->SetVisibility( theVisibility );
208       RepaintCurrentView();
209     }
210
211     ~TNodeSimulation()
212     {
213       myViewWindow->RemoveActor( myPreviewActor );
214       myPreviewActor->Delete();
215
216       myMapper->RemoveAllInputs();
217       myMapper->Delete();
218
219       myPoints->Delete();
220     }
221   };
222 }
223
224 //=================================================================================
225 // class    : SMESHGUI_NodesDlg()
226 // purpose  :
227 //=================================================================================
228 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( SMESHGUI* theModule ): 
229   QDialog( SMESH::GetDesktop( theModule ) ),
230   mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
231   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
232   mySMESHGUI( theModule )
233 {
234   setModal( false );
235   setAttribute( Qt::WA_DeleteOnClose, true );
236   setWindowTitle( tr("MESH_NODE_TITLE") );
237   setSizeGripEnabled( true );
238   
239   mySimulation = new SMESH::TNodeSimulation( SMESH::GetViewWindow( mySMESHGUI ) );
240   
241   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", 
242                                                                    tr( "ICON_DLG_NODE" ) ) );
243   
244   QVBoxLayout* SMESHGUI_NodesDlgLayout = new QVBoxLayout( this );
245   SMESHGUI_NodesDlgLayout->setSpacing( SPACING );
246   SMESHGUI_NodesDlgLayout->setMargin( MARGIN );
247
248   /***************************************************************/
249   GroupConstructors = new QGroupBox( tr( "MESH_NODE" ), this );
250   QButtonGroup* ButtonGroup = new QButtonGroup(this);
251   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout( GroupConstructors );
252   GroupConstructorsLayout->setSpacing( SPACING );
253   GroupConstructorsLayout->setMargin( MARGIN );
254
255   Constructor1 = new QRadioButton( GroupConstructors );
256   Constructor1->setIcon( image0 );
257   Constructor1->setChecked( true );
258   
259   GroupConstructorsLayout->addWidget( Constructor1 );
260   ButtonGroup->addButton( Constructor1, 0 );
261
262   /***************************************************************/
263   GroupCoordinates = new QGroupBox( tr( "SMESH_COORDINATES" ), this );
264   QHBoxLayout* GroupCoordinatesLayout = new QHBoxLayout(GroupCoordinates);
265   GroupCoordinatesLayout->setSpacing(SPACING);
266   GroupCoordinatesLayout->setMargin(MARGIN);
267
268   TextLabel_X = new QLabel( tr( "SMESH_X" ), GroupCoordinates );
269   SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates );
270
271   TextLabel_Y = new QLabel( tr( "SMESH_Y" ), GroupCoordinates );
272   SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates );
273
274   TextLabel_Z = new QLabel( tr( "SMESH_Z" ), GroupCoordinates );
275   SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates );
276
277   GroupCoordinatesLayout->addWidget( TextLabel_X );
278   GroupCoordinatesLayout->addWidget( SpinBox_X );
279   GroupCoordinatesLayout->addWidget( TextLabel_Y);
280   GroupCoordinatesLayout->addWidget( SpinBox_Y );
281   GroupCoordinatesLayout->addWidget( TextLabel_Z );
282   GroupCoordinatesLayout->addWidget( SpinBox_Z );
283
284
285   /***************************************************************/
286   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
287   GroupGroups->setCheckable( true );
288   QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
289   GroupGroupsLayout->setSpacing(SPACING);
290   GroupGroupsLayout->setMargin(MARGIN);
291
292   TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
293   ComboBox_GroupName = new QComboBox( GroupGroups );
294   ComboBox_GroupName->setEditable( true );
295
296   GroupGroupsLayout->addWidget( TextLabel_GroupName );
297   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
298
299   /***************************************************************/
300   GroupButtons = new QGroupBox( this );
301   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
302   GroupButtonsLayout->setSpacing( SPACING );
303   GroupButtonsLayout->setMargin( MARGIN );
304   buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
305   buttonOk->setAutoDefault( true );
306   buttonOk->setDefault( true );
307   buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
308   buttonApply->setAutoDefault( true );
309   buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
310   buttonCancel->setAutoDefault( true );
311   buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
312   buttonHelp->setAutoDefault( true );
313
314   GroupButtonsLayout->addWidget( buttonOk );
315   GroupButtonsLayout->addSpacing( 10 );
316   GroupButtonsLayout->addWidget( buttonApply );
317   GroupButtonsLayout->addSpacing( 10 );
318   GroupButtonsLayout->addStretch();
319   GroupButtonsLayout->addWidget( buttonCancel );
320   GroupButtonsLayout->addWidget( buttonHelp );
321
322   /***************************************************************/
323   SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors );
324   SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates );
325   SMESHGUI_NodesDlgLayout->addWidget( GroupGroups );
326   SMESHGUI_NodesDlgLayout->addWidget( GroupButtons );
327
328   myHelpFileName = "adding_nodes_and_elements_page.html#adding_nodes_anchor";
329
330   /* Initialisation and display */
331   Init();
332 }
333
334 //=======================================================================
335 // function : ~SMESHGUI_NodesDlg()
336 // purpose  : Destructor
337 //=======================================================================
338 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
339 {
340   delete mySimulation;
341 }
342
343 //=================================================================================
344 // function : Init()
345 // purpose  :
346 //=================================================================================
347 void SMESHGUI_NodesDlg::Init()
348 {
349   /* Get setting of step value from file configuration */
350   double step = 25.0;
351
352   /* min, max, step and decimals for spin boxes */
353   SpinBox_X->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
354   SpinBox_Y->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
355   SpinBox_Z->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY );
356   SpinBox_X->SetValue( 0.0 );
357   SpinBox_Y->SetValue( 0.0 );
358   SpinBox_Z->SetValue( 0.0 );
359
360   /* reset "Add to group" control */
361   GroupGroups->setChecked( false );
362
363   mySMESHGUI->SetActiveDialogBox( this );
364
365   /* signals and slots connections */
366   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
367   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
368   connect( buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
369   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
370
371   connect( SpinBox_X, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
372   connect( SpinBox_Y, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
373   connect( SpinBox_Z, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
374
375   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ),      SLOT( SelectionIntoArgument() ) );
376   connect( mySMESHGUI,     SIGNAL( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog() ) );
377   /* to close dialog if study frame change */
378   connect( mySMESHGUI,     SIGNAL( SignalStudyFrameChanged() ),      SLOT( ClickOnCancel() ) );
379
380   // set selection mode
381   SMESH::SetPointRepresentation( true );
382   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
383     aViewWindow->SetSelectionMode( NodeSelection );
384
385   SelectionIntoArgument();
386 }
387
388 //=================================================================================
389 // function : ValueChangedInSpinBox()
390 // purpose  :
391 //=================================================================================
392 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
393 {
394   if ( !myMesh->_is_nil() ) {
395     double vx = SpinBox_X->GetValue();
396     double vy = SpinBox_Y->GetValue();
397     double vz = SpinBox_Z->GetValue();
398
399     mySimulation->SetPosition( vx, vy, vz );
400   }
401 }
402
403 //=================================================================================
404 // function : ClickOnOk()
405 // purpose  :
406 //=================================================================================
407 void SMESHGUI_NodesDlg::ClickOnOk()
408 {
409   if ( ClickOnApply() )
410     ClickOnCancel();
411 }
412
413 //=================================================================================
414 // function : ClickOnApply()
415 // purpose  :
416 //=================================================================================
417 bool SMESHGUI_NodesDlg::ClickOnApply()
418 {
419   if ( mySMESHGUI->isActiveStudyLocked() )
420     return false;
421
422   if ( myMesh->_is_nil() ) {
423     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ),
424                               tr( "MESH_IS_NOT_SELECTED" ) );
425     return false;
426   }
427
428   if( !isValid() )
429     return false;
430
431   /* Recup args and call method */
432   double x = SpinBox_X->GetValue();
433   double y = SpinBox_Y->GetValue();
434   double z = SpinBox_Z->GetValue();
435
436   QStringList aParameters;
437   aParameters << SpinBox_X->text();
438   aParameters << SpinBox_Y->text();
439   aParameters << SpinBox_Z->text();
440
441   mySimulation->SetVisibility( false );
442   long aNodeId = SMESH::AddNode( myMesh, x, y, z, aParameters );
443   SMESH::SetPointRepresentation( true );
444
445   if( aNodeId != -1 && GroupGroups->isChecked() ) {
446     SMESH::SMESH_Group_var aGroup;
447     QString aGroupName = ComboBox_GroupName->currentText();
448     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
449     for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
450       SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
451       if( !aGroupBase->_is_nil() ) {
452         SMESH::SMESH_Group_var aRefGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
453         if( !aRefGroup->_is_nil() ) {
454           QString aRefGroupName( aRefGroup->GetName() );
455           if( aRefGroupName == aGroupName ) {
456             aGroup = aRefGroup; // // add node to existing group
457             break;
458           }
459         }
460       }
461     }
462     if( aGroup->_is_nil() ) // create new group
463       aGroup = SMESH::AddGroup( myMesh, SMESH::NODE, aGroupName );
464
465     if( !aGroup->_is_nil() ) {
466       SMESH::long_array_var anIdList = new SMESH::long_array;
467       anIdList->length( 1 );
468       anIdList[0] = aNodeId;
469       aGroup->Add( anIdList.inout() );
470     }
471   }
472
473   // select myMesh
474   SALOME_ListIO aList;
475   mySelectionMgr->selectedObjects( aList );
476   if ( aList.Extent() != 1 ) {
477     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() ) {
478       VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
479       vtkActorCollection *aCollection = aCopy.GetActors();
480       aCollection->InitTraversal();
481       while ( vtkActor *anAct = aCollection->GetNextActor() ) {
482         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) ) {
483           if ( anActor->hasIO() ) {
484             if ( SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>( anActor->GetObject().get() ) ) {
485               if ( myMesh->_is_equivalent( aMeshObj->GetMeshServer() ) ) {
486                 aList.Clear();
487                 aList.Append( anActor->getIO() );
488                 mySelectionMgr->setSelectedObjects( aList, false );
489                 break;
490               }
491             }
492           }
493         }
494       }
495     }
496   }
497   return true;
498 }
499
500 //=================================================================================
501 // function : ClickOnCancel()
502 // purpose  :
503 //=================================================================================
504 void SMESHGUI_NodesDlg::ClickOnCancel()
505 {
506   disconnect( mySelectionMgr, 0, this, 0 );
507   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
508     aViewWindow->SetSelectionMode( ActorSelection );
509
510   mySimulation->SetVisibility( false );
511   SMESH::SetPointRepresentation( false );
512   mySMESHGUI->ResetState();
513
514   reject();
515 }
516
517 //=================================================================================
518 // function : ClickOnHelp()
519 // purpose  :
520 //=================================================================================
521 void SMESHGUI_NodesDlg::ClickOnHelp()
522 {
523   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
524   if ( app ) 
525     app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : 
526                               QString( "" ), myHelpFileName );
527   else {
528     QString platform;
529 #ifdef WIN32
530     platform = "winapplication";
531 #else
532     platform = "application";
533 #endif
534     SUIT_MessageBox::warning( this, tr("WRN_WARNING"),
535                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
536                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
537                                                                     platform ) ).
538                               arg( myHelpFileName ) );
539   }
540 }
541
542 //=================================================================================
543 // function : SelectionIntoArgument()
544 // purpose  : Called when selection as changed or other case
545 //=================================================================================
546 void SMESHGUI_NodesDlg::SelectionIntoArgument()
547 {
548   if ( !GroupConstructors->isEnabled() )
549     return;
550
551   mySimulation->SetVisibility( false );
552   SMESH::SetPointRepresentation( true );
553
554   QString aCurrentEntry = myEntry;
555
556   const SALOME_ListIO& aList = mySelector->StoredIObjects();
557   if ( aList.Extent() == 1 ) {
558     Handle(SALOME_InteractiveObject) anIO = aList.First();
559     if ( anIO->hasEntry() ) {
560       myEntry = anIO->getEntry();
561       myMesh = SMESH::GetMeshByIO( anIO );
562       if ( myMesh->_is_nil() ) return;
563       QString aText;
564       if ( SMESH::GetNameOfSelectedNodes( mySelector, anIO, aText ) == 1 ) {
565         if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh.in() ) ) {
566           if ( SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh() ) {
567             if ( const SMDS_MeshNode* aNode = aMesh->FindNode( aText.toInt() ) ) {
568               SpinBox_X->SetValue( aNode->X() );
569               SpinBox_Y->SetValue( aNode->Y() );
570               SpinBox_Z->SetValue( aNode->Z() );
571             }
572           }
573         }
574       }
575       mySimulation->SetPosition( SpinBox_X->GetValue(),
576                                  SpinBox_Y->GetValue(),
577                                  SpinBox_Z->GetValue() );
578     }
579   }
580
581   // process groups
582   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
583     ComboBox_GroupName->clear();
584     ComboBox_GroupName->addItem( QString() );
585     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
586     for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
587       SMESH::SMESH_GroupBase_var aGroupBase = aListOfGroups[i];
588       if ( !aGroupBase->_is_nil() && aGroupBase->GetType() == SMESH::NODE ) {
589         SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupBase );
590         if ( !aGroup->_is_nil() ) {
591           QString aGroupName( aGroup->GetName() );
592           if ( !aGroupName.isEmpty() )
593             ComboBox_GroupName->addItem( aGroupName );
594         }
595       }
596     }
597   }
598 }
599
600 //=================================================================================
601 // function : closeEvent()
602 // purpose  :
603 //=================================================================================
604 void SMESHGUI_NodesDlg::closeEvent( QCloseEvent* )
605 {
606   this->ClickOnCancel(); /* same than click on cancel button */
607 }
608
609 //=================================================================================
610 // function : hideEvent()
611 // purpose  : caused by ESC key
612 //=================================================================================
613 void SMESHGUI_NodesDlg::hideEvent( QHideEvent* )
614 {
615   if ( !isMinimized() )
616     ClickOnCancel();
617 }
618
619 //=================================================================================
620 // function : enterEvent()
621 // purpose  : to reactivate this dialog box when mouse enter onto the window
622 //=================================================================================
623 void SMESHGUI_NodesDlg::enterEvent( QEvent* )
624 {
625   if ( !GroupConstructors->isEnabled() )
626     ActivateThisDialog();
627 }
628
629 //=================================================================================
630 // function : DeactivateActiveDialog()
631 // purpose  : public slot to deactivate if active
632 //=================================================================================
633 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
634 {
635   if ( GroupConstructors->isEnabled() ) {
636     GroupConstructors->setEnabled( false );
637     GroupCoordinates->setEnabled( false );
638     GroupButtons->setEnabled( false );
639     mySimulation->SetVisibility( false );
640     mySMESHGUI->ResetState();
641     mySMESHGUI->SetActiveDialogBox( 0 );
642   }
643 }
644
645 //=================================================================================
646 // function : ActivateThisDialog()
647 // purpose  :
648 //=================================================================================
649 void SMESHGUI_NodesDlg::ActivateThisDialog()
650 {
651   mySMESHGUI->EmitSignalDeactivateDialog();
652   GroupConstructors->setEnabled( true );
653   GroupCoordinates->setEnabled( true );
654   GroupButtons->setEnabled( true );
655
656   SMESH::SetPointRepresentation( true );
657   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
658     aViewWindow->SetSelectionMode( NodeSelection );
659
660   SelectionIntoArgument();
661 }
662
663 //=================================================================================
664 // function : keyPressEvent()
665 // purpose  :
666 //=================================================================================
667 void SMESHGUI_NodesDlg::keyPressEvent( QKeyEvent* e )
668 {
669   QDialog::keyPressEvent( e );
670   if ( e->isAccepted() )
671     return;
672
673   if ( e->key() == Qt::Key_F1 ) {
674     e->accept();
675     ClickOnHelp();
676   }
677 }
678
679 //=================================================================================
680 // function : isValid
681 // purpose  :
682 //=================================================================================
683 bool SMESHGUI_NodesDlg::isValid()
684 {
685   QString msg;
686   bool ok = true;
687   ok = SpinBox_X->isValid( msg, true ) && ok;
688   ok = SpinBox_Y->isValid( msg, true ) && ok;
689   ok = SpinBox_Z->isValid( msg, true ) && ok;
690
691   if( !ok ) {
692     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
693     if ( !msg.isEmpty() )
694       str += "\n" + msg;
695     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
696     return false;
697   }
698
699   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
700     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
701     return false;
702   }
703   return true;
704 }