Salome HOME
Prevent exception at shape selection if no mesh was pre-selected
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SewingDlg.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_SewingDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header: 
28
29 #include "SMESHGUI_SewingDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESH_Actor.h"
36 #include "SMDS_Mesh.hxx"
37
38 #include "GEOMBase.h"
39
40 #include "QAD_Application.h"
41 #include "QAD_Desktop.h"
42 #include "QAD_MessageBox.h"
43 #include "utilities.h"
44
45 // QT Includes
46 #include <qapplication.h>
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
49 #include <qlabel.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qradiobutton.h>
53 #include <qcheckbox.h>
54 #include <qlayout.h>
55 #include <qpixmap.h>
56
57 using namespace std;
58
59 //=================================================================================
60 // class    : SMESHGUI_SewingDlg()
61 // purpose  : 
62 //=================================================================================
63 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
64                                               bool modal, WFlags fl )
65   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
66              Qt::WDestructiveClose)
67 {
68   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_FREEBORDERS")));
69   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
70   QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
71   QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
72   QPixmap image4(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
73
74   if ( !name )
75     setName( "SMESHGUI_SewingDlg" );
76   resize( 303, 185 ); 
77   setCaption( tr( "SMESH_SEWING" ) );
78   setSizeGripEnabled( TRUE );
79   SMESHGUI_SewingDlgLayout = new QGridLayout( this ); 
80   SMESHGUI_SewingDlgLayout->setSpacing( 6 );
81   SMESHGUI_SewingDlgLayout->setMargin( 11 );
82
83   /***************************************************************/
84   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
85   GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
86   GroupConstructors->setTitle( tr( "SMESH_SEWING"  ) );
87   GroupConstructors->setExclusive( TRUE );
88   GroupConstructors->setColumnLayout(0, Qt::Vertical );
89   GroupConstructors->layout()->setSpacing( 0 );
90   GroupConstructors->layout()->setMargin( 0 );
91   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
92   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
93   GroupConstructorsLayout->setSpacing( 6 );
94   GroupConstructorsLayout->setMargin( 11 );
95   QHBoxLayout* RBLayout = new QHBoxLayout( 0, 0, 6, "Layout2");
96   RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
97   RadioButton1->setText( tr( ""  ) );
98   RadioButton1->setPixmap( image0 );
99   RBLayout->addWidget( RadioButton1);
100   RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
101   RadioButton2->setText( tr( ""  ) );
102   RadioButton2->setPixmap( image1 );
103   RBLayout->addWidget( RadioButton2);
104   RadioButton3= new QRadioButton( GroupConstructors, "RadioButton3" );
105   RadioButton3->setText( tr( ""  ) );
106   RadioButton3->setPixmap( image2 );
107   RBLayout->addWidget( RadioButton3);
108   RadioButton4= new QRadioButton( GroupConstructors, "RadioButton4" );
109   RadioButton4->setText( tr( ""  ) );
110   RadioButton4->setPixmap( image3 );
111   RBLayout->addWidget( RadioButton4);
112   GroupConstructorsLayout->addLayout( RBLayout, 0, 0 );
113   SMESHGUI_SewingDlgLayout->addWidget( GroupConstructors, 0, 0 );
114   
115   /***************************************************************/
116   GroupButtons = new QGroupBox( this, "GroupButtons" );
117   GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
118   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
119   GroupButtons->setTitle( tr( ""  ) );
120   GroupButtons->setColumnLayout(0, Qt::Vertical );
121   GroupButtons->layout()->setSpacing( 0 );
122   GroupButtons->layout()->setMargin( 0 );
123   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
124   GroupButtonsLayout->setAlignment( Qt::AlignTop );
125   GroupButtonsLayout->setSpacing( 6 );
126   GroupButtonsLayout->setMargin( 11 );
127   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
128   buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
129   buttonCancel->setAutoDefault( TRUE );
130   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
131   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
132   buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
133   buttonApply->setAutoDefault( TRUE );
134   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
135   QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
136   GroupButtonsLayout->addItem( spacer_9, 0, 2 );
137   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
138   buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
139   buttonOk->setAutoDefault( TRUE );
140   buttonOk->setDefault( TRUE );
141   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
142   SMESHGUI_SewingDlgLayout->addWidget( GroupButtons, 2, 0 );
143
144   /***************************************************************/
145   GroupArguments = new QGroupBox( this, "GroupArguments" );
146   GroupArguments->setColumnLayout(0, Qt::Vertical );
147   GroupArguments->layout()->setSpacing( 0 );
148   GroupArguments->layout()->setMargin( 0 );
149   GroupArgumentsLayout = new QGridLayout( GroupArguments->layout() );
150   GroupArgumentsLayout->setAlignment( Qt::AlignTop );
151   GroupArgumentsLayout->setSpacing( 6 );
152   GroupArgumentsLayout->setMargin( 11 );
153
154   // First subgroup
155   SubGroup1 = new QGroupBox( GroupArguments, "SubGroup1" );
156   SubGroup1->setColumnLayout(0, Qt::Vertical );
157   SubGroup1->layout()->setSpacing( 0 );
158   SubGroup1->layout()->setMargin( 0 );
159   QGridLayout* SubGroup1Layout = new QGridLayout( SubGroup1->layout() );
160   SubGroup1Layout->setAlignment( Qt::AlignTop );
161   SubGroup1Layout->setSpacing( 6 );
162   SubGroup1Layout->setMargin( 11 );
163   
164   // Controls of the first subgroup
165   TextLabel1 = new QLabel( SubGroup1, "TextLabel1" );
166   TextLabel1->setFixedWidth(104);
167   SubGroup1Layout->addWidget( TextLabel1, 0, 0 );
168   
169   SelectButton1  = new QPushButton( SubGroup1, "SelectButton1" );
170   SelectButton1->setPixmap( image4 );
171   SubGroup1Layout->addWidget( SelectButton1, 0, 1 );
172   
173   LineEdit1 = new QLineEdit( SubGroup1, "LineEdit1" );
174   SubGroup1Layout->addWidget( LineEdit1, 0, 2 );
175   
176   TextLabel2 = new QLabel( SubGroup1, "TextLabel2" );
177   SubGroup1Layout->addWidget( TextLabel2, 1, 0 );
178   
179   SelectButton2  = new QPushButton( SubGroup1, "SelectButton2" );
180   SelectButton2->setPixmap( image4 );
181   SubGroup1Layout->addWidget( SelectButton2, 1, 1 );
182   
183   LineEdit2 = new QLineEdit( SubGroup1, "LineEdit2" );
184   SubGroup1Layout->addWidget( LineEdit2, 1, 2 );
185
186   TextLabel3 = new QLabel( SubGroup1, "TextLabel3" );
187   SubGroup1Layout->addWidget( TextLabel3, 2, 0 );
188   
189   SelectButton3  = new QPushButton( SubGroup1, "SelectButton3" );
190   SelectButton3->setPixmap( image4 );
191   SubGroup1Layout->addWidget( SelectButton3, 2, 1 );
192   
193   LineEdit3 = new QLineEdit( SubGroup1, "LineEdit3" );
194   SubGroup1Layout->addWidget( LineEdit3, 2, 2 );
195
196
197   // Second subgroup
198   SubGroup2 = new QGroupBox( GroupArguments, "SubGroup2" );
199   SubGroup2->setColumnLayout(0, Qt::Vertical );
200   SubGroup2->layout()->setSpacing( 0 );
201   SubGroup2->layout()->setMargin( 0 );
202   QGridLayout* SubGroup2Layout = new QGridLayout( SubGroup2->layout() );
203   SubGroup2Layout->setAlignment( Qt::AlignTop );
204   SubGroup2Layout->setSpacing( 6 );
205   SubGroup2Layout->setMargin( 11 );
206   
207   // Controls of the first subgroup
208   TextLabel4 = new QLabel( SubGroup2, "TextLabel4" );
209   SubGroup2Layout->addWidget( TextLabel4, 0, 0 );
210   
211   SelectButton4  = new QPushButton( SubGroup2, "SelectButton4" );
212   SelectButton4->setPixmap( image4 );
213   SubGroup2Layout->addWidget( SelectButton4, 0, 1 );
214   
215   LineEdit4 = new QLineEdit( SubGroup2, "LineEdit4" );
216   SubGroup2Layout->addWidget( LineEdit4, 0, 2 );
217   
218   TextLabel5 = new QLabel( SubGroup2, "TextLabel5" );
219   SubGroup2Layout->addWidget( TextLabel5, 1, 0 );
220   
221   SelectButton5  = new QPushButton( SubGroup2, "SelectButton5" );
222   SelectButton5->setPixmap( image4 );
223   SubGroup2Layout->addWidget( SelectButton5, 1, 1 );
224   
225   LineEdit5 = new QLineEdit( SubGroup2, "LineEdit5" );
226   SubGroup2Layout->addWidget( LineEdit5, 1, 2 );
227
228   TextLabel6 = new QLabel( SubGroup2, "TextLabel6" );
229   SubGroup2Layout->addWidget( TextLabel6, 2, 0 );
230   
231   SelectButton6  = new QPushButton( SubGroup2, "SelectButton6" );
232   SelectButton6->setPixmap( image4 );
233   SubGroup2Layout->addWidget( SelectButton6, 2, 1 );
234   
235   LineEdit6 = new QLineEdit( SubGroup2, "LineEdit6" );
236   SubGroup2Layout->addWidget( LineEdit6, 2, 2 );
237
238   
239   // Add subgroups to the group of arguments
240   GroupArgumentsLayout->addWidget( SubGroup1, 0, 0 );
241   GroupArgumentsLayout->addWidget( SubGroup2, 1, 0 );
242
243   // Control for the merging equal elements
244   CheckBoxMerge = new QCheckBox( GroupArguments, "CheckBoxMerge" );
245   CheckBoxMerge->setText( tr( "MERGE_EQUAL_ELEMENTS"  ) );
246   GroupArgumentsLayout->addWidget( CheckBoxMerge, 2, 0 );
247   
248
249   SMESHGUI_SewingDlgLayout->addWidget( GroupArguments, 1, 0 );
250   
251   /* Initialisations */
252   GroupArguments->show();
253   RadioButton1->setChecked( TRUE );
254   mySelection = Sel;  
255   
256   LineEdit2->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
257   LineEdit3->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
258   LineEdit5->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
259   LineEdit6->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
260   
261   mySMESHGUI  = SMESHGUI::GetSMESHGUI() ;
262   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
263
264   Init();
265   /* signals and slots connections */
266   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
267   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
268   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
269   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
270   
271   connect( SelectButton1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
272   connect( SelectButton2, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
273   connect( SelectButton3, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
274   connect( SelectButton4, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
275   connect( SelectButton5, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
276   connect( SelectButton6, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
277
278   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
279   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
280   /* to close dialog if study change */
281   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
282
283   connect( LineEdit1, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
284   connect( LineEdit2, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
285   connect( LineEdit3, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
286   connect( LineEdit4, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
287   connect( LineEdit5, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
288   connect( LineEdit6, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
289   
290   /* Move widget on the botton right corner of main widget */
291   int x, y ;
292   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
293   this->move( x, y ) ;
294   this->show() ; /* displays Dialog */
295   
296   ConstructorsClicked(0);
297   resize(0,0);
298 }
299
300 //=================================================================================
301 // function : ~SMESHGUI_SewingDlg()
302 // purpose  : Destroys the object and frees any allocated resources
303 //=================================================================================
304 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
305 {
306   // no need to delete child widgets, Qt does it all for us
307 }
308
309
310 //=================================================================================
311 // function : Init()
312 // purpose  :
313 //=================================================================================
314 void SMESHGUI_SewingDlg::Init()
315 {
316   myBusy = false;
317
318   myEditCurrentArgument = LineEdit1;
319   LineEdit1->setFocus();
320   myActor     = 0;
321   myMesh = SMESH::SMESH_Mesh::_nil();
322   CheckBoxMerge->setChecked(false);
323   SelectionIntoArgument();
324 }
325
326
327 //=================================================================================
328 // function : ConstructorsClicked()
329 // purpose  : Radio button management
330 //=================================================================================
331 void SMESHGUI_SewingDlg::ConstructorsClicked(int constructorId)
332 {
333   disconnect(mySelection, 0, this, 0);
334   mySelection->ClearIObjects();
335   LineEdit1->setText("");
336   LineEdit2->setText("");
337   LineEdit3->setText("");
338   LineEdit4->setText("");
339   LineEdit5->setText("");
340   LineEdit6->setText("");
341   myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
342   myEditCurrentArgument = LineEdit1;
343   myEditCurrentArgument->setFocus();
344   
345   if (!TextLabel5->isEnabled())
346     {
347       TextLabel5->setEnabled(true);
348       SelectButton5->setEnabled(true);
349       LineEdit5->setEnabled(true);
350     }
351   else if (!TextLabel6->isEnabled())
352     {
353       TextLabel6->setEnabled(true);
354       SelectButton6->setEnabled(true);
355       LineEdit6->setEnabled(true);
356     }
357   
358   switch(constructorId)
359     {
360     case 0 :
361       { 
362         GroupArguments->setTitle( tr( "SEW_FREE_BORDERS" ) );
363         SubGroup1->setTitle( tr( "BORDER_1" ) );
364         SubGroup2->setTitle( tr( "BORDER_2" ) );
365         
366         break;
367       }
368     case 1 :
369       {
370         GroupArguments->setTitle( tr( "SEW_CONFORM_FREE_BORDERS" ) );
371         SubGroup1->setTitle( tr( "BORDER_1" ) );
372         SubGroup2->setTitle( tr( "BORDER_2" ) );
373         
374         TextLabel6->setEnabled(false);
375         SelectButton6->setEnabled(false);
376         LineEdit6->setEnabled(false);
377         
378         myOk6 = true;
379           
380         break;
381       }
382     case 2 :
383       {
384         GroupArguments->setTitle( tr( "SEW_BORDER_TO_SIDE" ) );
385         SubGroup1->setTitle( tr( "BORDER" ) );
386         SubGroup2->setTitle( tr( "SIDE" ) );
387
388         TextLabel5->setEnabled(false);
389         SelectButton5->setEnabled(false);
390         LineEdit5->setEnabled(false);
391         
392         myOk5 = true;
393
394         break;
395       }
396     case 3 :
397       { 
398         GroupArguments->setTitle( tr( "SEW_SIDE_ELEMENTS" ) );
399         SubGroup1->setTitle( tr( "SIDE_1" ) );
400         SubGroup2->setTitle( tr( "SIDE_2" ) );
401         
402         TextLabel1->setText( tr( "SMESH_ID_ELEMENTS" ) );
403         TextLabel2->setText( tr( "NODE1_TO_MERGE" ) );
404         TextLabel3->setText( tr( "NODE2_TO_MERGE" ) );
405         TextLabel4->setText( tr( "SMESH_ID_ELEMENTS" ) );
406         TextLabel5->setText( tr( "NODE1_TO_MERGE" ) );
407         TextLabel6->setText( tr( "NODE2_TO_MERGE" ) );
408
409         LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator"));
410         LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator"));
411
412         SMESH::SetPointRepresentation(false);
413         QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
414         break;
415       }
416     }
417   
418   if (constructorId != 3)
419     {
420       TextLabel1->setText( tr( "FIRST_NODE_ID" ) );
421       TextLabel2->setText( tr( "SECOND_NODE_ID" ) );
422       TextLabel3->setText( tr( "LAST_NODE_ID" ) );
423       TextLabel4->setText( tr( "FIRST_NODE_ID" ) );
424       TextLabel5->setText( tr( "SECOND_NODE_ID" ) );
425       TextLabel6->setText( tr( "LAST_NODE_ID" ) );
426       
427       LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
428       LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
429
430       SMESH::SetPointRepresentation(true);
431       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
432     }
433   
434   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
435 }
436
437
438 //=================================================================================
439 // function : ClickOnApply()
440 // purpose  :
441 //=================================================================================
442 bool SMESHGUI_SewingDlg::ClickOnApply()
443 {
444   if (mySMESHGUI->ActiveStudyLocked())
445     return false;
446   
447   bool aResult = false;
448
449   if ( IsValid() )
450     {
451       bool toMerge = CheckBoxMerge->isChecked();
452     
453       try
454         {
455           SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
456           QApplication::setOverrideCursor(Qt::waitCursor);
457         
458           int aConstructorId = GetConstructorId();
459           SMESH::SMESH_MeshEditor::Sew_Error anError;
460   
461           if (aConstructorId == 0)
462             anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
463                                                   LineEdit2->text().toLong(),
464                                                   LineEdit3->text().toLong(),
465                                                   LineEdit4->text().toLong(),
466                                                   LineEdit5->text().toLong(),
467                                                   LineEdit6->text().toLong());
468           else if (aConstructorId == 1)
469             anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
470                                                          LineEdit2->text().toLong(),
471                                                          LineEdit3->text().toLong(),
472                                                          LineEdit4->text().toLong(),
473                                                          LineEdit5->text().toLong());
474           else if (aConstructorId == 2)
475             anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
476                                                    LineEdit2->text().toLong(),
477                                                    LineEdit3->text().toLong(),
478                                                    LineEdit4->text().toLong(),
479                                                    LineEdit6->text().toLong());
480           else if (aConstructorId == 3)
481             {
482               QStringList aListElementsId1 = QStringList::split( " ", LineEdit1->text(), false);
483               QStringList aListElementsId2 = QStringList::split( " ", LineEdit4->text(), false);
484               
485               SMESH::long_array_var anElementsId1 = new SMESH::long_array;
486               SMESH::long_array_var anElementsId2 = new SMESH::long_array;
487       
488               anElementsId1->length( aListElementsId1.count() );
489               anElementsId2->length( aListElementsId2.count() );
490
491               for ( int i = 0; i < aListElementsId1.count(); i++ )
492                 anElementsId1[i] = aListElementsId1[i].toInt();
493               for ( int i = 0; i < aListElementsId2.count(); i++ )
494                 anElementsId2[i] = aListElementsId2[i].toInt();
495
496               anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
497                                                      anElementsId2.inout(),
498                                                      LineEdit2->text().toLong(),
499                                                      LineEdit5->text().toLong(),
500                                                      LineEdit3->text().toLong(),
501                                                      LineEdit6->text().toLong());
502             }
503           aResult = ( anError == SMESH::SMESH_MeshEditor::SEW_OK );
504
505           if (toMerge && aResult)
506             aMeshEditor->MergeEqualElements();
507           
508           QApplication::restoreOverrideCursor();
509
510           if ( !aResult ) {
511             QString msg = tr(QString("ERROR_%1").arg(anError));
512             QAD_MessageBox::warn1(QAD_Application::getDesktop(),
513                                   tr("SMESH_WRN_WARNING"),msg,tr("SMESH_BUT_OK"));
514           }
515         }
516       catch( ... )
517         {
518         }
519       
520       if ( aResult )
521         {
522           Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
523           mySelection->ClearIObjects();
524           SMESH::UpdateView();
525           mySelection->AddIObject( anIO, false );
526           Init();
527           ConstructorsClicked(GetConstructorId());
528         }
529     }
530
531   return aResult;
532 }
533
534 //=================================================================================
535 // function : ClickOnOk()
536 // purpose  :
537 //=================================================================================
538 void SMESHGUI_SewingDlg::ClickOnOk()
539 {
540   if( ClickOnApply())
541     ClickOnCancel() ;
542 }
543
544         
545 //=================================================================================
546 // function : ClickOnCancel()
547 // purpose  :
548 //=================================================================================
549 void SMESHGUI_SewingDlg::ClickOnCancel()
550 {
551   mySelection->ClearIObjects();
552   SMESH::SetPointRepresentation(false);
553   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
554   disconnect( mySelection, 0, this, 0 );
555   mySMESHGUI->ResetState() ;
556   reject() ;
557 }
558
559 //=======================================================================
560 //function : onTextChange
561 //purpose  : 
562 //=======================================================================
563
564 void SMESHGUI_SewingDlg::onTextChange(const QString& theNewText)
565 {
566   QLineEdit* send = (QLineEdit*)sender();
567
568   if ( myBusy ) return;
569   myBusy = true;
570
571   if (send)
572     myEditCurrentArgument = send;
573  
574   if      (send == LineEdit1)
575     myOk1 = false;
576   else if (send == LineEdit2)
577     myOk2 = false;
578   else if (send == LineEdit3)
579     myOk3 = false;
580   else if (send == LineEdit4)
581     myOk4 = false;
582   else if (send == LineEdit5)
583     myOk5 = false;
584   else if (send == LineEdit6)
585     myOk6 = false;
586
587   buttonOk->setEnabled( false );
588   buttonApply->setEnabled( false );
589   
590   // hilight entered elements/nodes
591   SMDS_Mesh* aMesh = 0;
592   
593   if ( myActor )
594     aMesh = myActor->GetObject()->GetMesh();
595   else
596     send->clear();
597   
598   if ( aMesh ) {
599     mySelection->ClearIObjects();
600     mySelection->AddIObject( myActor->getIO() );
601   
602     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4))
603       {
604         SMESH::SetPointRepresentation(true);
605         QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
606         
607         const SMDS_MeshNode * n = aMesh->FindNode( theNewText.toInt() );
608         if ( n ) {
609           if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
610             mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
611           
612           if      (send == LineEdit1)
613             myOk1 = true;
614           else if (send == LineEdit2)
615             myOk2 = true;
616           else if (send == LineEdit3)
617             myOk3 = true;
618           else if (send == LineEdit4)
619             myOk4 = true;
620           else if (send == LineEdit5)
621             myOk5 = true;
622           else if (send == LineEdit6)
623             myOk6 = true;
624         }
625       }
626     else
627       {
628         SMESH::SetPointRepresentation(false);
629         QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
630         
631         QStringList aListId = QStringList::split( " ", theNewText, false);
632         
633         bool isEvenOneExists = false;
634         
635         for ( int i = 0; i < aListId.count(); i++ ) {
636           const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
637           if ( e ) {
638             if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
639               mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
640             if (!isEvenOneExists) 
641               isEvenOneExists = true;
642           }
643         }
644         
645         if (isEvenOneExists)
646           {
647             if (send == LineEdit1)
648               myOk1 = true;
649             else if(send == LineEdit4)
650               myOk4 = true;
651           }
652         else
653           send->clear();
654       }
655   }
656   
657   if ( IsValid() ) {
658     buttonOk->setEnabled( true );
659     buttonApply->setEnabled( true );
660   }
661   
662   myBusy = false;
663 }
664
665
666 //=================================================================================
667 // function : SelectionIntoArgument()
668 // purpose  : Called when selection as changed or other case
669 //=================================================================================
670 void SMESHGUI_SewingDlg::SelectionIntoArgument(bool isSelectionChanged)
671 {
672   if ( myBusy ) return;
673   
674   // clear
675   if (isSelectionChanged)
676     myActor = 0;
677   
678   QString aString = "";
679   
680   myBusy = true;
681   myEditCurrentArgument->setText( aString );
682   myBusy = false;
683   
684   if ( !GroupButtons->isEnabled() ) // inactive
685     return;
686   
687   buttonOk->setEnabled( false );
688   buttonApply->setEnabled( false );
689   
690   // get selected mesh
691   int nbSel = mySelection->IObjectCount();
692   if(nbSel != 1)
693     return;
694   
695   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
696   myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
697   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
698   
699   if (myMesh->_is_nil() || !myActor)
700     return;
701   
702   // get selected elements/nodes
703   
704   int aNbUnits = 0;
705   
706   if (GetConstructorId() != 3 || (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4))
707     {
708       aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
709       if(aNbUnits != 1)
710         return;
711     }
712   else
713     {
714       aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString);
715       if(aNbUnits < 1) 
716         return;
717     }
718   
719   myBusy = true;
720   myEditCurrentArgument->setText( aString );
721   myBusy = false;
722   
723   // OK
724   if (myEditCurrentArgument == LineEdit1)
725     myOk1 = true;
726   else if(myEditCurrentArgument == LineEdit2)
727     myOk2 = true;
728   else if(myEditCurrentArgument == LineEdit3)
729     myOk3 = true;
730   else if(myEditCurrentArgument == LineEdit4)
731     myOk4 = true;
732   else if(myEditCurrentArgument == LineEdit5)
733     myOk5 = true;
734   else if(myEditCurrentArgument == LineEdit6)
735     myOk6 = true;
736   
737   if(IsValid())
738     {
739       buttonOk->setEnabled( true );
740       buttonApply->setEnabled( true );
741     }
742 }
743
744
745 //=================================================================================
746 // function : SetEditCurrentArgument()
747 // purpose  :
748 //=================================================================================
749 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
750 {
751   QPushButton* send = (QPushButton*)sender();
752   
753   disconnect( mySelection, 0, this, 0 );
754   mySelection->ClearIObjects();
755   
756   if(send == SelectButton1) {
757     myEditCurrentArgument = LineEdit1;
758     myOk1 = false;
759   }
760   else if (send == SelectButton2) {
761     myEditCurrentArgument = LineEdit2;
762     myOk2 = false;
763   }
764   else if (send == SelectButton3) {
765     myEditCurrentArgument = LineEdit3;
766     myOk3 = false;
767   }
768   else if (send == SelectButton4) {
769     myEditCurrentArgument = LineEdit4;
770     myOk4 = false;
771   }
772   else if (send == SelectButton5) {
773     myEditCurrentArgument = LineEdit5;
774     myOk5 = false;
775   }
776   else if (send == SelectButton6) {
777     myEditCurrentArgument = LineEdit6;
778     myOk6 = false;
779   }
780   
781   if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4))
782     {
783       SMESH::SetPointRepresentation(true);
784       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
785     }
786   else
787     {
788       SMESH::SetPointRepresentation(false);
789       QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
790     }
791   
792   myEditCurrentArgument->setFocus();
793   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
794   SelectionIntoArgument(false) ;
795 }
796
797 //=================================================================================
798 // function : DeactivateActiveDialog()
799 // purpose  :
800 //=================================================================================
801 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
802 {
803   if ( GroupConstructors->isEnabled() ) {
804     GroupConstructors->setEnabled(false) ;
805     GroupArguments->setEnabled(false) ;
806     GroupButtons->setEnabled(false) ;
807     mySMESHGUI->ResetState() ;    
808     mySMESHGUI->SetActiveDialogBox(0) ;
809   }
810 }
811
812
813 //=================================================================================
814 // function : ActivateThisDialog()
815 // purpose  :
816 //=================================================================================
817 void SMESHGUI_SewingDlg::ActivateThisDialog()
818 {
819   /* Emit a signal to deactivate the active dialog */
820   mySMESHGUI->EmitSignalDeactivateDialog() ;   
821   GroupConstructors->setEnabled(true) ;
822   GroupArguments->setEnabled(true) ;
823   GroupButtons->setEnabled(true) ;
824   
825   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
826   
827   ConstructorsClicked(GetConstructorId());
828   SelectionIntoArgument();
829 }
830
831
832 //=================================================================================
833 // function : enterEvent()
834 // purpose  :
835 //=================================================================================
836 void SMESHGUI_SewingDlg::enterEvent(QEvent* e)
837 {
838   if ( GroupConstructors->isEnabled() )
839     return ;  
840   ActivateThisDialog() ;
841 }
842
843
844 //=================================================================================
845 // function : closeEvent()
846 // purpose  :
847 //=================================================================================
848 void SMESHGUI_SewingDlg::closeEvent( QCloseEvent* e )
849 {
850   /* same than click on cancel button */
851   this->ClickOnCancel() ;
852 }
853
854
855 //=======================================================================
856 //function : hideEvent
857 //purpose  : caused by ESC key
858 //=======================================================================
859
860 void SMESHGUI_SewingDlg::hideEvent ( QHideEvent * e )
861 {
862   if ( !isMinimized() )
863     ClickOnCancel();
864 }
865
866
867 //=================================================================================
868 // function : GetConstructorId()
869 // purpose  : 
870 //=================================================================================
871 int SMESHGUI_SewingDlg::GetConstructorId()
872
873   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
874     return GroupConstructors->id( GroupConstructors->selected() );
875   return -1;
876 }
877
878
879 //=================================================================================
880 // function : GetConstructorId()
881 // purpose  : 
882 //=================================================================================
883 bool SMESHGUI_SewingDlg::IsValid()
884 {
885   return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
886 }