Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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   this->show(); /* displays Dialog */
317
318   ConstructorsClicked(0);
319   resize(0,0);
320 }
321
322 //=================================================================================
323 // function : ~SMESHGUI_SewingDlg()
324 // purpose  : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
327 {
328   // no need to delete child widgets, Qt does it all for us
329 }
330
331 //=================================================================================
332 // function : Init()
333 // purpose  :
334 //=================================================================================
335 void SMESHGUI_SewingDlg::Init()
336 {
337   myBusy = false;
338
339   myEditCurrentArgument = LineEdit1;
340   LineEdit1->setFocus();
341   myActor = 0;
342   myMesh = SMESH::SMESH_Mesh::_nil();
343   CheckBoxMerge->setChecked(false);
344   CheckBoxPolygons->setChecked(false);
345   CheckBoxPolyedrs->setChecked(false);
346   SelectionIntoArgument();
347 }
348
349 //=================================================================================
350 // function : ConstructorsClicked()
351 // purpose  : Radio button management
352 //=================================================================================
353 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
354 {
355   disconnect(mySelectionMgr, 0, this, 0);
356   SALOME_ListIO io;
357   mySelectionMgr->selectedObjects( io );
358   mySelectionMgr->clearSelected();
359   LineEdit1->setText("");
360   LineEdit2->setText("");
361   LineEdit3->setText("");
362   LineEdit4->setText("");
363   LineEdit5->setText("");
364   LineEdit6->setText("");
365   myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
366   myEditCurrentArgument = LineEdit1;
367   myEditCurrentArgument->setFocus();
368
369   if (!TextLabel5->isEnabled()) {
370     TextLabel5->setEnabled(true);
371     SelectButton5->setEnabled(true);
372     LineEdit5->setEnabled(true);
373   } else if (!TextLabel6->isEnabled()) {
374     TextLabel6->setEnabled(true);
375     SelectButton6->setEnabled(true);
376     LineEdit6->setEnabled(true);
377   }
378
379   if (constructorId == 1 || constructorId == 3) {
380     if (CheckBoxPolygons->isVisible())
381       CheckBoxPolygons->hide();
382     if (CheckBoxPolyedrs->isVisible())
383       CheckBoxPolyedrs->hide();
384   }
385
386   switch (constructorId) {
387   case 0:
388     {
389       GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
390       SubGroup1->setTitle(tr("BORDER_1"));
391       SubGroup2->setTitle(tr("BORDER_2"));
392
393         if (!CheckBoxPolygons->isVisible())
394           CheckBoxPolygons->show();
395         if (!CheckBoxPolyedrs->isVisible())
396           CheckBoxPolyedrs->show();
397
398
399       break;
400     }
401   case 1:
402     {
403       GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
404       SubGroup1->setTitle(tr("BORDER_1"));
405       SubGroup2->setTitle(tr("BORDER_2"));
406
407       TextLabel6->setEnabled(false);
408       SelectButton6->setEnabled(false);
409       LineEdit6->setEnabled(false);
410
411       myOk6 = true;
412
413       break;
414     }
415   case 2:
416     {
417       GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
418       SubGroup1->setTitle(tr("BORDER"));
419       SubGroup2->setTitle(tr("SIDE"));
420
421       TextLabel5->setEnabled(false);
422       SelectButton5->setEnabled(false);
423       LineEdit5->setEnabled(false);
424
425       if (!CheckBoxPolygons->isVisible())
426         CheckBoxPolygons->show();
427       if (!CheckBoxPolyedrs->isVisible())
428         CheckBoxPolyedrs->show();
429       
430
431       myOk5 = true;
432
433       break;
434     }
435   case 3:
436     {
437       GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
438       SubGroup1->setTitle(tr("SIDE_1"));
439       SubGroup2->setTitle(tr("SIDE_2"));
440
441       TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
442       TextLabel2->setText(tr("NODE1_TO_MERGE"));
443       TextLabel3->setText(tr("NODE2_TO_MERGE"));
444       TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
445       TextLabel5->setText(tr("NODE1_TO_MERGE"));
446       TextLabel6->setText(tr("NODE2_TO_MERGE"));
447
448       LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
449       LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator"));
450
451       SMESH::SetPointRepresentation(false);
452
453       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454         aViewWindow->SetSelectionMode(CellSelection);
455       break;
456     }
457   }
458
459   if (constructorId != 3) {
460     TextLabel1->setText(tr("FIRST_NODE_ID"));
461     TextLabel2->setText(tr("SECOND_NODE_ID"));
462     TextLabel3->setText(tr("LAST_NODE_ID"));
463     TextLabel4->setText(tr("FIRST_NODE_ID"));
464     TextLabel5->setText(tr("SECOND_NODE_ID"));
465     TextLabel6->setText(tr("LAST_NODE_ID"));
466
467     LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
468     LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
469
470     SMESH::SetPointRepresentation(true);
471
472     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
473       aViewWindow->SetSelectionMode(NodeSelection);
474   }
475
476   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
477   mySelectionMgr->setSelectedObjects( io );
478 }
479
480 //=================================================================================
481 // function : ClickOnApply()
482 // purpose  :
483 //=================================================================================
484 bool SMESHGUI_SewingDlg::ClickOnApply()
485 {
486   if (mySMESHGUI->isActiveStudyLocked())
487     return false;
488
489   bool aResult = false;
490
491   if (IsValid()) {
492     bool toMerge = CheckBoxMerge->isChecked();
493     bool toCreatePolygons = CheckBoxPolygons->isChecked();
494     bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
495
496     try {
497       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
498       QApplication::setOverrideCursor(Qt::waitCursor);
499
500       int aConstructorId = GetConstructorId();
501       SMESH::SMESH_MeshEditor::Sew_Error anError;
502
503       if (aConstructorId == 0)
504         anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
505                                               LineEdit2->text().toLong(),
506                                               LineEdit3->text().toLong(),
507                                               LineEdit4->text().toLong(),
508                                               LineEdit5->text().toLong(),
509                                               LineEdit6->text().toLong(),
510                                               toCreatePolygons,
511                                               toCreatePolyedrs);
512       else if (aConstructorId == 1)
513         anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
514                                                      LineEdit2->text().toLong(),
515                                                      LineEdit3->text().toLong(),
516                                                      LineEdit4->text().toLong(),
517                                                      LineEdit5->text().toLong());
518       else if (aConstructorId == 2)
519         anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
520                                                LineEdit2->text().toLong(),
521                                                LineEdit3->text().toLong(),
522                                                LineEdit4->text().toLong(),
523                                                LineEdit6->text().toLong(),
524                                                toCreatePolygons,
525                                                toCreatePolyedrs);
526       else if (aConstructorId == 3) {
527         QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
528         QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
529
530         SMESH::long_array_var anElementsId1 = new SMESH::long_array;
531         SMESH::long_array_var anElementsId2 = new SMESH::long_array;
532
533         anElementsId1->length(aListElementsId1.count());
534         anElementsId2->length(aListElementsId2.count());
535
536         for (int i = 0; i < aListElementsId1.count(); i++)
537           anElementsId1[i] = aListElementsId1[i].toInt();
538         for (int i = 0; i < aListElementsId2.count(); i++)
539           anElementsId2[i] = aListElementsId2[i].toInt();
540
541         anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
542                                                anElementsId2.inout(),
543                                                LineEdit2->text().toLong(),
544                                                LineEdit5->text().toLong(),
545                                                LineEdit3->text().toLong(),
546                                                LineEdit6->text().toLong());
547       }
548       aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
549
550       if (toMerge && aResult)
551         aMeshEditor->MergeEqualElements();
552
553       QApplication::restoreOverrideCursor();
554
555       if (!aResult) {
556         QString msg = tr(QString("ERROR_%1").arg(anError));
557         SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
558                                msg, tr("SMESH_BUT_OK"));
559       }
560     } catch (...) {
561     }
562
563     if (aResult) {
564       Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
565
566       SALOME_ListIO aList;
567       aList.Append(anIO);
568       mySelectionMgr->setSelectedObjects(aList, false);
569       SMESH::UpdateView();
570
571       Init();
572       ConstructorsClicked(GetConstructorId());
573     }
574   }
575
576   return aResult;
577 }
578
579 //=================================================================================
580 // function : ClickOnOk()
581 // purpose  :
582 //=================================================================================
583 void SMESHGUI_SewingDlg::ClickOnOk()
584 {
585   if (ClickOnApply())
586     ClickOnCancel();
587 }
588
589 //=================================================================================
590 // function : ClickOnCancel()
591 // purpose  :
592 //=================================================================================
593 void SMESHGUI_SewingDlg::ClickOnCancel()
594 {
595   //mySelectionMgr->clearSelected();
596   SMESH::SetPointRepresentation(false);
597   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
598     aViewWindow->SetSelectionMode(ActorSelection);
599   disconnect(mySelectionMgr, 0, this, 0);
600   mySMESHGUI->ResetState();
601   reject();
602 }
603
604 //=======================================================================
605 //function : onTextChange
606 //purpose  :
607 //=======================================================================
608 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
609 {
610   QLineEdit* send = (QLineEdit*)sender();
611
612   if (myBusy) return;
613   myBusy = true;
614
615   if (send)
616     myEditCurrentArgument = send;
617
618   if      (send == LineEdit1)
619     myOk1 = false;
620   else if (send == LineEdit2)
621     myOk2 = false;
622   else if (send == LineEdit3)
623     myOk3 = false;
624   else if (send == LineEdit4)
625     myOk4 = false;
626   else if (send == LineEdit5)
627     myOk5 = false;
628   else if (send == LineEdit6)
629     myOk6 = false;
630
631   buttonOk->setEnabled(false);
632   buttonApply->setEnabled(false);
633
634   // hilight entered elements/nodes
635   SMDS_Mesh* aMesh = 0;
636
637   if (myActor)
638     aMesh = myActor->GetObject()->GetMesh();
639   else
640     send->clear();
641
642   if (aMesh) {
643     TColStd_MapOfInteger newIndices;
644     
645     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
646       SMESH::SetPointRepresentation(true);
647
648       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
649         aViewWindow->SetSelectionMode(NodeSelection);
650
651       const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
652       if (n) {
653         newIndices.Add(n->GetID());
654         mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
655         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
656           aViewWindow->highlight( myActor->getIO(), true, true );
657         
658         if      (send == LineEdit1)
659           myOk1 = true;
660         else if (send == LineEdit2)
661           myOk2 = true;
662         else if (send == LineEdit3)
663           myOk3 = true;
664         else if (send == LineEdit4)
665           myOk4 = true;
666         else if (send == LineEdit5)
667           myOk5 = true;
668         else if (send == LineEdit6)
669           myOk6 = true;
670       }
671     } else {
672       SMESH::SetPointRepresentation(false);
673
674       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
675         aViewWindow->SetSelectionMode(CellSelection);
676
677       QStringList aListId = QStringList::split(" ", theNewText, false);
678
679       bool isEvenOneExists = false;
680
681       for (int i = 0; i < aListId.count(); i++) {
682         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
683         if (e) 
684           newIndices.Add(e->GetID());
685         
686           if (!isEvenOneExists)
687             isEvenOneExists = true;
688       }
689       
690
691       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
692       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
693         aViewWindow->highlight( myActor->getIO(), true, true );
694       
695       if (isEvenOneExists) {
696         if (send == LineEdit1)
697           myOk1 = true;
698         else if(send == LineEdit4)
699           myOk4 = true;
700       } else {
701         send->clear();
702       }
703     }
704   }
705
706   if (IsValid()) {
707     buttonOk->setEnabled(true);
708     buttonApply->setEnabled(true);
709   }
710
711   myBusy = false;
712 }
713
714 //=================================================================================
715 // function : SelectionIntoArgument()
716 // purpose  : Called when selection as changed or other case
717 //=================================================================================
718 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
719 {
720   if (myBusy) return;
721
722   // clear
723   if (isSelectionChanged)
724     myActor = 0;
725
726   QString aString = "";
727
728   myBusy = true;
729   myEditCurrentArgument->setText(aString);
730   myBusy = false;
731
732   if (!GroupButtons->isEnabled()) // inactive
733     return;
734
735   buttonOk->setEnabled(false);
736   buttonApply->setEnabled(false);
737
738   // get selected mesh
739   SALOME_ListIO aList;
740   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
741
742   int nbSel = aList.Extent();
743   if (nbSel != 1)
744     return;
745
746   Handle(SALOME_InteractiveObject) IO = aList.First();
747   myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
748   myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
749
750   if (myMesh->_is_nil() || !myActor)
751     return;
752
753   // get selected elements/nodes
754   int aNbUnits = 0;
755
756   if (GetConstructorId() != 3 ||
757       (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
758     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
759     if (aNbUnits != 1)
760       return;
761   } else {
762     aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
763     if (aNbUnits < 1)
764       return;
765   }
766
767   myBusy = true;
768   myEditCurrentArgument->setText(aString);
769   myBusy = false;
770
771   // OK
772   if (myEditCurrentArgument == LineEdit1)
773     myOk1 = true;
774   else if (myEditCurrentArgument == LineEdit2)
775     myOk2 = true;
776   else if (myEditCurrentArgument == LineEdit3)
777     myOk3 = true;
778   else if (myEditCurrentArgument == LineEdit4)
779     myOk4 = true;
780   else if (myEditCurrentArgument == LineEdit5)
781     myOk5 = true;
782   else if (myEditCurrentArgument == LineEdit6)
783     myOk6 = true;
784
785   if (IsValid()) {
786     buttonOk->setEnabled(true);
787     buttonApply->setEnabled(true);
788   }
789 }
790
791 //=================================================================================
792 // function : SetEditCurrentArgument()
793 // purpose  :
794 //=================================================================================
795 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
796 {
797   QPushButton* send = (QPushButton*)sender();
798
799   disconnect(mySelectionMgr, 0, this, 0);
800   mySelectionMgr->clearSelected();
801
802   if (send == SelectButton1) {
803     myEditCurrentArgument = LineEdit1;
804     myOk1 = false;
805   }
806   else if (send == SelectButton2) {
807     myEditCurrentArgument = LineEdit2;
808     myOk2 = false;
809   }
810   else if (send == SelectButton3) {
811     myEditCurrentArgument = LineEdit3;
812     myOk3 = false;
813   }
814   else if (send == SelectButton4) {
815     myEditCurrentArgument = LineEdit4;
816     myOk4 = false;
817   }
818   else if (send == SelectButton5) {
819     myEditCurrentArgument = LineEdit5;
820     myOk5 = false;
821   }
822   else if (send == SelectButton6) {
823     myEditCurrentArgument = LineEdit6;
824     myOk6 = false;
825   }
826
827   if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
828     SMESH::SetPointRepresentation(true);
829
830     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831       aViewWindow->SetSelectionMode(NodeSelection);
832
833   } else {
834     SMESH::SetPointRepresentation(false);
835     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
836       aViewWindow->SetSelectionMode(CellSelection);
837   }
838
839   myEditCurrentArgument->setFocus();
840   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
841   SelectionIntoArgument(false);
842 }
843
844 //=================================================================================
845 // function : DeactivateActiveDialog()
846 // purpose  :
847 //=================================================================================
848 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
849 {
850   if (GroupConstructors->isEnabled()) {
851     GroupConstructors->setEnabled(false);
852     GroupArguments->setEnabled(false);
853     GroupButtons->setEnabled(false);
854     mySMESHGUI->ResetState();
855     mySMESHGUI->SetActiveDialogBox(0);
856   }
857 }
858
859 //=================================================================================
860 // function : ActivateThisDialog()
861 // purpose  :
862 //=================================================================================
863 void SMESHGUI_SewingDlg::ActivateThisDialog()
864 {
865   /* Emit a signal to deactivate the active dialog */
866   mySMESHGUI->EmitSignalDeactivateDialog();
867   GroupConstructors->setEnabled(true);
868   GroupArguments->setEnabled(true);
869   GroupButtons->setEnabled(true);
870
871   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
872
873   ConstructorsClicked(GetConstructorId());
874   SelectionIntoArgument();
875 }
876
877 //=================================================================================
878 // function : enterEvent()
879 // purpose  :
880 //=================================================================================
881 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
882 {
883   if (!GroupConstructors->isEnabled())
884     ActivateThisDialog();
885 }
886
887 //=================================================================================
888 // function : closeEvent()
889 // purpose  :
890 //=================================================================================
891 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
892 {
893   /* same than click on cancel button */
894   this->ClickOnCancel();
895 }
896
897 //=======================================================================
898 //function : hideEvent
899 //purpose  : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
902 {
903   if (!isMinimized())
904     ClickOnCancel();
905 }
906
907 //=================================================================================
908 // function : GetConstructorId()
909 // purpose  :
910 //=================================================================================
911 int SMESHGUI_SewingDlg::GetConstructorId()
912 {
913   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
914     return GroupConstructors->id(GroupConstructors->selected());
915   return -1;
916 }
917
918 //=================================================================================
919 // function : GetConstructorId()
920 // purpose  :
921 //=================================================================================
922 bool SMESHGUI_SewingDlg::IsValid()
923 {
924   return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
925 }