Salome HOME
Merge with version on tag OCC-V2_1_0d
[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   if (mySelectionMode != theMode) {
502     mySelection->ClearIObjects();
503     mySelection->ClearFilters();
504     SMESH::SetPointRepresentation(false);
505     if (theMode < 4) {
506       switch(theMode){
507       case 0:
508         if ( myActor )
509           myActor->SetPointRepresentation(true);
510         else
511           SMESH::SetPointRepresentation(true);
512         QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
513         break;
514       case 1:
515         QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
516         break;
517       case 2:
518         QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
519         break;
520       default:
521         QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
522       }
523     }
524     else {
525       QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
526       if (theMode == 4)
527         mySelection->AddFilter(mySubMeshFilter);
528       else if (theMode == 5)
529         mySelection->AddFilter(myGroupFilter);
530       else if (theMode == 6)
531         mySelection->AddFilter(myMeshFilter);
532     }
533     mySelectionMode = theMode;
534   }
535
536
537 //=================================================================================
538 // function : onApply()
539 // purpose  :
540 //=================================================================================
541 bool SMESHGUI_GroupDlg::onApply()
542 {
543   if (mySMESHGUI->ActiveStudyLocked())
544     return false;
545   
546   if ( myGrpTypeId == 0 && !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
547     mySelection->ClearIObjects();
548     if (myGroup->_is_nil()) {
549       SMESH::ElementType aType = SMESH::ALL;
550       switch(myTypeId) {
551       case 0: aType = SMESH::NODE; break;
552       case 1: aType = SMESH::EDGE; break;
553       case 2: aType = SMESH::FACE; break;
554       case 3: aType = SMESH::VOLUME; break;
555       }
556       SMESH::long_array_var anIdList = new SMESH::long_array;
557       int i, k = myElements->count();
558       anIdList->length(k);
559       QListBoxItem* anItem;
560       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
561         anIdList[i] = anItem->text().toInt();
562       }
563
564       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
565       myGroup->Add(anIdList.inout());
566       
567       /* init for next operation */
568       myName->setText("");
569       myElements->clear();
570       myGroup = SMESH::SMESH_Group::_nil();
571     }
572     else {
573       myGroup->SetName(myName->text());
574
575       QValueList<int> aAddList;
576       QValueList<int>::iterator anIt;
577       QListBoxItem* anItem;
578       
579       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
580         int anId = anItem->text().toInt();
581         if ((anIt = myIdList.find(anId)) == myIdList.end())
582           aAddList.append(anId);
583         else
584           myIdList.remove(anIt);
585       }
586       if (!aAddList.empty()) {
587         SMESH::long_array_var anIdList = new SMESH::long_array;
588         anIdList->length(aAddList.count());
589         int i;
590         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
591           anIdList[i] = *anIt;
592         myGroup->Add(anIdList.inout());
593       }
594       if (!myIdList.empty()) {
595         SMESH::long_array_var anIdList = new SMESH::long_array;
596         anIdList->length(myIdList.count());
597         int i;
598         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
599           anIdList[i] = *anIt;
600         myGroup->Remove(anIdList.inout());
601       }
602       /* init for next operation */
603       myIdList.clear();
604       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
605         myIdList.append(anItem->text().toInt());
606     }
607
608     mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
609     SMESH::UpdateView(); // asv: fix of BUG PAL5515
610     mySelection->ClearIObjects();
611     return true;
612   }
613   else if (myGrpTypeId == 1 && !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup ))
614     {
615       SMESH::ElementType aType = SMESH::ALL;
616       switch(myTypeId) {
617       case 0: aType = SMESH::NODE; break;
618       case 1: aType = SMESH::EDGE; break;
619       case 2: aType = SMESH::FACE; break;
620       case 3: aType = SMESH::VOLUME; break;
621       }
622       
623       SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
624       GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
625       
626       SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
627       
628       mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
629       mySelection->ClearIObjects();
630       /* init for next operation */
631       myName->setText("");
632       return true;
633     }
634   
635   return false;
636 }
637
638 //=================================================================================
639 // function : onOK()
640 // purpose  :
641 //=================================================================================
642 void SMESHGUI_GroupDlg::onOK()
643 {
644   if ( onApply() )
645     onClose();
646 }
647
648 static bool busy = false;
649 //=================================================================================
650 // function : onListSelectionChanged()
651 // purpose  : Called when selection in element list is changed
652 //=================================================================================
653 void SMESHGUI_GroupDlg::onListSelectionChanged()
654 {
655   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
656   if (busy || !myActor) return;
657   busy = true;
658
659   if (myCurrentLineEdit == 0) {
660     mySelection->ClearIObjects();
661     TColStd_MapOfInteger aIndexes;
662     QListBoxItem* anItem;
663     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
664       if (anItem->isSelected()) {
665         int anId = anItem->text().toInt();
666         aIndexes.Add(anId);
667       }
668     }
669     mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
670     mySelection->AddIObject(myActor->getIO());
671   }
672   busy = false;
673 }
674
675 //=================================================================================
676 // function : onObjectSelectionChanged()
677 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
678 //=================================================================================
679 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
680 {
681   if (busy || !isEnabled()) return;
682   busy = true;
683
684   int aNbSel = mySelection->IObjectCount();
685   myElements->clearSelection();
686  
687   if (myCurrentLineEdit) {
688     myCurrentLineEdit->setText("") ;
689     QString aString = "";
690     
691     if (myCurrentLineEdit == myMeshGroupLine)
692       {
693         mySelectSubMesh->setEnabled(false);
694         mySelectGroup->setEnabled(false);
695         myGroupLine->setText("");
696         mySubMeshLine->setText("");
697         
698         myGeomGroupBtn->setEnabled(false);
699         myGeomGroupLine->setEnabled(false);
700         myGeomGroupLine->setText("");
701         if (!myCreate)
702           myName->setText("");
703         
704         myElements->clear();
705
706         if(aNbSel != 1)
707           {
708             myGroup = SMESH::SMESH_Group::_nil();
709             myMesh = SMESH::SMESH_Mesh::_nil();
710             busy = false;
711             return;
712           }
713         Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
714         
715         if (myCreate)
716           {
717             myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
718             if(myMesh->_is_nil())
719               return;
720             myGroup = SMESH::SMESH_Group::_nil();
721             
722             myActor = SMESH::FindActorByObject(myMesh);
723             SMESH::SetPickable(myActor);
724             
725             aString = mySelection->firstIObject()->getName();
726             myMeshGroupLine->setText(aString) ;
727             myMeshGroupLine->home( false );
728             
729             mySelectSubMesh->setEnabled(true);
730             mySelectGroup->setEnabled(true);
731             myGeomGroupBtn->setEnabled(true);
732             myGeomGroupLine->setEnabled(true);
733             updateButtons();
734           }
735         else
736           {
737             SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
738             if(aGroup->_is_nil())
739               return;
740             busy = false;
741             myCurrentLineEdit = 0;
742             init(aGroup);
743             busy = true;
744             mySelectSubMesh->setEnabled(true);
745             mySelectGroup->setEnabled(true);
746             myGeomGroupBtn->setEnabled(true);
747             myGeomGroupLine->setEnabled(true);
748           }
749         myCurrentLineEdit = 0;
750         busy = false;
751         if (!myCreate)
752           return;
753
754         if (myTypeId == -1)
755           onTypeChanged(0);
756         else
757           {
758             myElements->clear();
759             setSelectionMode(myTypeId);
760           }
761         
762         return;
763       }
764     else if (myCurrentLineEdit == myGeomGroupLine)
765       {
766         
767         if(aNbSel != 1)
768           {
769             myGeomGroup = GEOM::GEOM_Object::_nil();
770             busy = false;
771             return;
772           }
773         
774         Standard_Boolean testResult = Standard_False;
775         myGeomGroup = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
776         
777         // Check if the object is a geometry group
778         if(!testResult || CORBA::is_nil( myGeomGroup ))
779           {
780             myGeomGroup = GEOM::GEOM_Object::_nil();
781             busy = false;
782             return;
783           }
784         // Check if group constructed on the same shape as a mesh or on its child
785         SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
786         GEOM::GEOM_IGroupOperations_var anOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
787         // The main shape of the group 
788         GEOM::GEOM_Object_var aGroupMainShape;
789         if( myGeomGroup->GetType() == 37 ) 
790           aGroupMainShape = anOp->GetMainShape( myGeomGroup );
791         else
792           aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
793         SALOMEDS::SObject_var aGroupMainShapeSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aGroupMainShape) );
794         // The mesh SObject
795         SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myMesh) );
796         
797         SALOMEDS::SObject_var anObj, aRef;
798         bool isRefOrSubShape = false;
799         if ( aMeshSO->FindSubObject( 1, anObj ) &&  anObj->ReferencedObject( aRef )) {
800           if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
801             isRefOrSubShape = true;
802           else
803             {
804               SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
805               SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
806               while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
807                 {
808                   if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
809                     isRefOrSubShape = true;
810                   else
811                     aFather = aFather->GetFather();
812                 }
813             }
814         }
815         if ( !isRefOrSubShape ) 
816           {
817             myGeomGroup = GEOM::GEOM_Object::_nil();
818             busy = false;
819             return;
820           }
821       }
822     
823     if (aNbSel >= 1) {
824       if (aNbSel > 1) {
825         if (myCurrentLineEdit == mySubMeshLine)
826           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
827         else if (myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
828           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
829       }
830       else {
831         aString = mySelection->firstIObject()->getName();
832       }
833     }
834     
835     myCurrentLineEdit->setText(aString) ;
836     myCurrentLineEdit->home( false );
837     
838     updateButtons();
839   }
840   else {
841     if (aNbSel == 1) {
842       QString aListStr = "";
843       int aNbItems = 0;
844       if (myTypeId == 0) {
845         aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, aListStr);
846       }
847       else {
848         aNbItems = SMESH::GetNameOfSelectedElements(mySelection, aListStr);
849       }
850       if (aNbItems > 0) {
851         QStringList anElements = QStringList::split(" ", aListStr);
852         QListBoxItem* anItem = 0;
853         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
854           anItem = myElements->findItem(*it, Qt::ExactMatch);
855           if (anItem) myElements->setSelected(anItem, true);
856         }
857       }
858     }
859   }
860   
861   if ( !myActor ) {
862     if ( !myGroup->_is_nil() )
863       myActor = SMESH::FindActorByObject(myGroup);
864     else
865       myActor = SMESH::FindActorByObject(myMesh);
866   }
867   
868   busy = false;
869 }
870
871
872 //=================================================================================
873 // function : onSelectSubMesh()
874 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
875 //=================================================================================
876 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
877 {
878   if (on) {
879     if (mySelectGroup->isChecked()) {
880       mySelectGroup->setChecked(false);
881     } 
882     //VSR: else if (mySelectGeomGroup->isChecked()) {
883     //VSR:   mySelectGeomGroup->setChecked(false);
884     //VSR: }
885     myCurrentLineEdit = mySubMeshLine;
886     setSelectionMode(4);
887   }
888   else {
889     mySubMeshLine->setText("");
890     myCurrentLineEdit = 0;
891     if (myTypeId != -1)
892       setSelectionMode(myTypeId);
893   }
894   mySubMeshBtn->setEnabled(on);
895   mySubMeshLine->setEnabled(on);
896 }
897
898
899 //=================================================================================
900 // function : (onSelectGroup)
901 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
902 //=================================================================================
903 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
904 {
905   if (on) {
906     if (mySelectSubMesh->isChecked()) {
907       mySelectSubMesh->setChecked(false);
908     }
909     myCurrentLineEdit = myGroupLine;
910     setSelectionMode(5);
911   }
912   else {
913     myGroupLine->setText("");
914     myCurrentLineEdit = 0;
915     if (myTypeId != -1)
916       setSelectionMode(myTypeId);
917   }
918   myGroupBtn->setEnabled(on);
919   myGroupLine->setEnabled(on);
920 }
921
922
923 //=================================================================================
924 // function : (onSelectGeomGroup)
925 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
926 //=================================================================================
927 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
928 {
929   if (on) {
930     if (mySelectSubMesh->isChecked()) {
931       mySelectSubMesh->setChecked(false);
932     }
933     else if (mySelectGroup->isChecked()) {
934       mySelectGroup->setChecked(false);
935     }
936     myCurrentLineEdit = myGeomGroupLine;
937     setSelectionMode(7);
938   }
939   else {
940     myGeomGroupLine->setText("");
941     myCurrentLineEdit = 0;
942     if (myTypeId != -1)
943       setSelectionMode(myTypeId);
944   }
945 }
946
947
948 //=================================================================================
949 // function : setCurrentSelection()
950 // purpose  :
951 //=================================================================================
952 void SMESHGUI_GroupDlg::setCurrentSelection()
953 {
954   QPushButton* send = (QPushButton*)sender();
955   myCurrentLineEdit = 0;
956   if (send == myMeshGroupBtn) {
957     myCurrentLineEdit = myMeshGroupLine;
958     if (myCreate)
959       setSelectionMode(6);
960     else
961       setSelectionMode(5);
962     onObjectSelectionChanged();
963   }
964   else if (send == mySubMeshBtn) {
965     myCurrentLineEdit = mySubMeshLine;
966     onObjectSelectionChanged();
967   }
968   else if (send == myGroupBtn) {
969     myCurrentLineEdit = myGroupLine;
970     onObjectSelectionChanged();
971   }
972   else if (send == myGeomGroupBtn) {
973     myCurrentLineEdit = myGeomGroupLine;
974     setSelectionMode(7);
975     onObjectSelectionChanged();
976   }
977 }
978
979
980 //=================================================================================
981 // function : setFilters()
982 // purpose  : SLOT. Called when "Filter" button pressed. 
983 //=================================================================================
984 void SMESHGUI_GroupDlg::setFilters()
985 {
986   SMESH::ElementType aType = SMESH::ALL;
987   switch ( myTypeId )
988   {
989     case 0 : aType = SMESH::NODE; break;
990     case 1 : aType = SMESH::EDGE; break;
991     case 2 : aType = SMESH::FACE; break;
992     case 3 : aType = SMESH::VOLUME; break;
993     default: return;
994   }
995
996   if ( myFilterDlg == 0 )
997   {
998     myFilterDlg = new SMESHGUI_FilterDlg( (QWidget*)parent(), aType );
999     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1000   }
1001   else
1002     myFilterDlg->Init( aType );
1003
1004   myFilterDlg->SetSelection( mySelection );
1005   myFilterDlg->SetMesh( myMesh );
1006   myFilterDlg->SetSourceWg( myElements );
1007
1008   myFilterDlg->show();
1009 }
1010
1011 //=================================================================================
1012 // function : onFilterAccepted()
1013 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1014 //            Uncheck "Select submesh" and "Select group" checkboxes
1015 //=================================================================================
1016 void SMESHGUI_GroupDlg::onFilterAccepted()
1017 {
1018   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1019   {
1020     mySelectionMode = myTypeId;
1021     mySelectSubMesh->setChecked( false );
1022     mySelectGroup->setChecked( false );
1023   }
1024 }
1025
1026 //=================================================================================
1027 // function : onAdd()
1028 // purpose  :
1029 //=================================================================================
1030 void SMESHGUI_GroupDlg::onAdd()
1031 {
1032   int aNbSel = mySelection->IObjectCount();
1033   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1034
1035   busy = true;
1036
1037   SMESH::ElementType aType = SMESH::ALL;
1038   switch(myTypeId) {
1039   case 0: aType = SMESH::NODE; break;
1040   case 1: aType = SMESH::EDGE; break;
1041   case 2: aType = SMESH::FACE; break;
1042   case 3: aType = SMESH::VOLUME; break;
1043   }
1044
1045   if (myCurrentLineEdit == 0) {
1046     //if (aNbSel != 1) { busy = false; return; }
1047     QString aListStr = "";
1048     int aNbItems = 0;
1049     if (myTypeId == 0) {
1050       aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, myActor->getIO(), aListStr);
1051     }
1052     else {
1053       aNbItems = SMESH::GetNameOfSelectedElements(mySelection, myActor->getIO(), aListStr);
1054     }
1055     if (aNbItems > 0) {
1056       QStringList anElements = QStringList::split(" ", aListStr);
1057       QListBoxItem* anItem = 0;
1058       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1059         anItem = myElements->findItem(*it, Qt::ExactMatch);
1060         if (!anItem) {
1061           anItem = new QListBoxText(*it);
1062           myElements->insertItem(anItem);
1063         }
1064         myElements->setSelected(anItem, true);
1065       }
1066     }
1067   }
1068   else if (myCurrentLineEdit == mySubMeshLine) {
1069     SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1070     for (; anIt.More(); anIt.Next()) {
1071       SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1072       if (!aSubMesh->_is_nil()) {
1073         // check if mesh is the same
1074         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1075           try {
1076             SMESH::long_array_var anElements = aSubMesh->GetElementsByType ( aType );
1077             int k = anElements->length();
1078             QListBoxItem* anItem = 0;
1079             for (int i = 0; i < k; i++) {
1080               QString aText = QString::number(anElements[i]);
1081               anItem = myElements->findItem(aText, Qt::ExactMatch);
1082               if (!anItem) {
1083                 anItem = new QListBoxText(aText);
1084                 myElements->insertItem(anItem);
1085               }
1086               myElements->setSelected(anItem, true);
1087             }
1088           }
1089           catch (const SALOME::SALOME_Exception& ex) {
1090             QtCatchCorbaException(ex);
1091           }
1092         }
1093       }
1094     }
1095     mySelectSubMesh->setChecked(false);
1096     busy = false;
1097     onListSelectionChanged();
1098   }
1099   else if (myCurrentLineEdit == myGroupLine) {
1100     SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1101     for (; anIt.More(); anIt.Next()) {
1102       SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1103       if (!aGroup->_is_nil()) {
1104         // check if mesh is the same
1105         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1106           SMESH::long_array_var anElements = aGroup->GetListOfID();
1107           int k = anElements->length();
1108           QListBoxItem* anItem = 0;
1109           for (int i = 0; i < k; i++) {
1110             QString aText = QString::number(anElements[i]);
1111             anItem = myElements->findItem(aText, Qt::ExactMatch);
1112             if (!anItem) {
1113               anItem = new QListBoxText(aText);
1114               myElements->insertItem(anItem);
1115             }
1116             myElements->setSelected(anItem, true);
1117           }
1118         }
1119       }
1120     }
1121     mySelectGroup->setChecked(false);
1122     busy = false;
1123     onListSelectionChanged();
1124   }
1125   else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1126     
1127     SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
1128     GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1129     
1130     SMESH::ElementType aGroupType = SMESH::ALL;
1131     switch(aGroupOp->GetType(myGeomGroup)) {
1132     case 7: aGroupType = SMESH::NODE; break;
1133     case 6: aGroupType = SMESH::EDGE; break;
1134     case 4: aGroupType = SMESH::FACE; break;
1135     case 2: aGroupType = SMESH::VOLUME; break;
1136     default: return;
1137     }
1138     
1139     if (aGroupType == aType) {
1140       SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
1141       // Construct filter
1142       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1143       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1144       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1145       aBelongToGeom->SetGeom(myGeomGroup);
1146       aBelongToGeom->SetShapeName(aGroupSO->GetName());
1147       aBelongToGeom->SetElementType(aType);
1148       aFilter->SetPredicate( aBelongToGeom );
1149       
1150       SMESH::long_array_var anElements = aFilter->GetElementsId( myMesh );
1151       
1152       int k = anElements->length();
1153       QListBoxItem* anItem = 0;
1154       for (int i = 0; i < k; i++) {
1155         QString aText = QString::number(anElements[i]);
1156         anItem = myElements->findItem(aText, Qt::ExactMatch);
1157         if (!anItem) {
1158           anItem = new QListBoxText(aText);
1159           myElements->insertItem(anItem);
1160         }
1161         myElements->setSelected(anItem, true);
1162       }
1163     }
1164     
1165     //VSR: mySelectGeomGroup->setChecked(false);
1166     busy = false;
1167     onListSelectionChanged();
1168   }
1169   busy = false;
1170   //  mySelection->ClearIObjects();
1171   updateButtons();
1172 }
1173
1174 //=================================================================================
1175 // function : onRemove()
1176 // purpose  :
1177 //=================================================================================
1178 void SMESHGUI_GroupDlg::onRemove()
1179 {
1180   busy = true;
1181   if (myCurrentLineEdit == 0) {
1182     for (int i = myElements->count(); i > 0; i--) {
1183       if (myElements->isSelected(i-1)) {
1184         myElements->removeItem(i-1);
1185       }
1186     }
1187   }
1188   else {
1189     int aNbSel = mySelection->IObjectCount();
1190     if (aNbSel == 0) { busy = false; return; }
1191     
1192     SMESH::ElementType aType = SMESH::ALL;
1193     switch(myTypeId) {
1194     case 0: aType = SMESH::NODE; break;
1195     case 1: aType = SMESH::EDGE; break;
1196     case 2: aType = SMESH::FACE; break;
1197     case 3: aType = SMESH::VOLUME; break;
1198     }
1199
1200     if (myCurrentLineEdit == mySubMeshLine) {
1201       SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1202       for (; anIt.More(); anIt.Next()) {
1203         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1204         if (!aSubMesh->_is_nil()) {
1205           // check if mesh is the same
1206           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1207             if (aType == SMESH::NODE) {
1208               try {
1209                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1210                 int k = anElements->length();
1211                 QListBoxItem* anItem = 0;
1212                 for (int i = 0; i < k; i++) {
1213                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1214                   if (anItem) delete anItem;
1215                 }
1216               }
1217               catch (const SALOME::SALOME_Exception& ex) {
1218                 QtCatchCorbaException(ex);
1219               }
1220             }
1221             else {
1222               try {
1223                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1224                 int k = anElements->length();
1225                 QListBoxItem* anItem = 0;
1226                 for (int i = 0; i < k; i++) {
1227                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1228                   if (anItem) delete anItem;
1229                 }
1230               }
1231               catch (const SALOME::SALOME_Exception& ex) {
1232                 QtCatchCorbaException(ex);
1233               }
1234             }
1235           }
1236         }
1237       }
1238     }
1239     else if (myCurrentLineEdit == myGroupLine) {
1240       Standard_Boolean aRes;
1241       SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1242       for (; anIt.More(); anIt.Next()) {
1243         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1244         if (aRes && !aGroup->_is_nil()) {
1245           // check if mesh is the same
1246           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1247             SMESH::long_array_var anElements = aGroup->GetListOfID();
1248             int k = anElements->length();
1249             QListBoxItem* anItem = 0;
1250             for (int i = 0; i < k; i++) {
1251               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1252               if (anItem) delete anItem;
1253             }
1254           }
1255         }
1256       }
1257     }
1258   }
1259   busy = false;
1260   updateButtons();
1261 }
1262
1263 //=================================================================================
1264 // function : onSort()
1265 // purpose  :
1266 //=================================================================================
1267 void SMESHGUI_GroupDlg::onSort()
1268 {
1269   // PAL5412: sorts items in ascending by "string" value
1270   // myElements->sort(true);
1271   // myElements->update();
1272   int i, k = myElements->count();
1273   if (k > 0) {
1274     busy = true;
1275     QStringList aSelected;
1276     std::vector<int> anArray(k);
1277     //    QMemArray<int> anArray(k);
1278     QListBoxItem* anItem;
1279     // fill the array
1280     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1281       anArray[i] = anItem->text().toInt();
1282       if (anItem->isSelected()) 
1283         aSelected.append(anItem->text());
1284     }
1285     // sort & update list
1286     std::sort(anArray.begin(), anArray.end());
1287     //    anArray.sort();
1288     myElements->clear();
1289     for (i = 0; i < k; i++) {
1290       myElements->insertItem(QString::number(anArray[i]));
1291     }
1292     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1293       anItem = myElements->findItem(*it, Qt::ExactMatch);
1294       if (anItem) myElements->setSelected(anItem, true);
1295     }
1296     busy = false;
1297   }
1298 }
1299
1300 //=================================================================================
1301 // function : closeEvent()
1302 // purpose  :
1303 //=================================================================================
1304 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
1305 {
1306   onClose();
1307 }
1308
1309 //=======================================================================
1310 // name    : SMESHGUI_GroupDlg::onClose
1311 // Purpose : SLOT called when "Close" button pressed. Close dialog
1312 //=======================================================================
1313 void SMESHGUI_GroupDlg::onClose()
1314 {
1315   QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
1316   if (aStudyFrame->getTypeView() == VIEW_VTK) {
1317     SMESH::SetPointRepresentation(false);
1318     SMESH::SetPickable();
1319
1320     // remove filters from viewer
1321     if(VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle()){
1322       SMESH::RemoveFilter(SMESHGUI_EdgeFilter,aStyle);
1323       SMESH::RemoveFilter(SMESHGUI_FaceFilter,aStyle);
1324     }
1325   }
1326   
1327   mySelection->ClearIObjects();
1328   QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
1329   mySelection->ClearFilters();
1330   mySMESHGUI->ResetState();
1331
1332   reject();
1333 }
1334
1335 //=======================================================================
1336 // name    : SMESHGUI_GroupDlg::onDeactivate
1337 // Purpose : SLOT called when dialog must be deativated
1338 //=======================================================================
1339 void SMESHGUI_GroupDlg::onDeactivate()
1340 {
1341   setEnabled( false );
1342 }
1343
1344 //=======================================================================
1345 // name    : SMESHGUI_GroupDlg::enterEvent
1346 // Purpose : Event filter
1347 //=======================================================================
1348 void SMESHGUI_GroupDlg::enterEvent( QEvent* )
1349 {
1350   if ( !isEnabled() ) {
1351     SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1352     setEnabled( true );
1353     mySelectionMode = -1;
1354     setSelectionMode( myTypeId );
1355   }
1356 }
1357
1358 //=======================================================================
1359 //function : hideEvent
1360 //purpose  : caused by ESC key
1361 //=======================================================================
1362
1363 void SMESHGUI_GroupDlg::hideEvent ( QHideEvent * e )
1364 {
1365   if ( !isMinimized() )
1366     onClose();
1367 }