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