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