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