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