Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[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   
460           if (aConstructorId == 0)
461             aResult = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
462                                                   LineEdit2->text().toLong(),
463                                                   LineEdit3->text().toLong(),
464                                                   LineEdit4->text().toLong(),
465                                                   LineEdit5->text().toLong(),
466                                                   LineEdit6->text().toLong());
467           else if (aConstructorId == 1)
468             aResult = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
469                                                          LineEdit2->text().toLong(),
470                                                          LineEdit3->text().toLong(),
471                                                          LineEdit4->text().toLong(),
472                                                          LineEdit5->text().toLong());
473           else if (aConstructorId == 2)
474             aResult = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
475                                                    LineEdit2->text().toLong(),
476                                                    LineEdit3->text().toLong(),
477                                                    LineEdit4->text().toLong(),
478                                                    LineEdit6->text().toLong());
479           else if (aConstructorId == 3)
480             {
481               QStringList aListElementsId1 = QStringList::split( " ", LineEdit1->text(), false);
482               QStringList aListElementsId2 = QStringList::split( " ", LineEdit4->text(), false);
483               
484               SMESH::long_array_var anElementsId1 = new SMESH::long_array;
485               SMESH::long_array_var anElementsId2 = new SMESH::long_array;
486       
487               anElementsId1->length( aListElementsId1.count() );
488               anElementsId2->length( aListElementsId2.count() );
489
490               for ( int i = 0; i < aListElementsId1.count(); i++ )
491                 anElementsId1[i] = aListElementsId1[i].toInt();
492               for ( int i = 0; i < aListElementsId2.count(); i++ )
493                 anElementsId2[i] = aListElementsId2[i].toInt();
494
495               aResult = aMeshEditor->SewSideElements(anElementsId1.inout(),
496                                                      anElementsId2.inout(),
497                                                      LineEdit2->text().toLong(),
498                                                      LineEdit5->text().toLong(),
499                                                      LineEdit3->text().toLong(),
500                                                      LineEdit6->text().toLong());
501             }
502           
503           if (toMerge && aResult)
504             aMeshEditor->MergeEqualElements();
505           
506           QApplication::restoreOverrideCursor();
507         }
508       catch( ... )
509         {
510         }
511       
512       if ( aResult )
513         {
514           Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
515           mySelection->ClearIObjects();
516           SMESH::UpdateView();
517           mySelection->AddIObject( anIO, false );
518           Init();
519           ConstructorsClicked(GetConstructorId());
520         }
521     }
522
523   return aResult;
524 }
525
526 //=================================================================================
527 // function : ClickOnOk()
528 // purpose  :
529 //=================================================================================
530 void SMESHGUI_SewingDlg::ClickOnOk()
531 {
532   if( ClickOnApply())
533     ClickOnCancel() ;
534 }
535
536         
537 //=================================================================================
538 // function : ClickOnCancel()
539 // purpose  :
540 //=================================================================================
541 void SMESHGUI_SewingDlg::ClickOnCancel()
542 {
543   mySelection->ClearIObjects();
544   SMESH::SetPointRepresentation(false);
545   QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
546   disconnect( mySelection, 0, this, 0 );
547   mySMESHGUI->ResetState() ;
548   reject() ;
549 }
550
551 //=======================================================================
552 //function : onTextChange
553 //purpose  : 
554 //=======================================================================
555
556 void SMESHGUI_SewingDlg::onTextChange(const QString& theNewText)
557 {
558   QLineEdit* send = (QLineEdit*)sender();
559
560   if ( myBusy ) return;
561   myBusy = true;
562
563   if (send)
564     myEditCurrentArgument = send;
565  
566   if      (send == LineEdit1)
567     myOk1 = false;
568   else if (send == LineEdit2)
569     myOk2 = false;
570   else if (send == LineEdit3)
571     myOk3 = false;
572   else if (send == LineEdit4)
573     myOk4 = false;
574   else if (send == LineEdit5)
575     myOk5 = false;
576   else if (send == LineEdit6)
577     myOk6 = false;
578
579   buttonOk->setEnabled( false );
580   buttonApply->setEnabled( false );
581   
582   // hilight entered elements/nodes
583   SMDS_Mesh* aMesh = 0;
584   
585   if ( myActor )
586     aMesh = myActor->GetObject()->GetMesh();
587   else
588     send->clear();
589   
590   if ( aMesh ) {
591     mySelection->ClearIObjects();
592     mySelection->AddIObject( myActor->getIO() );
593   
594     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4))
595       {
596         SMESH::SetPointRepresentation(true);
597         QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
598         
599         const SMDS_MeshNode * n = aMesh->FindNode( theNewText.toInt() );
600         if ( n ) {
601           if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
602             mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
603           
604           if      (send == LineEdit1)
605             myOk1 = true;
606           else if (send == LineEdit2)
607             myOk2 = true;
608           else if (send == LineEdit3)
609             myOk3 = true;
610           else if (send == LineEdit4)
611             myOk4 = true;
612           else if (send == LineEdit5)
613             myOk5 = true;
614           else if (send == LineEdit6)
615             myOk6 = true;
616         }
617       }
618     else
619       {
620         SMESH::SetPointRepresentation(false);
621         QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
622         
623         QStringList aListId = QStringList::split( " ", theNewText, false);
624         
625         bool isEvenOneExists = false;
626         
627         for ( int i = 0; i < aListId.count(); i++ ) {
628           const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
629           if ( e ) {
630             if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
631               mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
632             if (!isEvenOneExists) 
633               isEvenOneExists = true;
634           }
635         }
636         
637         if (isEvenOneExists)
638           {
639             if (send == LineEdit1)
640               myOk1 = true;
641             else if(send == LineEdit4)
642               myOk4 = true;
643           }
644         else
645           send->clear();
646       }
647   }
648   
649   if ( IsValid() ) {
650     buttonOk->setEnabled( true );
651     buttonApply->setEnabled( true );
652   }
653   
654   myBusy = false;
655 }
656
657
658 //=================================================================================
659 // function : SelectionIntoArgument()
660 // purpose  : Called when selection as changed or other case
661 //=================================================================================
662 void SMESHGUI_SewingDlg::SelectionIntoArgument(bool isSelectionChanged)
663 {
664   if ( myBusy ) return;
665   
666   // clear
667   if (isSelectionChanged)
668     myActor = 0;
669   
670   QString aString = "";
671   
672   myBusy = true;
673   myEditCurrentArgument->setText( aString );
674   myBusy = false;
675   
676   if ( !GroupButtons->isEnabled() ) // inactive
677     return;
678   
679   buttonOk->setEnabled( false );
680   buttonApply->setEnabled( false );
681   
682   // get selected mesh
683   int nbSel = mySelection->IObjectCount();
684   if(nbSel != 1)
685     return;
686   
687   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
688   myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
689   myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
690   
691   if (myMesh->_is_nil() || !myActor)
692     return;
693   
694   // get selected elements/nodes
695   
696   int aNbUnits = 0;
697   
698   if (GetConstructorId() != 3 || (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4))
699     {
700       aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
701       if(aNbUnits != 1)
702         return;
703     }
704   else
705     {
706       aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString);
707       if(aNbUnits < 1) 
708         return;
709     }
710   
711   myBusy = true;
712   myEditCurrentArgument->setText( aString );
713   myBusy = false;
714   
715   // OK
716   if (myEditCurrentArgument == LineEdit1)
717     myOk1 = true;
718   else if(myEditCurrentArgument == LineEdit2)
719     myOk2 = true;
720   else if(myEditCurrentArgument == LineEdit3)
721     myOk3 = true;
722   else if(myEditCurrentArgument == LineEdit4)
723     myOk4 = true;
724   else if(myEditCurrentArgument == LineEdit5)
725     myOk5 = true;
726   else if(myEditCurrentArgument == LineEdit6)
727     myOk6 = true;
728   
729   if(IsValid())
730     {
731       buttonOk->setEnabled( true );
732       buttonApply->setEnabled( true );
733     }
734 }
735
736
737 //=================================================================================
738 // function : SetEditCurrentArgument()
739 // purpose  :
740 //=================================================================================
741 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
742 {
743   QPushButton* send = (QPushButton*)sender();
744   
745   disconnect( mySelection, 0, this, 0 );
746   mySelection->ClearIObjects();
747   
748   if(send == SelectButton1) {
749     myEditCurrentArgument = LineEdit1;
750     myOk1 = false;
751   }
752   else if (send == SelectButton2) {
753     myEditCurrentArgument = LineEdit2;
754     myOk2 = false;
755   }
756   else if (send == SelectButton3) {
757     myEditCurrentArgument = LineEdit3;
758     myOk3 = false;
759   }
760   else if (send == SelectButton4) {
761     myEditCurrentArgument = LineEdit4;
762     myOk4 = false;
763   }
764   else if (send == SelectButton5) {
765     myEditCurrentArgument = LineEdit5;
766     myOk5 = false;
767   }
768   else if (send == SelectButton6) {
769     myEditCurrentArgument = LineEdit6;
770     myOk6 = false;
771   }
772   
773   if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4))
774     {
775       SMESH::SetPointRepresentation(true);
776       QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
777     }
778   else
779     {
780       SMESH::SetPointRepresentation(false);
781       QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
782     }
783   
784   myEditCurrentArgument->setFocus();
785   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
786   SelectionIntoArgument(false) ;
787 }
788
789 //=================================================================================
790 // function : DeactivateActiveDialog()
791 // purpose  :
792 //=================================================================================
793 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
794 {
795   if ( GroupConstructors->isEnabled() ) {
796     GroupConstructors->setEnabled(false) ;
797     GroupArguments->setEnabled(false) ;
798     GroupButtons->setEnabled(false) ;
799     mySMESHGUI->ResetState() ;    
800     mySMESHGUI->SetActiveDialogBox(0) ;
801   }
802 }
803
804
805 //=================================================================================
806 // function : ActivateThisDialog()
807 // purpose  :
808 //=================================================================================
809 void SMESHGUI_SewingDlg::ActivateThisDialog()
810 {
811   /* Emit a signal to deactivate the active dialog */
812   mySMESHGUI->EmitSignalDeactivateDialog() ;   
813   GroupConstructors->setEnabled(true) ;
814   GroupArguments->setEnabled(true) ;
815   GroupButtons->setEnabled(true) ;
816   
817   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
818   
819   ConstructorsClicked(GetConstructorId());
820   SelectionIntoArgument();
821 }
822
823
824 //=================================================================================
825 // function : enterEvent()
826 // purpose  :
827 //=================================================================================
828 void SMESHGUI_SewingDlg::enterEvent(QEvent* e)
829 {
830   if ( GroupConstructors->isEnabled() )
831     return ;  
832   ActivateThisDialog() ;
833 }
834
835
836 //=================================================================================
837 // function : closeEvent()
838 // purpose  :
839 //=================================================================================
840 void SMESHGUI_SewingDlg::closeEvent( QCloseEvent* e )
841 {
842   /* same than click on cancel button */
843   this->ClickOnCancel() ;
844 }
845
846
847 //=======================================================================
848 //function : hideEvent
849 //purpose  : caused by ESC key
850 //=======================================================================
851
852 void SMESHGUI_SewingDlg::hideEvent ( QHideEvent * e )
853 {
854   if ( !isMinimized() )
855     ClickOnCancel();
856 }
857
858
859 //=================================================================================
860 // function : GetConstructorId()
861 // purpose  : 
862 //=================================================================================
863 int SMESHGUI_SewingDlg::GetConstructorId()
864
865   if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
866     return GroupConstructors->id( GroupConstructors->selected() );
867   return -1;
868 }
869
870
871 //=================================================================================
872 // function : GetConstructorId()
873 // purpose  : 
874 //=================================================================================
875 bool SMESHGUI_SewingDlg::IsValid()
876 {
877   return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
878 }