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