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