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