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