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