Salome HOME
Advanced feature for sewing - polygons creation instead of splitting.
[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   else {
238     elemName = "POLYHEDRON";
239     myIsPoly = true;
240   }
241
242   QString iconName      = tr( QString("ICON_DLG_%1").arg(elemName) );
243   QString buttonGrTitle = tr( QString("SMESH_%1").arg(elemName) );
244   QString caption       = tr( QString("SMESH_ADD_%1_TITLE").arg(elemName) );
245   QString grBoxTitle    = tr( QString("SMESH_ADD_%1").arg(elemName) );
246     
247   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", iconName ));
248   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH", tr("ICON_SELECT")));
249
250   if ( !name )
251     setName( "SMESHGUI_AddMeshElementDlg" );
252   resize( 303, 185 ); 
253   setCaption( caption );
254
255   setSizeGripEnabled( TRUE );
256   SMESHGUI_AddMeshElementDlgLayout = new QGridLayout( this ); 
257   SMESHGUI_AddMeshElementDlgLayout->setSpacing( 6 );
258   SMESHGUI_AddMeshElementDlgLayout->setMargin( 11 );
259
260   /***************************************************************/
261   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
262   GroupConstructors->setTitle( buttonGrTitle );
263   
264   GroupConstructors->setExclusive( TRUE );
265   GroupConstructors->setColumnLayout(0, Qt::Vertical );
266   GroupConstructors->layout()->setSpacing( 0 );
267   GroupConstructors->layout()->setMargin( 0 );
268   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
269   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
270   GroupConstructorsLayout->setSpacing( 6 );
271   GroupConstructorsLayout->setMargin( 11 );
272   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
273   Constructor1->setText( tr( ""  ) );
274   Constructor1->setPixmap( image0 );
275   Constructor1->setChecked( TRUE );
276   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
277   Constructor1->setMinimumSize( QSize( 50, 0 ) );
278   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
279   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
280   GroupConstructorsLayout->addItem( spacer, 0, 1 );
281   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupConstructors, 0, 0 );
282     
283   /***************************************************************/
284   GroupButtons = new QGroupBox( this, "GroupButtons" );
285   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
286   GroupButtons->setTitle( tr( ""  ) );
287   GroupButtons->setColumnLayout(0, Qt::Vertical );
288   GroupButtons->layout()->setSpacing( 0 );
289   GroupButtons->layout()->setMargin( 0 );
290   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
291   GroupButtonsLayout->setAlignment( Qt::AlignTop );
292   GroupButtonsLayout->setSpacing( 6 );
293   GroupButtonsLayout->setMargin( 11 );
294   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
295   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
296   buttonCancel->setAutoDefault( TRUE );
297   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
298   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
299   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
300   buttonApply->setAutoDefault( TRUE );
301   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
302   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
303   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
304   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
305   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
306   buttonOk->setAutoDefault( TRUE );
307   buttonOk->setDefault( TRUE );
308   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
309   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupButtons, 2, 0 );
310
311   /***************************************************************/
312   GroupC1 = new QGroupBox( this, "GroupC1" );
313   GroupC1->setTitle( grBoxTitle );
314
315   GroupC1->setMinimumSize( QSize( 0, 0 ) );
316   GroupC1->setFrameShape( QGroupBox::Box );
317   GroupC1->setFrameShadow( QGroupBox::Sunken );
318   GroupC1->setColumnLayout(0, Qt::Vertical );
319   GroupC1->layout()->setSpacing( 0 );
320   GroupC1->layout()->setMargin( 0 );
321   GroupC1Layout = new QGridLayout( GroupC1->layout() );
322   GroupC1Layout->setAlignment( Qt::AlignTop );
323   GroupC1Layout->setSpacing( 6 );
324   GroupC1Layout->setMargin( 11 );
325   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
326   TextLabelC1A1->setText( tr( "SMESH_ID_NODES"  ) );
327   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
328   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
329   TextLabelC1A1->setFrameShadow( QLabel::Plain );
330   GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
331   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
332   SelectButtonC1A1->setText( tr( ""  ) );
333   SelectButtonC1A1->setPixmap( image1 );
334   SelectButtonC1A1->setToggleButton( FALSE );
335   GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
336   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
337 //  LineEditC1A1->setReadOnly( TRUE );
338   if (elemName != "POLYGON" && elemName != "POLYHEDRON")
339     LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator", myNbNodes));
340   GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
341
342   if ( myElementType == SMDSAbs_Face ) {
343     Reverse = new QCheckBox( GroupC1, "Reverse" );
344     Reverse->setText( tr( "SMESH_REVERSE"  ) );
345     GroupC1Layout->addWidget( Reverse, 1, 0 );
346   }
347   else
348     Reverse = 0;
349
350   SMESHGUI_AddMeshElementDlgLayout->addWidget( GroupC1, 1, 0 );
351
352   Init(Sel) ; /* Initialisations */
353 }
354
355 //=================================================================================
356 // function : ~SMESHGUI_AddMeshElementDlg()
357 // purpose  : Destroys the object and frees any allocated resources
358 //=================================================================================
359 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
360 {
361     // no need to delete child widgets, Qt does it all for us
362   delete mySimulation;
363 }
364
365
366 //=================================================================================
367 // function : Init()
368 // purpose  :
369 //=================================================================================
370 void SMESHGUI_AddMeshElementDlg::Init( SALOME_Selection* Sel )
371 {
372
373   GroupC1->show();
374   Constructor1->setChecked( TRUE );
375   myEditCurrentArgument = LineEditC1A1 ;        
376   mySelection = Sel;  
377   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
378   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
379
380   myOkNodes = false ;
381   myActor = 0;
382
383   /* signals and slots connections */
384   connect(buttonOk, SIGNAL( clicked() ),     SLOT( ClickOnOk() ) );
385   connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) ) ;
386   connect(buttonApply, SIGNAL( clicked() ),  SLOT(ClickOnApply() ) );
387
388   connect(SelectButtonC1A1, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) ) ;
389   connect(LineEditC1A1, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
390   connect(mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog()));
391   connect(mySelection, SIGNAL( currentSelectionChanged() ), SLOT( SelectionIntoArgument() ) );
392   /* to close dialog if study frame change */
393   connect( mySMESHGUI, SIGNAL ( SignalStudyFrameChanged() ), SLOT( ClickOnCancel() ) ) ;
394
395   if ( Reverse )
396     connect( Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)) );
397
398   /* Move widget on the botton right corner of main widget */
399   int x, y ;
400   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
401   this->move( x, y ) ;
402   this->show() ; /* displays Dialog */
403
404   // set selection mode
405   SMESH::SetPointRepresentation(true);
406   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
407
408   SelectionIntoArgument();
409
410   myBusy = false;
411 }
412
413 //=================================================================================
414 // function : ClickOnApply()
415 // purpose  :
416 //=================================================================================
417 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
418 {
419   if ( myOkNodes && !mySMESHGUI->ActiveStudyLocked() ) {
420
421     myBusy = true;
422     SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
423     anArrayOfIdeces->length( myNbNodes );
424     bool reverse = ( Reverse && Reverse->isChecked() );
425     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
426     for ( int i = 0; i < aListId.count(); i++ )
427       if ( reverse )
428         anArrayOfIdeces[i] = aListId[ myNbNodes - i - 1 ].toInt();
429       else
430         anArrayOfIdeces[i] = aListId[ i ].toInt();
431
432     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
433     switch ( myElementType ) {
434     case SMDSAbs_Edge:
435       aMeshEditor->AddEdge(anArrayOfIdeces.inout()); break;
436     case SMDSAbs_Face:
437       aMeshEditor->AddFace(anArrayOfIdeces.inout()); break;
438     case SMDSAbs_Volume:
439       aMeshEditor->AddVolume(anArrayOfIdeces.inout()); break;
440     default:;
441     }
442     
443     mySelection->ClearIObjects();
444     mySelection->AddIObject( myActor->getIO(), false );
445
446     SMESH::UpdateView();
447     mySimulation->SetVisibility(false);
448
449     buttonOk->setEnabled( false );
450     buttonApply->setEnabled( false );
451
452     myEditCurrentArgument->setText("");
453
454     myBusy = false;
455   }
456 }
457
458 //=================================================================================
459 // function : ClickOnOk()
460 // purpose  :
461 //=================================================================================
462 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
463 {
464   this->ClickOnApply() ;
465   this->ClickOnCancel() ;
466   return ;
467 }
468
469 //=================================================================================
470 // function : ClickOnCancel()
471 // purpose  :
472 //=================================================================================
473 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
474 {
475   mySelection->ClearIObjects();
476   mySimulation->SetVisibility(false);
477   SMESH::SetPointRepresentation(false);
478   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
479   disconnect( mySelection, 0, this, 0 );
480   mySMESHGUI->ResetState() ;
481   reject() ;
482   return ;
483 }
484
485 //=======================================================================
486 //function : onTextChange
487 //purpose  : 
488 //=======================================================================
489
490 void SMESHGUI_AddMeshElementDlg::onTextChange(const QString& theNewText)
491 {
492   if ( myBusy ) return;
493   myBusy = true;
494
495   myOkNodes = false;
496
497   buttonOk->setEnabled( false );
498   buttonApply->setEnabled( false );
499
500   mySimulation->SetVisibility(false);
501
502   // hilight entered nodes
503   SMDS_Mesh* aMesh = 0;
504   if ( myActor )
505     aMesh = myActor->GetObject()->GetMesh();
506   if ( aMesh ) {
507
508     mySelection->ClearIObjects();
509     mySelection->AddIObject( myActor->getIO() );
510
511     QStringList aListId = QStringList::split( " ", theNewText, false);
512     bool allOk = true;
513     for ( int i = 0; i < aListId.count(); i++ ) {
514       const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
515       if ( n ) {
516         if ( mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
517           allOk = false;
518         else
519           mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
520       }
521       else
522         allOk = false;
523     }
524
525     bool aNodesOK = false;
526     if (myIsPoly && myElementType == SMDSAbs_Face && aListId.count() >=3 ){
527       myNbNodes = aListId.count();
528       cout << __LINE__<<": ENK::DEBUG myNbNodes" << myNbNodes << endl;
529       aNodesOK = true;
530     } else if (myIsPoly && myElementType == SMDSAbs_Volume && aListId.count() >=4 ){
531       myNbNodes = aListId.count();
532       cout << __LINE__<<": ENK::DEBUG myNbNodes" << myNbNodes << endl;
533       aNodesOK = true;
534     } else if (!myIsPoly){
535       aNodesOK = (myNbNodes == aListId.count());
536     }
537     myOkNodes = (allOk && aNodesOK);//myNbNodes == aListId.count() );
538
539     if ( myOkNodes ) {
540       buttonOk->setEnabled( true );
541       buttonApply->setEnabled( true );
542       displaySimulation();
543     }
544   }
545
546   myBusy = false;
547 }
548
549 //=================================================================================
550 // function : SelectionIntoArgument()
551 // purpose  : Called when selection has changed
552 //=================================================================================
553 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
554 {
555   if ( myBusy ) return;
556
557   // clear
558
559   myOkNodes = false;
560   myActor = 0;
561
562   myBusy = true;
563   myEditCurrentArgument->setText( "" );
564   myBusy = false;
565
566   if ( !GroupButtons->isEnabled() ) // inactive
567     return;
568
569   buttonOk->setEnabled( false );
570   buttonApply->setEnabled( false );
571
572   mySimulation->SetVisibility(false);
573 //  SMESH::SetPointRepresentation(true);
574
575   // get selected mesh
576
577   int nbSel = mySelection->IObjectCount();
578   if(nbSel != 1)
579     return;
580
581   myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
582   if ( myMesh->_is_nil() )
583     return;
584
585   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
586   if ( !myActor )
587     return;
588
589   // get selected nodes
590
591   QString aString = "";
592   int nbNodes = SMESH::GetNameOfSelectedNodes(mySelection, aString) ;
593   myBusy = true;
594   myEditCurrentArgument->setText( aString );
595   myBusy = false;
596   if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
597     myNbNodes = nbNodes;
598   } else if (myIsPoly && myElementType == SMDSAbs_Volume && nbNodes >= 4) {
599     myNbNodes = nbNodes;
600   } else if (myNbNodes != nbNodes) {
601     return;
602   }
603
604   // OK
605
606   myOkNodes = true;
607
608   buttonOk->setEnabled( true );
609   buttonApply->setEnabled( true );
610
611   displaySimulation();
612 }
613
614 //=======================================================================
615 //function : displaySimulation
616 //purpose  : 
617 //=======================================================================
618
619 void SMESHGUI_AddMeshElementDlg::displaySimulation()
620 {
621   if ( myOkNodes && GroupButtons->isEnabled() )
622   {
623     SMESH::TElementSimulation::TVTKIds anIds;
624     QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
625     for ( int i = 0; i < aListId.count(); i++ )
626       anIds.push_back( myActor->GetObject()->GetNodeVTKId( aListId[ i ].toInt() ));
627
628     if ( Reverse && Reverse->isChecked() )
629       reverse(anIds.begin(),anIds.end());
630
631     vtkIdType aType = 0;
632     if (myIsPoly)
633       switch ( myElementType ) {
634       case SMDSAbs_Face  : aType = VTK_POLYGON; break;
635       case SMDSAbs_Volume: aType = VTK_CONVEX_POINT_SET; break;
636       default: return;
637       }
638     else {
639       switch ( myNbNodes ) {
640       case 2: aType = VTK_LINE; break;
641       case 3: aType = VTK_TRIANGLE; break;
642       case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
643       case 8: aType = VTK_HEXAHEDRON; break;
644       default: return;
645       }
646     }
647       
648     mySimulation->SetPosition(myActor,aType,anIds);
649   }
650 }
651
652
653 //=================================================================================
654 // function : SetEditCurrentArgument()
655 // purpose  :
656 //=================================================================================
657 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
658 {
659   QPushButton* send = (QPushButton*)sender();
660   if(send == SelectButtonC1A1) {
661     LineEditC1A1->setFocus() ;
662     myEditCurrentArgument = LineEditC1A1;
663   }
664   SelectionIntoArgument() ;
665 }
666
667 //=================================================================================
668 // function : DeactivateActiveDialog()
669 // purpose  :
670 //=================================================================================
671 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
672 {
673   if ( GroupConstructors->isEnabled() ) {  
674     GroupConstructors->setEnabled(false) ;
675     GroupC1->setEnabled(false) ;
676     GroupButtons->setEnabled(false) ;
677     mySimulation->SetVisibility(false);
678     mySMESHGUI->ResetState() ;    
679     mySMESHGUI->SetActiveDialogBox(0) ;
680   }
681   return ;
682 }
683
684
685 //=================================================================================
686 // function : ActivateThisDialog()
687 // purpose  :
688 //=================================================================================
689 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
690 {
691   /* Emit a signal to deactivate the active dialog */
692   mySMESHGUI->EmitSignalDeactivateDialog() ;   
693
694   GroupConstructors->setEnabled(true) ;
695   GroupC1->setEnabled(true) ;
696   GroupButtons->setEnabled(true) ;
697
698   SMESH::SetPointRepresentation(true);
699   QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
700
701   SelectionIntoArgument();
702 }
703
704 //=================================================================================
705 // function : enterEvent()
706 // purpose  :
707 //=================================================================================
708 void SMESHGUI_AddMeshElementDlg::enterEvent(QEvent* e)
709 {
710   if ( GroupConstructors->isEnabled() )
711     return ;  
712   ActivateThisDialog() ;
713   return ;
714 }
715
716
717 //=================================================================================
718 // function : closeEvent()
719 // purpose  :
720 //=================================================================================
721 void SMESHGUI_AddMeshElementDlg::closeEvent( QCloseEvent* e )
722 {
723   /* same than click on cancel button */
724   this->ClickOnCancel() ;
725   return ;
726 }
727 //=======================================================================
728 //function : hideEvent
729 //purpose  : caused by ESC key
730 //=======================================================================
731
732 void SMESHGUI_AddMeshElementDlg::hideEvent ( QHideEvent * e )
733 {
734   if ( !isMinimized() )
735     ClickOnCancel() ;
736 }
737
738 //=======================================================================
739 //function : CheckBox
740 //purpose  : 
741 //=======================================================================
742
743 void SMESHGUI_AddMeshElementDlg::CheckBox( int state )
744 {
745   if ( !myOkNodes )
746     return;
747   
748   if ( state >= 0 ) {
749     mySimulation->SetVisibility(false);
750     displaySimulation();
751   }
752 }