Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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 = "sewing_meshes_page.html";
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                 QString platform;
629 #ifdef WIN32
630                 platform = "winapplication";
631 #else
632                 platform = "application";
633 #endif
634     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
635                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
636                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
637                            QObject::tr("BUT_OK"));
638   }
639 }
640
641 //=======================================================================
642 //function : onTextChange
643 //purpose  :
644 //=======================================================================
645 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
646 {
647   QLineEdit* send = (QLineEdit*)sender();
648
649   if (myBusy) return;
650   myBusy = true;
651
652   if (send)
653     myEditCurrentArgument = send;
654
655   if      (send == LineEdit1)
656     myOk1 = false;
657   else if (send == LineEdit2)
658     myOk2 = false;
659   else if (send == LineEdit3)
660     myOk3 = false;
661   else if (send == LineEdit4)
662     myOk4 = false;
663   else if (send == LineEdit5)
664     myOk5 = false;
665   else if (send == LineEdit6)
666     myOk6 = false;
667
668   buttonOk->setEnabled(false);
669   buttonApply->setEnabled(false);
670
671   // hilight entered elements/nodes
672   SMDS_Mesh* aMesh = 0;
673
674   if (myActor)
675     aMesh = myActor->GetObject()->GetMesh();
676   else
677     send->clear();
678
679   if (aMesh) {
680     TColStd_MapOfInteger newIndices;
681     
682     if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
683       SMESH::SetPointRepresentation(true);
684
685       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
686         aViewWindow->SetSelectionMode(NodeSelection);
687
688       const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
689       if (n) {
690         newIndices.Add(n->GetID());
691         mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
692         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
693           aViewWindow->highlight( myActor->getIO(), true, true );
694         
695         if      (send == LineEdit1)
696           myOk1 = true;
697         else if (send == LineEdit2)
698           myOk2 = true;
699         else if (send == LineEdit3)
700           myOk3 = true;
701         else if (send == LineEdit4)
702           myOk4 = true;
703         else if (send == LineEdit5)
704           myOk5 = true;
705         else if (send == LineEdit6)
706           myOk6 = true;
707       }
708     } else {
709       SMESH::SetPointRepresentation(false);
710
711       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
712         aViewWindow->SetSelectionMode(CellSelection);
713
714       QStringList aListId = QStringList::split(" ", theNewText, false);
715
716       bool isEvenOneExists = false;
717
718       for (int i = 0; i < aListId.count(); i++) {
719         const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
720         if (e) 
721           newIndices.Add(e->GetID());
722         
723           if (!isEvenOneExists)
724             isEvenOneExists = true;
725       }
726       
727
728       mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
729       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
730         aViewWindow->highlight( myActor->getIO(), true, true );
731       
732       if (isEvenOneExists) {
733         if (send == LineEdit1)
734           myOk1 = true;
735         else if(send == LineEdit4)
736           myOk4 = true;
737       } else {
738         send->clear();
739       }
740     }
741   }
742
743   if (IsValid()) {
744     buttonOk->setEnabled(true);
745     buttonApply->setEnabled(true);
746   }
747
748   myBusy = false;
749 }
750
751 //=================================================================================
752 // function : SelectionIntoArgument()
753 // purpose  : Called when selection as changed or other case
754 //=================================================================================
755 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
756 {
757   if (myBusy) return;
758
759   // clear
760   if (isSelectionChanged)
761     myActor = 0;
762
763   QString aString = "";
764
765   myBusy = true;
766   myEditCurrentArgument->setText(aString);
767   myBusy = false;
768
769   if (!GroupButtons->isEnabled()) // inactive
770     return;
771
772   buttonOk->setEnabled(false);
773   buttonApply->setEnabled(false);
774
775   // get selected mesh
776   SALOME_ListIO aList;
777   mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
778
779   int nbSel = aList.Extent();
780   if (nbSel != 1)
781     return;
782
783   Handle(SALOME_InteractiveObject) IO = aList.First();
784   myMesh = SMESH::GetMeshByIO(IO); //@ SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
785   myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
786
787   if (myMesh->_is_nil() || !myActor)
788     return;
789
790   // get selected elements/nodes
791   int aNbUnits = 0;
792
793   if (GetConstructorId() != 3 ||
794       (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
795     aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
796     if (aNbUnits != 1)
797       return;
798   } else {
799     aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
800     if (aNbUnits < 1)
801       return;
802   }
803
804   myBusy = true;
805   myEditCurrentArgument->setText(aString);
806   myBusy = false;
807
808   // OK
809   if (myEditCurrentArgument == LineEdit1)
810     myOk1 = true;
811   else if (myEditCurrentArgument == LineEdit2)
812     myOk2 = true;
813   else if (myEditCurrentArgument == LineEdit3)
814     myOk3 = true;
815   else if (myEditCurrentArgument == LineEdit4)
816     myOk4 = true;
817   else if (myEditCurrentArgument == LineEdit5)
818     myOk5 = true;
819   else if (myEditCurrentArgument == LineEdit6)
820     myOk6 = true;
821
822   if (IsValid()) {
823     buttonOk->setEnabled(true);
824     buttonApply->setEnabled(true);
825   }
826 }
827
828 //=================================================================================
829 // function : SetEditCurrentArgument()
830 // purpose  :
831 //=================================================================================
832 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
833 {
834   QPushButton* send = (QPushButton*)sender();
835
836   disconnect(mySelectionMgr, 0, this, 0);
837   mySelectionMgr->clearSelected();
838
839   if (send == SelectButton1) {
840     myEditCurrentArgument = LineEdit1;
841     myOk1 = false;
842   }
843   else if (send == SelectButton2) {
844     myEditCurrentArgument = LineEdit2;
845     myOk2 = false;
846   }
847   else if (send == SelectButton3) {
848     myEditCurrentArgument = LineEdit3;
849     myOk3 = false;
850   }
851   else if (send == SelectButton4) {
852     myEditCurrentArgument = LineEdit4;
853     myOk4 = false;
854   }
855   else if (send == SelectButton5) {
856     myEditCurrentArgument = LineEdit5;
857     myOk5 = false;
858   }
859   else if (send == SelectButton6) {
860     myEditCurrentArgument = LineEdit6;
861     myOk6 = false;
862   }
863
864   if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
865     SMESH::SetPointRepresentation(true);
866
867     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
868       aViewWindow->SetSelectionMode(NodeSelection);
869
870   } else {
871     SMESH::SetPointRepresentation(false);
872     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873       aViewWindow->SetSelectionMode(CellSelection);
874   }
875
876   myEditCurrentArgument->setFocus();
877   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
878   SelectionIntoArgument(false);
879 }
880
881 //=================================================================================
882 // function : DeactivateActiveDialog()
883 // purpose  :
884 //=================================================================================
885 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
886 {
887   if (GroupConstructors->isEnabled()) {
888     GroupConstructors->setEnabled(false);
889     GroupArguments->setEnabled(false);
890     GroupButtons->setEnabled(false);
891     mySMESHGUI->ResetState();
892     mySMESHGUI->SetActiveDialogBox(0);
893   }
894 }
895
896 //=================================================================================
897 // function : ActivateThisDialog()
898 // purpose  :
899 //=================================================================================
900 void SMESHGUI_SewingDlg::ActivateThisDialog()
901 {
902   /* Emit a signal to deactivate the active dialog */
903   mySMESHGUI->EmitSignalDeactivateDialog();
904   GroupConstructors->setEnabled(true);
905   GroupArguments->setEnabled(true);
906   GroupButtons->setEnabled(true);
907
908   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
909
910   ConstructorsClicked(GetConstructorId());
911   SelectionIntoArgument();
912 }
913
914 //=================================================================================
915 // function : enterEvent()
916 // purpose  :
917 //=================================================================================
918 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
919 {
920   if (!GroupConstructors->isEnabled())
921     ActivateThisDialog();
922 }
923
924 //=================================================================================
925 // function : closeEvent()
926 // purpose  :
927 //=================================================================================
928 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
929 {
930   /* same than click on cancel button */
931   this->ClickOnCancel();
932 }
933
934 //=======================================================================
935 //function : hideEvent
936 //purpose  : caused by ESC key
937 //=======================================================================
938 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
939 {
940   if (!isMinimized())
941     ClickOnCancel();
942 }
943
944 //=================================================================================
945 // function : GetConstructorId()
946 // purpose  :
947 //=================================================================================
948 int SMESHGUI_SewingDlg::GetConstructorId()
949 {
950   if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
951     return GroupConstructors->id(GroupConstructors->selected());
952   return -1;
953 }
954
955 //=================================================================================
956 // function : GetConstructorId()
957 // purpose  :
958 //=================================================================================
959 bool SMESHGUI_SewingDlg::IsValid()
960 {
961   return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
962 }
963
964 //=================================================================================
965 // function : keyPressEvent()
966 // purpose  :
967 //=================================================================================
968 void SMESHGUI_SewingDlg::keyPressEvent( QKeyEvent* e )
969 {
970   QDialog::keyPressEvent( e );
971   if ( e->isAccepted() )
972     return;
973
974   if ( e->key() == Key_F1 )
975     {
976       e->accept();
977       ClickOnHelp();
978     }
979 }