]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_MergeNodesDlg.cxx
Salome HOME
PAL13460 (PAL EDF 301 force the mesh to go through a point)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MergeNodesDlg.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_MergeNodesDlg.cxx
25 //  Author : Michael ZORIN
26 //  Module : SMESH
27 //  $Header:
28
29 #include "SMESHGUI_MergeNodesDlg.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_SpinBox.h"
36
37 #include "SMESH_Actor.h"
38 #include "SMESH_TypeFilter.hxx"
39 #include "SMDS_Mesh.hxx"
40
41 #include "GEOMBase.h"
42
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
46
47 #include "LightApp_Application.h"
48
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51 #include "SVTK_Selector.h"
52 #include "SVTK_Selection.h"
53 #include "SALOME_ListIO.hxx"
54
55 #include "utilities.h"
56
57 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
58
59 // OCCT Includes
60 #include <TColStd_MapOfInteger.hxx>
61
62 // QT Includes
63 #include <qapplication.h>
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
66 #include <qlabel.h>
67 #include <qlineedit.h>
68 #include <qlistbox.h>
69 #include <qlistview.h>
70 #include <qpushbutton.h>
71 #include <qradiobutton.h>
72 #include <qcheckbox.h>
73 #include <qlayout.h>
74 #include <qpixmap.h>
75 #include <qheader.h>
76
77 using namespace std;
78
79 //=================================================================================
80 // class    : SMESHGUI_MergeNodesDlg()
81 // purpose  :
82 //=================================================================================
83 SMESHGUI_MergeNodesDlg::SMESHGUI_MergeNodesDlg( SMESHGUI* theModule, const char* name,
84                                                 bool modal, WFlags fl)
85      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
86                 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
87      mySMESHGUI( theModule ),
88      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
89 {
90   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
91   QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
92
93   if (!name)
94     setName("SMESHGUI_MergeNodesDlg");
95   resize(303, 185);
96   setCaption(tr("SMESH_MERGE_NODES"));
97   setSizeGripEnabled(TRUE);
98   SMESHGUI_MergeNodesDlgLayout = new QGridLayout(this);
99   SMESHGUI_MergeNodesDlgLayout->setSpacing(6);
100   SMESHGUI_MergeNodesDlgLayout->setMargin(11);
101
102   /***************************************************************/
103   GroupConstructors = new QButtonGroup(this, "GroupConstructors");
104   GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
105                                                (QSizePolicy::SizeType)0, 0, 0,
106                                                GroupConstructors->sizePolicy().hasHeightForWidth()));
107   GroupConstructors->setTitle(tr("SMESH_MERGE_NODES" ));
108   GroupConstructors->setExclusive(TRUE);
109   GroupConstructors->setColumnLayout(0, Qt::Vertical);
110   GroupConstructors->layout()->setSpacing(0);
111   GroupConstructors->layout()->setMargin(0);
112   GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
113   GroupConstructorsLayout->setAlignment(Qt::AlignTop);
114   GroupConstructorsLayout->setSpacing(6);
115   GroupConstructorsLayout->setMargin(11);
116   QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
117   RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
118   RadioButton1->setText(tr("" ));
119   RadioButton1->setPixmap(image0);
120   RBLayout->addWidget(RadioButton1);
121   GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
122   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupConstructors, 0, 0);
123
124   /***************************************************************/
125   GroupButtons = new QGroupBox(this, "GroupButtons");
126   GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
127                                           (QSizePolicy::SizeType)0, 0, 0,
128                                           GroupButtons->sizePolicy().hasHeightForWidth()));
129   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
130   GroupButtons->setTitle(tr("" ));
131   GroupButtons->setColumnLayout(0, Qt::Vertical);
132   GroupButtons->layout()->setSpacing(0);
133   GroupButtons->layout()->setMargin(0);
134   GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
135   GroupButtonsLayout->setAlignment(Qt::AlignTop);
136   GroupButtonsLayout->setSpacing(6);
137   GroupButtonsLayout->setMargin(11);
138   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
139   buttonHelp->setText(tr("SMESH_BUT_HELP" ));
140   buttonHelp->setAutoDefault(TRUE);
141   GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
142   buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
143   buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
144   buttonCancel->setAutoDefault(TRUE);
145   GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
146   buttonApply = new QPushButton(GroupButtons, "buttonApply");
147   buttonApply->setText(tr("SMESH_BUT_APPLY" ));
148   buttonApply->setAutoDefault(TRUE);
149   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
150   QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
151   GroupButtonsLayout->addItem(spacer_9, 0, 2);
152   buttonOk = new QPushButton(GroupButtons, "buttonOk");
153   buttonOk->setText(tr("SMESH_BUT_OK" ));
154   buttonOk->setAutoDefault(TRUE);
155   buttonOk->setDefault(TRUE);
156   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
157   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupButtons, 4, 0);
158
159   /***************************************************************/
160
161   // Controls for mesh defining
162   GroupMesh = new QGroupBox(this, "GroupMesh");
163   GroupMesh->setTitle(tr("SMESH_MESH"));
164   GroupMesh->setColumnLayout(0, Qt::Vertical);
165   GroupMesh->layout()->setSpacing(0);
166   GroupMesh->layout()->setMargin(0);
167   GroupMeshLayout = new QGridLayout(GroupMesh->layout());
168   GroupMeshLayout->setAlignment(Qt::AlignTop);
169   GroupMeshLayout->setSpacing(6);
170   GroupMeshLayout->setMargin(11);
171
172   TextLabelName = new QLabel(GroupMesh, "TextLabelName");
173   TextLabelName->setText(tr("SMESH_NAME"));
174   GroupMeshLayout->addWidget(TextLabelName, 0, 0);
175
176   SelectMeshButton = new QPushButton(GroupMesh, "SelectMeshButton");
177   SelectMeshButton->setPixmap(image1);
178   GroupMeshLayout->addWidget(SelectMeshButton, 0, 1);
179
180   LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
181   LineEditMesh->setReadOnly(true);
182   GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
183
184   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupMesh, 1, 0);
185
186   // Controls for coincident nodes detecting
187   GroupCoincident = new QGroupBox(this, "GroupCoincident");
188   GroupCoincident->setTitle(tr("COINCIDENT_NODES"));
189   GroupCoincident->setColumnLayout(0, Qt::Vertical);
190   GroupCoincident->layout()->setSpacing(0);
191   GroupCoincident->layout()->setMargin(0);
192   QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident->layout());
193   GroupCoincidentLayout->setAlignment(Qt::AlignTop);
194   GroupCoincidentLayout->setSpacing(6);
195   GroupCoincidentLayout->setMargin(11);
196
197   TextLabelTolerance = new QLabel(GroupCoincident, "TextLabelTolerance");
198   TextLabelTolerance->setText(tr("SMESH_TOLERANCE"));
199   GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
200
201   SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident, "SpinBoxTolerance");
202   GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
203
204   QPushButton* DetectButton = new QPushButton(GroupCoincident, "DetectButton");
205   DetectButton->setText(tr("DETECT"));
206   GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
207
208   ListCoincident = new QListView(GroupCoincident);
209   ListCoincident->setSorting(-1);
210   ListCoincident->addColumn("Nodes");
211   ListCoincident->header()->hide();
212
213   GroupCoincidentLayout->addMultiCellWidget(ListCoincident, 1, 1, 0, 1);
214
215   SelectAllCB = new QCheckBox(GroupCoincident, "SelectAllCB");
216   SelectAllCB->setText(tr("SELECT_ALL"));
217   GroupCoincidentLayout->addWidget(SelectAllCB, 2, 0);
218
219   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupCoincident, 2, 0);
220
221   // Controls for editing group of nodes
222   GroupEdit = new QGroupBox(this, "GroupEdit");
223   GroupEdit->setTitle(tr("EDIT_GROUP_OF_NODES"));
224   GroupEdit->setColumnLayout(0, Qt::Vertical);
225   GroupEdit->layout()->setSpacing(0);
226   GroupEdit->layout()->setMargin(0);
227   QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit->layout());
228   GroupEditLayout->setAlignment(Qt::AlignTop);
229   GroupEditLayout->setSpacing(6);
230   GroupEditLayout->setMargin(11);
231
232   ListEdit = new QListBox(GroupEdit, "ListEdit");
233   ListEdit->setColumnMode(QListBox::FitToHeight);
234   ListEdit->setSelectionMode(QListBox::Extended);
235   GroupEditLayout->addMultiCellWidget(ListEdit, 0, 2, 0, 0);
236
237   QPushButton* AddButton = new QPushButton(GroupEdit, "AddButton");
238   AddButton->setText(tr("SMESH_BUT_ADD"));
239   GroupEditLayout->addWidget(AddButton, 0, 1);
240
241   QPushButton* RemoveButton = new QPushButton(GroupEdit, "RemoveButton");
242   RemoveButton->setText(tr("SMESH_BUT_REMOVE"));
243   GroupEditLayout->addWidget(RemoveButton, 1, 1);
244
245   QSpacerItem* spacer = new QSpacerItem(20, 200, QSizePolicy::Minimum, QSizePolicy::Expanding);
246   GroupEditLayout->addItem(spacer, 2, 1);
247
248   SMESHGUI_MergeNodesDlgLayout->addWidget(GroupEdit, 3, 0);
249
250   /* Initialisations */
251   SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 3);
252   SpinBoxTolerance->SetValue(1e-05);
253
254   RadioButton1->setChecked(TRUE);
255
256   myEditCurrentArgument = (QWidget*)LineEditMesh; 
257
258   myActor = 0;
259
260   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
261
262   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
263
264   myMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
265
266   /* signals and slots connections */
267   connect(buttonOk, SIGNAL(clicked()),     this, SLOT(ClickOnOk()));
268   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
269   connect(buttonApply, SIGNAL(clicked()),  this, SLOT(ClickOnApply()));
270   connect(buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
271
272   connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
273   connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
274   connect(ListCoincident, SIGNAL (selectionChanged()), this, SLOT(onSelectNodesGroup()));
275   connect(ListCoincident, SIGNAL (pressed(QListViewItem*)), this, SLOT(updateControls()));
276   connect(ListCoincident, SIGNAL (currentChanged(QListViewItem*)), this, SLOT(updateControls()));
277   connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
278   connect(ListEdit, SIGNAL (selectionChanged()), this, SLOT(onSelectNodesFromGroup()));
279   connect(AddButton, SIGNAL (clicked()), this, SLOT(onAdd()));
280   connect(RemoveButton, SIGNAL (clicked()), this, SLOT(onRemove()));
281
282   connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
283   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
284   /* to close dialog if study change */
285   connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
286
287   this->show(); /* displays Dialog */
288
289   resize(0,0);
290   buttonOk->setEnabled(false);
291   buttonApply->setEnabled(false);
292
293   // Init Mesh field from selection
294   SelectionIntoArgument();
295
296   myHelpFileName = "/files/merging_nodes.htm";
297 }
298
299 //=================================================================================
300 // function : ~SMESHGUI_MergeNodesDlg()
301 // purpose  : Destroys the object and frees any allocated resources
302 //=================================================================================
303 SMESHGUI_MergeNodesDlg::~SMESHGUI_MergeNodesDlg()
304 {
305   // no need to delete child widgets, Qt does it all for us
306 }
307
308 //=================================================================================
309 // function : ClickOnApply()
310 // purpose  :
311 //=================================================================================
312 bool SMESHGUI_MergeNodesDlg::ClickOnApply()
313 {
314   if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
315     return false;
316
317   try {
318     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
319
320     QApplication::setOverrideCursor(Qt::waitCursor);
321     SMESH::array_of_long_array_var aGroupsOfNodes = new SMESH::array_of_long_array;
322     aGroupsOfNodes->length(ListCoincident->childCount());
323     QListViewItem* item = ListCoincident->firstChild();
324
325     int anArrayNum = 0;
326     while (item) {
327       QStringList aListIds = QStringList("");
328       if (((QCheckListItem*) item)->isOn())
329         aListIds = QStringList::split(" ", item->text(0), false);
330
331       SMESH::long_array_var anIds = new SMESH::long_array;
332       anIds->length(aListIds.count());
333
334       for (int i = 0; i < aListIds.count(); i++)
335         anIds[i] = aListIds[i].toInt();
336
337       aGroupsOfNodes[anArrayNum++] = anIds.inout();
338
339       item = item->itemBelow();
340     }
341
342     aMeshEditor->MergeNodes (aGroupsOfNodes.inout());
343     QApplication::restoreOverrideCursor();
344   } catch(...) {
345   }
346
347   //mySelectionMgr->clearSelected();
348   SMESH::UpdateView();
349
350   onDetect();
351   return true;
352 }
353
354 //=================================================================================
355 // function : ClickOnOk()
356 // purpose  :
357 //=================================================================================
358 void SMESHGUI_MergeNodesDlg::ClickOnOk()
359 {
360   if (ClickOnApply())
361     ClickOnCancel();
362 }
363
364 //=================================================================================
365 // function : ClickOnCancel()
366 // purpose  :
367 //=================================================================================
368 void SMESHGUI_MergeNodesDlg::ClickOnCancel()
369 {
370   mySelectionMgr->clearFilters();
371   //mySelectionMgr->clearSelected();
372   SMESH::SetPointRepresentation(false);
373   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
374     aViewWindow->SetSelectionMode(ActorSelection);
375   disconnect(mySelectionMgr, 0, this, 0);
376   mySMESHGUI->ResetState();
377   reject();
378 }
379
380 //=================================================================================
381 // function : ClickOnHelp()
382 // purpose  :
383 //=================================================================================
384 void SMESHGUI_MergeNodesDlg::ClickOnHelp()
385 {
386   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
387   if (app) 
388     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
389   else {
390     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
391                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
392                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
393                            QObject::tr("BUT_OK"));
394   }
395 }
396
397 //=================================================================================
398 // function : onEditNodesGroup()
399 // purpose  :
400 //=================================================================================
401 void SMESHGUI_MergeNodesDlg::onEditNodesGroup()
402 {
403   if (ListCoincident->childCount() < 1)
404     return;
405
406   QString aNewIds = "";
407
408   QListBoxItem* anItem;
409   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next())
410     aNewIds+=QString(" %1").arg(anItem->text());
411
412   ListCoincident->currentItem()->setText(0, aNewIds);
413 }
414
415 //=================================================================================
416 // function : updateControls()
417 // purpose  :
418 //=================================================================================
419 void SMESHGUI_MergeNodesDlg::updateControls()
420 {
421   if (ListCoincident->childCount() < 1) {
422     SMESH::SetPointRepresentation(false);
423     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
424       aViewWindow->SetSelectionMode(ActorSelection);
425     return;
426   }
427
428   bool hasChecked = false, hasUnchecked = false;
429
430   QListViewItem* item = ListCoincident->firstChild();
431
432   while (item && (!hasChecked || !hasUnchecked)) {
433     if (((QCheckListItem*) item)->isOn())
434       hasChecked = true;
435     else
436       hasUnchecked = true;
437
438     item = item->itemBelow();
439   }
440
441   if (hasUnchecked)
442     SelectAllCB->setChecked(false);
443
444   bool enable = !(myMesh->_is_nil()) && hasChecked;
445
446   buttonOk->setEnabled(enable);
447   buttonApply->setEnabled(enable);
448 }
449
450 //=================================================================================
451 // function : onDetect()
452 // purpose  :
453 //=================================================================================
454 void SMESHGUI_MergeNodesDlg::onDetect()
455 {
456   if (myMesh->_is_nil())
457     return;
458
459   try {
460     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
461
462     QApplication::setOverrideCursor(Qt::waitCursor);
463     ListCoincident->clear();
464     ListEdit->clear();
465
466     SMESH::array_of_long_array_var aNodeGroups;
467     aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aNodeGroups);
468
469     for (int i = 0; i < aNodeGroups->length(); i++) {
470       SMESH::long_array& aGroup = aNodeGroups[i];
471
472       QString aNodeIds;
473       for (int j = 0; j < aGroup.length(); j++)
474         aNodeIds+=QString(" %1").arg(aGroup[j]);
475
476       new QCheckListItem (ListCoincident, aNodeIds, QCheckListItem::CheckBox);
477     }
478     QApplication::restoreOverrideCursor();
479   } catch(...) {
480   }
481
482   updateControls();
483 }
484
485 //=================================================================================
486 // function : onSelectNodesGroup()
487 // purpose  :
488 //=================================================================================
489 void SMESHGUI_MergeNodesDlg::onSelectNodesGroup()
490 {
491   if (!myActor)
492     return;
493
494   myEditCurrentArgument = (QWidget*)ListCoincident;
495
496   QListViewItem* aSelectedItem = ListCoincident->selectedItem();
497   if (!aSelectedItem)
498     return;
499
500   QStringList aListId = QStringList::split(" ", aSelectedItem->text(0), false);
501
502   ListEdit->clear();
503   ListEdit->insertStringList(aListId);
504
505   //mySelectionMgr->clearSelected();
506   //mySelectionMgr->AddIObject(myActor->getIO());
507   SALOME_ListIO aList;
508   aList.Append(myActor->getIO());
509   mySelectionMgr->setSelectedObjects(aList, false);
510
511   SMESH::SetPointRepresentation(true);
512   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
513     aViewWindow->SetSelectionMode(NodeSelection);
514
515   ListEdit->selectAll(true);
516 }
517
518 //=================================================================================
519 // function : onSelectAll()
520 // purpose  :
521 //=================================================================================
522 void SMESHGUI_MergeNodesDlg::onSelectAll (bool isToggled)
523 {
524   if (isToggled) {
525     int aNbItems = 0;
526     QListViewItem* item = ListCoincident->firstChild();
527     while (item) {
528       aNbItems++;
529       if (!((QCheckListItem*) item)->isOn())
530         ((QCheckListItem*) item)->setOn(true);
531       item = item->itemBelow();
532     }
533
534     if (aNbItems) {
535       buttonOk->setEnabled(true);
536       buttonApply->setEnabled(true);
537     }
538   }
539 }
540
541 //=================================================================================
542 // function : onSelectNodesFromGroup()
543 // purpose  :
544 //=================================================================================
545 void SMESHGUI_MergeNodesDlg::onSelectNodesFromGroup()
546 {
547   if (!myActor)
548     return;
549
550   TColStd_MapOfInteger aIndexes;
551   QListBoxItem* anItem;
552   for (anItem = ListEdit->firstItem(); anItem != 0; anItem = anItem->next()) {
553     if (anItem->isSelected()) {
554       int anId = anItem->text().toInt();
555       aIndexes.Add(anId);
556     }
557   }
558
559   mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
560   SALOME_ListIO aList;
561   aList.Append(myActor->getIO());
562   mySelectionMgr->setSelectedObjects(aList);
563 }
564
565 //=================================================================================
566 // function : onAdd()
567 // purpose  :
568 //=================================================================================
569 void SMESHGUI_MergeNodesDlg::onAdd()
570 {
571   if (!myActor)
572     return;
573
574   QString aListStr = "";
575   int aNbNnodes = 0;
576
577   aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
578   if (aNbNnodes < 1)
579     return;
580
581   QStringList aNodes = QStringList::split(" ", aListStr);
582   QListBoxItem* anItem = 0;
583
584   for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
585     anItem = ListEdit->findItem(*it, Qt::ExactMatch);
586     if (!anItem) {
587       anItem = new QListBoxText(*it);
588       ListEdit->insertItem(anItem);
589     }
590     ListEdit->setSelected(anItem, true);
591   }
592
593   onEditNodesGroup();
594 }
595
596 //=================================================================================
597 // function : onRemove()
598 // purpose  :
599 //=================================================================================
600 void SMESHGUI_MergeNodesDlg::onRemove()
601 {
602   if (myEditCurrentArgument != (QWidget*)ListCoincident)
603     return;
604
605   for (int i = ListEdit->count(); i > 0; i--) {
606     if (ListEdit->isSelected(i-1))
607       ListEdit->removeItem(i-1);
608   }
609   onEditNodesGroup();
610 }
611
612 //=================================================================================
613 // function : SetEditCurrentArgument()
614 // purpose  :
615 //=================================================================================
616 void SMESHGUI_MergeNodesDlg::SetEditCurrentArgument()
617 {
618   QPushButton* send = (QPushButton*)sender();
619
620   disconnect(mySelectionMgr, 0, this, 0);
621   mySelectionMgr->clearSelected();
622   mySelectionMgr->clearFilters();
623
624   if (send == SelectMeshButton) {
625     myEditCurrentArgument = (QWidget*)LineEditMesh;
626     SMESH::SetPointRepresentation(false);
627     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
628       aViewWindow->SetSelectionMode(ActorSelection);
629     mySelectionMgr->installFilter(myMeshOrSubMeshFilter);
630   }
631
632   myEditCurrentArgument->setFocus();
633   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
634   SelectionIntoArgument();
635 }
636
637 //=================================================================================
638 // function : SelectionIntoArgument()
639 // purpose  : Called when selection as changed or other case
640 //=================================================================================
641 void SMESHGUI_MergeNodesDlg::SelectionIntoArgument()
642 {
643   if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
644     QString aString = "";
645     LineEditMesh->setText(aString);
646
647     ListCoincident->clear();
648     ListEdit->clear();
649
650     int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
651     if (nbSel != 1)
652       return;
653
654     SALOME_ListIO aList;
655     mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
656
657     Handle(SALOME_InteractiveObject) IO = aList.First();
658     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
659     myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
660     if (myMesh->_is_nil() || !myActor)
661       return;
662
663     LineEditMesh->setText(aString);
664   }
665 }
666
667 //=================================================================================
668 // function : DeactivateActiveDialog()
669 // purpose  :
670 //=================================================================================
671 void SMESHGUI_MergeNodesDlg::DeactivateActiveDialog()
672 {
673   if (GroupConstructors->isEnabled()) {
674     GroupConstructors->setEnabled(false);
675     GroupMesh->setEnabled(false);
676     GroupCoincident->setEnabled(false);
677     GroupEdit->setEnabled(false);
678     GroupButtons->setEnabled(false);
679     mySMESHGUI->ResetState();
680     mySMESHGUI->SetActiveDialogBox(0);
681   }
682 }
683
684 //=================================================================================
685 // function : ActivateThisDialog()
686 // purpose  :
687 //=================================================================================
688 void SMESHGUI_MergeNodesDlg::ActivateThisDialog()
689 {
690   /* Emit a signal to deactivate the active dialog */
691   mySMESHGUI->EmitSignalDeactivateDialog();
692   GroupConstructors->setEnabled(true);
693   GroupMesh->setEnabled(true);
694   GroupCoincident->setEnabled(true);
695   GroupEdit->setEnabled(true);
696   GroupButtons->setEnabled(true);
697
698   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
699
700   SelectionIntoArgument();
701 }
702
703 //=================================================================================
704 // function : enterEvent()
705 // purpose  :
706 //=================================================================================
707 void SMESHGUI_MergeNodesDlg::enterEvent (QEvent*)
708 {
709   if (!GroupConstructors->isEnabled())
710     ActivateThisDialog();
711 }
712
713 //=================================================================================
714 // function : closeEvent()
715 // purpose  :
716 //=================================================================================
717 void SMESHGUI_MergeNodesDlg::closeEvent (QCloseEvent*)
718 {
719   /* same than click on cancel button */
720   ClickOnCancel();
721 }
722
723 //=======================================================================
724 //function : hideEvent()
725 //purpose  : caused by ESC key
726 //=======================================================================
727 void SMESHGUI_MergeNodesDlg::hideEvent (QHideEvent*)
728 {
729   if (!isMinimized())
730     ClickOnCancel();
731 }
732
733 //=================================================================================
734 // function : keyPressEvent()
735 // purpose  :
736 //=================================================================================
737 void SMESHGUI_MergeNodesDlg::keyPressEvent( QKeyEvent* e )
738 {
739   QDialog::keyPressEvent( e );
740   if ( e->isAccepted() )
741     return;
742
743   if ( e->key() == Key_F1 )
744     {
745       e->accept();
746       ClickOnHelp();
747     }
748 }