Salome HOME
aa3a15cbda1887e3e11e2447ed10742f8f422f19
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.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.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_GroupDlg.cxx
25 //  Author : Natalia KOPNOVA
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Filter.h"
32
33 #include "SMESHGUI.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESHGUI_MeshUtils.h"
37 #include "SMESHGUI_GroupUtils.h"
38 #include "SMESHGUI_FilterUtils.h"
39 #include "SMESHGUI_GEOMGenUtils.h"
40
41 #include "SALOMEGUI_QtCatchCorbaException.hxx"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "VTKViewer_ViewFrame.h"
44 #include "QAD_Application.h"
45 #include "QAD_Desktop.h"
46 #include "QAD_MessageBox.h"
47 #include "QAD_RightFrame.h"
48 #include "utilities.h"
49
50 #include "SMESH_Actor.h"
51
52 #include "GEOMBase.h"
53
54 // QT Includes
55 #include <qbuttongroup.h>
56 #include <qgroupbox.h>
57 #include <qhbox.h>
58 #include <qlabel.h>
59 #include <qlineedit.h>
60 #include <qpushbutton.h>
61 #include <qradiobutton.h>
62 #include <qcheckbox.h>
63 #include <qlayout.h>
64 #include <qlistbox.h>
65 #include <qimage.h>
66 #include <qpixmap.h>
67 #include <qmemarray.h>
68 #include <qwidgetstack.h>
69
70 // STL includes
71 #include <vector>
72 #include <algorithm>
73
74 using namespace std;
75
76 //=================================================================================
77 // class    : SMESHGUI_GroupDlg()
78 // purpose  : 
79 //=================================================================================
80 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
81                                       SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl )
82   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
83 {
84   if ( !name ) setName( "SMESHGUI_GroupDlg" );
85   initDialog(theSel, true);
86   if (!theMesh->_is_nil())
87     init(theMesh);
88   else {
89     mySelectSubMesh->setEnabled(false);
90     mySelectGroup->setEnabled(false);
91     myGeomGroupBtn->setEnabled(false);
92     myGeomGroupLine->setEnabled(false);
93   }
94   
95   /* Move widget on the botton right corner of main widget */
96   int x, y ;
97   mySMESHGUI->DefineDlgPosition(this, x, y);
98   this->move(x, y);
99 }
100
101 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
102                                       SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl )
103   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
104 {
105   if ( !name ) setName( "SMESHGUI_GroupDlg" );
106   initDialog(theSel, false);
107   if (!theGroup->_is_nil())
108     init(theGroup);
109   else {
110     mySelectSubMesh->setEnabled(false);
111     mySelectGroup->setEnabled(false);
112   }
113   
114   /* Move widget on the botton right corner of main widget */
115   int x, y ;
116   mySMESHGUI->DefineDlgPosition(this, x, y);
117   this->move(x, y);
118 }
119
120 void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
121 {
122   myFilterDlg = 0;
123   myCreate = create;
124   myCurrentLineEdit = 0;
125   
126   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
127
128   if (create)
129     setCaption( tr( "SMESH_CREATE_GROUP_TITLE"  ) );
130   else
131     setCaption( tr( "SMESH_EDIT_GROUP_TITLE"  ) );
132         
133   setSizeGripEnabled( TRUE );
134
135   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
136   
137   /***************************************************************/
138   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
139   if (create)
140     meshGroupLab->setText(tr("SMESH_MESH"));
141   else
142     meshGroupLab->setText(tr("SMESH_GROUP"));
143   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
144   myMeshGroupBtn->setPixmap(image0);
145   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
146   myMeshGroupLine->setReadOnly(true);
147  
148   /***************************************************************/
149   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
150   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
151   myTypeGroup->setExclusive(true);
152
153   QStringList types;
154   types.append(tr("MESH_NODE"));
155   types.append(tr("SMESH_EDGE"));
156   types.append(tr("SMESH_FACE"));
157   types.append(tr("SMESH_VOLUME"));
158   QRadioButton* rb;
159   for (int i = 0; i < types.count(); i++) {
160     rb = new QRadioButton(types[i], myTypeGroup);
161   }
162   myTypeGroup->setEnabled(create);
163   myTypeId = -1;
164     
165   /***************************************************************/
166   QLabel* aName = new QLabel(this, "name label");
167   aName->setText(tr("SMESH_NAME"));
168   aName->setMinimumSize(50,0);
169   myName = new QLineEdit(this, "name");
170
171   /***************************************************************/
172   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
173   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
174   myGrpTypeGroup->setExclusive(true);
175   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
176   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
177   myGrpTypeGroup->setEnabled(create);
178   myGrpTypeId = -1;
179
180   /***************************************************************/
181   myWGStack = new QWidgetStack( this, "widget stack");
182   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
183   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
184   
185   /***************************************************************/
186   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
187   aContentBox->setTitle(tr("SMESH_CONTENT"));
188   QFrame* aContent = new QFrame(aContentBox, "content");
189   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
190   aLayout->setSpacing(6);
191   aLayout->setAutoAdd(false);
192
193   QLabel* aLabel = new QLabel(aContent, "elements label");
194   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
195   myElements = new QListBox(aContent, "elements list");
196   myElements->setSelectionMode(QListBox::Extended);
197
198   myFilter = new QPushButton(aContent, "filter");
199   myFilter->setText(tr("SMESH_BUT_FILTER"));
200   QPushButton* aAddBtn = new QPushButton(aContent, "add");
201   aAddBtn->setText(tr("SMESH_BUT_ADD"));
202   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
203   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
204   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
205   aSortBtn->setText(tr("SMESH_BUT_SORT"));
206
207   aLayout->addWidget(aLabel, 0, 0);
208   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
209   aLayout->addWidget(myFilter, 1, 2);
210   aLayout->addWidget(aAddBtn, 3, 2);
211   aLayout->addWidget(aRemoveBtn, 4, 2);
212   aLayout->addWidget(aSortBtn, 6, 2);
213
214   aLayout->setColStretch(0, 1);
215   aLayout->addColSpacing(1, 20);
216   aLayout->addColSpacing(3, 20);
217   aLayout->setRowStretch(2, 1);
218   aLayout->setRowStretch(5, 1);
219
220   /***************************************************************/
221   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
222   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
223   
224   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
225   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
226   mySelectSubMesh->setMinimumSize(50, 0);
227   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
228   mySubMeshBtn->setText("");
229   mySubMeshBtn->setPixmap(image0);
230   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
231   mySubMeshLine->setReadOnly(true);
232   onSelectSubMesh(false);
233   
234   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
235   mySelectGroup->setText(tr("SMESH_GROUP"));
236   mySelectGroup->setMinimumSize(50, 0);
237   myGroupBtn = new QPushButton(aSelectBox, "group button");
238   myGroupBtn->setText("");
239   myGroupBtn->setPixmap(image0);
240   myGroupLine = new QLineEdit(aSelectBox, "group line");
241   myGroupLine->setReadOnly(true);
242   onSelectGroup(false);
243   
244   /***************************************************************/
245   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
246   wg1Layout->addWidget(aContentBox, 0, 0);
247   wg1Layout->addWidget(aSelectBox, 1, 0);
248   wg1Layout->setRowStretch(2, 5);
249
250   /***************************************************************/
251   QLabel* geomObject = new QLabel(wg2, "geometry object label");
252   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
253   myGeomGroupBtn = new QPushButton(wg2, "geometry group button");
254   myGeomGroupBtn->setText("");
255   myGeomGroupBtn->setPixmap(image0);
256   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
257   myGeomGroupLine->setReadOnly(true); //VSR ???
258   onSelectGeomGroup(false);
259   
260   /***************************************************************/
261   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
262   wg2Layout->addWidget(geomObject,     0, 0);
263   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
264   wg2Layout->addWidget(myGeomGroupLine,0, 2);
265   wg2Layout->setRowStretch(1, 5);
266
267   /***************************************************************/
268   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
269   dumb->addWidget(wg1);
270   dumb->addWidget(wg2);
271   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
272   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
273
274   /***************************************************************/
275   QFrame* aButtons = new QFrame(this, "button box");
276   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
277   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
278   aBtnLayout->setAutoAdd(false);
279
280   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
281   aOKBtn->setText(tr("SMESH_BUT_OK"));
282   aOKBtn->setAutoDefault(true);
283   aOKBtn->setDefault(true);
284   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
285   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
286   aApplyBtn->setAutoDefault(true);
287   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
288   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
289   aCloseBtn->setAutoDefault(true);
290
291   aBtnLayout->addWidget(aOKBtn);
292   aBtnLayout->addWidget(aApplyBtn);
293   aBtnLayout->addStretch();
294   aBtnLayout->addWidget(aCloseBtn);
295
296   /***************************************************************/
297   aMainLayout->addWidget(meshGroupLab,    0, 0);
298   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
299   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
300   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
301   aMainLayout->addWidget(aName,      2, 0);
302   aMainLayout->addWidget(myName,     2, 2);
303   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
304   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
305   aMainLayout->setRowStretch( 5, 5 );
306   aMainLayout->addMultiCellWidget(aButtons,       6, 6, 0, 2);
307
308   /* signals and slots connections */
309   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
310
311   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
312
313   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
314
315   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
316   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
317
318   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
319   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
320   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
321   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
322
323   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
324   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
325   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
326   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
327   connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
328
329   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
330   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
331   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
332
333   /* Init selection */
334   mySelection = theSel;  
335   mySMESHGUI = SMESHGUI::GetSMESHGUI();
336   mySMESHGUI->SetActiveDialogBox(this);
337   mySMESHGUI->SetState(800);
338
339   mySelectionMode = -1;
340   myMeshFilter = new SMESH_TypeFilter(MESH);
341   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
342   myGroupFilter = new SMESH_TypeFilter(GROUP);
343
344   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
345   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
346   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
347
348   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
349   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
350
351   if (myMesh->_is_nil() )
352     myTypeGroup->setButton(0);
353   
354   updateButtons();
355 }
356
357 //=================================================================================
358 // function : ~SMESHGUI_GroupDlg()
359 // purpose  : Destroys the object and frees any allocated resources
360 //=================================================================================
361 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
362 {
363   // no need to delete child widgets, Qt does it all for us
364   if ( myFilterDlg != 0 )
365   {
366     myFilterDlg->reparent( 0, QPoint() );
367     delete myFilterDlg;
368   }
369 }
370
371
372 //=================================================================================
373 // function : Init()
374 // purpose  :
375 //=================================================================================
376 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
377 {
378   /* init data from current selection */
379   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
380   myGroup = SMESH::SMESH_Group::_nil();
381   
382   myActor = SMESH::FindActorByObject(myMesh);
383   SMESH::SetPickable(myActor);
384    
385   QString aName = mySelection->firstIObject()->getName();
386   myMeshGroupLine->setText(aName) ;
387   myMeshGroupLine->home( false );
388
389   myCurrentLineEdit = 0;
390
391   myTypeGroup->setButton(0);
392   onTypeChanged(0);
393 }
394
395 //=================================================================================
396 // function : Init()
397 // purpose  :
398 //=================================================================================
399 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
400 {
401   myMesh = theGroup->GetMesh();
402   myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
403   
404   myActor = SMESH::FindActorByObject(myMesh);
405   if ( !myActor )
406     myActor = SMESH::FindActorByObject(myGroup);
407   SMESH::SetPickable(myActor);
408   
409   int aType = 0;
410   switch(theGroup->GetType()) {
411   case SMESH::NODE: aType= 0; break;
412   case SMESH::EDGE: aType = 1; break;
413   case SMESH::FACE: aType = 2; break;
414   case SMESH::VOLUME: aType = 3; break;
415   } 
416   
417   myName->setText(myGroup->GetName());
418   myName->home(false);
419   myMeshGroupLine->setText(myGroup->GetName());
420
421   myCurrentLineEdit = 0;
422   myTypeGroup->setButton(aType);
423   myElements->clear();
424   setSelectionMode(aType);
425   myTypeId = aType;
426   
427   myIdList.clear();
428   if (!theGroup->IsEmpty()) {
429     SMESH::long_array_var anElements = myGroup->GetListOfID();
430     int k = anElements->length();
431     for (int i = 0; i < k; i++) {
432       myIdList.append(anElements[i]);
433       myElements->insertItem(QString::number(anElements[i]));
434     }
435     myElements->selectAll(true);
436   }
437 }
438
439
440 //=================================================================================
441 // function : updateButtons()
442 // purpose  : 
443 //=================================================================================
444 void SMESHGUI_GroupDlg::updateButtons()
445 {
446   bool enable; 
447   
448   if (myGrpTypeId == 0)
449     enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
450   else if (myGrpTypeId == 1)
451     enable = !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup );
452   QPushButton* aBtn;
453   aBtn = (QPushButton*) child("ok", "QPushButton");
454   if (aBtn) aBtn->setEnabled(enable);
455   aBtn = (QPushButton*) child("apply", "QPushButton");
456   if (aBtn) aBtn->setEnabled(enable);
457 }
458
459 //=================================================================================
460 // function : onNameChanged()
461 // purpose  : 
462 //=================================================================================
463 void SMESHGUI_GroupDlg::onNameChanged(const QString& text)
464 {
465   updateButtons();
466 }
467
468 //=================================================================================
469 // function : onTypeChanged()
470 // purpose  : Group elements type radio button management
471 //=================================================================================
472 void SMESHGUI_GroupDlg::onTypeChanged(int id)
473 {
474   if (myTypeId != id) {
475     myElements->clear();
476     if (myCurrentLineEdit == 0)
477       setSelectionMode(id);
478   }
479   myTypeId = id;
480 }
481
482 //=================================================================================
483 // function : onGrpTypeChanged()
484 // purpose  : Group type radio button management
485 //=================================================================================
486 void SMESHGUI_GroupDlg::onGrpTypeChanged(int id)
487 {
488   if (myGrpTypeId != id) {
489     myWGStack->raiseWidget( id );
490     onSelectGeomGroup(id == 1);
491   }
492   myGrpTypeId = id;
493 }
494
495 //=================================================================================
496 // function : setSelectionMode()
497 // purpose  : Radio button management
498 //=================================================================================
499 void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
500 {
501   // PAL7314
502   if (myMesh->_is_nil())
503     return;
504   
505   if (mySelectionMode != theMode) {
506     mySelection->ClearIObjects();
507     mySelection->ClearFilters();
508     SMESH::SetPointRepresentation(false);
509     if (theMode < 4) {
510       switch(theMode){
511       case 0:
512         if ( myActor )
513           myActor->SetPointRepresentation(true);
514         else
515           SMESH::SetPointRepresentation(true);
516         QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
517         break;
518       case 1:
519         QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
520         break;
521       case 2:
522         QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
523         break;
524       default:
525         QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
526       }
527     }
528     else {
529       QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
530       if (theMode == 4)
531         mySelection->AddFilter(mySubMeshFilter);
532       else if (theMode == 5)
533         mySelection->AddFilter(myGroupFilter);
534       else if (theMode == 6)
535         mySelection->AddFilter(myMeshFilter);
536     }
537     mySelectionMode = theMode;
538   }
539
540
541 //=================================================================================
542 // function : onApply()
543 // purpose  :
544 //=================================================================================
545 bool SMESHGUI_GroupDlg::onApply()
546 {
547   if (mySMESHGUI->ActiveStudyLocked())
548     return false;
549   
550   if ( myGrpTypeId == 0 && !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
551     mySelection->ClearIObjects();
552     if (myGroup->_is_nil()) {
553       SMESH::ElementType aType = SMESH::ALL;
554       switch(myTypeId) {
555       case 0: aType = SMESH::NODE; break;
556       case 1: aType = SMESH::EDGE; break;
557       case 2: aType = SMESH::FACE; break;
558       case 3: aType = SMESH::VOLUME; break;
559       }
560       SMESH::long_array_var anIdList = new SMESH::long_array;
561       int i, k = myElements->count();
562       anIdList->length(k);
563       QListBoxItem* anItem;
564       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
565         anIdList[i] = anItem->text().toInt();
566       }
567
568       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
569       myGroup->Add(anIdList.inout());
570       
571       /* init for next operation */
572       myName->setText("");
573       myElements->clear();
574       myGroup = SMESH::SMESH_Group::_nil();
575     }
576     else {
577       myGroup->SetName(myName->text());
578
579       QValueList<int> aAddList;
580       QValueList<int>::iterator anIt;
581       QListBoxItem* anItem;
582       
583       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
584         int anId = anItem->text().toInt();
585         if ((anIt = myIdList.find(anId)) == myIdList.end())
586           aAddList.append(anId);
587         else
588           myIdList.remove(anIt);
589       }
590       if (!aAddList.empty()) {
591         SMESH::long_array_var anIdList = new SMESH::long_array;
592         anIdList->length(aAddList.count());
593         int i;
594         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
595           anIdList[i] = *anIt;
596         myGroup->Add(anIdList.inout());
597       }
598       if (!myIdList.empty()) {
599         SMESH::long_array_var anIdList = new SMESH::long_array;
600         anIdList->length(myIdList.count());
601         int i;
602         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
603           anIdList[i] = *anIt;
604         myGroup->Remove(anIdList.inout());
605       }
606       /* init for next operation */
607       myIdList.clear();
608       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
609         myIdList.append(anItem->text().toInt());
610     }
611
612     mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
613     SMESH::UpdateView(); // asv: fix of BUG PAL5515
614     mySelection->ClearIObjects();
615     return true;
616   }
617   else if (myGrpTypeId == 1 && !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup ))
618     {
619       SMESH::ElementType aType = SMESH::ALL;
620       switch(myTypeId) {
621       case 0: aType = SMESH::NODE; break;
622       case 1: aType = SMESH::EDGE; break;
623       case 2: aType = SMESH::FACE; break;
624       case 3: aType = SMESH::VOLUME; break;
625       }
626       
627       SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
628       GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
629       
630       SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
631       
632       mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
633       mySelection->ClearIObjects();
634       /* init for next operation */
635       myName->setText("");
636       return true;
637     }
638   
639   return false;
640 }
641
642 //=================================================================================
643 // function : onOK()
644 // purpose  :
645 //=================================================================================
646 void SMESHGUI_GroupDlg::onOK()
647 {
648   if ( onApply() )
649     onClose();
650 }
651
652 static bool busy = false;
653 //=================================================================================
654 // function : onListSelectionChanged()
655 // purpose  : Called when selection in element list is changed
656 //=================================================================================
657 void SMESHGUI_GroupDlg::onListSelectionChanged()
658 {
659   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
660   if (busy || !myActor) return;
661   busy = true;
662
663   if (myCurrentLineEdit == 0) {
664     mySelection->ClearIObjects();
665     TColStd_MapOfInteger aIndexes;
666     QListBoxItem* anItem;
667     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
668       if (anItem->isSelected()) {
669         int anId = anItem->text().toInt();
670         aIndexes.Add(anId);
671       }
672     }
673     mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
674     mySelection->AddIObject(myActor->getIO());
675   }
676   busy = false;
677 }
678
679 //=================================================================================
680 // function : onObjectSelectionChanged()
681 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
682 //=================================================================================
683 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
684 {
685   if (busy || !isEnabled()) return;
686   busy = true;
687
688   int aNbSel = mySelection->IObjectCount();
689   myElements->clearSelection();
690  
691   if (myCurrentLineEdit) {
692     myCurrentLineEdit->setText("") ;
693     QString aString = "";
694     
695     if (myCurrentLineEdit == myMeshGroupLine)
696       {
697         mySelectSubMesh->setEnabled(false);
698         mySelectGroup->setEnabled(false);
699         myGroupLine->setText("");
700         mySubMeshLine->setText("");
701         
702         myGeomGroupBtn->setEnabled(false);
703         myGeomGroupLine->setEnabled(false);
704         myGeomGroupLine->setText("");
705         if (!myCreate)
706           myName->setText("");
707         
708         myElements->clear();
709
710         if(aNbSel != 1)
711           {
712             myGroup = SMESH::SMESH_Group::_nil();
713             myMesh = SMESH::SMESH_Mesh::_nil();
714             busy = false;
715             return;
716           }
717         Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
718         
719         if (myCreate)
720           {
721             myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
722             if(myMesh->_is_nil())
723               return;
724             myGroup = SMESH::SMESH_Group::_nil();
725             
726             myActor = SMESH::FindActorByObject(myMesh);
727             SMESH::SetPickable(myActor);
728             
729             aString = mySelection->firstIObject()->getName();
730             myMeshGroupLine->setText(aString) ;
731             myMeshGroupLine->home( false );
732             
733             mySelectSubMesh->setEnabled(true);
734             mySelectGroup->setEnabled(true);
735             myGeomGroupBtn->setEnabled(true);
736             myGeomGroupLine->setEnabled(true);
737             updateButtons();
738           }
739         else
740           {
741             SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
742             if(aGroup->_is_nil())
743               return;
744             busy = false;
745             myCurrentLineEdit = 0;
746             init(aGroup);
747             busy = true;
748             mySelectSubMesh->setEnabled(true);
749             mySelectGroup->setEnabled(true);
750             myGeomGroupBtn->setEnabled(true);
751             myGeomGroupLine->setEnabled(true);
752           }
753         myCurrentLineEdit = 0;
754         busy = false;
755         if (!myCreate)
756           return;
757
758         if (myTypeId == -1)
759           onTypeChanged(0);
760         else
761           {
762             myElements->clear();
763             setSelectionMode(myTypeId);
764           }
765         
766         return;
767       }
768     else if (myCurrentLineEdit == myGeomGroupLine)
769       {
770         
771         if(aNbSel != 1)
772           {
773             myGeomGroup = GEOM::GEOM_Object::_nil();
774             busy = false;
775             return;
776           }
777         
778         Standard_Boolean testResult = Standard_False;
779         myGeomGroup = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
780         
781         // Check if the object is a geometry group
782         if(!testResult || CORBA::is_nil( myGeomGroup ))
783           {
784             myGeomGroup = GEOM::GEOM_Object::_nil();
785             busy = false;
786             return;
787           }
788         // Check if group constructed on the same shape as a mesh or on its child
789         SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
790         GEOM::GEOM_IGroupOperations_var anOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
791         // The main shape of the group 
792         GEOM::GEOM_Object_var aGroupMainShape;
793         if( myGeomGroup->GetType() == 37 ) 
794           aGroupMainShape = anOp->GetMainShape( myGeomGroup );
795         else
796           aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
797         SALOMEDS::SObject_var aGroupMainShapeSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aGroupMainShape) );
798         // The mesh SObject
799         SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myMesh) );
800         
801         SALOMEDS::SObject_var anObj, aRef;
802         bool isRefOrSubShape = false;
803         if ( aMeshSO->FindSubObject( 1, anObj ) &&  anObj->ReferencedObject( aRef )) {
804           if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
805             isRefOrSubShape = true;
806           else
807             {
808               SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
809               SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
810               while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
811                 {
812                   if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
813                     isRefOrSubShape = true;
814                   else
815                     aFather = aFather->GetFather();
816                 }
817             }
818         }
819         if ( !isRefOrSubShape ) 
820           {
821             myGeomGroup = GEOM::GEOM_Object::_nil();
822             busy = false;
823             return;
824           }
825       }
826     
827     if (aNbSel >= 1) {
828       if (aNbSel > 1) {
829         if (myCurrentLineEdit == mySubMeshLine)
830           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
831         else if (myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
832           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
833       }
834       else {
835         aString = mySelection->firstIObject()->getName();
836       }
837     }
838     
839     myCurrentLineEdit->setText(aString) ;
840     myCurrentLineEdit->home( false );
841     
842     updateButtons();
843   }
844   else {
845     if (aNbSel == 1) {
846       QString aListStr = "";
847       int aNbItems = 0;
848       if (myTypeId == 0) {
849         aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, aListStr);
850       }
851       else {
852         aNbItems = SMESH::GetNameOfSelectedElements(mySelection, aListStr);
853       }
854       if (aNbItems > 0) {
855         QStringList anElements = QStringList::split(" ", aListStr);
856         QListBoxItem* anItem = 0;
857         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
858           anItem = myElements->findItem(*it, Qt::ExactMatch);
859           if (anItem) myElements->setSelected(anItem, true);
860         }
861       }
862     }
863   }
864   
865   if ( !myActor ) {
866     if ( !myGroup->_is_nil() )
867       myActor = SMESH::FindActorByObject(myGroup);
868     else
869       myActor = SMESH::FindActorByObject(myMesh);
870   }
871   
872   busy = false;
873 }
874
875
876 //=================================================================================
877 // function : onSelectSubMesh()
878 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
879 //=================================================================================
880 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
881 {
882   if (on) {
883     if (mySelectGroup->isChecked()) {
884       mySelectGroup->setChecked(false);
885     } 
886     //VSR: else if (mySelectGeomGroup->isChecked()) {
887     //VSR:   mySelectGeomGroup->setChecked(false);
888     //VSR: }
889     myCurrentLineEdit = mySubMeshLine;
890     setSelectionMode(4);
891   }
892   else {
893     mySubMeshLine->setText("");
894     myCurrentLineEdit = 0;
895     if (myTypeId != -1)
896       setSelectionMode(myTypeId);
897   }
898   mySubMeshBtn->setEnabled(on);
899   mySubMeshLine->setEnabled(on);
900 }
901
902
903 //=================================================================================
904 // function : (onSelectGroup)
905 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
906 //=================================================================================
907 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
908 {
909   if (on) {
910     if (mySelectSubMesh->isChecked()) {
911       mySelectSubMesh->setChecked(false);
912     }
913     myCurrentLineEdit = myGroupLine;
914     setSelectionMode(5);
915   }
916   else {
917     myGroupLine->setText("");
918     myCurrentLineEdit = 0;
919     if (myTypeId != -1)
920       setSelectionMode(myTypeId);
921   }
922   myGroupBtn->setEnabled(on);
923   myGroupLine->setEnabled(on);
924 }
925
926
927 //=================================================================================
928 // function : (onSelectGeomGroup)
929 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
930 //=================================================================================
931 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
932 {
933   if (on) {
934     if (mySelectSubMesh->isChecked()) {
935       mySelectSubMesh->setChecked(false);
936     }
937     else if (mySelectGroup->isChecked()) {
938       mySelectGroup->setChecked(false);
939     }
940     myCurrentLineEdit = myGeomGroupLine;
941     setSelectionMode(7);
942   }
943   else {
944     myGeomGroupLine->setText("");
945     myCurrentLineEdit = 0;
946     if (myTypeId != -1)
947       setSelectionMode(myTypeId);
948   }
949 }
950
951
952 //=================================================================================
953 // function : setCurrentSelection()
954 // purpose  :
955 //=================================================================================
956 void SMESHGUI_GroupDlg::setCurrentSelection()
957 {
958   QPushButton* send = (QPushButton*)sender();
959   myCurrentLineEdit = 0;
960   if (send == myMeshGroupBtn) {
961     myCurrentLineEdit = myMeshGroupLine;
962     if (myCreate)
963       setSelectionMode(6);
964     else
965       setSelectionMode(5);
966     onObjectSelectionChanged();
967   }
968   else if (send == mySubMeshBtn) {
969     myCurrentLineEdit = mySubMeshLine;
970     onObjectSelectionChanged();
971   }
972   else if (send == myGroupBtn) {
973     myCurrentLineEdit = myGroupLine;
974     onObjectSelectionChanged();
975   }
976   else if (send == myGeomGroupBtn) {
977     myCurrentLineEdit = myGeomGroupLine;
978     setSelectionMode(7);
979     onObjectSelectionChanged();
980   }
981 }
982
983
984 //=================================================================================
985 // function : setFilters()
986 // purpose  : SLOT. Called when "Filter" button pressed. 
987 //=================================================================================
988 void SMESHGUI_GroupDlg::setFilters()
989 {
990   SMESH::ElementType aType = SMESH::ALL;
991   switch ( myTypeId )
992   {
993     case 0 : aType = SMESH::NODE; break;
994     case 1 : aType = SMESH::EDGE; break;
995     case 2 : aType = SMESH::FACE; break;
996     case 3 : aType = SMESH::VOLUME; break;
997     default: return;
998   }
999
1000   if ( myFilterDlg == 0 )
1001   {
1002     myFilterDlg = new SMESHGUI_FilterDlg( (QWidget*)parent(), aType );
1003     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1004   }
1005   else
1006     myFilterDlg->Init( aType );
1007
1008   myFilterDlg->SetSelection( mySelection );
1009   myFilterDlg->SetMesh( myMesh );
1010   myFilterDlg->SetSourceWg( myElements );
1011
1012   myFilterDlg->show();
1013 }
1014
1015 //=================================================================================
1016 // function : onFilterAccepted()
1017 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1018 //            Uncheck "Select submesh" and "Select group" checkboxes
1019 //=================================================================================
1020 void SMESHGUI_GroupDlg::onFilterAccepted()
1021 {
1022   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1023   {
1024     mySelectionMode = myTypeId;
1025     mySelectSubMesh->setChecked( false );
1026     mySelectGroup->setChecked( false );
1027   }
1028 }
1029
1030 //=================================================================================
1031 // function : onAdd()
1032 // purpose  :
1033 //=================================================================================
1034 void SMESHGUI_GroupDlg::onAdd()
1035 {
1036   int aNbSel = mySelection->IObjectCount();
1037   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1038
1039   busy = true;
1040
1041   SMESH::ElementType aType = SMESH::ALL;
1042   switch(myTypeId) {
1043   case 0: aType = SMESH::NODE; break;
1044   case 1: aType = SMESH::EDGE; break;
1045   case 2: aType = SMESH::FACE; break;
1046   case 3: aType = SMESH::VOLUME; break;
1047   }
1048
1049   if (myCurrentLineEdit == 0) {
1050     //if (aNbSel != 1) { busy = false; return; }
1051     QString aListStr = "";
1052     int aNbItems = 0;
1053     if (myTypeId == 0) {
1054       aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, myActor->getIO(), aListStr);
1055     }
1056     else {
1057       aNbItems = SMESH::GetNameOfSelectedElements(mySelection, myActor->getIO(), aListStr);
1058     }
1059     if (aNbItems > 0) {
1060       QStringList anElements = QStringList::split(" ", aListStr);
1061       QListBoxItem* anItem = 0;
1062       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1063         anItem = myElements->findItem(*it, Qt::ExactMatch);
1064         if (!anItem) {
1065           anItem = new QListBoxText(*it);
1066           myElements->insertItem(anItem);
1067         }
1068         myElements->setSelected(anItem, true);
1069       }
1070     }
1071   }
1072   else if (myCurrentLineEdit == mySubMeshLine) {
1073     SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1074     for (; anIt.More(); anIt.Next()) {
1075       SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1076       if (!aSubMesh->_is_nil()) {
1077         // check if mesh is the same
1078         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1079           try {
1080             SMESH::long_array_var anElements = aSubMesh->GetElementsByType ( aType );
1081             int k = anElements->length();
1082             QListBoxItem* anItem = 0;
1083             for (int i = 0; i < k; i++) {
1084               QString aText = QString::number(anElements[i]);
1085               anItem = myElements->findItem(aText, Qt::ExactMatch);
1086               if (!anItem) {
1087                 anItem = new QListBoxText(aText);
1088                 myElements->insertItem(anItem);
1089               }
1090               myElements->setSelected(anItem, true);
1091             }
1092           }
1093           catch (const SALOME::SALOME_Exception& ex) {
1094             QtCatchCorbaException(ex);
1095           }
1096         }
1097       }
1098     }
1099     mySelectSubMesh->setChecked(false);
1100     busy = false;
1101     onListSelectionChanged();
1102   }
1103   else if (myCurrentLineEdit == myGroupLine) {
1104     SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1105     for (; anIt.More(); anIt.Next()) {
1106       SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1107       if (!aGroup->_is_nil()) {
1108         // check if mesh is the same
1109         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1110           SMESH::long_array_var anElements = aGroup->GetListOfID();
1111           int k = anElements->length();
1112           QListBoxItem* anItem = 0;
1113           for (int i = 0; i < k; i++) {
1114             QString aText = QString::number(anElements[i]);
1115             anItem = myElements->findItem(aText, Qt::ExactMatch);
1116             if (!anItem) {
1117               anItem = new QListBoxText(aText);
1118               myElements->insertItem(anItem);
1119             }
1120             myElements->setSelected(anItem, true);
1121           }
1122         }
1123       }
1124     }
1125     mySelectGroup->setChecked(false);
1126     busy = false;
1127     onListSelectionChanged();
1128   }
1129   else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1130     
1131     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
1132     GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1133     
1134     SMESH::ElementType aGroupType = SMESH::ALL;
1135     switch(aGroupOp->GetType(myGeomGroup)) {
1136     case 7: aGroupType = SMESH::NODE; break;
1137     case 6: aGroupType = SMESH::EDGE; break;
1138     case 4: aGroupType = SMESH::FACE; break;
1139     case 2: aGroupType = SMESH::VOLUME; break;
1140     default: return;
1141     }
1142     
1143     if (aGroupType == aType) {
1144       SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
1145       // Construct filter
1146       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1147       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1148       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1149       aBelongToGeom->SetGeom(myGeomGroup);
1150       aBelongToGeom->SetShapeName(aGroupSO->GetName());
1151       aBelongToGeom->SetElementType(aType);
1152       aFilter->SetPredicate( aBelongToGeom );
1153       
1154       SMESH::long_array_var anElements = aFilter->GetElementsId( myMesh );
1155       
1156       int k = anElements->length();
1157       QListBoxItem* anItem = 0;
1158       for (int i = 0; i < k; i++) {
1159         QString aText = QString::number(anElements[i]);
1160         anItem = myElements->findItem(aText, Qt::ExactMatch);
1161         if (!anItem) {
1162           anItem = new QListBoxText(aText);
1163           myElements->insertItem(anItem);
1164         }
1165         myElements->setSelected(anItem, true);
1166       }
1167     }
1168     
1169     //VSR: mySelectGeomGroup->setChecked(false);
1170     busy = false;
1171     onListSelectionChanged();
1172   }
1173   busy = false;
1174   //  mySelection->ClearIObjects();
1175   updateButtons();
1176 }
1177
1178 //=================================================================================
1179 // function : onRemove()
1180 // purpose  :
1181 //=================================================================================
1182 void SMESHGUI_GroupDlg::onRemove()
1183 {
1184   busy = true;
1185   if (myCurrentLineEdit == 0) {
1186     for (int i = myElements->count(); i > 0; i--) {
1187       if (myElements->isSelected(i-1)) {
1188         myElements->removeItem(i-1);
1189       }
1190     }
1191   }
1192   else {
1193     int aNbSel = mySelection->IObjectCount();
1194     if (aNbSel == 0) { busy = false; return; }
1195     
1196     SMESH::ElementType aType = SMESH::ALL;
1197     switch(myTypeId) {
1198     case 0: aType = SMESH::NODE; break;
1199     case 1: aType = SMESH::EDGE; break;
1200     case 2: aType = SMESH::FACE; break;
1201     case 3: aType = SMESH::VOLUME; break;
1202     }
1203
1204     if (myCurrentLineEdit == mySubMeshLine) {
1205       SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1206       for (; anIt.More(); anIt.Next()) {
1207         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1208         if (!aSubMesh->_is_nil()) {
1209           // check if mesh is the same
1210           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1211             if (aType == SMESH::NODE) {
1212               try {
1213                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1214                 int k = anElements->length();
1215                 QListBoxItem* anItem = 0;
1216                 for (int i = 0; i < k; i++) {
1217                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1218                   if (anItem) delete anItem;
1219                 }
1220               }
1221               catch (const SALOME::SALOME_Exception& ex) {
1222                 QtCatchCorbaException(ex);
1223               }
1224             }
1225             else {
1226               try {
1227                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1228                 int k = anElements->length();
1229                 QListBoxItem* anItem = 0;
1230                 for (int i = 0; i < k; i++) {
1231                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1232                   if (anItem) delete anItem;
1233                 }
1234               }
1235               catch (const SALOME::SALOME_Exception& ex) {
1236                 QtCatchCorbaException(ex);
1237               }
1238             }
1239           }
1240         }
1241       }
1242     }
1243     else if (myCurrentLineEdit == myGroupLine) {
1244       Standard_Boolean aRes;
1245       SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1246       for (; anIt.More(); anIt.Next()) {
1247         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1248         if (aRes && !aGroup->_is_nil()) {
1249           // check if mesh is the same
1250           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1251             SMESH::long_array_var anElements = aGroup->GetListOfID();
1252             int k = anElements->length();
1253             QListBoxItem* anItem = 0;
1254             for (int i = 0; i < k; i++) {
1255               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1256               if (anItem) delete anItem;
1257             }
1258           }
1259         }
1260       }
1261     }
1262   }
1263   busy = false;
1264   updateButtons();
1265 }
1266
1267 //=================================================================================
1268 // function : onSort()
1269 // purpose  :
1270 //=================================================================================
1271 void SMESHGUI_GroupDlg::onSort()
1272 {
1273   // PAL5412: sorts items in ascending by "string" value
1274   // myElements->sort(true);
1275   // myElements->update();
1276   int i, k = myElements->count();
1277   if (k > 0) {
1278     busy = true;
1279     QStringList aSelected;
1280     std::vector<int> anArray(k);
1281     //    QMemArray<int> anArray(k);
1282     QListBoxItem* anItem;
1283     // fill the array
1284     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1285       anArray[i] = anItem->text().toInt();
1286       if (anItem->isSelected()) 
1287         aSelected.append(anItem->text());
1288     }
1289     // sort & update list
1290     std::sort(anArray.begin(), anArray.end());
1291     //    anArray.sort();
1292     myElements->clear();
1293     for (i = 0; i < k; i++) {
1294       myElements->insertItem(QString::number(anArray[i]));
1295     }
1296     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1297       anItem = myElements->findItem(*it, Qt::ExactMatch);
1298       if (anItem) myElements->setSelected(anItem, true);
1299     }
1300     busy = false;
1301   }
1302 }
1303
1304 //=================================================================================
1305 // function : closeEvent()
1306 // purpose  :
1307 //=================================================================================
1308 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
1309 {
1310   onClose();
1311 }
1312
1313 //=======================================================================
1314 // name    : SMESHGUI_GroupDlg::onClose
1315 // Purpose : SLOT called when "Close" button pressed. Close dialog
1316 //=======================================================================
1317 void SMESHGUI_GroupDlg::onClose()
1318 {
1319   QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
1320   if (aStudyFrame->getTypeView() == VIEW_VTK) {
1321     SMESH::SetPointRepresentation(false);
1322     SMESH::SetPickable();
1323
1324     // remove filters from viewer
1325     if(VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle()){
1326       SMESH::RemoveFilter(SMESHGUI_EdgeFilter,aStyle);
1327       SMESH::RemoveFilter(SMESHGUI_FaceFilter,aStyle);
1328     }
1329   }
1330   
1331   mySelection->ClearIObjects();
1332   QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
1333   mySelection->ClearFilters();
1334   mySMESHGUI->ResetState();
1335
1336   reject();
1337 }
1338
1339 //=======================================================================
1340 // name    : SMESHGUI_GroupDlg::onDeactivate
1341 // Purpose : SLOT called when dialog must be deativated
1342 //=======================================================================
1343 void SMESHGUI_GroupDlg::onDeactivate()
1344 {
1345   mySMESHGUI->ResetState();
1346   setEnabled( false );
1347 }
1348
1349 //=======================================================================
1350 // name    : SMESHGUI_GroupDlg::enterEvent
1351 // Purpose : Event filter
1352 //=======================================================================
1353 void SMESHGUI_GroupDlg::enterEvent( QEvent* )
1354 {
1355   if ( !isEnabled() ) {
1356     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1357     setEnabled( true );
1358     mySelectionMode = -1;
1359     setSelectionMode( myTypeId );
1360     mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
1361     mySMESHGUI->SetState(800);
1362   }
1363 }
1364
1365 //=======================================================================
1366 //function : hideEvent
1367 //purpose  : caused by ESC key
1368 //=======================================================================
1369
1370 void SMESHGUI_GroupDlg::hideEvent ( QHideEvent * e )
1371 {
1372   if ( !isMinimized() )
1373     onClose();
1374 }