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