Salome HOME
DumpPython Filter / Controls
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_AddMeshElementDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_AddMeshElementDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_ActorUtils.h"
37  
38 #include "VTKViewer_ViewFrame.h"
39 #include "SMDS_Mesh.hxx"
40 #include "SMESH_Actor.h"
41
42 #include "QAD_Application.h"
43 #include "QAD_Desktop.h"
44 #include "QAD_MessageBox.h"
45
46 #include "utilities.h"
47
48 #include <vtkCell.h>
49 #include <vtkIdList.h>
50 #include <vtkIntArray.h>
51 #include <vtkCellArray.h>
52 #include <vtkUnsignedCharArray.h>
53 #include <vtkUnstructuredGrid.h>
54 #include <vtkDataSetMapper.h>
55
56 // QT Includes
57 #include <qbuttongroup.h>
58 #include <qgroupbox.h>
59 #include <qlabel.h>
60 #include <qlineedit.h>
61 #include <qpushbutton.h>
62 #include <qradiobutton.h>
63 #include <qlayout.h>
64 #include <qvariant.h>
65 #include <qtooltip.h>
66 #include <qwhatsthis.h>
67 #include <qimage.h>
68 #include <qpixmap.h>
69 #include <qcheckbox.h>
70 #include <qregexp.h>
71
72 #include <list>
73 #include <TColStd_IndexedMapOfInteger.hxx>
74
75 using namespace std;
76
77 namespace SMESH{
78
79   class TElementSimulation{
80     QAD_Study* myStudy;
81     QAD_StudyFrame* myStudyFrame;
82     VTKViewer_ViewFrame* myViewFrame;
83
84     SALOME_Actor *myPreviewActor;
85     vtkDataSetMapper* myMapper;
86     vtkUnstructuredGrid* myGrid;
87
88   public:
89
90     TElementSimulation(QAD_Study* theStudy):
91       myStudy(theStudy),
92       myStudyFrame(theStudy->getActiveStudyFrame()),
93       myViewFrame(GetVtkViewFrame(theStudy->getActiveStudyFrame()))
94     {
95       myGrid = vtkUnstructuredGrid::New();
96   
97       // Create and display actor
98       myMapper = vtkDataSetMapper::New();
99       myMapper->SetInput( myGrid );
100
101       myPreviewActor = SALOME_Actor::New();
102       myPreviewActor->PickableOff();
103       myPreviewActor->VisibilityOff();
104       myPreviewActor->SetMapper( myMapper );
105
106       vtkProperty* aProp = vtkProperty::New();
107       float anRGB[3];
108       anRGB[0] = GetFloat("SMESH:SettingsFillColorRed", 0)/255.;
109       anRGB[1] = GetFloat("SMESH:SettingsFillColorGreen", 170)/255.;
110       anRGB[2] = GetFloat("SMESH:SettingsFillColorBlue", 255)/255.;
111       aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
112       myPreviewActor->SetProperty( aProp );
113       aProp->Delete();
114
115       vtkProperty* aBackProp = vtkProperty::New();
116       anRGB[0] = GetFloat("SMESH:SettingsBackFaceColorRed", 0)/255.;
117       anRGB[1] = GetFloat("SMESH:SettingsBackFaceColorGreen", 0)/255.;
118       anRGB[2] = GetFloat("SMESH:SettingsBackFaceColorBlue", 255)/255.;
119       aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
120       myPreviewActor->SetBackfaceProperty( aBackProp );
121       aBackProp->Delete();
122
123       myViewFrame->AddActor( myPreviewActor );
124
125     }
126
127
128     typedef std::vector<vtkIdType> TVTKIds;
129     void SetPosition(SMESH_Actor* theActor, 
130                      vtkIdType theType, 
131                      const TVTKIds& theIds)
132     {
133       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
134       myGrid->SetPoints(aGrid->GetPoints());
135
136       const int* aConn = NULL;
137       switch(theType){
138       case VTK_TETRA:{
139         static int anIds[] = {0,2,1,3};
140         aConn = anIds;
141         break;
142       }
143       case VTK_PYRAMID:{
144         static int anIds[] = {0,3,2,1,4};
145         aConn = anIds;
146         break;
147       }
148       case VTK_HEXAHEDRON:{
149         static int anIds[] = {0,3,2,1,4,7,6,5};
150         aConn = anIds;
151         break;
152       }}
153
154       myGrid->Reset();
155       vtkIdList *anIds = vtkIdList::New();
156
157       if(aConn)
158         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
159           anIds->InsertId(i,theIds[aConn[i]]);
160       else
161         for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
162           anIds->InsertId(i,theIds[i]);
163
164       myGrid->InsertNextCell(theType,anIds);
165       anIds->Delete();
166
167       myGrid->Modified();
168
169       SetVisibility(true);
170     }
171
172
173     void SetVisibility(bool theVisibility){
174       myPreviewActor->SetVisibility(theVisibility);
175       RepaintCurrentView();
176     }
177
178
179     ~TElementSimulation(){
180       if(FindVtkViewFrame(myStudy,myStudyFrame)){
181         myViewFrame->RemoveActor(myPreviewActor);
182       }
183       myPreviewActor->Delete();
184
185       myMapper->RemoveAllInputs();
186       myMapper->Delete();
187
188       myGrid->Delete();
189     }
190
191   };
192
193 }
194
195 //=================================================================================
196 // class    : SMESHGUI_AddMeshElementDlg()
197 // purpose  : 
198 //=================================================================================
199 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( QWidget* parent, const char* name,
200                                                        SALOME_Selection* Sel, 
201                                                        SMDSAbs_ElementType ElementType, int nbNodes,
202                                                        bool modal, WFlags fl )
203     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
204                Qt::WDestructiveClose)
205 {
206   myIsPoly = false;
207   mySimulation = new SMESH::TElementSimulation(SMESH::GetActiveStudy());
208   
209   // verify nb nodes and type
210   myNbNodes = nbNodes;
211   myElementType = ElementType;
212   switch ( ElementType ) {
213   case SMDSAbs_Face:
214   case SMDSAbs_Volume:
215     break;
216   default:
217     myElementType = SMDSAbs_Edge;
218     myNbNodes = 2;
219   }
220
221   QString elemName;
222   if (myNbNodes == 2)
223     elemName = "EDGE";
224   else if (myNbNodes == 3)
225     elemName = "TRIANGLE";
226   else if (myNbNodes == 4)
227     if (myElementType == SMDSAbs_Face)
228       elemName = "QUADRANGLE";
229     else
230       elemName = "TETRAS";
231   else if (myNbNodes == 8)
232     elemName = "HEXAS";
233   else if (myElementType == SMDSAbs_Face){
234     elemName = "POLYGON";
235     myIsPoly = true;
236   }
237
238   QString iconName      = tr( QString("ICON_DLG_%1").arg(elemName) );
239   QString buttonGrTitle = tr( QString("SMESH_%1").arg(elemName) );
240   QString caption       = tr( QString("SMESH_ADD_%1_TITLE").arg(elemName) );
241   QString grBoxTitle    = tr( QString("SMESH_ADD_%1").arg(elemName) );
242     
243   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", iconName ));
244   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr("ICON_SELECT")));
245
246   if ( !name )
247     setName( "SMESHGUI_AddMeshElementDlg" );
248   resize( 303, 185 ); 
249   setCaption( caption );
250
251   setSizeGripEnabled( TRUE );
252   SMESHGUI_AddMeshElementDlgLayout = new QGridLayout( this ); 
253   SMESHGUI_AddMeshElementDlgLayout->setSpacing( 6 );
254   SMESHGUI_AddMeshElementDlgLayout->setMargin( 11 );
255
256   /***************************************************************/
257   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
258   GroupConstructors->setTitle( buttonGrTitle );
259   
260   GroupConstructors->setExclusive( TRUE );
261   GroupConstructors->setColumnLayout(0, Qt::Vertical );
262   GroupConstructors->layout()->setSpacing( 0 );
263   GroupConstructors->layout()->setMargin( 0 );
264   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
265   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
266   GroupConstructorsLayout->setSpacing( 6 );
267   GroupConstructorsLayout->setMargin( 11 );
268   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
269   Constructor1->setText( tr( ""  ) );
270   Constructor1->setPixmap( image0 );
271   Constructor1->setChecked( TRUE );
272   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
273   Constructor1->setMinimumSize( QSize( 50, 0 ) );
274   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
275   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
276   GroupConstructorsLayout->addItem( spacer, 0, 1 );
277   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupConstructors, 0, 0 );
278     
279   /***************************************************************/
280   GroupButtons = new QGroupBox( this, "GroupButtons" );
281   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
282   GroupButtons->setTitle( tr( ""  ) );
283   GroupButtons->setColumnLayout(0, Qt::Vertical );
284   GroupButtons->layout()->setSpacing( 0 );
285   GroupButtons->layout()->setMargin( 0 );
286   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
287   GroupButtonsLayout->setAlignment( Qt::AlignTop );
288   GroupButtonsLayout->setSpacing( 6 );
289   GroupButtonsLayout->setMargin( 11 );
290   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
291   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
292   buttonCancel->setAutoDefault( TRUE );
293   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
294   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
295   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
296   buttonApply->setAutoDefault( TRUE );
297   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
298   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
299   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
300   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
301   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
302   buttonOk->setAutoDefault( TRUE );
303   buttonOk->setDefault( TRUE );
304   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
305   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupButtons, 2, 0 );
306
307   /***************************************************************/
308   GroupC1 = new QGroupBox( this, "GroupC1" );
309   GroupC1->setTitle( grBoxTitle );
310
311   GroupC1->setMinimumSize( QSize( 0, 0 ) );
312   GroupC1->setFrameShape( QGroupBox::Box );
313   GroupC1->setFrameShadow( QGroupBox::Sunken );
314   GroupC1->setColumnLayout(0, Qt::Vertical );
315   GroupC1->layout()->setSpacing( 0 );
316   GroupC1->layout()->setMargin( 0 );
317   GroupC1Layout = new QGridLayout( GroupC1->layout() );
318   GroupC1Layout->setAlignment( Qt::AlignTop );
319   GroupC1Layout->setSpacing( 6 );
320   GroupC1Layout->setMargin( 11 );
321   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
322   TextLabelC1A1->setText( tr( "SMESH_ID_NODES"  ) );
323   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
324   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
325   TextLabelC1A1->setFrameShadow( QLabel::Plain );
326   GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
327   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
328   SelectButtonC1A1->setText( tr( ""  ) );
329   SelectButtonC1A1->setPixmap( image1 );
330   SelectButtonC1A1->setToggleButton( FALSE );
331   GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
332   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
333 //  LineEditC1A1->setReadOnly( TRUE );
334   if (!myIsPoly)
335     LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator", myNbNodes));
336   GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
337
338   if ( myElementType == SMDSAbs_Face ) {
339     Reverse = new QCheckBox( GroupC1, "Reverse" );
340     Reverse->setText( tr( "SMESH_REVERSE"  ) );
341     GroupC1Layout->addWidget( Reverse, 1, 0 );
342   }
343   else
344     Reverse = 0;
345
346   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupC1, 1, 0 );
347
348   Init(Sel) ; /* Initialisations */
349 }
350
351 //=================================================================================
352 // function : ~SMESHGUI_AddMeshElementDlg()
353 // purpose  : Destroys the object and frees any allocated resources
354 //=================================================================================
355 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
356 {
357     // no need to delete child widgets, Qt does it all for us
358   delete mySimulation;
359 }
360
361
362 //=================================================================================
363 // function : Init()
364 // purpose  :
365 //=================================================================================
366 void SMESHGUI_AddMeshElementDlg::Init( SALOME_Selection* Sel )
367 {
368
369   GroupC1->show();
370   Constructor1->setChecked( TRUE );
371   myEditCurrentArgument = LineEditC1A1 ;        
372   mySelection = Sel;  
373   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
374   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
375
376   myOkNodes = false ;
377   myActor = 0;
378
379   /* signals and slots connections */
380   connect(buttonOk, SIGNAL( clicked() ),     SLOT( ClickOnOk() ) );
381   connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
382   connect(buttonApply, SIGNAL( clicked() ),  SLOT(ClickOnApply() ) );
383
384   connect(SelectButtonC1A1, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
385   connect(LineEditC1A1, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
386   connect(mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog()));
387   connect(mySelection, SIGNAL( currentSelectionChanged() ), SLOT( SelectionIntoArgument() ) );
388   /* to close dialog if study frame change */
389   connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), SLOT( ClickOnCancel() ) ) ;
390
391   if ( Reverse )
392     connect( Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
393
394   /* Move widget on the botton right corner of main widget */
395   int x, y ;
396   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
397   this->move( x, y ) ;
398   this->show() ; /* displays Dialog */
399
400   // set selection mode
401   SMESH::SetPointRepresentation(true);
402   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
403
404   SelectionIntoArgument();
405
406   myBusy = false;
407 }
408
409 //=================================================================================
410 // function : ClickOnApply()
411 // purpose  :
412 //=================================================================================
413 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
414 {
415   if ( myOkNodes && !mySMESHGUI->ActiveStudyLocked() ) {
416
417     myBusy = true;
418     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
419     anArrayOfIdeces->length( myNbNodes );
420     bool reverse = ( Reverse && Reverse->isChecked() );
421     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
422     for ( int i = 0; i < aListId.count(); i++ )
423       if ( reverse )
424         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
425       else
426         anArrayOfIdeces[i] = aListId[ i ].toInt();
427
428     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
429     switch ( myElementType ) {
430     case SMDSAbs_Edge:
431       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
432     case SMDSAbs_Face:
433       aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
434     case SMDSAbs_Volume:
435       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
436     default:;
437     }
438     
439     mySelection->ClearIObjects();
440     mySelection->AddIObject( myActor->getIO(), false );
441
442     SMESH::UpdateView();
443     mySimulation->SetVisibility(false);
444
445     buttonOk->setEnabled( false );
446     buttonApply->setEnabled( false );
447
448     myEditCurrentArgument->setText("");
449
450     myBusy = false;
451   }
452 }
453
454 //=================================================================================
455 // function : ClickOnOk()
456 // purpose  :
457 //=================================================================================
458 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
459 {
460   this->ClickOnApply() ;
461   this->ClickOnCancel() ;
462   return ;
463 }
464
465 //=================================================================================
466 // function : ClickOnCancel()
467 // purpose  :
468 //=================================================================================
469 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
470 {
471   mySelection->ClearIObjects();
472   mySimulation->SetVisibility(false);
473   SMESH::SetPointRepresentation(false);
474   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
475   disconnect( mySelection, 0, this, 0 );
476   mySMESHGUI->ResetState() ;
477   reject() ;
478   return ;
479 }
480
481 //=======================================================================
482 //function : onTextChange
483 //purpose  : 
484 //=======================================================================
485
486 void SMESHGUI_AddMeshElementDlg::onTextChange(const QString& theNewText)
487 {
488   if ( myBusy ) return;
489   myBusy = true;
490
491   myOkNodes = false;
492
493   buttonOk->setEnabled( false );
494   buttonApply->setEnabled( false );
495
496   mySimulation->SetVisibility(false);
497
498   // hilight entered nodes
499   SMDS_Mesh* aMesh = 0;
500   if ( myActor )
501     aMesh = myActor->GetObject()->GetMesh();
502   if ( aMesh ) {
503
504     mySelection->ClearIObjects();
505     mySelection->AddIObject( myActor->getIO() );
506
507     QStringList aListId = QStringList::split( " ", theNewText, false);
508     bool allOk = true;
509     for ( int i = 0; i < aListId.count(); i++ ) {
510       const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
511       if ( n ) {
512         if ( mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
513           allOk = false;
514         else
515           mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
516       }
517       else
518         allOk = false;
519     }
520
521     bool aNodesOK = false;
522     if (myIsPoly && myElementType == SMDSAbs_Face && aListId.count() >=3 ){
523       myNbNodes = aListId.count();
524       aNodesOK = true;
525     } else if (!myIsPoly){
526       aNodesOK = (myNbNodes == aListId.count());
527     }
528     myOkNodes = (allOk && aNodesOK);//myNbNodes == aListId.count() );
529
530     if ( myOkNodes ) {
531       buttonOk->setEnabled( true );
532       buttonApply->setEnabled( true );
533       displaySimulation();
534     }
535   }
536
537   myBusy = false;
538 }
539
540 //=================================================================================
541 // function : SelectionIntoArgument()
542 // purpose  : Called when selection has changed
543 //=================================================================================
544 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
545 {
546   if ( myBusy ) return;
547
548   // clear
549
550   myOkNodes = false;
551   myActor = 0;
552
553   myBusy = true;
554   myEditCurrentArgument->setText( "" );
555   myBusy = false;
556
557   if ( !GroupButtons->isEnabled() ) // inactive
558     return;
559
560   buttonOk->setEnabled( false );
561   buttonApply->setEnabled( false );
562
563   mySimulation->SetVisibility(false);
564 //  SMESH::SetPointRepresentation(true);
565
566   // get selected mesh
567
568   int nbSel = mySelection->IObjectCount();
569   if(nbSel != 1)
570     return;
571
572   myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
573   if ( myMesh->_is_nil() )
574     return;
575
576   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
577   if ( !myActor )
578     return;
579
580   // get selected nodes
581
582   QString aString = "";
583   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelection, aString) ;
584   myBusy = true;
585   myEditCurrentArgument->setText( aString );
586   myBusy = false;
587   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
588     myNbNodes = nbNodes;
589   } else if (myNbNodes != nbNodes) {
590     return;
591   }
592
593   // OK
594
595   myOkNodes = true;
596
597   buttonOk->setEnabled( true );
598   buttonApply->setEnabled( true );
599
600   displaySimulation();
601 }
602
603 //=======================================================================
604 //function : displaySimulation
605 //purpose  : 
606 //=======================================================================
607
608 void SMESHGUI_AddMeshElementDlg::displaySimulation()
609 {
610   if ( myOkNodes && GroupButtons->isEnabled() )
611   {
612     SMESH::TElementSimulation::TVTKIds anIds;
613     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
614     for ( int i = 0; i < aListId.count(); i++ )
615       anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ i ].toInt() ));
616
617     if ( Reverse && Reverse->isChecked() )
618       reverse(anIds.begin(),anIds.end());
619
620     vtkIdType aType = 0;
621     if (myIsPoly)
622       switch ( myElementType ) {
623       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
624       default: return;
625       }
626     else {
627       switch ( myNbNodes ) {
628       case 2: aType = VTK_LINE; break;
629       case 3: aType = VTK_TRIANGLE; break;
630       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
631       case 8: aType = VTK_HEXAHEDRON; break;
632       default: return;
633       }
634     }
635       
636     mySimulation->SetPosition(myActor,aType,anIds);
637   }
638 }
639
640
641 //=================================================================================
642 // function : SetEditCurrentArgument()
643 // purpose  :
644 //=================================================================================
645 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
646 {
647   QPushButton* send = (QPushButton*)sender();
648   if(send == SelectButtonC1A1) {
649     LineEditC1A1->setFocus() ;
650     myEditCurrentArgument = LineEditC1A1;
651   }
652   SelectionIntoArgument() ;
653 }
654
655 //=================================================================================
656 // function : DeactivateActiveDialog()
657 // purpose  :
658 //=================================================================================
659 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
660 {
661   if ( GroupConstructors->isEnabled() ) {  
662     GroupConstructors->setEnabled(false) ;
663     GroupC1->setEnabled(false) ;
664     GroupButtons->setEnabled(false) ;
665     mySimulation->SetVisibility(false);
666     mySMESHGUI->ResetState() ;    
667     mySMESHGUI->SetActiveDialogBox(0) ;
668   }
669   return ;
670 }
671
672
673 //=================================================================================
674 // function : ActivateThisDialog()
675 // purpose  :
676 //=================================================================================
677 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
678 {
679   /* Emit a signal to deactivate the active dialog */
680   mySMESHGUI->EmitSignalDeactivateDialog() ;   
681
682   GroupConstructors->setEnabled(true) ;
683   GroupC1->setEnabled(true) ;
684   GroupButtons->setEnabled(true) ;
685
686   SMESH::SetPointRepresentation(true);
687   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
688
689   SelectionIntoArgument();
690 }
691
692 //=================================================================================
693 // function : enterEvent()
694 // purpose  :
695 //=================================================================================
696 void SMESHGUI_AddMeshElementDlg::enterEvent(QEvent* e)
697 {
698   if ( GroupConstructors->isEnabled() )
699     return ;  
700   ActivateThisDialog() ;
701   return ;
702 }
703
704
705 //=================================================================================
706 // function : closeEvent()
707 // purpose  :
708 //=================================================================================
709 void SMESHGUI_AddMeshElementDlg::closeEvent( QCloseEvent* e )
710 {
711   /* same than click on cancel button */
712   this->ClickOnCancel() ;
713   return ;
714 }
715 //=======================================================================
716 //function : hideEvent
717 //purpose  : caused by ESC key
718 //=======================================================================
719
720 void SMESHGUI_AddMeshElementDlg::hideEvent ( QHideEvent * e )
721 {
722   if ( !isMinimized() )
723     ClickOnCancel() ;
724 }
725
726 //=======================================================================
727 //function : CheckBox
728 //purpose  : 
729 //=======================================================================
730
731 void SMESHGUI_AddMeshElementDlg::CheckBox( int state )
732 {
733   if ( !myOkNodes )
734     return;
735   
736   if ( state >= 0 ) {
737     mySimulation->SetVisibility(false);
738     displaySimulation();
739   }
740 }