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